blob: e47e0c470508b0f7f10d36880e8de366bd297c9a [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
Tony Nguyen01ec5522017-05-18 14:55:07 -070079#define DRV_VERSION "5.1.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
Alexander Duyck68ae7422017-11-22 10:56:52 -0800195static const struct net_device_ops ixgbe_netdev_ops;
196
197static bool netif_is_ixgbe(struct net_device *dev)
198{
199 return dev && (dev->netdev_ops == &ixgbe_netdev_ops);
200}
201
Jacob Kellerb8e82002013-04-09 07:20:09 +0000202static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
203 u32 reg, u16 *value)
204{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000205 struct pci_dev *parent_dev;
206 struct pci_bus *parent_bus;
207
208 parent_bus = adapter->pdev->bus->parent;
209 if (!parent_bus)
210 return -1;
211
212 parent_dev = parent_bus->self;
213 if (!parent_dev)
214 return -1;
215
Yijing Wangc0798ed2013-09-04 17:30:08 +0000216 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000217 return -1;
218
Yijing Wangc0798ed2013-09-04 17:30:08 +0000219 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800220 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
221 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
222 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000223 return 0;
224}
225
226static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
227{
228 struct ixgbe_hw *hw = &adapter->hw;
229 u16 link_status = 0;
230 int err;
231
232 hw->bus.type = ixgbe_bus_type_pci_express;
233
234 /* Get the negotiated link width and speed from PCI config space of the
235 * parent, as this device is behind a switch
236 */
237 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
238
239 /* assume caller will handle error case */
240 if (err)
241 return err;
242
243 hw->bus.width = ixgbe_convert_bus_width(link_status);
244 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
245
246 return 0;
247}
248
Jacob Kellere027d1a2013-07-31 06:53:31 +0000249/**
250 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
251 * @hw: hw specific details
252 *
253 * This function is used by probe to determine whether a device's PCI-Express
254 * bandwidth details should be gathered from the parent bus instead of from the
255 * device. Used to ensure that various locations all have the correct device ID
256 * checks.
257 */
258static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
259{
260 switch (hw->device_id) {
261 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000262 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000263 return true;
264 default:
265 return false;
266 }
267}
268
269static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
270 int expected_gts)
271{
Don Skidmoref9328bc2015-06-18 13:24:06 -0400272 struct ixgbe_hw *hw = &adapter->hw;
Jacob Kellere027d1a2013-07-31 06:53:31 +0000273 int max_gts = 0;
274 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
275 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
276 struct pci_dev *pdev;
277
Don Skidmoref9328bc2015-06-18 13:24:06 -0400278 /* Some devices are not connected over PCIe and thus do not negotiate
279 * speed. These devices do not have valid bus info, and thus any report
280 * we generate may not be correct.
281 */
282 if (hw->bus.type == ixgbe_bus_type_internal)
283 return;
284
Jacob Keller56d13922015-06-10 11:44:45 -0700285 /* determine whether to use the parent device */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000286 if (ixgbe_pcie_from_parent(&adapter->hw))
287 pdev = adapter->pdev->bus->parent->self;
288 else
289 pdev = adapter->pdev;
290
291 if (pcie_get_minimum_link(pdev, &speed, &width) ||
292 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
293 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
294 return;
295 }
296
297 switch (speed) {
298 case PCIE_SPEED_2_5GT:
299 /* 8b/10b encoding reduces max throughput by 20% */
300 max_gts = 2 * width;
301 break;
302 case PCIE_SPEED_5_0GT:
303 /* 8b/10b encoding reduces max throughput by 20% */
304 max_gts = 4 * width;
305 break;
306 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000307 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000308 max_gts = 8 * width;
309 break;
310 default:
311 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
312 return;
313 }
314
315 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
316 max_gts);
317 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
318 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
319 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
320 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
321 "Unknown"),
322 width,
323 (speed == PCIE_SPEED_2_5GT ? "20%" :
324 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000325 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000326 "Unknown"));
327
328 if (max_gts < expected_gts) {
329 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
330 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
331 expected_gts);
332 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
333 }
334}
335
Alexander Duyck70864002011-04-27 09:13:56 +0000336static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
337{
338 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800339 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000340 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
Mark Rustad780484d2015-10-21 17:21:10 -0700341 queue_work(ixgbe_wq, &adapter->service_task);
Alexander Duyck70864002011-04-27 09:13:56 +0000342}
343
Mark Rustad2a1a0912014-01-14 18:53:15 -0800344static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
345{
346 struct ixgbe_adapter *adapter = hw->back;
347
348 if (!hw->hw_addr)
349 return;
350 hw->hw_addr = NULL;
351 e_dev_err("Adapter removed\n");
Mark Rustad58cf6632014-03-12 00:38:40 +0000352 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
353 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800354}
355
Mark Rustadf8e24722014-03-18 07:03:40 +0000356static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800357{
358 u32 value;
359
360 /* The following check not only optimizes a bit by not
361 * performing a read on the status register when the
362 * register just read was a status register read that
363 * returned IXGBE_FAILED_READ_REG. It also blocks any
364 * potential recursion.
365 */
366 if (reg == IXGBE_STATUS) {
367 ixgbe_remove_adapter(hw);
368 return;
369 }
370 value = ixgbe_read_reg(hw, IXGBE_STATUS);
371 if (value == IXGBE_FAILED_READ_REG)
372 ixgbe_remove_adapter(hw);
373}
374
Mark Rustadf8e24722014-03-18 07:03:40 +0000375/**
376 * ixgbe_read_reg - Read from device register
377 * @hw: hw specific details
378 * @reg: offset of register to read
379 *
380 * Returns : value read or IXGBE_FAILED_READ_REG if removed
381 *
382 * This function is used to read device registers. It checks for device
383 * removal by confirming any read that returns all ones by checking the
384 * status register value for all ones. This function avoids reading from
385 * the hardware if a removal was previously detected in which case it
386 * returns IXGBE_FAILED_READ_REG (all ones).
387 */
388u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
389{
Mark Rutland6aa7de02017-10-23 14:07:29 -0700390 u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
Mark Rustadf8e24722014-03-18 07:03:40 +0000391 u32 value;
392
393 if (ixgbe_removed(reg_addr))
394 return IXGBE_FAILED_READ_REG;
Mark Rustad2f2219b2016-04-07 10:43:50 -0700395 if (unlikely(hw->phy.nw_mng_if_sel &
Tony Nguyen48301cf2017-06-07 14:36:19 -0700396 IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE)) {
Mark Rustad2f2219b2016-04-07 10:43:50 -0700397 struct ixgbe_adapter *adapter;
398 int i;
399
400 for (i = 0; i < 200; ++i) {
401 value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
402 if (likely(!value))
403 goto writes_completed;
404 if (value == IXGBE_FAILED_READ_REG) {
405 ixgbe_remove_adapter(hw);
406 return IXGBE_FAILED_READ_REG;
407 }
408 udelay(5);
409 }
410
411 adapter = hw->back;
412 e_warn(hw, "register writes incomplete %08x\n", value);
413 }
414
415writes_completed:
Mark Rustadf8e24722014-03-18 07:03:40 +0000416 value = readl(reg_addr + reg);
417 if (unlikely(value == IXGBE_FAILED_READ_REG))
418 ixgbe_check_remove(hw, reg);
419 return value;
420}
421
Mark Rustad14438462014-02-28 15:48:57 -0800422static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
423{
424 u16 value;
425
426 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
427 if (value == IXGBE_FAILED_READ_CFG_WORD) {
428 ixgbe_remove_adapter(hw);
429 return true;
430 }
431 return false;
432}
433
434u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
435{
436 struct ixgbe_adapter *adapter = hw->back;
437 u16 value;
438
439 if (ixgbe_removed(hw->hw_addr))
440 return IXGBE_FAILED_READ_CFG_WORD;
441 pci_read_config_word(adapter->pdev, reg, &value);
442 if (value == IXGBE_FAILED_READ_CFG_WORD &&
443 ixgbe_check_cfg_remove(hw, adapter->pdev))
444 return IXGBE_FAILED_READ_CFG_WORD;
445 return value;
446}
447
448#ifdef CONFIG_PCI_IOV
449static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
450{
451 struct ixgbe_adapter *adapter = hw->back;
452 u32 value;
453
454 if (ixgbe_removed(hw->hw_addr))
455 return IXGBE_FAILED_READ_CFG_DWORD;
456 pci_read_config_dword(adapter->pdev, reg, &value);
457 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
458 ixgbe_check_cfg_remove(hw, adapter->pdev))
459 return IXGBE_FAILED_READ_CFG_DWORD;
460 return value;
461}
462#endif /* CONFIG_PCI_IOV */
463
Jacob Kellered192312014-02-22 01:23:53 +0000464void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
465{
466 struct ixgbe_adapter *adapter = hw->back;
467
468 if (ixgbe_removed(hw->hw_addr))
469 return;
470 pci_write_config_word(adapter->pdev, reg, value);
471}
472
Alexander Duyck70864002011-04-27 09:13:56 +0000473static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
474{
475 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
476
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000477 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100478 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000479 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
480}
481
Taku Izumidcd79ae2010-04-27 14:39:53 +0000482struct ixgbe_reg_info {
483 u32 ofs;
484 char *name;
485};
486
487static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
488
489 /* General Registers */
490 {IXGBE_CTRL, "CTRL"},
491 {IXGBE_STATUS, "STATUS"},
492 {IXGBE_CTRL_EXT, "CTRL_EXT"},
493
494 /* Interrupt Registers */
495 {IXGBE_EICR, "EICR"},
496
497 /* RX Registers */
498 {IXGBE_SRRCTL(0), "SRRCTL"},
499 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
500 {IXGBE_RDLEN(0), "RDLEN"},
501 {IXGBE_RDH(0), "RDH"},
502 {IXGBE_RDT(0), "RDT"},
503 {IXGBE_RXDCTL(0), "RXDCTL"},
504 {IXGBE_RDBAL(0), "RDBAL"},
505 {IXGBE_RDBAH(0), "RDBAH"},
506
507 /* TX Registers */
508 {IXGBE_TDBAL(0), "TDBAL"},
509 {IXGBE_TDBAH(0), "TDBAH"},
510 {IXGBE_TDLEN(0), "TDLEN"},
511 {IXGBE_TDH(0), "TDH"},
512 {IXGBE_TDT(0), "TDT"},
513 {IXGBE_TXDCTL(0), "TXDCTL"},
514
515 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000516 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000517};
518
519
520/*
521 * ixgbe_regdump - register printout routine
522 */
523static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
524{
Joe Perches332f2352017-01-03 07:28:11 -0800525 int i;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000526 char rname[16];
527 u32 regs[64];
528
529 switch (reginfo->ofs) {
530 case IXGBE_SRRCTL(0):
531 for (i = 0; i < 64; i++)
532 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
533 break;
534 case IXGBE_DCA_RXCTRL(0):
535 for (i = 0; i < 64; i++)
536 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
537 break;
538 case IXGBE_RDLEN(0):
539 for (i = 0; i < 64; i++)
540 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
541 break;
542 case IXGBE_RDH(0):
543 for (i = 0; i < 64; i++)
544 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
545 break;
546 case IXGBE_RDT(0):
547 for (i = 0; i < 64; i++)
548 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
549 break;
550 case IXGBE_RXDCTL(0):
551 for (i = 0; i < 64; i++)
552 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
553 break;
554 case IXGBE_RDBAL(0):
555 for (i = 0; i < 64; i++)
556 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
557 break;
558 case IXGBE_RDBAH(0):
559 for (i = 0; i < 64; i++)
560 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
561 break;
562 case IXGBE_TDBAL(0):
563 for (i = 0; i < 64; i++)
564 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
565 break;
566 case IXGBE_TDBAH(0):
567 for (i = 0; i < 64; i++)
568 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
569 break;
570 case IXGBE_TDLEN(0):
571 for (i = 0; i < 64; i++)
572 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
573 break;
574 case IXGBE_TDH(0):
575 for (i = 0; i < 64; i++)
576 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
577 break;
578 case IXGBE_TDT(0):
579 for (i = 0; i < 64; i++)
580 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
581 break;
582 case IXGBE_TXDCTL(0):
583 for (i = 0; i < 64; i++)
584 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
585 break;
586 default:
Joe Perches332f2352017-01-03 07:28:11 -0800587 pr_info("%-15s %08x\n",
588 reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000589 return;
590 }
591
Joe Perches332f2352017-01-03 07:28:11 -0800592 i = 0;
593 while (i < 64) {
594 int j;
595 char buf[9 * 8 + 1];
596 char *p = buf;
597
598 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000599 for (j = 0; j < 8; j++)
Joe Perches332f2352017-01-03 07:28:11 -0800600 p += sprintf(p, " %08x", regs[i++]);
601 pr_err("%-15s%s\n", rname, buf);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000602 }
603
604}
605
John Fastabend33fdc822017-04-24 03:30:18 -0700606static void ixgbe_print_buffer(struct ixgbe_ring *ring, int n)
607{
608 struct ixgbe_tx_buffer *tx_buffer;
609
610 tx_buffer = &ring->tx_buffer_info[ring->next_to_clean];
611 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
612 n, ring->next_to_use, ring->next_to_clean,
613 (u64)dma_unmap_addr(tx_buffer, dma),
614 dma_unmap_len(tx_buffer, len),
615 tx_buffer->next_to_watch,
616 (u64)tx_buffer->time_stamp);
617}
618
Taku Izumidcd79ae2010-04-27 14:39:53 +0000619/*
620 * ixgbe_dump - Print registers, tx-rings and rx-rings
621 */
622static void ixgbe_dump(struct ixgbe_adapter *adapter)
623{
624 struct net_device *netdev = adapter->netdev;
625 struct ixgbe_hw *hw = &adapter->hw;
626 struct ixgbe_reg_info *reginfo;
627 int n = 0;
John Fastabend33fdc822017-04-24 03:30:18 -0700628 struct ixgbe_ring *ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000629 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000630 union ixgbe_adv_tx_desc *tx_desc;
631 struct my_u0 { u64 a; u64 b; } *u0;
632 struct ixgbe_ring *rx_ring;
633 union ixgbe_adv_rx_desc *rx_desc;
634 struct ixgbe_rx_buffer *rx_buffer_info;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000635 int i = 0;
636
637 if (!netif_msg_hw(adapter))
638 return;
639
640 /* Print netdevice Info */
641 if (netdev) {
642 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000643 pr_info("Device Name state "
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100644 "trans_start\n");
645 pr_info("%-15s %016lX %016lX\n",
Joe Perchesc7689572010-09-07 21:35:17 +0000646 netdev->name,
647 netdev->state,
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100648 dev_trans_start(netdev));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000649 }
650
651 /* Print Registers */
652 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000653 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000654 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
655 reginfo->name; reginfo++) {
656 ixgbe_regdump(hw, reginfo);
657 }
658
659 /* Print TX Ring Summary */
660 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000661 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000662
663 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000664 pr_info(" %s %s %s %s\n",
665 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
666 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000667 for (n = 0; n < adapter->num_tx_queues; n++) {
John Fastabend33fdc822017-04-24 03:30:18 -0700668 ring = adapter->tx_ring[n];
669 ixgbe_print_buffer(ring, n);
670 }
671
672 for (n = 0; n < adapter->num_xdp_queues; n++) {
673 ring = adapter->xdp_ring[n];
674 ixgbe_print_buffer(ring, n);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000675 }
676
677 /* Print TX Rings */
678 if (!netif_msg_tx_done(adapter))
679 goto rx_ring_summary;
680
681 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
682
683 /* Transmit Descriptor Formats
684 *
Josh Hay39ac8682012-09-26 05:59:36 +0000685 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000686 * +--------------------------------------------------------------+
687 * 0 | Buffer Address [63:0] |
688 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000689 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000690 * +--------------------------------------------------------------+
691 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000692 *
693 * 82598 Advanced Transmit Descriptor (Write-Back Format)
694 * +--------------------------------------------------------------+
695 * 0 | RSV [63:0] |
696 * +--------------------------------------------------------------+
697 * 8 | RSV | STA | NXTSEQ |
698 * +--------------------------------------------------------------+
699 * 63 36 35 32 31 0
700 *
701 * 82599+ Advanced Transmit Descriptor
702 * +--------------------------------------------------------------+
703 * 0 | Buffer Address [63:0] |
704 * +--------------------------------------------------------------+
705 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
706 * +--------------------------------------------------------------+
707 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
708 *
709 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
710 * +--------------------------------------------------------------+
711 * 0 | RSV [63:0] |
712 * +--------------------------------------------------------------+
713 * 8 | RSV | STA | RSV |
714 * +--------------------------------------------------------------+
715 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000716 */
717
718 for (n = 0; n < adapter->num_tx_queues; n++) {
John Fastabend33fdc822017-04-24 03:30:18 -0700719 ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000720 pr_info("------------------------------------\n");
John Fastabend33fdc822017-04-24 03:30:18 -0700721 pr_info("TX QUEUE INDEX = %d\n", ring->queue_index);
Joe Perchesc7689572010-09-07 21:35:17 +0000722 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000723 pr_info("%s%s %s %s %s %s\n",
724 "T [desc] [address 63:0 ] ",
725 "[PlPOIdStDDt Ln] [bi->dma ] ",
726 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000727
John Fastabend33fdc822017-04-24 03:30:18 -0700728 for (i = 0; ring->desc && (i < ring->count); i++) {
729 tx_desc = IXGBE_TX_DESC(ring, i);
730 tx_buffer = &ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000731 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000732 if (dma_unmap_len(tx_buffer, len) > 0) {
Joe Perches332f2352017-01-03 07:28:11 -0800733 const char *ring_desc;
734
John Fastabend33fdc822017-04-24 03:30:18 -0700735 if (i == ring->next_to_use &&
736 i == ring->next_to_clean)
Joe Perches332f2352017-01-03 07:28:11 -0800737 ring_desc = " NTC/U";
John Fastabend33fdc822017-04-24 03:30:18 -0700738 else if (i == ring->next_to_use)
Joe Perches332f2352017-01-03 07:28:11 -0800739 ring_desc = " NTU";
John Fastabend33fdc822017-04-24 03:30:18 -0700740 else if (i == ring->next_to_clean)
Joe Perches332f2352017-01-03 07:28:11 -0800741 ring_desc = " NTC";
742 else
743 ring_desc = "";
744 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
Josh Hay8ad88e32012-09-26 05:59:41 +0000745 i,
746 le64_to_cpu(u0->a),
747 le64_to_cpu(u0->b),
748 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000749 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000750 tx_buffer->next_to_watch,
751 (u64)tx_buffer->time_stamp,
Joe Perches332f2352017-01-03 07:28:11 -0800752 tx_buffer->skb,
753 ring_desc);
Josh Hay8ad88e32012-09-26 05:59:41 +0000754
755 if (netif_msg_pktdata(adapter) &&
756 tx_buffer->skb)
757 print_hex_dump(KERN_INFO, "",
758 DUMP_PREFIX_ADDRESS, 16, 1,
759 tx_buffer->skb->data,
760 dma_unmap_len(tx_buffer, len),
761 true);
762 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000763 }
764 }
765
766 /* Print RX Rings Summary */
767rx_ring_summary:
768 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000769 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000770 for (n = 0; n < adapter->num_rx_queues; n++) {
771 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000772 pr_info("%5d %5X %5X\n",
773 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000774 }
775
776 /* Print RX Rings */
777 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000778 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000779
780 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
781
Josh Hay39ac8682012-09-26 05:59:36 +0000782 /* Receive Descriptor Formats
783 *
784 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000785 * 63 1 0
786 * +-----------------------------------------------------+
787 * 0 | Packet Buffer Address [63:1] |A0/NSE|
788 * +----------------------------------------------+------+
789 * 8 | Header Buffer Address [63:1] | DD |
790 * +-----------------------------------------------------+
791 *
792 *
Josh Hay39ac8682012-09-26 05:59:36 +0000793 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000794 *
795 * 63 48 47 32 31 30 21 20 16 15 4 3 0
796 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000797 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
798 * | Packet | IP | | | | Type | Type |
799 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000800 * +------------------------------------------------------+
801 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
802 * +------------------------------------------------------+
803 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000804 *
805 * 82599+ Advanced Receive Descriptor (Read) Format
806 * 63 1 0
807 * +-----------------------------------------------------+
808 * 0 | Packet Buffer Address [63:1] |A0/NSE|
809 * +----------------------------------------------+------+
810 * 8 | Header Buffer Address [63:1] | DD |
811 * +-----------------------------------------------------+
812 *
813 *
814 * 82599+ Advanced Receive Descriptor (Write-Back) Format
815 *
816 * 63 48 47 32 31 30 21 20 17 16 4 3 0
817 * +------------------------------------------------------+
818 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
819 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
820 * |/ Flow Dir Flt ID | | | | | |
821 * +------------------------------------------------------+
822 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
823 * +------------------------------------------------------+
824 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000825 */
Josh Hay39ac8682012-09-26 05:59:36 +0000826
Taku Izumidcd79ae2010-04-27 14:39:53 +0000827 for (n = 0; n < adapter->num_rx_queues; n++) {
828 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000829 pr_info("------------------------------------\n");
830 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
831 pr_info("------------------------------------\n");
Joe Perches332f2352017-01-03 07:28:11 -0800832 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000833 "R [desc] [ PktBuf A0] ",
834 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800835 "<-- Adv Rx Read format");
836 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000837 "RWB[desc] [PcsmIpSHl PtRs] ",
838 "[vl er S cks ln] ---------------- [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800839 "<-- Adv Rx Write-Back format");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000840
841 for (i = 0; i < rx_ring->count; i++) {
Joe Perches332f2352017-01-03 07:28:11 -0800842 const char *ring_desc;
843
844 if (i == rx_ring->next_to_use)
845 ring_desc = " NTU";
846 else if (i == rx_ring->next_to_clean)
847 ring_desc = " NTC";
848 else
849 ring_desc = "";
850
Taku Izumidcd79ae2010-04-27 14:39:53 +0000851 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000852 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000853 u0 = (struct my_u0 *)rx_desc;
Alexander Duyck18a8cc92017-03-02 15:01:36 -0800854 if (rx_desc->wb.upper.length) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000855 /* Descriptor Done */
Joe Perches332f2352017-01-03 07:28:11 -0800856 pr_info("RWB[0x%03X] %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),
Joe Perches332f2352017-01-03 07:28:11 -0800860 rx_buffer_info->skb,
861 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000862 } else {
Joe Perches332f2352017-01-03 07:28:11 -0800863 pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
864 i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000865 le64_to_cpu(u0->a),
866 le64_to_cpu(u0->b),
867 (u64)rx_buffer_info->dma,
Joe Perches332f2352017-01-03 07:28:11 -0800868 rx_buffer_info->skb,
869 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000870
Emil Tantilov9c50c032012-07-26 01:21:24 +0000871 if (netif_msg_pktdata(adapter) &&
872 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000873 print_hex_dump(KERN_INFO, "",
874 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000875 page_address(rx_buffer_info->page) +
876 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000877 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000878 }
879 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000880 }
881 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000882}
883
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800884static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
885{
886 u32 ctrl_ext;
887
888 /* Let firmware take over control of h/w */
889 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
890 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000891 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800892}
893
894static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
895{
896 u32 ctrl_ext;
897
898 /* Let firmware know the driver has taken over */
899 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
900 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000901 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800902}
Auke Kok9a799d72007-09-15 14:07:45 -0700903
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000904/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000905 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
906 * @adapter: pointer to adapter struct
907 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
908 * @queue: queue to map the corresponding interrupt to
909 * @msix_vector: the vector to map to the corresponding queue
910 *
911 */
912static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000913 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700914{
915 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000916 struct ixgbe_hw *hw = &adapter->hw;
917 switch (hw->mac.type) {
918 case ixgbe_mac_82598EB:
919 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
920 if (direction == -1)
921 direction = 0;
922 index = (((direction * 64) + queue) >> 2) & 0x1F;
923 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
924 ivar &= ~(0xFF << (8 * (queue & 0x3)));
925 ivar |= (msix_vector << (8 * (queue & 0x3)));
926 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
927 break;
928 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800929 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000930 case ixgbe_mac_X550:
931 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700932 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000933 if (direction == -1) {
934 /* other causes */
935 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
936 index = ((queue & 1) * 8);
937 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
938 ivar &= ~(0xFF << index);
939 ivar |= (msix_vector << index);
940 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
941 break;
942 } else {
943 /* tx or rx causes */
944 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
945 index = ((16 * (queue & 1)) + (8 * direction));
946 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
947 ivar &= ~(0xFF << index);
948 ivar |= (msix_vector << index);
949 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
950 break;
951 }
952 default:
953 break;
954 }
Auke Kok9a799d72007-09-15 14:07:45 -0700955}
956
Alexander Duyckfe49f042009-06-04 16:00:09 +0000957static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000958 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000959{
960 u32 mask;
961
Alexander Duyckbd508172010-11-16 19:27:03 -0800962 switch (adapter->hw.mac.type) {
963 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000964 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
965 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800966 break;
967 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800968 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000969 case ixgbe_mac_X550:
970 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700971 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000972 mask = (qmask & 0xFFFFFFFF);
973 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
974 mask = (qmask >> 32);
975 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800976 break;
977 default:
978 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000979 }
980}
981
Alexander Duyck943561d2012-05-09 22:14:44 -0700982static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
983{
984 struct ixgbe_hw *hw = &adapter->hw;
985 struct ixgbe_hw_stats *hwstats = &adapter->stats;
986 int i;
987 u32 data;
988
989 if ((hw->fc.current_mode != ixgbe_fc_full) &&
990 (hw->fc.current_mode != ixgbe_fc_rx_pause))
991 return;
992
993 switch (hw->mac.type) {
994 case ixgbe_mac_82598EB:
995 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
996 break;
997 default:
998 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
999 }
1000 hwstats->lxoffrxc += data;
1001
1002 /* refill credits (no tx hang) if we received xoff */
1003 if (!data)
1004 return;
1005
1006 for (i = 0; i < adapter->num_tx_queues; i++)
1007 clear_bit(__IXGBE_HANG_CHECK_ARMED,
1008 &adapter->tx_ring[i]->state);
John Fastabend33fdc822017-04-24 03:30:18 -07001009
1010 for (i = 0; i < adapter->num_xdp_queues; i++)
1011 clear_bit(__IXGBE_HANG_CHECK_ARMED,
1012 &adapter->xdp_ring[i]->state);
Alexander Duyck943561d2012-05-09 22:14:44 -07001013}
1014
John Fastabendc84d3242010-11-16 19:27:12 -08001015static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001016{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001017 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001018 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -08001019 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001020 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001021 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -07001022 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001023
Alexander Duyck943561d2012-05-09 22:14:44 -07001024 if (adapter->ixgbe_ieee_pfc)
1025 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -08001026
Alexander Duyck943561d2012-05-09 22:14:44 -07001027 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
1028 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -08001029 return;
Alexander Duyck943561d2012-05-09 22:14:44 -07001030 }
John Fastabendc84d3242010-11-16 19:27:12 -08001031
1032 /* update stats for each tc, only valid with PFC enabled */
1033 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001034 u32 pxoffrxc;
1035
John Fastabendc84d3242010-11-16 19:27:12 -08001036 switch (hw->mac.type) {
1037 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001038 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001039 break;
1040 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001041 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001042 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001043 hwstats->pxoffrxc[i] += pxoffrxc;
1044 /* Get the TC for given UP */
1045 tc = netdev_get_prio_tc_map(adapter->netdev, i);
1046 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -07001047 }
1048
John Fastabendc84d3242010-11-16 19:27:12 -08001049 /* disarm tx queues that have received xoff frames */
1050 for (i = 0; i < adapter->num_tx_queues; i++) {
1051 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -08001052
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001053 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001054 if (xoff[tc])
1055 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1056 }
John Fastabend33fdc822017-04-24 03:30:18 -07001057
1058 for (i = 0; i < adapter->num_xdp_queues; i++) {
1059 struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
1060
1061 tc = xdp_ring->dcb_tc;
1062 if (xoff[tc])
1063 clear_bit(__IXGBE_HANG_CHECK_ARMED, &xdp_ring->state);
1064 }
John Fastabendc84d3242010-11-16 19:27:12 -08001065}
1066
1067static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1068{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001069 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001070}
1071
1072static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1073{
Alexander Duyck14895422017-11-22 10:56:46 -08001074 unsigned int head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001075
Alexander Duyck14895422017-11-22 10:56:46 -08001076 head = ring->next_to_clean;
1077 tail = ring->next_to_use;
John Fastabend2a47fa42013-11-06 09:54:52 -08001078
Alexander Duyck14895422017-11-22 10:56:46 -08001079 return ((head <= tail) ? tail : tail + ring->count) - head;
John Fastabendc84d3242010-11-16 19:27:12 -08001080}
1081
1082static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1083{
1084 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1085 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1086 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001087
1088 clear_check_for_tx_hang(tx_ring);
1089
1090 /*
1091 * Check for a hung queue, but be thorough. This verifies
1092 * that a transmit has been completed since the previous
1093 * check AND there is at least one packet pending. The
1094 * ARMED bit is set to indicate a potential hang. The
1095 * bit is cleared if a pause frame is received to remove
1096 * false hang detection due to PFC or 802.3x frames. By
1097 * requiring this to fail twice we avoid races with
1098 * pfc clearing the ARMED bit and conditions where we
1099 * run the check_tx_hang logic with a transmit completion
1100 * pending but without time to complete it yet.
1101 */
Mark Rustade90dd262014-07-22 06:51:08 +00001102 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001103 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001104 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1105 &tx_ring->state);
1106 /* update completed stats and continue */
1107 tx_ring->tx_stats.tx_done_old = tx_done;
1108 /* reset the countdown */
1109 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001110
Mark Rustade90dd262014-07-22 06:51:08 +00001111 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001112}
1113
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001114/**
1115 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1116 * @adapter: driver private struct
1117 **/
1118static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1119{
1120
1121 /* Do the reset outside of interrupt context */
1122 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
Emil Tantilov57ca2a42016-07-29 14:46:31 -07001123 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Jacob Keller12ff3f32012-12-01 07:57:17 +00001124 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001125 ixgbe_service_event_schedule(adapter);
1126 }
1127}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001128
Auke Kok9a799d72007-09-15 14:07:45 -07001129/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001130 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1131 **/
1132static int ixgbe_tx_maxrate(struct net_device *netdev,
1133 int queue_index, u32 maxrate)
1134{
1135 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1136 struct ixgbe_hw *hw = &adapter->hw;
1137 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1138
1139 if (!maxrate)
1140 return 0;
1141
1142 /* Calculate the rate factor values to set */
1143 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1144 bcnrc_val /= maxrate;
1145
1146 /* clear everything but the rate factor */
1147 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1148 IXGBE_RTTBCNRC_RF_DEC_MASK;
1149
1150 /* enable the rate scheduler */
1151 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1152
1153 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1154 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1155
1156 return 0;
1157}
1158
1159/**
Auke Kok9a799d72007-09-15 14:07:45 -07001160 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001161 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001162 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001163 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001164 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001165static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001166 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001167{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001168 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001169 struct ixgbe_tx_buffer *tx_buffer;
1170 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001171 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001172 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001173 unsigned int i = tx_ring->next_to_clean;
1174
1175 if (test_bit(__IXGBE_DOWN, &adapter->state))
1176 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001177
Alexander Duyckd3d00232011-07-15 02:31:25 +00001178 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001179 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001180 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001181
Alexander Duyck729739b2012-02-08 07:51:06 +00001182 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001183 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001184
Alexander Duyckd3d00232011-07-15 02:31:25 +00001185 /* if next_to_watch is not set then there is no work pending */
1186 if (!eop_desc)
1187 break;
1188
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001189 /* prevent any other reads prior to eop_desc */
Brian King0a9a17e2017-11-17 11:05:43 -06001190 smp_rmb();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001191
Alexander Duyckd3d00232011-07-15 02:31:25 +00001192 /* if DD is not set pending work has not been completed */
1193 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1194 break;
1195
Alexander Duyckd3d00232011-07-15 02:31:25 +00001196 /* clear next_to_watch to prevent false hangs */
1197 tx_buffer->next_to_watch = NULL;
1198
Alexander Duyck091a6242012-02-08 07:51:01 +00001199 /* update the statistics for this packet */
1200 total_bytes += tx_buffer->bytecount;
1201 total_packets += tx_buffer->gso_segs;
1202
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001203 /* free the skb */
John Fastabend33fdc822017-04-24 03:30:18 -07001204 if (ring_is_xdp(tx_ring))
1205 page_frag_free(tx_buffer->data);
1206 else
1207 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001208
Alexander Duyck729739b2012-02-08 07:51:06 +00001209 /* unmap skb header data */
1210 dma_unmap_single(tx_ring->dev,
1211 dma_unmap_addr(tx_buffer, dma),
1212 dma_unmap_len(tx_buffer, len),
1213 DMA_TO_DEVICE);
1214
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001215 /* clear tx_buffer data */
Alexander Duyck729739b2012-02-08 07:51:06 +00001216 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001217
Alexander Duyck729739b2012-02-08 07:51:06 +00001218 /* unmap remaining buffers */
1219 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001220 tx_buffer++;
1221 tx_desc++;
1222 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001223 if (unlikely(!i)) {
1224 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001225 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001226 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001227 }
1228
Alexander Duyck729739b2012-02-08 07:51:06 +00001229 /* unmap any remaining paged data */
1230 if (dma_unmap_len(tx_buffer, len)) {
1231 dma_unmap_page(tx_ring->dev,
1232 dma_unmap_addr(tx_buffer, dma),
1233 dma_unmap_len(tx_buffer, len),
1234 DMA_TO_DEVICE);
1235 dma_unmap_len_set(tx_buffer, len, 0);
1236 }
1237 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001238
Alexander Duyck729739b2012-02-08 07:51:06 +00001239 /* move us one more past the eop_desc for start of next pkt */
1240 tx_buffer++;
1241 tx_desc++;
1242 i++;
1243 if (unlikely(!i)) {
1244 i -= tx_ring->count;
1245 tx_buffer = tx_ring->tx_buffer_info;
1246 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1247 }
1248
1249 /* issue prefetch for next Tx descriptor */
1250 prefetch(tx_desc);
1251
1252 /* update budget accounting */
1253 budget--;
1254 } while (likely(budget));
1255
1256 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001257 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001258 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001259 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001260 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001261 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001262 q_vector->tx.total_bytes += total_bytes;
1263 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001264
John Fastabendc84d3242010-11-16 19:27:12 -08001265 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001266 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001267 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend33fdc822017-04-24 03:30:18 -07001268 e_err(drv, "Detected Tx Unit Hang %s\n"
John Fastabendc84d3242010-11-16 19:27:12 -08001269 " Tx Queue <%d>\n"
1270 " TDH, TDT <%x>, <%x>\n"
1271 " next_to_use <%x>\n"
1272 " next_to_clean <%x>\n"
1273 "tx_buffer_info[next_to_clean]\n"
1274 " time_stamp <%lx>\n"
1275 " jiffies <%lx>\n",
John Fastabend33fdc822017-04-24 03:30:18 -07001276 ring_is_xdp(tx_ring) ? "(XDP)" : "",
John Fastabendc84d3242010-11-16 19:27:12 -08001277 tx_ring->queue_index,
1278 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1279 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001280 tx_ring->next_to_use, i,
1281 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001282
John Fastabend33fdc822017-04-24 03:30:18 -07001283 if (!ring_is_xdp(tx_ring))
1284 netif_stop_subqueue(tx_ring->netdev,
1285 tx_ring->queue_index);
John Fastabendc84d3242010-11-16 19:27:12 -08001286
1287 e_info(probe,
1288 "tx hang %d detected on queue %d, resetting adapter\n",
1289 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1290
1291 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001292 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001293
1294 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001295 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001296 }
Auke Kok9a799d72007-09-15 14:07:45 -07001297
John Fastabend33fdc822017-04-24 03:30:18 -07001298 if (ring_is_xdp(tx_ring))
1299 return !!budget;
1300
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001301 netdev_tx_completed_queue(txring_txq(tx_ring),
1302 total_packets, total_bytes);
1303
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001304#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001305 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001306 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001307 /* Make sure that anybody stopping the queue after this
1308 * sees the new next_to_clean.
1309 */
1310 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001311 if (__netif_subqueue_stopped(tx_ring->netdev,
1312 tx_ring->queue_index)
1313 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1314 netif_wake_subqueue(tx_ring->netdev,
1315 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001316 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001317 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001318 }
Auke Kok9a799d72007-09-15 14:07:45 -07001319
Alexander Duyck59224552011-08-31 00:01:06 +00001320 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001321}
1322
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001323#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001324static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001325 struct ixgbe_ring *tx_ring,
1326 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001327{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001328 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001329 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001330 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001331
Mark Rustad9de76052015-08-08 16:27:41 -07001332 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1333 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1334
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001335 switch (hw->mac.type) {
1336 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001337 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001338 break;
1339 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001340 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001341 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1342 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1343 break;
1344 default:
1345 /* for unknown hardware do not write register */
1346 return;
1347 }
1348
1349 /*
1350 * We can enable relaxed ordering for reads, but not writes when
1351 * DCA is enabled. This is due to a known issue in some chipsets
1352 * which will cause the DCA tag to be cleared.
1353 */
1354 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1355 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1356 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1357
1358 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1359}
1360
1361static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1362 struct ixgbe_ring *rx_ring,
1363 int cpu)
1364{
1365 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001366 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001367 u8 reg_idx = rx_ring->reg_idx;
1368
Mark Rustad9de76052015-08-08 16:27:41 -07001369 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1370 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001371
1372 switch (hw->mac.type) {
1373 case ixgbe_mac_82599EB:
1374 case ixgbe_mac_X540:
1375 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001376 break;
1377 default:
1378 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001379 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001380
1381 /*
1382 * We can enable relaxed ordering for reads, but not writes when
1383 * DCA is enabled. This is due to a known issue in some chipsets
1384 * which will cause the DCA tag to be cleared.
1385 */
1386 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Mark Rustad9de76052015-08-08 16:27:41 -07001387 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001388 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1389
1390 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001391}
1392
1393static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1394{
1395 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001396 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001397 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001398
1399 if (q_vector->cpu == cpu)
1400 goto out_no_update;
1401
Alexander Duycka5579282012-02-08 07:50:04 +00001402 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001403 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001404
Alexander Duycka5579282012-02-08 07:50:04 +00001405 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001406 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001407
1408 q_vector->cpu = cpu;
1409out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001410 put_cpu();
1411}
1412
1413static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1414{
1415 int i;
1416
Alexander Duycke35ec122009-05-21 13:07:12 +00001417 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001418 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1419 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1420 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1421 else
1422 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1423 IXGBE_DCA_CTRL_DCA_DISABLE);
Alexander Duycke35ec122009-05-21 13:07:12 +00001424
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001425 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001426 adapter->q_vector[i]->cpu = -1;
1427 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001428 }
1429}
1430
1431static int __ixgbe_notify_dca(struct device *dev, void *data)
1432{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001433 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001434 unsigned long event = *(unsigned long *)data;
1435
Don Skidmore2a72c312011-07-20 02:27:05 +00001436 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001437 return 0;
1438
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001439 switch (event) {
1440 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001441 /* if we're already enabled, don't do it again */
1442 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1443 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001444 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001445 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001446 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1447 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001448 break;
1449 }
Tony Nguyen93df9462017-05-31 04:43:47 -07001450 /* fall through - DCA is disabled. */
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001451 case DCA_PROVIDER_REMOVE:
1452 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1453 dca_remove_requester(dev);
1454 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001455 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1456 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001457 }
1458 break;
1459 }
1460
Denis V. Lunev652f0932008-03-27 14:39:17 +03001461 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001462}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001463
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001464#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b82015-04-29 10:57:39 +08001465
1466#define IXGBE_RSS_L4_TYPES_MASK \
1467 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1468 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1469 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1470 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1471
Alexander Duyck8a0da212012-01-31 02:59:49 +00001472static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1473 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001474 struct sk_buff *skb)
1475{
Fan Du7edda4b82015-04-29 10:57:39 +08001476 u16 rss_type;
1477
1478 if (!(ring->netdev->features & NETIF_F_RXHASH))
1479 return;
1480
1481 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1482 IXGBE_RXDADV_RSSTYPE_MASK;
1483
1484 if (!rss_type)
1485 return;
1486
1487 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1488 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1489 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001490}
1491
Alexander Duyckf8003262012-03-03 02:35:52 +00001492#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001493/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001494 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001495 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001496 * @rx_desc: advanced rx descriptor
1497 *
1498 * Returns : true if it is FCoE pkt
1499 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001500static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001501 union ixgbe_adv_rx_desc *rx_desc)
1502{
1503 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1504
Alexander Duyck57efd442012-06-25 21:54:46 +00001505 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001506 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1507 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1508 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1509}
1510
Alexander Duyckf8003262012-03-03 02:35:52 +00001511#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001512/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001513 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001514 * @ring: structure containing ring specific data
1515 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001516 * @skb: skb currently being received and modified
1517 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001518static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001519 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001520 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001521{
Don Skidmore3f207802014-12-23 07:40:34 +00001522 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore3f207802014-12-23 07:40:34 +00001523 bool encap_pkt = false;
1524
Alexander Duyck8a0da212012-01-31 02:59:49 +00001525 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001526
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001527 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001528 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001529 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001530
Emil Tantilova21d0822016-08-10 11:19:23 -07001531 /* check for VXLAN and Geneve packets */
1532 if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
Don Skidmore3f207802014-12-23 07:40:34 +00001533 encap_pkt = true;
1534 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001535 }
1536
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001537 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001538 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1539 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001540 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001541 return;
1542 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001543
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001544 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001545 return;
1546
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001547 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001548 /*
1549 * 82599 errata, UDP frames with a 0 checksum can be marked as
1550 * checksum errors.
1551 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001552 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1553 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001554 return;
1555
Alexander Duyck8a0da212012-01-31 02:59:49 +00001556 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001557 return;
1558 }
1559
Auke Kok9a799d72007-09-15 14:07:45 -07001560 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001561 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001562 if (encap_pkt) {
1563 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1564 return;
1565
1566 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
Mark Rustadd4692512015-12-04 11:26:43 -08001567 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001568 return;
1569 }
1570 /* If we checked the outer header let the stack know */
1571 skb->csum_level = 1;
1572 }
Auke Kok9a799d72007-09-15 14:07:45 -07001573}
1574
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001575static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
1576{
1577 return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
1578}
1579
Alexander Duyckf990b792012-01-31 02:59:34 +00001580static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1581 struct ixgbe_rx_buffer *bi)
1582{
1583 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001584 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001585
Alexander Duyckf8003262012-03-03 02:35:52 +00001586 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001587 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001588 return true;
1589
Alexander Duyckf8003262012-03-03 02:35:52 +00001590 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001591 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1592 if (unlikely(!page)) {
1593 rx_ring->rx_stats.alloc_rx_page_failed++;
1594 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001595 }
1596
Alexander Duyckf8003262012-03-03 02:35:52 +00001597 /* map page for use */
Alexander Duyckf3213d92017-01-17 08:35:54 -08001598 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
1599 ixgbe_rx_pg_size(rx_ring),
1600 DMA_FROM_DEVICE,
1601 IXGBE_RX_DMA_ATTR);
Alexander Duyckf990b792012-01-31 02:59:34 +00001602
Alexander Duyckf8003262012-03-03 02:35:52 +00001603 /*
1604 * if mapping failed free memory back to system since
1605 * there isn't much point in holding memory we can't use
1606 */
1607 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001608 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001609
Alexander Duyckf990b792012-01-31 02:59:34 +00001610 rx_ring->rx_stats.alloc_rx_page_failed++;
1611 return false;
1612 }
1613
Alexander Duyckf8003262012-03-03 02:35:52 +00001614 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001615 bi->page = page;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001616 bi->page_offset = ixgbe_rx_offset(rx_ring);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001617 bi->pagecnt_bias = 1;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02001618 rx_ring->rx_stats.alloc_rx_page++;
Alexander Duyckf8003262012-03-03 02:35:52 +00001619
Alexander Duyckf990b792012-01-31 02:59:34 +00001620 return true;
1621}
1622
Auke Kok9a799d72007-09-15 14:07:45 -07001623/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001624 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001625 * @rx_ring: ring to place buffers on
1626 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001627 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001628void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001629{
Auke Kok9a799d72007-09-15 14:07:45 -07001630 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001631 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001632 u16 i = rx_ring->next_to_use;
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001633 u16 bufsz;
Auke Kok9a799d72007-09-15 14:07:45 -07001634
Alexander Duyckf8003262012-03-03 02:35:52 +00001635 /* nothing to do */
1636 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001637 return;
1638
Alexander Duycke4f74022012-01-31 02:59:44 +00001639 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001640 bi = &rx_ring->rx_buffer_info[i];
1641 i -= rx_ring->count;
1642
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001643 bufsz = ixgbe_rx_bufsz(rx_ring);
1644
Alexander Duyckf8003262012-03-03 02:35:52 +00001645 do {
1646 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001647 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001648
Alexander Duyckf3213d92017-01-17 08:35:54 -08001649 /* sync the buffer for use by the device */
1650 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001651 bi->page_offset, bufsz,
Alexander Duyckf3213d92017-01-17 08:35:54 -08001652 DMA_FROM_DEVICE);
1653
Alexander Duyckf8003262012-03-03 02:35:52 +00001654 /*
1655 * Refresh the desc even if buffer_addrs didn't change
1656 * because each write-back erases this info.
1657 */
1658 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001659
Alexander Duyckf990b792012-01-31 02:59:34 +00001660 rx_desc++;
1661 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001662 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001663 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001664 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001665 bi = rx_ring->rx_buffer_info;
1666 i -= rx_ring->count;
1667 }
1668
Alexander Duyckc3630cc2017-01-17 08:36:28 -08001669 /* clear the length for the next_to_use descriptor */
1670 rx_desc->wb.upper.length = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001671
1672 cleaned_count--;
1673 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001674
Alexander Duyckf990b792012-01-31 02:59:34 +00001675 i += rx_ring->count;
1676
Alexander Duyckad435ec2014-11-14 00:56:35 +00001677 if (rx_ring->next_to_use != i) {
1678 rx_ring->next_to_use = i;
1679
1680 /* update next to alloc since we have filled the ring */
1681 rx_ring->next_to_alloc = i;
1682
1683 /* Force memory writes to complete before letting h/w
1684 * know there are new descriptors to fetch. (Only
1685 * applicable for weak-ordered memory model archs,
1686 * such as IA-64).
1687 */
1688 wmb();
1689 writel(i, rx_ring->tail);
1690 }
Auke Kok9a799d72007-09-15 14:07:45 -07001691}
1692
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001693static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1694 struct sk_buff *skb)
1695{
Alexander Duyckf8003262012-03-03 02:35:52 +00001696 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001697
1698 /* set gso_size to avoid messing up TCP MSS */
1699 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1700 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001701 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001702}
1703
1704static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1705 struct sk_buff *skb)
1706{
1707 /* if append_cnt is 0 then frame is not RSC */
1708 if (!IXGBE_CB(skb)->append_cnt)
1709 return;
1710
1711 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1712 rx_ring->rx_stats.rsc_flush++;
1713
1714 ixgbe_set_rsc_gso_size(rx_ring, skb);
1715
1716 /* gso_size is computed using append_cnt so always clear it last */
1717 IXGBE_CB(skb)->append_cnt = 0;
1718}
1719
Alexander Duyck8a0da212012-01-31 02:59:49 +00001720/**
1721 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1722 * @rx_ring: rx descriptor ring packet is being transacted on
1723 * @rx_desc: pointer to the EOP Rx descriptor
1724 * @skb: pointer to current skb being populated
1725 *
1726 * This function checks the ring, descriptor, and packet information in
1727 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1728 * other fields within the skb.
1729 **/
1730static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1731 union ixgbe_adv_rx_desc *rx_desc,
1732 struct sk_buff *skb)
1733{
John Fastabend43e95f12012-05-15 06:12:17 +00001734 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001735 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001736
Alexander Duyck8a0da212012-01-31 02:59:49 +00001737 ixgbe_update_rsc_stats(rx_ring, skb);
1738
1739 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1740
1741 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1742
Mark Rustada9763f32015-10-27 09:58:07 -07001743 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1744 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001745
Patrick McHardyf6469682013-04-19 02:04:27 +00001746 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001747 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001748 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001749 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001750 }
1751
1752 skb_record_rx_queue(skb, rx_ring->queue_index);
1753
John Fastabend43e95f12012-05-15 06:12:17 +00001754 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001755}
1756
1757static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1758 struct sk_buff *skb)
1759{
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08001760 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001761}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001762
Alexander Duyckf8003262012-03-03 02:35:52 +00001763/**
1764 * ixgbe_is_non_eop - process handling of non-EOP buffers
1765 * @rx_ring: Rx ring being processed
1766 * @rx_desc: Rx descriptor for current buffer
1767 * @skb: Current socket buffer containing buffer in progress
1768 *
1769 * This function updates next to clean. If the buffer is an EOP buffer
1770 * this function exits returning false, otherwise it will place the
1771 * sk_buff in the next buffer to be chained and return true indicating
1772 * that this is in fact a non-EOP buffer.
1773 **/
1774static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1775 union ixgbe_adv_rx_desc *rx_desc,
1776 struct sk_buff *skb)
1777{
1778 u32 ntc = rx_ring->next_to_clean + 1;
1779
1780 /* fetch, update, and store next to clean */
1781 ntc = (ntc < rx_ring->count) ? ntc : 0;
1782 rx_ring->next_to_clean = ntc;
1783
1784 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1785
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001786 /* update RSC append count if present */
1787 if (ring_is_rsc_enabled(rx_ring)) {
1788 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1789 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1790
1791 if (unlikely(rsc_enabled)) {
1792 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1793
1794 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1795 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1796
1797 /* update ntc based on RSC value */
1798 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1799 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1800 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1801 }
1802 }
1803
1804 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001805 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1806 return false;
1807
Alexander Duyckf8003262012-03-03 02:35:52 +00001808 /* place skb in next buffer to be received */
1809 rx_ring->rx_buffer_info[ntc].skb = skb;
1810 rx_ring->rx_stats.non_eop_descs++;
1811
1812 return true;
1813}
1814
1815/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001816 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1817 * @rx_ring: rx descriptor ring packet is being transacted on
1818 * @skb: pointer to current skb being adjusted
1819 *
1820 * This function is an ixgbe specific version of __pskb_pull_tail. The
1821 * main difference between this version and the original function is that
1822 * this function can make several assumptions about the state of things
1823 * that allow for significant optimizations versus the standard function.
1824 * As a result we can do things like drop a frag and maintain an accurate
1825 * truesize for the skb.
1826 */
1827static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1828 struct sk_buff *skb)
1829{
1830 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1831 unsigned char *va;
1832 unsigned int pull_len;
1833
1834 /*
1835 * it is valid to use page_address instead of kmap since we are
1836 * working with pages allocated out of the lomem pool per
1837 * alloc_page(GFP_ATOMIC)
1838 */
1839 va = skb_frag_address(frag);
1840
1841 /*
1842 * we need the header to contain the greater of either ETH_HLEN or
1843 * 60 bytes if the skb->len is less than 60 for skb_pad.
1844 */
Alexander Duyck8496e3382014-09-05 19:22:18 -04001845 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001846
1847 /* align pull length to size of long to optimize memcpy performance */
1848 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1849
1850 /* update all of the pointers */
1851 skb_frag_size_sub(frag, pull_len);
1852 frag->page_offset += pull_len;
1853 skb->data_len -= pull_len;
1854 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001855}
1856
1857/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001858 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1859 * @rx_ring: rx descriptor ring packet is being transacted on
1860 * @skb: pointer to current skb being updated
1861 *
1862 * This function provides a basic DMA sync up for the first fragment of an
1863 * skb. The reason for doing this is that the first fragment cannot be
1864 * unmapped until we have reached the end of packet descriptor for a buffer
1865 * chain.
1866 */
1867static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1868 struct sk_buff *skb)
1869{
1870 /* if the page was released unmap it, else just sync our portion */
1871 if (unlikely(IXGBE_CB(skb)->page_released)) {
Alexander Duyckf3213d92017-01-17 08:35:54 -08001872 dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
1873 ixgbe_rx_pg_size(rx_ring),
1874 DMA_FROM_DEVICE,
1875 IXGBE_RX_DMA_ATTR);
Alexander Duyck42073d92012-07-20 08:08:28 +00001876 } else {
1877 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1878
1879 dma_sync_single_range_for_cpu(rx_ring->dev,
1880 IXGBE_CB(skb)->dma,
1881 frag->page_offset,
Alexander Duyckf215af82017-01-17 08:35:44 -08001882 skb_frag_size(frag),
Alexander Duyck42073d92012-07-20 08:08:28 +00001883 DMA_FROM_DEVICE);
1884 }
Alexander Duyck42073d92012-07-20 08:08:28 +00001885}
1886
1887/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001888 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1889 * @rx_ring: rx descriptor ring packet is being transacted on
1890 * @rx_desc: pointer to the EOP Rx descriptor
1891 * @skb: pointer to current skb being fixed
1892 *
John Fastabend92470802017-04-24 03:30:17 -07001893 * Check if the skb is valid in the XDP case it will be an error pointer.
1894 * Return true in this case to abort processing and advance to next
1895 * descriptor.
1896 *
Alexander Duyckf8003262012-03-03 02:35:52 +00001897 * Check for corrupted packet headers caused by senders on the local L2
1898 * embedded NIC switch not setting up their Tx Descriptors right. These
1899 * should be very rare.
1900 *
1901 * Also address the case where we are pulling data in on pages only
1902 * and as such no data is present in the skb header.
1903 *
1904 * In addition if skb is not at least 60 bytes we need to pad it so that
1905 * it is large enough to qualify as a valid Ethernet frame.
1906 *
1907 * Returns true if an error was encountered and skb was freed.
1908 **/
1909static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1910 union ixgbe_adv_rx_desc *rx_desc,
1911 struct sk_buff *skb)
1912{
Alexander Duyckf8003262012-03-03 02:35:52 +00001913 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001914
John Fastabend92470802017-04-24 03:30:17 -07001915 /* XDP packets use error pointer so abort at this point */
1916 if (IS_ERR(skb))
1917 return true;
1918
Alexander Duyckf8003262012-03-03 02:35:52 +00001919 /* verify that the packet does not have any known errors */
1920 if (unlikely(ixgbe_test_staterr(rx_desc,
1921 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1922 !(netdev->features & NETIF_F_RXALL))) {
1923 dev_kfree_skb_any(skb);
1924 return true;
1925 }
1926
Alexander Duyck19861ce2012-07-20 08:08:33 +00001927 /* place header in linear portion of buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08001928 if (!skb_headlen(skb))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001929 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001930
Alexander Duyck57efd442012-06-25 21:54:46 +00001931#ifdef IXGBE_FCOE
1932 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1933 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1934 return false;
1935
1936#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001937 /* if eth_skb_pad returns an error the skb was freed */
1938 if (eth_skb_pad(skb))
1939 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001940
1941 return false;
1942}
1943
1944/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001945 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1946 * @rx_ring: rx descriptor ring to store buffers on
1947 * @old_buff: donor buffer to have page reused
1948 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001949 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001950 **/
1951static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1952 struct ixgbe_rx_buffer *old_buff)
1953{
1954 struct ixgbe_rx_buffer *new_buff;
1955 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001956
1957 new_buff = &rx_ring->rx_buffer_info[nta];
1958
1959 /* update, and store next to alloc */
1960 nta++;
1961 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1962
Alexander Duyck3fd218762017-01-17 08:36:45 -08001963 /* Transfer page from old buffer to new buffer.
1964 * Move each member individually to avoid possible store
1965 * forwarding stalls and unnecessary copy of skb.
1966 */
1967 new_buff->dma = old_buff->dma;
1968 new_buff->page = old_buff->page;
1969 new_buff->page_offset = old_buff->page_offset;
1970 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
Alexander Duyckf8003262012-03-03 02:35:52 +00001971}
1972
Alexander Duyck18cb6522014-11-14 00:56:29 +00001973static inline bool ixgbe_page_is_reserved(struct page *page)
1974{
Michal Hocko2f064f32015-08-21 14:11:51 -07001975 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001976}
1977
Alexander Duyck3fd218762017-01-17 08:36:45 -08001978static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
Alexander Duyckf8003262012-03-03 02:35:52 +00001979{
Alexander Duyck3fd218762017-01-17 08:36:45 -08001980 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
1981 struct page *page = rx_buffer->page;
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001982
Alexander Duyck09816fb2012-07-20 08:08:23 +00001983 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001984 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001985 return false;
1986
1987#if (PAGE_SIZE < 8192)
1988 /* if we are only owner of page we can reuse it */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001989 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001990 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001991#else
Alexander Duyck3fd218762017-01-17 08:36:45 -08001992 /* The last offset is a bit aggressive in that we assume the
1993 * worst case of FCoE being enabled and using a 3K buffer.
1994 * However this should have minimal impact as the 1K extra is
1995 * still less than one buffer in size.
1996 */
1997#define IXGBE_LAST_OFFSET \
1998 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
1999 if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
Alexander Duyck09816fb2012-07-20 08:08:23 +00002000 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00002001#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00002002
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002003 /* If we have drained the page fragment pool we need to update
2004 * the pagecnt_bias and page count so that we fully restock the
2005 * number of references the driver holds.
Alexander Duyck18cb6522014-11-14 00:56:29 +00002006 */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002007 if (unlikely(!pagecnt_bias)) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002008 page_ref_add(page, USHRT_MAX);
2009 rx_buffer->pagecnt_bias = USHRT_MAX;
2010 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00002011
Alexander Duyck0549ae22012-07-20 08:08:18 +00002012 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00002013}
2014
Alexander Duyckaf43da02017-01-17 08:35:34 -08002015/**
2016 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
2017 * @rx_ring: rx descriptor ring to transact packets on
2018 * @rx_buffer: buffer containing page to add
2019 * @rx_desc: descriptor containing length of buffer written by hardware
2020 * @skb: sk_buff to place the data into
2021 *
2022 * This function will add the data contained in rx_buffer->page to the skb.
2023 * This is done either through a direct copy if the data in the buffer is
2024 * less than the skb header size, otherwise it will just attach the page as
2025 * a frag to the skb.
2026 *
2027 * The function will then update the page offset if necessary and return
2028 * true if the buffer can be reused by the adapter.
2029 **/
Alexander Duyck3fd218762017-01-17 08:36:45 -08002030static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckaf43da02017-01-17 08:35:34 -08002031 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck3fd218762017-01-17 08:36:45 -08002032 struct sk_buff *skb,
2033 unsigned int size)
Alexander Duyckaf43da02017-01-17 08:35:34 -08002034{
Alexander Duyckaf43da02017-01-17 08:35:34 -08002035#if (PAGE_SIZE < 8192)
Alexander Duyck4f4542b2017-01-17 08:36:14 -08002036 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
Alexander Duyckaf43da02017-01-17 08:35:34 -08002037#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08002038 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2039 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2040 SKB_DATA_ALIGN(size);
Alexander Duyckaf43da02017-01-17 08:35:34 -08002041#endif
Alexander Duyck3fd218762017-01-17 08:36:45 -08002042 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
Alexander Duyckaf43da02017-01-17 08:35:34 -08002043 rx_buffer->page_offset, size, truesize);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002044#if (PAGE_SIZE < 8192)
2045 rx_buffer->page_offset ^= truesize;
2046#else
2047 rx_buffer->page_offset += truesize;
2048#endif
Alexander Duyckaf43da02017-01-17 08:35:34 -08002049}
2050
Alexander Duyck3fd218762017-01-17 08:36:45 -08002051static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
2052 union ixgbe_adv_rx_desc *rx_desc,
2053 struct sk_buff **skb,
2054 const unsigned int size)
Alexander Duyck18806c92012-07-20 08:08:44 +00002055{
2056 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyck18806c92012-07-20 08:08:44 +00002057
2058 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
Alexander Duyck3fd218762017-01-17 08:36:45 -08002059 prefetchw(rx_buffer->page);
2060 *skb = rx_buffer->skb;
Alexander Duyck18806c92012-07-20 08:08:44 +00002061
Alexander Duyck3fd218762017-01-17 08:36:45 -08002062 /* Delay unmapping of the first packet. It carries the header
2063 * information, HW may still access the header after the writeback.
2064 * Only unmap it when EOP is reached
2065 */
2066 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
2067 if (!*skb)
2068 goto skip_sync;
Alexander Duyck18806c92012-07-20 08:08:44 +00002069 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002070 if (*skb)
2071 ixgbe_dma_sync_frag(rx_ring, *skb);
Alexander Duyck18806c92012-07-20 08:08:44 +00002072 }
2073
Alexander Duyck3fd218762017-01-17 08:36:45 -08002074 /* we are reusing so sync this buffer for CPU use */
2075 dma_sync_single_range_for_cpu(rx_ring->dev,
2076 rx_buffer->dma,
2077 rx_buffer->page_offset,
2078 size,
2079 DMA_FROM_DEVICE);
2080skip_sync:
2081 rx_buffer->pagecnt_bias--;
2082
2083 return rx_buffer;
2084}
2085
2086static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
2087 struct ixgbe_rx_buffer *rx_buffer,
2088 struct sk_buff *skb)
2089{
2090 if (ixgbe_can_reuse_rx_page(rx_buffer)) {
Alexander Duyck18806c92012-07-20 08:08:44 +00002091 /* hand second half of page back to the ring */
2092 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
Alexander Duyck18806c92012-07-20 08:08:44 +00002093 } else {
John Fastabend92470802017-04-24 03:30:17 -07002094 if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002095 /* the page has been released from the ring */
2096 IXGBE_CB(skb)->page_released = true;
2097 } else {
2098 /* we are not reusing the buffer so unmap it */
2099 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
2100 ixgbe_rx_pg_size(rx_ring),
2101 DMA_FROM_DEVICE,
2102 IXGBE_RX_DMA_ATTR);
2103 }
Alexander Duyck3fd218762017-01-17 08:36:45 -08002104 __page_frag_cache_drain(rx_buffer->page,
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002105 rx_buffer->pagecnt_bias);
Alexander Duyck18806c92012-07-20 08:08:44 +00002106 }
2107
Alexander Duyck3fd218762017-01-17 08:36:45 -08002108 /* clear contents of rx_buffer */
Alexander Duyck18806c92012-07-20 08:08:44 +00002109 rx_buffer->page = NULL;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002110 rx_buffer->skb = NULL;
2111}
2112
2113static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
2114 struct ixgbe_rx_buffer *rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002115 struct xdp_buff *xdp,
2116 union ixgbe_adv_rx_desc *rx_desc)
Alexander Duyck3fd218762017-01-17 08:36:45 -08002117{
John Fastabend92470802017-04-24 03:30:17 -07002118 unsigned int size = xdp->data_end - xdp->data;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002119#if (PAGE_SIZE < 8192)
2120 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2121#else
John Fastabend92470802017-04-24 03:30:17 -07002122 unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end -
2123 xdp->data_hard_start);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002124#endif
2125 struct sk_buff *skb;
2126
2127 /* prefetch first cache line of first page */
John Fastabend92470802017-04-24 03:30:17 -07002128 prefetch(xdp->data);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002129#if L1_CACHE_BYTES < 128
John Fastabend92470802017-04-24 03:30:17 -07002130 prefetch(xdp->data + L1_CACHE_BYTES);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002131#endif
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002132 /* Note, we get here by enabling legacy-rx via:
2133 *
2134 * ethtool --set-priv-flags <dev> legacy-rx on
2135 *
2136 * In this mode, we currently get 0 extra XDP headroom as
2137 * opposed to having legacy-rx off, where we process XDP
2138 * packets going to stack via ixgbe_build_skb(). The latter
2139 * provides us currently with 192 bytes of headroom.
2140 *
2141 * For ixgbe_construct_skb() mode it means that the
2142 * xdp->data_meta will always point to xdp->data, since
2143 * the helper cannot expand the head. Should this ever
2144 * change in future for legacy-rx mode on, then lets also
2145 * add xdp->data_meta handling here.
2146 */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002147
2148 /* allocate a skb to store the frags */
2149 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
2150 if (unlikely(!skb))
2151 return NULL;
2152
2153 if (size > IXGBE_RX_HDR_SIZE) {
2154 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2155 IXGBE_CB(skb)->dma = rx_buffer->dma;
2156
2157 skb_add_rx_frag(skb, 0, rx_buffer->page,
John Fastabend92470802017-04-24 03:30:17 -07002158 xdp->data - page_address(rx_buffer->page),
Alexander Duyck3fd218762017-01-17 08:36:45 -08002159 size, truesize);
2160#if (PAGE_SIZE < 8192)
2161 rx_buffer->page_offset ^= truesize;
2162#else
2163 rx_buffer->page_offset += truesize;
2164#endif
2165 } else {
John Fastabend92470802017-04-24 03:30:17 -07002166 memcpy(__skb_put(skb, size),
2167 xdp->data, ALIGN(size, sizeof(long)));
Alexander Duyck3fd218762017-01-17 08:36:45 -08002168 rx_buffer->pagecnt_bias++;
2169 }
Alexander Duyck18806c92012-07-20 08:08:44 +00002170
2171 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002172}
2173
Alexander Duyck6f429222017-01-17 08:37:13 -08002174static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
2175 struct ixgbe_rx_buffer *rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002176 struct xdp_buff *xdp,
2177 union ixgbe_adv_rx_desc *rx_desc)
Alexander Duyck6f429222017-01-17 08:37:13 -08002178{
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002179 unsigned int metasize = xdp->data - xdp->data_meta;
Alexander Duyck6f429222017-01-17 08:37:13 -08002180#if (PAGE_SIZE < 8192)
2181 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2182#else
2183 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
John Fastabend92470802017-04-24 03:30:17 -07002184 SKB_DATA_ALIGN(xdp->data_end -
2185 xdp->data_hard_start);
Alexander Duyck6f429222017-01-17 08:37:13 -08002186#endif
2187 struct sk_buff *skb;
2188
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002189 /* Prefetch first cache line of first page. If xdp->data_meta
2190 * is unused, this points extactly as xdp->data, otherwise we
2191 * likely have a consumer accessing first few bytes of meta
2192 * data, and then actual data.
2193 */
2194 prefetch(xdp->data_meta);
Alexander Duyck6f429222017-01-17 08:37:13 -08002195#if L1_CACHE_BYTES < 128
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002196 prefetch(xdp->data_meta + L1_CACHE_BYTES);
Alexander Duyck6f429222017-01-17 08:37:13 -08002197#endif
2198
John Fastabend92470802017-04-24 03:30:17 -07002199 /* build an skb to around the page buffer */
2200 skb = build_skb(xdp->data_hard_start, truesize);
Alexander Duyck6f429222017-01-17 08:37:13 -08002201 if (unlikely(!skb))
2202 return NULL;
2203
2204 /* update pointers within the skb to store the data */
John Fastabend92470802017-04-24 03:30:17 -07002205 skb_reserve(skb, xdp->data - xdp->data_hard_start);
2206 __skb_put(skb, xdp->data_end - xdp->data);
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002207 if (metasize)
2208 skb_metadata_set(skb, metasize);
Alexander Duyck6f429222017-01-17 08:37:13 -08002209
2210 /* record DMA address if this is the start of a chain of buffers */
2211 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2212 IXGBE_CB(skb)->dma = rx_buffer->dma;
2213
2214 /* update buffer offset */
2215#if (PAGE_SIZE < 8192)
2216 rx_buffer->page_offset ^= truesize;
2217#else
2218 rx_buffer->page_offset += truesize;
2219#endif
2220
2221 return skb;
2222}
2223
John Fastabend92470802017-04-24 03:30:17 -07002224#define IXGBE_XDP_PASS 0
2225#define IXGBE_XDP_CONSUMED 1
John Fastabend33fdc822017-04-24 03:30:18 -07002226#define IXGBE_XDP_TX 2
John Fastabend92470802017-04-24 03:30:17 -07002227
John Fastabend33fdc822017-04-24 03:30:18 -07002228static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
2229 struct xdp_buff *xdp);
2230
2231static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
2232 struct ixgbe_ring *rx_ring,
John Fastabend92470802017-04-24 03:30:17 -07002233 struct xdp_buff *xdp)
2234{
John Fastabend64530732017-07-17 09:28:12 -07002235 int err, result = IXGBE_XDP_PASS;
John Fastabend92470802017-04-24 03:30:17 -07002236 struct bpf_prog *xdp_prog;
2237 u32 act;
2238
2239 rcu_read_lock();
2240 xdp_prog = READ_ONCE(rx_ring->xdp_prog);
2241
2242 if (!xdp_prog)
2243 goto xdp_out;
2244
2245 act = bpf_prog_run_xdp(xdp_prog, xdp);
2246 switch (act) {
2247 case XDP_PASS:
2248 break;
John Fastabend33fdc822017-04-24 03:30:18 -07002249 case XDP_TX:
2250 result = ixgbe_xmit_xdp_ring(adapter, xdp);
2251 break;
John Fastabend64530732017-07-17 09:28:12 -07002252 case XDP_REDIRECT:
John Fastabend5acaee02017-07-17 09:28:35 -07002253 err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog);
John Fastabend64530732017-07-17 09:28:12 -07002254 if (!err)
2255 result = IXGBE_XDP_TX;
2256 else
2257 result = IXGBE_XDP_CONSUMED;
2258 break;
John Fastabend92470802017-04-24 03:30:17 -07002259 default:
2260 bpf_warn_invalid_xdp_action(act);
Tony Nguyen93df9462017-05-31 04:43:47 -07002261 /* fallthrough */
John Fastabend92470802017-04-24 03:30:17 -07002262 case XDP_ABORTED:
2263 trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
2264 /* fallthrough -- handle aborts by dropping packet */
2265 case XDP_DROP:
2266 result = IXGBE_XDP_CONSUMED;
2267 break;
2268 }
2269xdp_out:
2270 rcu_read_unlock();
2271 return ERR_PTR(-result);
2272}
2273
John Fastabend33fdc822017-04-24 03:30:18 -07002274static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
2275 struct ixgbe_rx_buffer *rx_buffer,
2276 unsigned int size)
2277{
2278#if (PAGE_SIZE < 8192)
2279 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2280
2281 rx_buffer->page_offset ^= truesize;
2282#else
2283 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2284 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2285 SKB_DATA_ALIGN(size);
2286
2287 rx_buffer->page_offset += truesize;
2288#endif
2289}
2290
Alexander Duyckf8003262012-03-03 02:35:52 +00002291/**
2292 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2293 * @q_vector: structure containing interrupt and ring information
2294 * @rx_ring: rx descriptor ring to transact packets on
2295 * @budget: Total limit on number of packets to process
2296 *
2297 * This function provides a "bounce buffer" approach to Rx interrupt
2298 * processing. The advantage to this is that on systems that have
2299 * expensive overhead for IOMMU access this provides a means of avoiding
2300 * it by maintaining the mapping of the page to the syste.
2301 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002302 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002303 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002304static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002305 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002306 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002307{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002308 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00002309 struct ixgbe_adapter *adapter = q_vector->adapter;
John Fastabend33fdc822017-04-24 03:30:18 -07002310#ifdef IXGBE_FCOE
Mark Rustad4ffdf912012-07-18 06:05:50 +00002311 int ddp_bytes;
2312 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002313#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002314 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
John Fastabend7379f972017-03-28 09:47:03 -07002315 bool xdp_xmit = false;
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01002316 struct xdp_buff xdp;
2317
2318 xdp.rxq = &rx_ring->xdp_rxq;
Auke Kok9a799d72007-09-15 14:07:45 -07002319
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002320 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002321 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002322 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyckf8003262012-03-03 02:35:52 +00002323 struct sk_buff *skb;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002324 unsigned int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002325
Alexander Duyckf8003262012-03-03 02:35:52 +00002326 /* return some buffers to hardware, one at a time is too slow */
2327 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2328 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2329 cleaned_count = 0;
2330 }
Auke Kok9a799d72007-09-15 14:07:45 -07002331
Alexander Duyck18806c92012-07-20 08:08:44 +00002332 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002333 size = le16_to_cpu(rx_desc->wb.upper.length);
2334 if (!size)
Alexander Duyckf8003262012-03-03 02:35:52 +00002335 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002336
Alexander Duyck124b74c2014-12-11 15:02:28 -08002337 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002338 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002339 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002340 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002341 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002342
Alexander Duyck3fd218762017-01-17 08:36:45 -08002343 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
2344
Alexander Duyck18806c92012-07-20 08:08:44 +00002345 /* retrieve a buffer from the ring */
John Fastabend92470802017-04-24 03:30:17 -07002346 if (!skb) {
2347 xdp.data = page_address(rx_buffer->page) +
2348 rx_buffer->page_offset;
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002349 xdp.data_meta = xdp.data;
John Fastabend92470802017-04-24 03:30:17 -07002350 xdp.data_hard_start = xdp.data -
2351 ixgbe_rx_offset(rx_ring);
2352 xdp.data_end = xdp.data + size;
2353
John Fastabend33fdc822017-04-24 03:30:18 -07002354 skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
John Fastabend92470802017-04-24 03:30:17 -07002355 }
2356
2357 if (IS_ERR(skb)) {
John Fastabend7379f972017-03-28 09:47:03 -07002358 if (PTR_ERR(skb) == -IXGBE_XDP_TX) {
2359 xdp_xmit = true;
John Fastabend33fdc822017-04-24 03:30:18 -07002360 ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
John Fastabend7379f972017-03-28 09:47:03 -07002361 } else {
John Fastabend33fdc822017-04-24 03:30:18 -07002362 rx_buffer->pagecnt_bias++;
John Fastabend7379f972017-03-28 09:47:03 -07002363 }
John Fastabend92470802017-04-24 03:30:17 -07002364 total_rx_packets++;
2365 total_rx_bytes += size;
John Fastabend92470802017-04-24 03:30:17 -07002366 } else if (skb) {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002367 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
John Fastabend92470802017-04-24 03:30:17 -07002368 } else if (ring_uses_build_skb(rx_ring)) {
Alexander Duyck6f429222017-01-17 08:37:13 -08002369 skb = ixgbe_build_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002370 &xdp, rx_desc);
2371 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002372 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002373 &xdp, rx_desc);
2374 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002375
Alexander Duyck18806c92012-07-20 08:08:44 +00002376 /* exit if we failed to retrieve a buffer */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002377 if (!skb) {
2378 rx_ring->rx_stats.alloc_rx_buff_failed++;
2379 rx_buffer->pagecnt_bias++;
Alexander Duyck18806c92012-07-20 08:08:44 +00002380 break;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002381 }
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002382
Alexander Duyck3fd218762017-01-17 08:36:45 -08002383 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002384 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002385
Alexander Duyckf8003262012-03-03 02:35:52 +00002386 /* place incomplete frames back on ring for completion */
2387 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2388 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002389
Alexander Duyckf8003262012-03-03 02:35:52 +00002390 /* verify the packet layout is correct */
2391 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2392 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002393
2394 /* probably a little skewed due to removing CRC */
2395 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002396
Alexander Duyck8a0da212012-01-31 02:59:49 +00002397 /* populate checksum, timestamp, VLAN, and protocol */
2398 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2399
Yi Zou332d4a72009-05-13 13:11:53 +00002400#ifdef IXGBE_FCOE
2401 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002402 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002403 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002404 /* include DDPed FCoE data */
2405 if (ddp_bytes > 0) {
2406 if (!mss) {
2407 mss = rx_ring->netdev->mtu -
2408 sizeof(struct fcoe_hdr) -
2409 sizeof(struct fc_frame_header) -
2410 sizeof(struct fcoe_crc_eof);
2411 if (mss > 512)
2412 mss &= ~511;
2413 }
2414 total_rx_bytes += ddp_bytes;
2415 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2416 mss);
2417 }
David S. Miller823dcd22011-08-20 10:39:12 -07002418 if (!ddp_bytes) {
2419 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002420 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002421 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002422 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002423
Yi Zou332d4a72009-05-13 13:11:53 +00002424#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002425 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002426
Alexander Duyckf8003262012-03-03 02:35:52 +00002427 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002428 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002429 }
Auke Kok9a799d72007-09-15 14:07:45 -07002430
John Fastabend7379f972017-03-28 09:47:03 -07002431 if (xdp_xmit) {
2432 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
2433
2434 /* Force memory writes to complete before letting h/w
2435 * know there are new descriptors to fetch.
2436 */
2437 wmb();
2438 writel(ring->next_to_use, ring->tail);
John Fastabend11393cc2017-07-17 09:29:40 -07002439
2440 xdp_do_flush_map();
John Fastabend7379f972017-03-28 09:47:03 -07002441 }
2442
Alexander Duyckc267fc12010-11-16 19:27:00 -08002443 u64_stats_update_begin(&rx_ring->syncp);
2444 rx_ring->stats.packets += total_rx_packets;
2445 rx_ring->stats.bytes += total_rx_bytes;
2446 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002447 q_vector->rx.total_packets += total_rx_packets;
2448 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002449
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002450 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002451}
2452
Auke Kok9a799d72007-09-15 14:07:45 -07002453/**
2454 * ixgbe_configure_msix - Configure MSI-X hardware
2455 * @adapter: board private structure
2456 *
2457 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2458 * interrupts.
2459 **/
2460static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2461{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002462 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002463 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002464 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002465
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002466 /* Populate MSIX to EITR Select */
2467 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002468 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002469 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2470 }
2471
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002472 /*
2473 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002474 * corresponding register.
2475 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002476 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002477 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002478 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002479
Alexander Duycka5579282012-02-08 07:50:04 +00002480 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002481 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002482
Alexander Duycka5579282012-02-08 07:50:04 +00002483 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002484 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002485
Alexander Duyckfe49f042009-06-04 16:00:09 +00002486 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002487 }
2488
Alexander Duyckbd508172010-11-16 19:27:03 -08002489 switch (adapter->hw.mac.type) {
2490 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002491 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002492 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002493 break;
2494 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002495 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002496 case ixgbe_mac_X550:
2497 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002498 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002499 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002500 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002501 default:
2502 break;
2503 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002504 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002505
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002506 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002507 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002508 mask &= ~(IXGBE_EIMS_OTHER |
2509 IXGBE_EIMS_MAILBOX |
2510 IXGBE_EIMS_LSC);
2511
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002512 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002513}
2514
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002515/**
2516 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002517 * @q_vector: structure containing interrupt and ring information
2518 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002519 *
2520 * Stores a new ITR value based on packets and byte
2521 * counts during the last interrupt. The advantage of per interrupt
2522 * computation is faster updates and more accurate ITR for the current
2523 * traffic pattern. Constants in this function were computed
2524 * based on theoretical maximum wire speed and thresholds were set based
2525 * on testing data as well as attempting to minimize response time
2526 * while increasing bulk throughput.
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002527 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002528static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2529 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002530{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002531 unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS |
2532 IXGBE_ITR_ADAPTIVE_LATENCY;
2533 unsigned int avg_wire_size, packets, bytes;
2534 unsigned long next_update = jiffies;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002535
Alexander Duyckb4ded832017-09-25 14:55:36 -07002536 /* If we don't have any rings just leave ourselves set for maximum
2537 * possible latency so we take ourselves out of the equation.
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002538 */
Alexander Duyckb4ded832017-09-25 14:55:36 -07002539 if (!ring_container->ring)
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002540 return;
2541
Alexander Duyckb4ded832017-09-25 14:55:36 -07002542 /* If we didn't update within up to 1 - 2 jiffies we can assume
2543 * that either packets are coming in so slow there hasn't been
2544 * any work, or that there is so much work that NAPI is dealing
2545 * with interrupt moderation and we don't need to do anything.
2546 */
2547 if (time_after(next_update, ring_container->next_update))
2548 goto clear_counts;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002549
Alexander Duyckb4ded832017-09-25 14:55:36 -07002550 packets = ring_container->total_packets;
2551
2552 /* We have no packets to actually measure against. This means
2553 * either one of the other queues on this vector is active or
2554 * we are a Tx queue doing TSO with too high of an interrupt rate.
2555 *
2556 * When this occurs just tick up our delay by the minimum value
2557 * and hope that this extra delay will prevent us from being called
2558 * without any work on our queue.
2559 */
2560 if (!packets) {
2561 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2562 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2563 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2564 itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY;
2565 goto clear_counts;
2566 }
2567
2568 bytes = ring_container->total_bytes;
2569
2570 /* If packets are less than 4 or bytes are less than 9000 assume
2571 * insufficient data to use bulk rate limiting approach. We are
2572 * likely latency driven.
2573 */
2574 if (packets < 4 && bytes < 9000) {
2575 itr = IXGBE_ITR_ADAPTIVE_LATENCY;
2576 goto adjust_by_size;
2577 }
2578
2579 /* Between 4 and 48 we can assume that our current interrupt delay
2580 * is only slightly too low. As such we should increase it by a small
2581 * fixed amount.
2582 */
2583 if (packets < 48) {
2584 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2585 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2586 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2587 goto clear_counts;
2588 }
2589
2590 /* Between 48 and 96 is our "goldilocks" zone where we are working
2591 * out "just right". Just report that our current ITR is good for us.
2592 */
2593 if (packets < 96) {
2594 itr = q_vector->itr >> 2;
2595 goto clear_counts;
2596 }
2597
2598 /* If packet count is 96 or greater we are likely looking at a slight
2599 * overrun of the delay we want. Try halving our delay to see if that
2600 * will cut the number of packets in half per interrupt.
2601 */
2602 if (packets < 256) {
2603 itr = q_vector->itr >> 3;
2604 if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS)
2605 itr = IXGBE_ITR_ADAPTIVE_MIN_USECS;
2606 goto clear_counts;
2607 }
2608
2609 /* The paths below assume we are dealing with a bulk ITR since number
2610 * of packets is 256 or greater. We are just going to have to compute
2611 * a value and try to bring the count under control, though for smaller
2612 * packet sizes there isn't much we can do as NAPI polling will likely
2613 * be kicking in sooner rather than later.
2614 */
2615 itr = IXGBE_ITR_ADAPTIVE_BULK;
2616
2617adjust_by_size:
2618 /* If packet counts are 256 or greater we can assume we have a gross
2619 * overestimation of what the rate should be. Instead of trying to fine
2620 * tune it just use the formula below to try and dial in an exact value
2621 * give the current packet size of the frame.
2622 */
2623 avg_wire_size = bytes / packets;
2624
2625 /* The following is a crude approximation of:
2626 * wmem_default / (size + overhead) = desired_pkts_per_int
2627 * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
2628 * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
2629 *
2630 * Assuming wmem_default is 212992 and overhead is 640 bytes per
2631 * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
2632 * formula down to
2633 *
2634 * (170 * (size + 24)) / (size + 640) = ITR
2635 *
2636 * We first do some math on the packet size and then finally bitshift
2637 * by 8 after rounding up. We also have to account for PCIe link speed
2638 * difference as ITR scales based on this.
2639 */
2640 if (avg_wire_size <= 60) {
2641 /* Start at 50k ints/sec */
2642 avg_wire_size = 5120;
2643 } else if (avg_wire_size <= 316) {
2644 /* 50K ints/sec to 16K ints/sec */
2645 avg_wire_size *= 40;
2646 avg_wire_size += 2720;
2647 } else if (avg_wire_size <= 1084) {
2648 /* 16K ints/sec to 9.2K ints/sec */
2649 avg_wire_size *= 15;
2650 avg_wire_size += 11452;
2651 } else if (avg_wire_size <= 1980) {
2652 /* 9.2K ints/sec to 8K ints/sec */
2653 avg_wire_size *= 5;
2654 avg_wire_size += 22420;
2655 } else {
2656 /* plateau at a limit of 8K ints/sec */
2657 avg_wire_size = 32256;
2658 }
2659
2660 /* If we are in low latency mode half our delay which doubles the rate
2661 * to somewhere between 100K to 16K ints/sec
2662 */
2663 if (itr & IXGBE_ITR_ADAPTIVE_LATENCY)
2664 avg_wire_size >>= 1;
2665
2666 /* Resultant value is 256 times larger than it needs to be. This
2667 * gives us room to adjust the value as needed to either increase
2668 * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
2669 *
2670 * Use addition as we have already recorded the new latency flag
2671 * for the ITR value.
2672 */
2673 switch (q_vector->adapter->link_speed) {
2674 case IXGBE_LINK_SPEED_10GB_FULL:
2675 case IXGBE_LINK_SPEED_100_FULL:
2676 default:
2677 itr += DIV_ROUND_UP(avg_wire_size,
2678 IXGBE_ITR_ADAPTIVE_MIN_INC * 256) *
2679 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002680 break;
Alexander Duyckb4ded832017-09-25 14:55:36 -07002681 case IXGBE_LINK_SPEED_2_5GB_FULL:
2682 case IXGBE_LINK_SPEED_1GB_FULL:
2683 case IXGBE_LINK_SPEED_10_FULL:
2684 itr += DIV_ROUND_UP(avg_wire_size,
2685 IXGBE_ITR_ADAPTIVE_MIN_INC * 64) *
2686 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002687 break;
2688 }
2689
Alexander Duyckb4ded832017-09-25 14:55:36 -07002690clear_counts:
2691 /* write back value */
2692 ring_container->itr = itr;
2693
2694 /* next update should occur within next jiffy */
2695 ring_container->next_update = next_update + 1;
2696
Alexander Duyckbd198052011-06-11 01:45:08 +00002697 ring_container->total_bytes = 0;
2698 ring_container->total_packets = 0;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002699}
2700
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002701/**
2702 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002703 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002704 *
2705 * This function is made to be called by ethtool and by the driver
2706 * when it needs to update EITR registers at runtime. Hardware
2707 * specific quirks/differences are taken care of here.
2708 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002709void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002710{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002711 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002712 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002713 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002714 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002715
Alexander Duyckbd508172010-11-16 19:27:03 -08002716 switch (adapter->hw.mac.type) {
2717 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002718 /* must write high and low 16 bits to reset counter */
2719 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002720 break;
2721 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002722 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002723 case ixgbe_mac_X550:
2724 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002725 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002726 /*
2727 * set the WDIS bit to not clear the timer bits and cause an
2728 * immediate assertion of the interrupt
2729 */
2730 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002731 break;
2732 default:
2733 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002734 }
2735 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2736}
2737
Alexander Duyckbd198052011-06-11 01:45:08 +00002738static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002739{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002740 u32 new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002741
Alexander Duyckbd198052011-06-11 01:45:08 +00002742 ixgbe_update_itr(q_vector, &q_vector->tx);
2743 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002744
Alexander Duyckb4ded832017-09-25 14:55:36 -07002745 /* use the smallest value of new ITR delay calculations */
2746 new_itr = min(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002747
Alexander Duyckb4ded832017-09-25 14:55:36 -07002748 /* Clear latency flag if set, shift into correct position */
2749 new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY;
2750 new_itr <<= 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002751
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002752 if (new_itr != q_vector->itr) {
Alexander Duyckbd198052011-06-11 01:45:08 +00002753 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002754 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002755
2756 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002757 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002758}
2759
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002760/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002761 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002762 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002763 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002764static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002765{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002766 struct ixgbe_hw *hw = &adapter->hw;
2767 u32 eicr = adapter->interrupt_event;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002768 s32 rc;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002769
Alexander Duyckf0f97782011-04-22 04:08:09 +00002770 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002771 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002772
Mark Rustad22cb4ff2017-04-25 13:55:25 -07002773 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
Alexander Duyckf0f97782011-04-22 04:08:09 +00002774 return;
2775
2776 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2777
Joe Perches7ca647b2010-09-07 21:35:40 +00002778 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002779 case IXGBE_DEV_ID_82599_T3_LOM:
2780 /*
2781 * Since the warning interrupt is for both ports
2782 * we don't have to check if:
2783 * - This interrupt wasn't for our port.
2784 * - We may have missed the interrupt so always have to
2785 * check if we got a LSC
2786 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002787 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002788 !(eicr & IXGBE_EICR_LSC))
2789 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002790
Alexander Duyckf0f97782011-04-22 04:08:09 +00002791 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002792 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002793 bool link_up = false;
2794
Josh Hay3d292262012-12-15 03:28:19 +00002795 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002796
Alexander Duyckf0f97782011-04-22 04:08:09 +00002797 if (link_up)
2798 return;
2799 }
2800
2801 /* Check if this is not due to overtemp */
2802 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2803 return;
2804
2805 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002806 case IXGBE_DEV_ID_X550EM_A_1G_T:
2807 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2808 rc = hw->phy.ops.check_overtemp(hw);
2809 if (rc != IXGBE_ERR_OVERTEMP)
2810 return;
2811 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002812 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002813 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2814 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002815 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002816 return;
2817 break;
2818 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002819 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002820
2821 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002822}
2823
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002824static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2825{
2826 struct ixgbe_hw *hw = &adapter->hw;
2827
2828 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002829 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002830 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002831 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002832 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002833 }
2834}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002835
Jacob Keller4f51bf72011-08-20 04:49:45 +00002836static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2837{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002838 struct ixgbe_hw *hw = &adapter->hw;
2839
Jacob Keller4f51bf72011-08-20 04:49:45 +00002840 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2841 return;
2842
2843 switch (adapter->hw.mac.type) {
2844 case ixgbe_mac_82599EB:
2845 /*
2846 * Need to check link state so complete overtemp check
2847 * on service task
2848 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002849 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2850 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002851 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2852 adapter->interrupt_event = eicr;
2853 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2854 ixgbe_service_event_schedule(adapter);
2855 return;
2856 }
2857 return;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002858 case ixgbe_mac_x550em_a:
2859 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2860 adapter->interrupt_event = eicr;
2861 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2862 ixgbe_service_event_schedule(adapter);
2863 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2864 IXGBE_EICR_GPI_SDP0_X550EM_a);
2865 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2866 IXGBE_EICR_GPI_SDP0_X550EM_a);
2867 }
2868 return;
2869 case ixgbe_mac_X550:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002870 case ixgbe_mac_X540:
2871 if (!(eicr & IXGBE_EICR_TS))
2872 return;
2873 break;
2874 default:
2875 return;
2876 }
2877
Don Skidmoref44e7512015-06-09 16:36:23 -07002878 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002879}
2880
Don Skidmore45788d22015-06-09 16:59:04 -07002881static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2882{
2883 switch (hw->mac.type) {
2884 case ixgbe_mac_82598EB:
2885 if (hw->phy.type == ixgbe_phy_nl)
2886 return true;
2887 return false;
2888 case ixgbe_mac_82599EB:
2889 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002890 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002891 switch (hw->mac.ops.get_media_type(hw)) {
2892 case ixgbe_media_type_fiber:
2893 case ixgbe_media_type_fiber_qsfp:
2894 return true;
2895 default:
2896 return false;
2897 }
2898 default:
2899 return false;
2900 }
2901}
2902
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002903static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2904{
2905 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002906 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002907
Don Skidmore4ccc6502015-09-02 13:47:54 -07002908 if (!ixgbe_is_sfp(hw))
2909 return;
2910
2911 /* Later MAC's use different SDP */
2912 if (hw->mac.type >= ixgbe_mac_X540)
2913 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2914
2915 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002916 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002917 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002918 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2919 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002920 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002921 ixgbe_service_event_schedule(adapter);
2922 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002923 }
2924
Don Skidmore4ccc6502015-09-02 13:47:54 -07002925 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2926 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002927 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002928 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002929 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2930 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2931 ixgbe_service_event_schedule(adapter);
2932 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002933 }
2934}
2935
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002936static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2937{
2938 struct ixgbe_hw *hw = &adapter->hw;
2939
2940 adapter->lsc_int++;
2941 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2942 adapter->link_check_timeout = jiffies;
2943 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2944 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002945 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002946 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002947 }
2948}
2949
Alexander Duyckfe49f042009-06-04 16:00:09 +00002950static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2951 u64 qmask)
2952{
2953 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002954 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002955
Alexander Duyckbd508172010-11-16 19:27:03 -08002956 switch (hw->mac.type) {
2957 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002958 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002959 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2960 break;
2961 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002962 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002963 case ixgbe_mac_X550:
2964 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002965 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002966 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002967 if (mask)
2968 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002969 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002970 if (mask)
2971 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2972 break;
2973 default:
2974 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002975 }
2976 /* skip the flush */
2977}
2978
2979static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002980 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002981{
2982 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002983 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002984
Alexander Duyckbd508172010-11-16 19:27:03 -08002985 switch (hw->mac.type) {
2986 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002987 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002988 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2989 break;
2990 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002991 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002992 case ixgbe_mac_X550:
2993 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002994 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002995 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002996 if (mask)
2997 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002998 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002999 if (mask)
3000 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
3001 break;
3002 default:
3003 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003004 }
3005 /* skip the flush */
3006}
3007
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003008/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00003009 * ixgbe_irq_enable - Enable default interrupt generation settings
3010 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003011 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00003012static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
3013 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07003014{
Don Skidmore9a900ec2015-06-09 17:15:01 -07003015 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00003016 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003017
Alexander Duyck2c4af692011-07-15 07:29:55 +00003018 /* don't reenable LSC while waiting for link */
3019 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
3020 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003021
Alexander Duyck2c4af692011-07-15 07:29:55 +00003022 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00003023 switch (adapter->hw.mac.type) {
3024 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003025 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003026 break;
3027 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003028 case ixgbe_mac_X550:
3029 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003030 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00003031 mask |= IXGBE_EIMS_TS;
3032 break;
3033 default:
3034 break;
3035 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003036 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07003037 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003038 switch (adapter->hw.mac.type) {
3039 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003040 mask |= IXGBE_EIMS_GPI_SDP1(hw);
3041 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003042 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00003043 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003044 case ixgbe_mac_X550:
3045 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003046 case ixgbe_mac_x550em_a:
3047 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07003048 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07003049 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07003050 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07003051 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
3052 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00003053 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00003054 mask |= IXGBE_EIMS_MAILBOX;
3055 break;
3056 default:
3057 break;
3058 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003059
Alexander Duyck2c4af692011-07-15 07:29:55 +00003060 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
3061 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
3062 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003063
Alexander Duyck2c4af692011-07-15 07:29:55 +00003064 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
3065 if (queues)
3066 ixgbe_irq_enable_queues(adapter, ~0);
3067 if (flush)
3068 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07003069}
3070
Alexander Duyck2c4af692011-07-15 07:29:55 +00003071static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003072{
Alexander Duyck2c4af692011-07-15 07:29:55 +00003073 struct ixgbe_adapter *adapter = data;
3074 struct ixgbe_hw *hw = &adapter->hw;
3075 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003076
Alexander Duyck2c4af692011-07-15 07:29:55 +00003077 /*
3078 * Workaround for Silicon errata. Use clear-by-write instead
3079 * of clear-by-read. Reading with EICS will return the
3080 * interrupt causes without clearing, which later be done
3081 * with the write to EICR.
3082 */
3083 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00003084
3085 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08003086 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00003087 * the bits are high when ixgbe_msix_other is called. There is a race
3088 * condition otherwise which results in possible performance loss
3089 * especially if the ixgbe_msix_other interrupt is triggering
3090 * consistently (as it would when PPS is turned on for the X540 device)
3091 */
3092 eicr &= 0xFFFF0000;
3093
Alexander Duyck2c4af692011-07-15 07:29:55 +00003094 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003095
Alexander Duyck2c4af692011-07-15 07:29:55 +00003096 if (eicr & IXGBE_EICR_LSC)
3097 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003098
Alexander Duyck2c4af692011-07-15 07:29:55 +00003099 if (eicr & IXGBE_EICR_MAILBOX)
3100 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003101
Alexander Duyck2c4af692011-07-15 07:29:55 +00003102 switch (hw->mac.type) {
3103 case ixgbe_mac_82599EB:
3104 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003105 case ixgbe_mac_X550:
3106 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003107 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07003108 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
3109 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
3110 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
3111 ixgbe_service_event_schedule(adapter);
3112 IXGBE_WRITE_REG(hw, IXGBE_EICR,
3113 IXGBE_EICR_GPI_SDP0_X540);
3114 }
Don Skidmored773ce22014-02-25 17:58:53 -08003115 if (eicr & IXGBE_EICR_ECC) {
3116 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003117 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003118 ixgbe_service_event_schedule(adapter);
3119 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3120 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003121 /* Handle Flow Director Full threshold interrupt */
3122 if (eicr & IXGBE_EICR_FLOW_DIR) {
3123 int reinit_count = 0;
3124 int i;
3125 for (i = 0; i < adapter->num_tx_queues; i++) {
3126 struct ixgbe_ring *ring = adapter->tx_ring[i];
3127 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
3128 &ring->state))
3129 reinit_count++;
3130 }
3131 if (reinit_count) {
3132 /* no more flow director interrupts until after init */
3133 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
3134 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
3135 ixgbe_service_event_schedule(adapter);
3136 }
3137 }
3138 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003139 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003140 break;
3141 default:
3142 break;
Auke Kok9a799d72007-09-15 14:07:45 -07003143 }
3144
Alexander Duyck2c4af692011-07-15 07:29:55 +00003145 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003146
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003147 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003148 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003149
Alexander Duyck2c4af692011-07-15 07:29:55 +00003150 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00003151 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00003152 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003153
Alexander Duyck2c4af692011-07-15 07:29:55 +00003154 return IRQ_HANDLED;
3155}
3156
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003157static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07003158{
3159 struct ixgbe_q_vector *q_vector = data;
3160
Auke Kok9a799d72007-09-15 14:07:45 -07003161 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003162
3163 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07003164 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003165
3166 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003167}
3168
Auke Kok9a799d72007-09-15 14:07:45 -07003169/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00003170 * ixgbe_poll - NAPI Rx polling callback
3171 * @napi: structure for representing this polling device
3172 * @budget: how many packets driver is allowed to clean
3173 *
3174 * This function is used for legacy and MSI, NAPI mode
3175 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00003176int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00003177{
3178 struct ixgbe_q_vector *q_vector =
3179 container_of(napi, struct ixgbe_q_vector, napi);
3180 struct ixgbe_adapter *adapter = q_vector->adapter;
3181 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003182 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00003183 bool clean_complete = true;
3184
3185#ifdef CONFIG_IXGBE_DCA
3186 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
3187 ixgbe_update_dca(q_vector);
3188#endif
3189
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003190 ixgbe_for_each_ring(ring, q_vector->tx) {
3191 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
3192 clean_complete = false;
3193 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003194
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08003195 /* Exit if we are called by netpoll */
3196 if (budget <= 0)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003197 return budget;
3198
Alexander Duyckeb01b972012-02-08 07:51:27 +00003199 /* attempt to distribute budget to each queue fairly, but don't allow
3200 * the budget to go below 1 because we'll exit polling */
3201 if (q_vector->rx.count > 1)
3202 per_ring_budget = max(budget/q_vector->rx.count, 1);
3203 else
3204 per_ring_budget = budget;
3205
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003206 ixgbe_for_each_ring(ring, q_vector->rx) {
3207 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
3208 per_ring_budget);
3209
3210 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003211 if (cleaned >= per_ring_budget)
3212 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003213 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003214
3215 /* If all work not completed, return budget and keep polling */
3216 if (!clean_complete)
3217 return budget;
3218
3219 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003220 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003221 if (adapter->rx_itr_setting & 1)
3222 ixgbe_set_itr(q_vector);
3223 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003224 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00003225
Paolo Abeni4b732cd2016-06-15 15:37:59 +02003226 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003227}
3228
3229/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003230 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
3231 * @adapter: board private structure
3232 *
3233 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
3234 * interrupts from the kernel.
3235 **/
3236static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
3237{
3238 struct net_device *netdev = adapter->netdev;
Tony Nguyene61e4c82017-05-12 11:38:07 -07003239 unsigned int ri = 0, ti = 0;
Alexander Duyck207867f2011-07-15 03:05:37 +00003240 int vector, err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003241
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003242 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003243 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00003244 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08003245
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003246 if (q_vector->tx.ring && q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003247 snprintf(q_vector->name, sizeof(q_vector->name),
3248 "%s-TxRx-%u", netdev->name, ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003249 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003250 } else if (q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003251 snprintf(q_vector->name, sizeof(q_vector->name),
3252 "%s-rx-%u", netdev->name, ri++);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003253 } else if (q_vector->tx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003254 snprintf(q_vector->name, sizeof(q_vector->name),
3255 "%s-tx-%u", netdev->name, ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003256 } else {
3257 /* skip this unused q_vector */
3258 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003259 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003260 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
3261 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003262 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00003263 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00003264 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003265 goto free_queue_irqs;
3266 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003267 /* If Flow Director is enabled, set interrupt affinity */
3268 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3269 /* assign the mask for this irq */
3270 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00003271 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00003272 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003273 }
3274
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003275 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00003276 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003277 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00003278 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003279 goto free_queue_irqs;
3280 }
3281
3282 return 0;
3283
3284free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00003285 while (vector) {
3286 vector--;
3287 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3288 NULL);
3289 free_irq(adapter->msix_entries[vector].vector,
3290 adapter->q_vector[vector]);
3291 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003292 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3293 pci_disable_msix(adapter->pdev);
3294 kfree(adapter->msix_entries);
3295 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003296 return err;
3297}
3298
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08003299/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003300 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07003301 * @irq: interrupt number
3302 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07003303 **/
3304static irqreturn_t ixgbe_intr(int irq, void *data)
3305{
Alexander Duycka65151ba22011-05-27 05:31:32 +00003306 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07003307 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003308 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003309 u32 eicr;
3310
Don Skidmore54037502009-02-21 15:42:56 -08003311 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00003312 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08003313 * before the read of EICR.
3314 */
3315 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3316
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003317 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003318 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003319 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003320 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003321 /*
3322 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003323 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003324 * have disabled interrupts due to EIAM
3325 * finish the workaround of silicon errata on 82598. Unmask
3326 * the interrupt that we masked before the EICR read.
3327 */
3328 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3329 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003330 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003331 }
Auke Kok9a799d72007-09-15 14:07:45 -07003332
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003333 if (eicr & IXGBE_EICR_LSC)
3334 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003335
Alexander Duyckbd508172010-11-16 19:27:03 -08003336 switch (hw->mac.type) {
3337 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003338 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003339 /* Fall through */
3340 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003341 case ixgbe_mac_X550:
3342 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003343 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003344 if (eicr & IXGBE_EICR_ECC) {
3345 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003346 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003347 ixgbe_service_event_schedule(adapter);
3348 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3349 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003350 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003351 break;
3352 default:
3353 break;
3354 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003355
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003356 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003357 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003358 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003359
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003360 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003361 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003362
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003363 /*
3364 * re-enable link(maybe) and non-queue interrupts, no flush.
3365 * ixgbe_poll will re-enable the queue interrupts
3366 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003367 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3368 ixgbe_irq_enable(adapter, false, false);
3369
Auke Kok9a799d72007-09-15 14:07:45 -07003370 return IRQ_HANDLED;
3371}
3372
3373/**
3374 * ixgbe_request_irq - initialize interrupts
3375 * @adapter: board private structure
3376 *
3377 * Attempts to configure interrupts using the best available
3378 * capabilities of the hardware and kernel.
3379 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003380static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003381{
3382 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003383 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003384
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003385 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003386 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003387 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003388 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003389 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003390 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003391 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003392 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003393
Alexander Duyckde88eee2012-02-08 07:49:59 +00003394 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003395 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003396
Auke Kok9a799d72007-09-15 14:07:45 -07003397 return err;
3398}
3399
3400static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3401{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003402 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003403
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003404 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003405 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003406 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003407 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003408
Mark Rustad1fa71252016-09-28 15:36:38 -07003409 if (!adapter->msix_entries)
3410 return;
3411
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003412 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3413 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3414 struct msix_entry *entry = &adapter->msix_entries[vector];
3415
3416 /* free only the irqs that were actually requested */
3417 if (!q_vector->rx.ring && !q_vector->tx.ring)
3418 continue;
3419
3420 /* clear the affinity_mask in the IRQ descriptor */
3421 irq_set_affinity_hint(entry->vector, NULL);
3422
3423 free_irq(entry->vector, q_vector);
3424 }
3425
Babu Moger90c6f872016-06-18 17:40:47 -07003426 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003427}
3428
3429/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003430 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3431 * @adapter: board private structure
3432 **/
3433static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3434{
Alexander Duyckbd508172010-11-16 19:27:03 -08003435 switch (adapter->hw.mac.type) {
3436 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003437 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003438 break;
3439 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003440 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003441 case ixgbe_mac_X550:
3442 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003443 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003444 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3445 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003446 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003447 break;
3448 default:
3449 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003450 }
3451 IXGBE_WRITE_FLUSH(&adapter->hw);
3452 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003453 int vector;
3454
3455 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3456 synchronize_irq(adapter->msix_entries[vector].vector);
3457
3458 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003459 } else {
3460 synchronize_irq(adapter->pdev->irq);
3461 }
3462}
3463
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003464/**
Auke Kok9a799d72007-09-15 14:07:45 -07003465 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3466 *
3467 **/
3468static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3469{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003470 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003471
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003472 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003473
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003474 ixgbe_set_ivar(adapter, 0, 0, 0);
3475 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003476
Emil Tantilov396e7992010-07-01 20:05:12 +00003477 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003478}
3479
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003480/**
3481 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3482 * @adapter: board private structure
3483 * @ring: structure containing ring specific data
3484 *
3485 * Configure the Tx descriptor ring after a reset.
3486 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003487void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3488 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003489{
3490 struct ixgbe_hw *hw = &adapter->hw;
3491 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003492 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003493 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003494 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003495
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003496 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003497 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003498 IXGBE_WRITE_FLUSH(hw);
3499
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003500 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003501 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003502 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3503 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3504 ring->count * sizeof(union ixgbe_adv_tx_desc));
3505 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3506 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003507 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003508
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003509 /*
3510 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003511 * higher than 1 when:
3512 * - ITR is 0 as it could cause false TX hangs
3513 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003514 *
3515 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3516 * to or less than the number of on chip descriptors, which is
3517 * currently 40.
3518 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003519 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003520 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003521 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003522 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003523
Alexander Duycke954b372012-02-08 07:49:38 +00003524 /*
3525 * Setting PTHRESH to 32 both improves performance
3526 * and avoids a TX hang with DFP enabled
3527 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003528 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003529 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003530
3531 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003532 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003533 ring->atr_sample_rate = adapter->atr_sample_rate;
3534 ring->atr_count = 0;
3535 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3536 } else {
3537 ring->atr_sample_rate = 0;
3538 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003539
Alexander Duyckfd786b72013-01-12 06:33:31 +00003540 /* initialize XPS */
3541 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3542 struct ixgbe_q_vector *q_vector = ring->q_vector;
3543
3544 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003545 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003546 &q_vector->affinity_mask,
3547 ring->queue_index);
3548 }
3549
John Fastabendc84d3242010-11-16 19:27:12 -08003550 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3551
Alexander Duyckffed21b2017-01-17 08:37:29 -08003552 /* reinitialize tx_buffer_info */
3553 memset(ring->tx_buffer_info, 0,
3554 sizeof(struct ixgbe_tx_buffer) * ring->count);
3555
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003556 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003557 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3558
3559 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3560 if (hw->mac.type == ixgbe_mac_82598EB &&
3561 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3562 return;
3563
3564 /* poll to verify queue is enabled */
3565 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003566 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003567 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3568 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3569 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003570 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003571}
3572
Alexander Duyck120ff942010-08-19 13:34:50 +00003573static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3574{
3575 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003576 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003577 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003578
3579 if (hw->mac.type == ixgbe_mac_82598EB)
3580 return;
3581
3582 /* disable the arbiter while setting MTQC */
3583 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3584 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3585 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3586
3587 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003588 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3589 mtqc = IXGBE_MTQC_VT_ENA;
3590 if (tcs > 4)
3591 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3592 else if (tcs > 1)
3593 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003594 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3595 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003596 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003597 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003598 mtqc |= IXGBE_MTQC_64VF;
3599 } else {
3600 if (tcs > 4)
3601 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3602 else if (tcs > 1)
3603 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3604 else
3605 mtqc = IXGBE_MTQC_64Q_1PB;
3606 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003607
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003608 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003609
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003610 /* Enable Security TX Buffer IFG for multiple pb */
3611 if (tcs) {
3612 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3613 sectx |= IXGBE_SECTX_DCB;
3614 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003615 }
3616
3617 /* re-enable the arbiter */
3618 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3619 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3620}
3621
Auke Kok9a799d72007-09-15 14:07:45 -07003622/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003623 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003624 * @adapter: board private structure
3625 *
3626 * Configure the Tx unit of the MAC after a reset.
3627 **/
3628static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3629{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003630 struct ixgbe_hw *hw = &adapter->hw;
3631 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003632 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003633
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003634 ixgbe_setup_mtqc(adapter);
3635
3636 if (hw->mac.type != ixgbe_mac_82598EB) {
3637 /* DMATXCTL.EN must be before Tx queues are enabled */
3638 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3639 dmatxctl |= IXGBE_DMATXCTL_TE;
3640 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3641 }
3642
Auke Kok9a799d72007-09-15 14:07:45 -07003643 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003644 for (i = 0; i < adapter->num_tx_queues; i++)
3645 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07003646 for (i = 0; i < adapter->num_xdp_queues; i++)
3647 ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003648}
3649
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003650static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3651 struct ixgbe_ring *ring)
3652{
3653 struct ixgbe_hw *hw = &adapter->hw;
3654 u8 reg_idx = ring->reg_idx;
3655 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3656
3657 srrctl |= IXGBE_SRRCTL_DROP_EN;
3658
3659 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3660}
3661
3662static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3663 struct ixgbe_ring *ring)
3664{
3665 struct ixgbe_hw *hw = &adapter->hw;
3666 u8 reg_idx = ring->reg_idx;
3667 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3668
3669 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3670
3671 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3672}
3673
3674#ifdef CONFIG_IXGBE_DCB
3675void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3676#else
3677static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3678#endif
3679{
3680 int i;
3681 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3682
3683 if (adapter->ixgbe_ieee_pfc)
3684 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3685
3686 /*
3687 * We should set the drop enable bit if:
3688 * SR-IOV is enabled
3689 * or
3690 * Number of Rx queues > 1 and flow control is disabled
3691 *
3692 * This allows us to avoid head of line blocking for security
3693 * and performance reasons.
3694 */
3695 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3696 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3697 for (i = 0; i < adapter->num_rx_queues; i++)
3698 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3699 } else {
3700 for (i = 0; i < adapter->num_rx_queues; i++)
3701 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3702 }
3703}
3704
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003705#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003706
Yi Zoua6616b42009-08-06 13:05:23 +00003707static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003708 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003709{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003710 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003711 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003712 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003713
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003714 if (hw->mac.type == ixgbe_mac_82598EB) {
3715 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3716
3717 /*
3718 * if VMDq is not active we must program one srrctl register
3719 * per RSS queue since we have enabled RDRXCTL.MVMEN
3720 */
3721 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003722 }
3723
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003724 /* configure header buffer length, needed for RSC */
3725 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003726
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003727 /* configure the packet buffer length */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003728 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3729 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3730 else
3731 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003732
3733 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003734 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003735
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003736 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003737}
3738
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003739/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003740 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003741 * @adapter: device handle
3742 *
3743 * - 82598/82599/X540: 128
3744 * - X550(non-SRIOV mode): 512
3745 * - X550(SRIOV mode): 64
3746 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003747u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003748{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003749 if (adapter->hw.mac.type < ixgbe_mac_X550)
3750 return 128;
3751 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3752 return 64;
3753 else
3754 return 512;
3755}
3756
3757/**
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003758 * ixgbe_store_key - Write the RSS key to HW
3759 * @adapter: device handle
3760 *
3761 * Write the RSS key stored in adapter.rss_key to HW.
3762 */
3763void ixgbe_store_key(struct ixgbe_adapter *adapter)
3764{
3765 struct ixgbe_hw *hw = &adapter->hw;
3766 int i;
3767
3768 for (i = 0; i < 10; i++)
3769 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3770}
3771
3772/**
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07003773 * ixgbe_init_rss_key - Initialize adapter RSS key
3774 * @adapter: device handle
3775 *
3776 * Allocates and initializes the RSS key if it is not allocated.
3777 **/
3778static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
3779{
3780 u32 *rss_key;
3781
3782 if (!adapter->rss_key) {
3783 rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
3784 if (unlikely(!rss_key))
3785 return -ENOMEM;
3786
3787 netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
3788 adapter->rss_key = rss_key;
3789 }
3790
3791 return 0;
3792}
3793
3794/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003795 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003796 * @adapter: device handle
3797 *
3798 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3799 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003800void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003801{
3802 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003803 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003804 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003805 u32 indices_multi;
3806 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003807
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003808 /* Fill out the redirection table as follows:
3809 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3810 * indices.
3811 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3812 * - X550: 8 bit wide entries containing 6 bit RSS index
3813 */
3814 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3815 indices_multi = 0x11;
3816 else
3817 indices_multi = 0x1;
3818
3819 /* Write redirection table to HW */
3820 for (i = 0; i < reta_entries; i++) {
3821 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3822 if ((i & 3) == 3) {
3823 if (i < 128)
3824 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3825 else
3826 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3827 reta);
3828 reta = 0;
3829 }
3830 }
3831}
3832
3833/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003834 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003835 * @adapter: device handle
3836 *
3837 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3838 */
3839static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3840{
3841 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3842 struct ixgbe_hw *hw = &adapter->hw;
3843 u32 vfreta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003844
3845 /* Write redirection table to HW */
3846 for (i = 0; i < reta_entries; i++) {
Alexander Duyck2af62c52017-11-22 10:56:28 -08003847 u16 pool = adapter->num_rx_pools;
3848
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003849 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
Alexander Duyck2af62c52017-11-22 10:56:28 -08003850 if ((i & 3) != 3)
3851 continue;
3852
3853 while (pool--)
3854 IXGBE_WRITE_REG(hw,
3855 IXGBE_PFVFRETA(i >> 2, VMDQ_P(pool)),
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003856 vfreta);
Alexander Duyck2af62c52017-11-22 10:56:28 -08003857 vfreta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003858 }
3859}
3860
3861static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3862{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003863 u32 i, j;
3864 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3865 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3866
Alexander Duycke24fcf22016-09-07 20:28:24 -07003867 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003868 * make full use of any rings they may have. We will use the
3869 * PSRTYPE register to control how many rings we use within the PF.
3870 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003871 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3872 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003873
Alexander Duyck05abb122010-08-19 13:35:41 +00003874 /* Fill out hash function seeds */
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003875 ixgbe_store_key(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003876
Alexander Duyck05abb122010-08-19 13:35:41 +00003877 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003878 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3879
Don Skidmore0f9b2322014-11-18 09:35:08 +00003880 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003881 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003882 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003883
3884 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003885 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003886
3887 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003888}
3889
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003890static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003891{
3892 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003893 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003894 int i, j;
3895
3896 /* Fill out hash function seeds */
Alexander Duyck2af62c52017-11-22 10:56:28 -08003897 for (i = 0; i < 10; i++) {
3898 u16 pool = adapter->num_rx_pools;
3899
3900 while (pool--)
3901 IXGBE_WRITE_REG(hw,
3902 IXGBE_PFVFRSSRK(i, VMDQ_P(pool)),
3903 *(adapter->rss_key + i));
3904 }
Don Skidmore0f9b2322014-11-18 09:35:08 +00003905
3906 /* Fill out the redirection table */
3907 for (i = 0, j = 0; i < 64; i++, j++) {
3908 if (j == rss_i)
3909 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003910
3911 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003912 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003913
3914 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003915}
3916
3917static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3918{
3919 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003920 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003921 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003922
3923 /* Disable indicating checksum in descriptor, enables RSS hash */
3924 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3925 rxcsum |= IXGBE_RXCSUM_PCSD;
3926 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3927
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003928 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003929 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003930 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003931 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003932 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003933
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003934 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3935 if (tcs > 4)
3936 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3937 else if (tcs > 1)
3938 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003939 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3940 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003941 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3942 else
3943 mrqc = IXGBE_MRQC_VMDQRSS64EN;
Emil Tantilove6b41c82017-04-25 11:31:06 -07003944
3945 /* Enable L3/L4 for Tx Switched packets */
3946 mrqc |= IXGBE_MRQC_L3L4TXSWEN;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003947 } else {
3948 if (tcs > 4)
3949 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3950 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003951 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3952 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003953 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003954 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003955 }
3956
Alexander Duyck05abb122010-08-19 13:35:41 +00003957 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003958 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3959 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3960 IXGBE_MRQC_RSS_FIELD_IPV6 |
3961 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003962
Alexander Duyckef6afc02012-02-08 07:51:53 +00003963 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003964 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003965 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003966 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003967
Don Skidmore0f9b2322014-11-18 09:35:08 +00003968 if ((hw->mac.type >= ixgbe_mac_X550) &&
3969 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
Alexander Duyck2af62c52017-11-22 10:56:28 -08003970 u16 pool = adapter->num_rx_pools;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003971
3972 /* Enable VF RSS mode */
3973 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3974 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3975
3976 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003977 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003978 vfmrqc = IXGBE_MRQC_RSSEN;
3979 vfmrqc |= rss_field;
Alexander Duyck2af62c52017-11-22 10:56:28 -08003980
3981 while (pool--)
3982 IXGBE_WRITE_REG(hw,
3983 IXGBE_PFVFMRQC(VMDQ_P(pool)),
3984 vfmrqc);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003985 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003986 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003987 mrqc |= rss_field;
3988 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3989 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003990}
3991
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003992/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003993 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3994 * @adapter: address of board private structure
3995 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003996 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003997static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003998 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003999{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00004000 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00004001 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004002 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00004003
Alexander Duyck7d637bc2010-11-16 19:26:56 -08004004 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00004005 return;
4006
Alexander Duyck73670962010-08-19 13:38:34 +00004007 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00004008 rscctrl |= IXGBE_RSCCTL_RSCEN;
4009 /*
4010 * we must limit the number of descriptors so that the
4011 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00004012 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00004013 */
Alexander Duyckf8003262012-03-03 02:35:52 +00004014 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00004015 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00004016}
4017
Alexander Duyck9e10e042010-08-19 13:40:06 +00004018#define IXGBE_MAX_RX_DESC_POLL 10
4019static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
4020 struct ixgbe_ring *ring)
4021{
4022 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004023 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
4024 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004025 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004026
Mark Rustadb0483c82014-01-14 18:53:17 -08004027 if (ixgbe_removed(hw->hw_addr))
4028 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004029 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
4030 if (hw->mac.type == ixgbe_mac_82598EB &&
4031 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
4032 return;
4033
4034 do {
Don Skidmore032b4322011-03-18 09:32:53 +00004035 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004036 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4037 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
4038
4039 if (!wait_loop) {
4040 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
4041 "the polling period\n", reg_idx);
4042 }
4043}
4044
Yi Zou2d39d572011-01-06 14:29:56 +00004045void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
4046 struct ixgbe_ring *ring)
4047{
4048 struct ixgbe_hw *hw = &adapter->hw;
4049 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
4050 u32 rxdctl;
4051 u8 reg_idx = ring->reg_idx;
4052
Mark Rustadb0483c82014-01-14 18:53:17 -08004053 if (ixgbe_removed(hw->hw_addr))
4054 return;
Yi Zou2d39d572011-01-06 14:29:56 +00004055 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4056 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
4057
4058 /* write value back with RXDCTL.ENABLE bit cleared */
4059 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4060
4061 if (hw->mac.type == ixgbe_mac_82598EB &&
4062 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
4063 return;
4064
4065 /* the hardware may take up to 100us to really disable the rx queue */
4066 do {
4067 udelay(10);
4068 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4069 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
4070
4071 if (!wait_loop) {
4072 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
4073 "the polling period\n", reg_idx);
4074 }
4075}
4076
Alexander Duyck84418e32010-08-19 13:40:54 +00004077void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
4078 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00004079{
4080 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc3630cc2017-01-17 08:36:28 -08004081 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyckacd37172010-08-19 13:36:05 +00004082 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004083 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004084 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00004085
Alexander Duyck9e10e042010-08-19 13:40:06 +00004086 /* disable queue to avoid issues while updating state */
4087 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00004088 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004089
Alexander Duyckacd37172010-08-19 13:36:05 +00004090 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
4091 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
4092 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
4093 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08004094 /* Force flushing of IXGBE_RDLEN to prevent MDD */
4095 IXGBE_WRITE_FLUSH(hw);
4096
Alexander Duyckacd37172010-08-19 13:36:05 +00004097 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
4098 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08004099 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004100
4101 ixgbe_configure_srrctl(adapter, ring);
4102 ixgbe_configure_rscctl(adapter, ring);
4103
4104 if (hw->mac.type == ixgbe_mac_82598EB) {
4105 /*
4106 * enable cache line friendly hardware writes:
4107 * PTHRESH=32 descriptors (half the internal cache),
4108 * this also removes ugly rx_no_buffer_count increment
4109 * HTHRESH=4 descriptors (to minimize latency on fetch)
4110 * WTHRESH=8 burst writeback up to two cache lines
4111 */
4112 rxdctl &= ~0x3FFFFF;
4113 rxdctl |= 0x080420;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004114#if (PAGE_SIZE < 8192)
4115 } else {
4116 rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
4117 IXGBE_RXDCTL_RLPML_EN);
4118
4119 /* Limit the maximum frame size so we don't overrun the skb */
4120 if (ring_uses_build_skb(ring) &&
4121 !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
Alexander Duyck541ea692017-03-02 15:01:05 -08004122 rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004123 IXGBE_RXDCTL_RLPML_EN;
4124#endif
Alexander Duyck9e10e042010-08-19 13:40:06 +00004125 }
4126
Alexander Duyckffed21b2017-01-17 08:37:29 -08004127 /* initialize rx_buffer_info */
4128 memset(ring->rx_buffer_info, 0,
4129 sizeof(struct ixgbe_rx_buffer) * ring->count);
4130
Alexander Duyckc3630cc2017-01-17 08:36:28 -08004131 /* initialize Rx descriptor 0 */
4132 rx_desc = IXGBE_RX_DESC(ring, 0);
4133 rx_desc->wb.upper.length = 0;
4134
Alexander Duyck9e10e042010-08-19 13:40:06 +00004135 /* enable receive descriptor ring */
4136 rxdctl |= IXGBE_RXDCTL_ENABLE;
4137 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4138
4139 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00004140 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00004141}
4142
Alexander Duyck48654522010-08-19 13:36:27 +00004143static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
4144{
4145 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004146 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck2af62c52017-11-22 10:56:28 -08004147 u16 pool = adapter->num_rx_pools;
Alexander Duyck48654522010-08-19 13:36:27 +00004148
4149 /* PSRTYPE must be initialized in non 82598 adapters */
4150 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004151 IXGBE_PSRTYPE_UDPHDR |
4152 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00004153 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004154 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00004155
4156 if (hw->mac.type == ixgbe_mac_82598EB)
4157 return;
4158
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004159 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004160 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004161 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004162 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00004163
Alexander Duyck2af62c52017-11-22 10:56:28 -08004164 while (pool--)
John Fastabend2a47fa42013-11-06 09:54:52 -08004165 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00004166}
4167
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004168static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
4169{
4170 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004171 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004172 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00004173 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004174
4175 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
4176 return;
4177
4178 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00004179 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
4180 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004181 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004182 vmdctl |= IXGBE_VT_CTL_REPLEN;
4183 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004184
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004185 vf_shift = VMDQ_P(0) % 32;
4186 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004187
4188 /* Enable only the PF's pool for Tx/Rx */
Emil Tantilov11f2b492016-05-04 15:01:27 -07004189 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004190 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
Emil Tantilov11f2b492016-05-04 15:01:27 -07004191 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004192 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07004193 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00004194 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004195
4196 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004197 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004198
Alexander Duyck16369562015-11-02 17:10:13 -08004199 /* clear VLAN promisc flag so VFTA will be updated if necessary */
4200 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4201
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004202 /*
4203 * Set up VF register offsets for selected VT Mode,
4204 * i.e. 32 or 64 VFs for SR-IOV
4205 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00004206 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4207 case IXGBE_82599_VMDQ_8Q_MASK:
4208 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
4209 break;
4210 case IXGBE_82599_VMDQ_4Q_MASK:
4211 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
4212 break;
4213 default:
4214 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
4215 break;
4216 }
4217
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004218 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
4219
Greg Rosede4c7f62011-09-29 05:57:33 +00004220 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07004221 /* configure spoof checking */
4222 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
4223 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03004224
4225 /* Enable/Disable RSS query feature */
4226 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
4227 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00004228 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004229}
4230
Alexander Duyck477de6e2010-08-19 13:38:11 +00004231static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004232{
Auke Kok9a799d72007-09-15 14:07:45 -07004233 struct ixgbe_hw *hw = &adapter->hw;
4234 struct net_device *netdev = adapter->netdev;
4235 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004236 struct ixgbe_ring *rx_ring;
4237 int i;
4238 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00004239
Alexander Duyck477de6e2010-08-19 13:38:11 +00004240#ifdef IXGBE_FCOE
4241 /* adjust max frame to be able to do baby jumbo for FCoE */
4242 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
4243 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
4244 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4245
4246#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00004247
4248 /* adjust max frame to be at least the size of a standard frame */
4249 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
4250 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
4251
Alexander Duyck477de6e2010-08-19 13:38:11 +00004252 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
4253 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
4254 mhadd &= ~IXGBE_MHADD_MFS_MASK;
4255 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
4256
4257 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07004258 }
4259
Auke Kok9a799d72007-09-15 14:07:45 -07004260 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004261 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
4262 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07004263 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4264
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004265 /*
4266 * Setup the HW Rx Head and Tail Descriptor Pointers and
4267 * the Base and Length of the Rx Descriptor Ring
4268 */
Auke Kok9a799d72007-09-15 14:07:45 -07004269 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004270 rx_ring = adapter->rx_ring[i];
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004271
4272 clear_ring_rsc_enabled(rx_ring);
4273 clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004274 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004275
Alexander Duyck7d637bc2010-11-16 19:26:56 -08004276 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4277 set_ring_rsc_enabled(rx_ring);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004278
4279 if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
4280 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004281
Alexander Duyck6f429222017-01-17 08:37:13 -08004282 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004283 if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
4284 continue;
4285
4286 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
4287
4288#if (PAGE_SIZE < 8192)
4289 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4290 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4291
Alexander Duyck541ea692017-03-02 15:01:05 -08004292 if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
4293 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004294 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4295#endif
Alexander Duyck477de6e2010-08-19 13:38:11 +00004296 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00004297}
4298
Alexander Duyck73670962010-08-19 13:38:34 +00004299static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
4300{
4301 struct ixgbe_hw *hw = &adapter->hw;
4302 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
4303
4304 switch (hw->mac.type) {
4305 case ixgbe_mac_82598EB:
4306 /*
4307 * For VMDq support of different descriptor types or
4308 * buffer sizes through the use of multiple SRRCTL
4309 * registers, RDRXCTL.MVMEN must be set to 1
4310 *
4311 * also, the manual doesn't mention it clearly but DCA hints
4312 * will only use queue 0's tags unless this bit is set. Side
4313 * effects of setting this bit are only that SRRCTL must be
4314 * fully programmed [0..15]
4315 */
4316 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
4317 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07004318 case ixgbe_mac_X550:
4319 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004320 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07004321 if (adapter->num_vfs)
4322 rdrxctl |= IXGBE_RDRXCTL_PSP;
Tony Nguyen93df9462017-05-31 04:43:47 -07004323 /* fall through */
Alexander Duyck73670962010-08-19 13:38:34 +00004324 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004325 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00004326 /* Disable RSC for ACK packets */
4327 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
4328 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
4329 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
4330 /* hardware requires some bits to be set by default */
4331 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
4332 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
4333 break;
4334 default:
4335 /* We should do nothing since we don't know this hardware */
4336 return;
4337 }
4338
4339 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
4340}
4341
Alexander Duyck477de6e2010-08-19 13:38:11 +00004342/**
4343 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4344 * @adapter: board private structure
4345 *
4346 * Configure the Rx unit of the MAC after a reset.
4347 **/
4348static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
4349{
4350 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004351 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004352 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004353
4354 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07004355 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004356
4357 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00004358 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004359
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004360 /* RSC Setup */
4361 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4362 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
4363 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
4364 rfctl |= IXGBE_RFCTL_RSC_DIS;
Emil Tantilova21d0822016-08-10 11:19:23 -07004365
4366 /* disable NFS filtering */
4367 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004368 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
4369
Alexander Duyck9e10e042010-08-19 13:40:06 +00004370 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004371 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004372
Alexander Duyck477de6e2010-08-19 13:38:11 +00004373 /* set_rx_buffer_len must be called before ring initialization */
4374 ixgbe_set_rx_buffer_len(adapter);
4375
4376 /*
4377 * Setup the HW Rx Head and Tail Descriptor Pointers and
4378 * the Base and Length of the Rx Descriptor Ring
4379 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00004380 for (i = 0; i < adapter->num_rx_queues; i++)
4381 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004382
Don Skidmore1f9ac572015-03-13 13:54:30 -07004383 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004384 /* disable drop enable for 82598 parts */
4385 if (hw->mac.type == ixgbe_mac_82598EB)
4386 rxctrl |= IXGBE_RXCTRL_DMBYPS;
4387
4388 /* enable all receives */
4389 rxctrl |= IXGBE_RXCTRL_RXEN;
4390 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004391}
4392
Patrick McHardy80d5c362013-04-19 02:04:28 +00004393static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
4394 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004395{
4396 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004397 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004398
4399 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004400 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4401 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
4402
Jesse Grossf62bbb52010-10-20 13:56:10 +00004403 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004404
4405 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004406}
4407
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004408static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
4409{
4410 u32 vlvf;
4411 int idx;
4412
4413 /* short cut the special case */
4414 if (vlan == 0)
4415 return 0;
4416
4417 /* Search for the vlan id in the VLVF entries */
4418 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
4419 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
4420 if ((vlvf & VLAN_VID_MASK) == vlan)
4421 break;
4422 }
4423
4424 return idx;
4425}
4426
4427void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
4428{
4429 struct ixgbe_hw *hw = &adapter->hw;
4430 u32 bits, word;
4431 int idx;
4432
4433 idx = ixgbe_find_vlvf_entry(hw, vid);
4434 if (!idx)
4435 return;
4436
4437 /* See if any other pools are set for this VLAN filter
4438 * entry other than the PF.
4439 */
4440 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004441 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004442 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4443
4444 /* Disable the filter so this falls into the default pool. */
4445 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4446 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4447 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4448 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4449 }
4450}
4451
Patrick McHardy80d5c362013-04-19 02:04:28 +00004452static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4453 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004454{
4455 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004456 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004457
Auke Kok9a799d72007-09-15 14:07:45 -07004458 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004459 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004460 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4461
Jesse Grossf62bbb52010-10-20 13:56:10 +00004462 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004463
4464 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004465}
4466
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004467/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004468 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4469 * @adapter: driver data
4470 */
4471static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4472{
4473 struct ixgbe_hw *hw = &adapter->hw;
4474 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004475 int i, j;
4476
4477 switch (hw->mac.type) {
4478 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004479 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4480 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004481 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4482 break;
4483 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004484 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004485 case ixgbe_mac_X550:
4486 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004487 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004488 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004489 struct ixgbe_ring *ring = adapter->rx_ring[i];
4490
Alexander Duyck68ae7422017-11-22 10:56:52 -08004491 if (!netif_is_ixgbe(ring->netdev))
John Fastabend2a47fa42013-11-06 09:54:52 -08004492 continue;
Alexander Duyck68ae7422017-11-22 10:56:52 -08004493
John Fastabend2a47fa42013-11-06 09:54:52 -08004494 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004495 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4496 vlnctrl &= ~IXGBE_RXDCTL_VME;
4497 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4498 }
4499 break;
4500 default:
4501 break;
4502 }
4503}
4504
4505/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004506 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004507 * @adapter: driver data
4508 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004509static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004510{
4511 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004512 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004513 int i, j;
4514
4515 switch (hw->mac.type) {
4516 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004517 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4518 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004519 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4520 break;
4521 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004522 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004523 case ixgbe_mac_X550:
4524 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004525 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004526 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004527 struct ixgbe_ring *ring = adapter->rx_ring[i];
4528
Alexander Duyck68ae7422017-11-22 10:56:52 -08004529 if (!netif_is_ixgbe(ring->netdev))
John Fastabend2a47fa42013-11-06 09:54:52 -08004530 continue;
Alexander Duyck68ae7422017-11-22 10:56:52 -08004531
John Fastabend2a47fa42013-11-06 09:54:52 -08004532 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004533 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4534 vlnctrl |= IXGBE_RXDCTL_VME;
4535 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4536 }
4537 break;
4538 default:
4539 break;
4540 }
4541}
4542
Alexander Duyck16369562015-11-02 17:10:13 -08004543static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4544{
4545 struct ixgbe_hw *hw = &adapter->hw;
4546 u32 vlnctrl, i;
4547
Alexander Duyckf60439b2016-08-11 14:51:56 -07004548 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4549
Emil Tantilov691e4122016-08-22 16:17:46 -07004550 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4551 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4552 vlnctrl |= IXGBE_VLNCTRL_VFE;
4553 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4554 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004555 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004556 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4557 return;
4558 }
4559
Emil Tantilov691e4122016-08-22 16:17:46 -07004560 /* Nothing to do for 82598 */
4561 if (hw->mac.type == ixgbe_mac_82598EB)
4562 return;
4563
Alexander Duyck16369562015-11-02 17:10:13 -08004564 /* We are already in VLAN promisc, nothing to do */
4565 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4566 return;
4567
4568 /* Set flag so we don't redo unnecessary work */
4569 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4570
4571 /* Add PF to all active pools */
4572 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4573 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4574 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4575
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004576 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004577 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4578 }
4579
4580 /* Set all bits in the VLAN filter table array */
4581 for (i = hw->mac.vft_size; i--;)
4582 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4583}
4584
4585#define VFTA_BLOCK_SIZE 8
4586static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4587{
4588 struct ixgbe_hw *hw = &adapter->hw;
4589 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4590 u32 vid_start = vfta_offset * 32;
4591 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4592 u32 i, vid, word, bits;
4593
4594 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4595 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4596
4597 /* pull VLAN ID from VLVF */
4598 vid = vlvf & VLAN_VID_MASK;
4599
4600 /* only concern outselves with a certain range */
4601 if (vid < vid_start || vid >= vid_end)
4602 continue;
4603
4604 if (vlvf) {
4605 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004606 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004607
4608 /* if PF is part of this then continue */
4609 if (test_bit(vid, adapter->active_vlans))
4610 continue;
4611 }
4612
4613 /* remove PF from the pool */
4614 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004615 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004616 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4617 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4618 }
4619
4620 /* extract values from active_vlans and write back to VFTA */
4621 for (i = VFTA_BLOCK_SIZE; i--;) {
4622 vid = (vfta_offset + i) * 32;
4623 word = vid / BITS_PER_LONG;
4624 bits = vid % BITS_PER_LONG;
4625
4626 vfta[i] |= adapter->active_vlans[word] >> bits;
4627
4628 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4629 }
4630}
4631
4632static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4633{
4634 struct ixgbe_hw *hw = &adapter->hw;
4635 u32 vlnctrl, i;
4636
Alexander Duyckf60439b2016-08-11 14:51:56 -07004637 /* Set VLAN filtering to enabled */
4638 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4639 vlnctrl |= IXGBE_VLNCTRL_VFE;
4640 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4641
Emil Tantilov691e4122016-08-22 16:17:46 -07004642 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4643 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004644 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004645
4646 /* We are not in VLAN promisc, nothing to do */
4647 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4648 return;
4649
4650 /* Set flag so we don't redo unnecessary work */
4651 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4652
4653 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4654 ixgbe_scrub_vfta(adapter, i);
4655}
4656
Auke Kok9a799d72007-09-15 14:07:45 -07004657static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4658{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004659 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004660
Patrick McHardy80d5c362013-04-19 02:04:28 +00004661 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004662
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004663 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004664 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004665}
4666
4667/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004668 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4669 * @netdev: network interface device structure
4670 *
4671 * Writes multicast address list to the MTA hash table.
4672 * Returns: -ENOMEM on failure
4673 * 0 on no addresses written
4674 * X on writing X addresses to MTA
4675 **/
4676static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4677{
4678 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4679 struct ixgbe_hw *hw = &adapter->hw;
4680
4681 if (!netif_running(netdev))
4682 return 0;
4683
4684 if (hw->mac.ops.update_mc_addr_list)
4685 hw->mac.ops.update_mc_addr_list(hw, netdev);
4686 else
4687 return -ENOMEM;
4688
4689#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004690 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004691#endif
4692
4693 return netdev_mc_count(netdev);
4694}
4695
Jacob Keller5d7daa32014-03-29 06:51:25 +00004696#ifdef CONFIG_PCI_IOV
4697void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4698{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004699 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004700 struct ixgbe_hw *hw = &adapter->hw;
4701 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004702
4703 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4704 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4705
4706 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4707 hw->mac.ops.set_rar(hw, i,
4708 mac_table->addr,
4709 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004710 IXGBE_RAH_AV);
4711 else
4712 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004713 }
4714}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004715
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004716#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004717static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4718{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004719 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004720 struct ixgbe_hw *hw = &adapter->hw;
4721 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004722
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004723 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4724 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4725 continue;
4726
4727 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4728
4729 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4730 hw->mac.ops.set_rar(hw, i,
4731 mac_table->addr,
4732 mac_table->pool,
4733 IXGBE_RAH_AV);
4734 else
4735 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004736 }
4737}
4738
4739static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4740{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004741 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004742 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004743 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004744
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004745 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4746 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4747 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004748 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004749
Jacob Keller5d7daa32014-03-29 06:51:25 +00004750 ixgbe_sync_mac_table(adapter);
4751}
4752
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004753static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004754{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004755 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004756 struct ixgbe_hw *hw = &adapter->hw;
4757 int i, count = 0;
4758
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004759 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4760 /* do not count default RAR as available */
4761 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4762 continue;
4763
4764 /* only count unused and addresses that belong to us */
4765 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4766 if (mac_table->pool != pool)
4767 continue;
4768 }
4769
4770 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004771 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004772
Jacob Keller5d7daa32014-03-29 06:51:25 +00004773 return count;
4774}
4775
4776/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004777static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004778{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004779 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004780 struct ixgbe_hw *hw = &adapter->hw;
4781
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004782 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4783 mac_table->pool = VMDQ_P(0);
4784
4785 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4786
4787 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004788 IXGBE_RAH_AV);
4789}
4790
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004791int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4792 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004793{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004794 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004795 struct ixgbe_hw *hw = &adapter->hw;
4796 int i;
4797
4798 if (is_zero_ether_addr(addr))
4799 return -EINVAL;
4800
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004801 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4802 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004803 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004804
4805 ether_addr_copy(mac_table->addr, addr);
4806 mac_table->pool = pool;
4807
4808 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4809 IXGBE_MAC_STATE_IN_USE;
4810
Jacob Keller5d7daa32014-03-29 06:51:25 +00004811 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004812
Jacob Keller5d7daa32014-03-29 06:51:25 +00004813 return i;
4814 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004815
Jacob Keller5d7daa32014-03-29 06:51:25 +00004816 return -ENOMEM;
4817}
4818
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004819int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4820 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004821{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004822 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004823 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004824 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004825
4826 if (is_zero_ether_addr(addr))
4827 return -EINVAL;
4828
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004829 /* search table for addr, if found clear IN_USE flag and sync */
4830 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4831 /* we can only delete an entry if it is in use */
4832 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4833 continue;
4834 /* we only care about entries that belong to the given pool */
4835 if (mac_table->pool != pool)
4836 continue;
4837 /* we only care about a specific MAC address */
4838 if (!ether_addr_equal(addr, mac_table->addr))
4839 continue;
4840
4841 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4842 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4843
4844 ixgbe_sync_mac_table(adapter);
4845
4846 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004847 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004848
Jacob Keller5d7daa32014-03-29 06:51:25 +00004849 return -ENOMEM;
4850}
Jacob Kellerb335e752014-03-25 07:45:27 +00004851/**
Alexander Duyck28500622010-06-15 09:25:48 +00004852 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4853 * @netdev: network interface device structure
4854 *
4855 * Writes unicast address list to the RAR table.
4856 * Returns: -ENOMEM on failure/insufficient address space
4857 * 0 on no addresses written
4858 * X on writing X addresses to the RAR table
4859 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004860static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004861{
4862 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004863 int count = 0;
4864
4865 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004866 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004867 return -ENOMEM;
4868
John Fastabend95447462012-05-31 12:42:26 +00004869 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004870 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004871 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004872 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4873 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004874 count++;
4875 }
4876 }
Alexander Duyck28500622010-06-15 09:25:48 +00004877 return count;
4878}
4879
Alexander Duyck0f079d22015-10-22 16:26:36 -07004880static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4881{
4882 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4883 int ret;
4884
4885 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4886
4887 return min_t(int, ret, 0);
4888}
4889
4890static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4891{
4892 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4893
4894 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4895
4896 return 0;
4897}
4898
Alexander Duyck28500622010-06-15 09:25:48 +00004899/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004900 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004901 * @netdev: network interface device structure
4902 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004903 * The set_rx_method entry point is called whenever the unicast/multicast
4904 * address list or the network interface flags are updated. This routine is
4905 * responsible for configuring the hardware for proper unicast, multicast and
4906 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004907 **/
Greg Rose7f870472010-01-09 02:25:29 +00004908void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004909{
4910 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4911 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004912 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004913 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004914 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004915
4916 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004917 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4918
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004919 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004920 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004921 fctrl |= IXGBE_FCTRL_BAM;
4922 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4923 fctrl |= IXGBE_FCTRL_PMCF;
4924
Alexander Duyck28500622010-06-15 09:25:48 +00004925 /* clear the bits we are changing the status of */
4926 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004927 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004928 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004929 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004930 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004931 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004932 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004933 if (netdev->flags & IFF_ALLMULTI) {
4934 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004935 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004936 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004937 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004938 }
4939
4940 /*
4941 * Write addresses to available RAR registers, if there is not
4942 * sufficient space to store all the addresses then enable
4943 * unicast promiscuous mode
4944 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004945 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004946 fctrl |= IXGBE_FCTRL_UPE;
4947 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004948 }
4949
Emil Tantilovcf789592013-10-26 08:13:20 +00004950 /* Write addresses to the MTA, if the attempt fails
4951 * then we should just turn on promiscuous mode so
4952 * that we can at least receive multicast traffic
4953 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004954 count = ixgbe_write_mc_addr_list(netdev);
4955 if (count < 0) {
4956 fctrl |= IXGBE_FCTRL_MPE;
4957 vmolr |= IXGBE_VMOLR_MPE;
4958 } else if (count) {
4959 vmolr |= IXGBE_VMOLR_ROMPE;
4960 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004961
4962 if (hw->mac.type != ixgbe_mac_82598EB) {
4963 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004964 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4965 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004966 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004967 }
4968
Ben Greear3f2d1c02012-03-08 08:28:41 +00004969 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004970 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004971 /* UPE and MPE will be handled by normal PROMISC logic
4972 * in e1000e_set_rx_mode */
4973 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4974 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4975 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4976
4977 fctrl &= ~(IXGBE_FCTRL_DPF);
4978 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4979 }
4980
Auke Kok9a799d72007-09-15 14:07:45 -07004981 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004982
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004983 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004984 ixgbe_vlan_strip_enable(adapter);
4985 else
4986 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004987
4988 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4989 ixgbe_vlan_promisc_disable(adapter);
4990 else
4991 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004992}
4993
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004994static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4995{
4996 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004997
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004998 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004999 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005000}
5001
5002static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
5003{
5004 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005005
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08005006 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005007 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005008}
5009
Emil Tantilova21d0822016-08-10 11:19:23 -07005010static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07005011{
Emil Tantilova21d0822016-08-10 11:19:23 -07005012 struct ixgbe_hw *hw = &adapter->hw;
5013 u32 vxlanctrl;
5014
5015 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
5016 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
5017 return;
5018
Sabrina Dubrocaa39221c2017-07-03 13:02:55 +02005019 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask;
Emil Tantilova21d0822016-08-10 11:19:23 -07005020 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
5021
5022 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07005023 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07005024
5025 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
5026 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07005027}
5028
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005029#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005030/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08005031 * ixgbe_configure_dcb - Configure DCB hardware
5032 * @adapter: ixgbe adapter struct
5033 *
5034 * This is called by the driver on open to configure the DCB hardware.
5035 * This is also called by the gennetlink interface when reconfiguring
5036 * the DCB state.
5037 */
5038static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
5039{
5040 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00005041 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005042
Alexander Duyck67ebd792010-08-19 13:34:04 +00005043 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
5044 if (hw->mac.type == ixgbe_mac_82598EB)
5045 netif_set_gso_max_size(adapter->netdev, 65536);
5046 return;
5047 }
5048
5049 if (hw->mac.type == ixgbe_mac_82598EB)
5050 netif_set_gso_max_size(adapter->netdev, 32768);
5051
John Fastabendb1208182011-10-15 05:00:10 +00005052#ifdef IXGBE_FCOE
5053 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
5054 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
5055#endif
5056
Alexander Duyck01fa7d92010-11-16 19:26:53 -08005057 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00005058 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00005059 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5060 DCB_TX_CONFIG);
5061 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5062 DCB_RX_CONFIG);
5063 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00005064 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
5065 ixgbe_dcb_hw_ets(&adapter->hw,
5066 adapter->ixgbe_ieee_ets,
5067 max_frame);
5068 ixgbe_dcb_hw_pfc_config(&adapter->hw,
5069 adapter->ixgbe_ieee_pfc->pfc_en,
5070 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00005071 }
John Fastabend8187cd42011-02-23 05:58:08 +00005072
5073 /* Enable RSS Hash per TC */
5074 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00005075 u32 msb = 0;
5076 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005077
Alexander Duyckd411a932012-06-30 00:14:01 +00005078 while (rss_i) {
5079 msb++;
5080 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005081 }
Alexander Duyckd411a932012-06-30 00:14:01 +00005082
Alexander Duyck4ae63732012-06-22 06:46:33 +00005083 /* write msb to all 8 TCs in one write */
5084 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00005085 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005086}
John Fastabend9da712d2011-08-23 03:14:22 +00005087#endif
5088
5089/* Additional bittime to account for IXGBE framing */
5090#define IXGBE_ETH_FRAMING 20
5091
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005092/**
John Fastabend9da712d2011-08-23 03:14:22 +00005093 * ixgbe_hpbthresh - calculate high water mark for flow control
5094 *
5095 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005096 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005097 */
5098static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
5099{
5100 struct ixgbe_hw *hw = &adapter->hw;
5101 struct net_device *dev = adapter->netdev;
5102 int link, tc, kb, marker;
5103 u32 dv_id, rx_pba;
5104
5105 /* Calculate max LAN frame size */
5106 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
5107
5108#ifdef IXGBE_FCOE
5109 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00005110 if ((dev->features & NETIF_F_FCOE_MTU) &&
5111 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5112 (pb == ixgbe_fcoe_get_tc(adapter)))
5113 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005114#endif
Jacob Kellere5776622014-04-05 02:35:52 +00005115
John Fastabend9da712d2011-08-23 03:14:22 +00005116 /* Calculate delay value for device */
5117 switch (hw->mac.type) {
5118 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005119 case ixgbe_mac_X550:
5120 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005121 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005122 dv_id = IXGBE_DV_X540(link, tc);
5123 break;
5124 default:
5125 dv_id = IXGBE_DV(link, tc);
5126 break;
5127 }
5128
5129 /* Loopback switch introduces additional latency */
5130 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5131 dv_id += IXGBE_B2BT(tc);
5132
5133 /* Delay value is calculated in bit times convert to KB */
5134 kb = IXGBE_BT2KB(dv_id);
5135 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
5136
5137 marker = rx_pba - kb;
5138
5139 /* It is possible that the packet buffer is not large enough
5140 * to provide required headroom. In this case throw an error
5141 * to user and a do the best we can.
5142 */
5143 if (marker < 0) {
5144 e_warn(drv, "Packet Buffer(%i) can not provide enough"
5145 "headroom to support flow control."
5146 "Decrease MTU or number of traffic classes\n", pb);
5147 marker = tc + 1;
5148 }
5149
5150 return marker;
5151}
5152
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005153/**
John Fastabend9da712d2011-08-23 03:14:22 +00005154 * ixgbe_lpbthresh - calculate low water mark for for flow control
5155 *
5156 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005157 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005158 */
Jacob Kellere5776622014-04-05 02:35:52 +00005159static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00005160{
5161 struct ixgbe_hw *hw = &adapter->hw;
5162 struct net_device *dev = adapter->netdev;
5163 int tc;
5164 u32 dv_id;
5165
5166 /* Calculate max LAN frame size */
5167 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
5168
Jacob Kellere5776622014-04-05 02:35:52 +00005169#ifdef IXGBE_FCOE
5170 /* FCoE traffic class uses FCOE jumbo frames */
5171 if ((dev->features & NETIF_F_FCOE_MTU) &&
5172 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5173 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
5174 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
5175#endif
5176
John Fastabend9da712d2011-08-23 03:14:22 +00005177 /* Calculate delay value for device */
5178 switch (hw->mac.type) {
5179 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005180 case ixgbe_mac_X550:
5181 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005182 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005183 dv_id = IXGBE_LOW_DV_X540(tc);
5184 break;
5185 default:
5186 dv_id = IXGBE_LOW_DV(tc);
5187 break;
5188 }
5189
5190 /* Delay value is calculated in bit times convert to KB */
5191 return IXGBE_BT2KB(dv_id);
5192}
5193
5194/*
5195 * ixgbe_pbthresh_setup - calculate and setup high low water marks
5196 */
5197static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
5198{
5199 struct ixgbe_hw *hw = &adapter->hw;
5200 int num_tc = netdev_get_num_tc(adapter->netdev);
5201 int i;
5202
5203 if (!num_tc)
5204 num_tc = 1;
5205
John Fastabend9da712d2011-08-23 03:14:22 +00005206 for (i = 0; i < num_tc; i++) {
5207 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00005208 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00005209
5210 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00005211 if (hw->fc.low_water[i] > hw->fc.high_water[i])
5212 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005213 }
Jacob Kellere5776622014-04-05 02:35:52 +00005214
5215 for (; i < MAX_TRAFFIC_CLASS; i++)
5216 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005217}
John Fastabend80605c652011-05-02 12:34:10 +00005218
5219static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
5220{
John Fastabend80605c652011-05-02 12:34:10 +00005221 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00005222 int hdrm;
5223 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00005224
5225 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5226 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00005227 hdrm = 32 << adapter->fdir_pballoc;
5228 else
5229 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00005230
Alexander Duyckf7e10272011-07-21 00:40:35 +00005231 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00005232 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00005233}
5234
Alexander Duycke4911d52011-05-11 07:18:52 +00005235static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
5236{
5237 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08005238 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005239 struct ixgbe_fdir_filter *filter;
5240
5241 spin_lock(&adapter->fdir_perfect_lock);
5242
5243 if (!hlist_empty(&adapter->fdir_filter_list))
5244 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
5245
Sasha Levinb67bfe02013-02-27 17:06:00 -08005246 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005247 &adapter->fdir_filter_list, fdir_node) {
5248 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00005249 &filter->filter,
5250 filter->sw_idx,
5251 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
5252 IXGBE_FDIR_DROP_QUEUE :
5253 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00005254 }
5255
5256 spin_unlock(&adapter->fdir_perfect_lock);
5257}
5258
John Fastabend2a47fa42013-11-06 09:54:52 -08005259static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
5260 struct ixgbe_adapter *adapter)
5261{
5262 struct ixgbe_hw *hw = &adapter->hw;
5263 u32 vmolr;
5264
5265 /* No unicast promiscuous support for VMDQ devices. */
5266 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
5267 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
5268
5269 /* clear the affected bit */
5270 vmolr &= ~IXGBE_VMOLR_MPE;
5271
5272 if (dev->flags & IFF_ALLMULTI) {
5273 vmolr |= IXGBE_VMOLR_MPE;
5274 } else {
5275 vmolr |= IXGBE_VMOLR_ROMPE;
5276 hw->mac.ops.update_mc_addr_list(hw, dev);
5277 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00005278 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08005279 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
5280}
5281
John Fastabend2a47fa42013-11-06 09:54:52 -08005282/**
5283 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
5284 * @rx_ring: ring to free buffers from
5285 **/
5286static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
5287{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005288 u16 i = rx_ring->next_to_clean;
5289 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08005290
5291 /* Free all the Rx ring sk_buffs */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005292 while (i != rx_ring->next_to_alloc) {
John Fastabend2a47fa42013-11-06 09:54:52 -08005293 if (rx_buffer->skb) {
5294 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00005295 if (IXGBE_CB(skb)->page_released)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005296 dma_unmap_page_attrs(rx_ring->dev,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005297 IXGBE_CB(skb)->dma,
5298 ixgbe_rx_pg_size(rx_ring),
5299 DMA_FROM_DEVICE,
5300 IXGBE_RX_DMA_ATTR);
John Fastabend2a47fa42013-11-06 09:54:52 -08005301 dev_kfree_skb(skb);
5302 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00005303
Alexander Duyckf3213d92017-01-17 08:35:54 -08005304 /* Invalidate cache lines that may have been written to by
5305 * device so that we avoid corrupting memory.
5306 */
5307 dma_sync_single_range_for_cpu(rx_ring->dev,
5308 rx_buffer->dma,
5309 rx_buffer->page_offset,
5310 ixgbe_rx_bufsz(rx_ring),
5311 DMA_FROM_DEVICE);
5312
5313 /* free resources associated with mapping */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005314 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005315 ixgbe_rx_pg_size(rx_ring),
5316 DMA_FROM_DEVICE,
5317 IXGBE_RX_DMA_ATTR);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08005318 __page_frag_cache_drain(rx_buffer->page,
5319 rx_buffer->pagecnt_bias);
Alexander Duyck18cb6522014-11-14 00:56:29 +00005320
Alexander Duyckffed21b2017-01-17 08:37:29 -08005321 i++;
5322 rx_buffer++;
5323 if (i == rx_ring->count) {
5324 i = 0;
5325 rx_buffer = rx_ring->rx_buffer_info;
5326 }
John Fastabend2a47fa42013-11-06 09:54:52 -08005327 }
5328
John Fastabend2a47fa42013-11-06 09:54:52 -08005329 rx_ring->next_to_alloc = 0;
5330 rx_ring->next_to_clean = 0;
5331 rx_ring->next_to_use = 0;
5332}
5333
5334static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
5335 struct ixgbe_ring *rx_ring)
5336{
5337 struct ixgbe_adapter *adapter = vadapter->real_adapter;
5338 int index = rx_ring->queue_index + vadapter->rx_base_queue;
5339
5340 /* shutdown specific queue receive and wait for dma to settle */
5341 ixgbe_disable_rx_queue(adapter, rx_ring);
5342 usleep_range(10000, 20000);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005343 ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
John Fastabend2a47fa42013-11-06 09:54:52 -08005344 ixgbe_clean_rx_ring(rx_ring);
John Fastabend2a47fa42013-11-06 09:54:52 -08005345}
5346
John Fastabendae72c8d2013-11-09 07:11:26 +00005347static int ixgbe_fwd_ring_down(struct net_device *vdev,
5348 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08005349{
5350 struct ixgbe_adapter *adapter = accel->real_adapter;
5351 unsigned int rxbase = accel->rx_base_queue;
5352 unsigned int txbase = accel->tx_base_queue;
5353 int i;
5354
5355 netif_tx_stop_all_queues(vdev);
5356
5357 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5358 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5359 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
5360 }
5361
Alexander Duyck68ae7422017-11-22 10:56:52 -08005362 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
John Fastabend2a47fa42013-11-06 09:54:52 -08005363 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
John Fastabend2a47fa42013-11-06 09:54:52 -08005364
5365
5366 return 0;
5367}
5368
5369static int ixgbe_fwd_ring_up(struct net_device *vdev,
5370 struct ixgbe_fwd_adapter *accel)
5371{
5372 struct ixgbe_adapter *adapter = accel->real_adapter;
5373 unsigned int rxbase, txbase, queues;
5374 int i, baseq, err = 0;
5375
Alexander Duyck4e039c12017-11-22 10:56:40 -08005376 if (!test_bit(accel->pool, adapter->fwd_bitmask))
John Fastabend2a47fa42013-11-06 09:54:52 -08005377 return 0;
5378
5379 baseq = accel->pool * adapter->num_rx_queues_per_pool;
Alexander Duyck4e039c12017-11-22 10:56:40 -08005380 netdev_dbg(vdev, "pool %i:%i queues %i:%i\n",
John Fastabend2a47fa42013-11-06 09:54:52 -08005381 accel->pool, adapter->num_rx_pools,
Alexander Duyck4e039c12017-11-22 10:56:40 -08005382 baseq, baseq + adapter->num_rx_queues_per_pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08005383
5384 accel->netdev = vdev;
5385 accel->rx_base_queue = rxbase = baseq;
5386 accel->tx_base_queue = txbase = baseq;
5387
5388 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5389 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5390
5391 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5392 adapter->rx_ring[rxbase + i]->netdev = vdev;
John Fastabend2a47fa42013-11-06 09:54:52 -08005393 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
5394 }
5395
Alexander Duyck68ae7422017-11-22 10:56:52 -08005396 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
John Fastabend2a47fa42013-11-06 09:54:52 -08005397 adapter->tx_ring[txbase + i]->netdev = vdev;
John Fastabend2a47fa42013-11-06 09:54:52 -08005398
5399 queues = min_t(unsigned int,
5400 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
5401 err = netif_set_real_num_tx_queues(vdev, queues);
5402 if (err)
5403 goto fwd_queue_err;
5404
John Fastabend2a47fa42013-11-06 09:54:52 -08005405 err = netif_set_real_num_rx_queues(vdev, queues);
5406 if (err)
5407 goto fwd_queue_err;
5408
5409 if (is_valid_ether_addr(vdev->dev_addr))
Alexander Duyck361b5342017-11-22 10:56:16 -08005410 ixgbe_add_mac_filter(adapter, vdev->dev_addr,
5411 VMDQ_P(accel->pool));
John Fastabend2a47fa42013-11-06 09:54:52 -08005412
Alexander Duyck361b5342017-11-22 10:56:16 -08005413 ixgbe_macvlan_set_rx_mode(vdev, VMDQ_P(accel->pool), adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005414 return err;
5415fwd_queue_err:
5416 ixgbe_fwd_ring_down(vdev, accel);
5417 return err;
5418}
5419
David Ahern1cd127f2016-10-17 19:15:48 -07005420static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
5421{
5422 if (netif_is_macvlan(upper)) {
5423 struct macvlan_dev *dfwd = netdev_priv(upper);
5424 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5425
5426 if (dfwd->fwd_priv)
5427 ixgbe_fwd_ring_up(upper, vadapter);
5428 }
5429
5430 return 0;
5431}
5432
John Fastabend2a47fa42013-11-06 09:54:52 -08005433static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5434{
David Ahern1cd127f2016-10-17 19:15:48 -07005435 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5436 ixgbe_upper_dev_walk, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005437}
5438
Auke Kok9a799d72007-09-15 14:07:45 -07005439static void ixgbe_configure(struct ixgbe_adapter *adapter)
5440{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005441 struct ixgbe_hw *hw = &adapter->hw;
5442
John Fastabend80605c652011-05-02 12:34:10 +00005443 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005444#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005445 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005446#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005447 /*
5448 * We must restore virtualization before VLANs or else
5449 * the VLVF registers will not be populated
5450 */
5451 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005452
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005453 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005454 ixgbe_restore_vlan(adapter);
5455
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005456 switch (hw->mac.type) {
5457 case ixgbe_mac_82599EB:
5458 case ixgbe_mac_X540:
5459 hw->mac.ops.disable_rx_buff(hw);
5460 break;
5461 default:
5462 break;
5463 }
5464
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005465 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005466 ixgbe_init_fdir_signature_82599(&adapter->hw,
5467 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005468 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5469 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5470 adapter->fdir_pballoc);
5471 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005472 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005473
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005474 switch (hw->mac.type) {
5475 case ixgbe_mac_82599EB:
5476 case ixgbe_mac_X540:
5477 hw->mac.ops.enable_rx_buff(hw);
5478 break;
5479 default:
5480 break;
5481 }
5482
Mark Rustad9de76052015-08-08 16:27:41 -07005483#ifdef CONFIG_IXGBE_DCA
5484 /* configure DCA */
5485 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5486 ixgbe_setup_dca(adapter);
5487#endif /* CONFIG_IXGBE_DCA */
5488
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005489#ifdef IXGBE_FCOE
5490 /* configure FCoE L2 filters, redirection table, and Rx control */
5491 ixgbe_configure_fcoe(adapter);
5492
5493#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005494 ixgbe_configure_tx(adapter);
5495 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005496 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005497}
5498
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005499/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005500 * ixgbe_sfp_link_config - set up SFP+ link
5501 * @adapter: pointer to private adapter struct
5502 **/
5503static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5504{
Alexander Duyck70864002011-04-27 09:13:56 +00005505 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005506 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005507 * is that an SFP was inserted/removed after the reset
5508 * but before SFP detection was enabled. As such the best
5509 * solution is to just start searching as soon as we start
5510 */
5511 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5512 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005513
Alexander Duyck70864002011-04-27 09:13:56 +00005514 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005515 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005516}
5517
5518/**
5519 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005520 * @hw: pointer to private hardware struct
5521 *
5522 * Returns 0 on success, negative on failure
5523 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005524static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005525{
Josh Hay3d292262012-12-15 03:28:19 +00005526 u32 speed;
5527 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005528 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005529
5530 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005531 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005532
5533 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005534 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005535
Josh Hay3d292262012-12-15 03:28:19 +00005536 speed = hw->phy.autoneg_advertised;
5537 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5538 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5539 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005540 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005541 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005542
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005543 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005544 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005545
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005546 return ret;
5547}
5548
Alexander Duycka34bcff2010-08-19 13:39:20 +00005549static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005550{
Auke Kok9a799d72007-09-15 14:07:45 -07005551 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005552 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005553
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005554 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005555 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5556 IXGBE_GPIE_OCD;
5557 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005558 /*
5559 * use EIAM to auto-mask when MSI-X interrupt is asserted
5560 * this saves a register write for every interrupt
5561 */
5562 switch (hw->mac.type) {
5563 case ixgbe_mac_82598EB:
5564 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5565 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005566 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005567 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005568 case ixgbe_mac_X550:
5569 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005570 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005571 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005572 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5573 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5574 break;
5575 }
5576 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005577 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5578 * specifically only auto mask tx and rx interrupts */
5579 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005580 }
5581
Alexander Duycka34bcff2010-08-19 13:39:20 +00005582 /* XXX: to interrupt immediately for EICS writes, enable this */
5583 /* gpie |= IXGBE_GPIE_EIMEN; */
5584
5585 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5586 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005587
5588 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5589 case IXGBE_82599_VMDQ_8Q_MASK:
5590 gpie |= IXGBE_GPIE_VTMODE_16;
5591 break;
5592 case IXGBE_82599_VMDQ_4Q_MASK:
5593 gpie |= IXGBE_GPIE_VTMODE_32;
5594 break;
5595 default:
5596 gpie |= IXGBE_GPIE_VTMODE_64;
5597 break;
5598 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005599 }
5600
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005601 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005602 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5603 switch (adapter->hw.mac.type) {
5604 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005605 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005606 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005607 default:
5608 break;
5609 }
5610 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005611
Alexander Duycka34bcff2010-08-19 13:39:20 +00005612 /* Enable fan failure interrupt */
5613 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005614 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005615
Don Skidmorea023bbd2015-06-24 16:38:53 -04005616 switch (hw->mac.type) {
5617 case ixgbe_mac_82599EB:
5618 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5619 break;
5620 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005621 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005622 gpie |= IXGBE_SDP0_GPIEN_X540;
5623 break;
5624 default:
5625 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005626 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005627
5628 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5629}
5630
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005631static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005632{
5633 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005634 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005635 u32 ctrl_ext;
5636
5637 ixgbe_get_hw_control(adapter);
5638 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005639
Auke Kok9a799d72007-09-15 14:07:45 -07005640 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5641 ixgbe_configure_msix(adapter);
5642 else
5643 ixgbe_configure_msi_and_legacy(adapter);
5644
Emil Tantilovec74a472012-09-20 03:33:56 +00005645 /* enable the optics for 82599 SFP+ fiber */
5646 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005647 hw->mac.ops.enable_tx_laser(hw);
5648
Don Skidmore961fac82015-06-09 16:09:47 -07005649 if (hw->phy.ops.set_phy_power)
5650 hw->phy.ops.set_phy_power(hw, true);
5651
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005652 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005653 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005654 ixgbe_napi_enable_all(adapter);
5655
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005656 if (ixgbe_is_sfp(hw)) {
5657 ixgbe_sfp_link_config(adapter);
5658 } else {
5659 err = ixgbe_non_sfp_link_config(hw);
5660 if (err)
5661 e_err(probe, "link_config FAILED %d\n", err);
5662 }
5663
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005664 /* clear any pending interrupts, may auto mask */
5665 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005666 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005667
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005668 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005669 * If this adapter has a fan, check to see if we had a failure
5670 * before we enabled the interrupt.
5671 */
5672 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5673 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5674 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005675 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005676 }
5677
Auke Kok9a799d72007-09-15 14:07:45 -07005678 /* bring the link up in the watchdog, this could race with our first
5679 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005680 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5681 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005682 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005683
5684 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5685 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5686 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5687 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005688}
5689
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005690void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5691{
5692 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005693 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005694 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005695
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005696 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005697 usleep_range(1000, 2000);
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005698 if (adapter->hw.phy.type == ixgbe_phy_fw)
5699 ixgbe_watchdog_link_is_down(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005700 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005701 /*
5702 * If SR-IOV enabled then wait a bit before bringing the adapter
5703 * back up to give the VFs time to respond to the reset. The
5704 * two second wait is based upon the watchdog timer cycle in
5705 * the VF driver.
5706 */
5707 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5708 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005709 ixgbe_up(adapter);
5710 clear_bit(__IXGBE_RESETTING, &adapter->state);
5711}
5712
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005713void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005714{
5715 /* hardware has been reset, we need to reload some things */
5716 ixgbe_configure(adapter);
5717
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005718 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005719}
5720
5721void ixgbe_reset(struct ixgbe_adapter *adapter)
5722{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005723 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005724 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005725 int err;
5726
Mark Rustadb0483c82014-01-14 18:53:17 -08005727 if (ixgbe_removed(hw->hw_addr))
5728 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005729 /* lock SFP init bit to prevent race conditions with the watchdog */
5730 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5731 usleep_range(1000, 2000);
5732
5733 /* clear all SFP and link config related flags while holding SFP_INIT */
5734 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5735 IXGBE_FLAG2_SFP_NEEDS_RESET);
5736 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5737
Don Skidmore8ca783a2009-05-26 20:40:47 -07005738 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005739 switch (err) {
5740 case 0:
5741 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005742 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005743 break;
5744 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005745 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005746 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005747 case IXGBE_ERR_EEPROM_VERSION:
5748 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005749 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005750 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005751 "your hardware. If you are experiencing problems "
5752 "please contact your Intel or hardware "
5753 "representative who provided you with this "
5754 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005755 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005756 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005757 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005758 }
Auke Kok9a799d72007-09-15 14:07:45 -07005759
Alexander Duyck70864002011-04-27 09:13:56 +00005760 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005761
5762 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005763 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005764 __dev_uc_unsync(netdev, NULL);
5765
5766 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005767 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005768
5769 /* update SAN MAC vmdq pool selection */
5770 if (hw->mac.san_mac_rar_index)
5771 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005772
Jacob Keller8fecf672013-06-21 08:14:32 +00005773 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005774 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005775
5776 if (hw->phy.ops.set_phy_power) {
5777 if (!netif_running(adapter->netdev) && !adapter->wol)
5778 hw->phy.ops.set_phy_power(hw, false);
5779 else
5780 hw->phy.ops.set_phy_power(hw, true);
5781 }
Auke Kok9a799d72007-09-15 14:07:45 -07005782}
5783
Auke Kok9a799d72007-09-15 14:07:45 -07005784/**
Auke Kok9a799d72007-09-15 14:07:45 -07005785 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005786 * @tx_ring: ring to be cleaned
5787 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005788static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005789{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005790 u16 i = tx_ring->next_to_clean;
5791 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07005792
Alexander Duyckffed21b2017-01-17 08:37:29 -08005793 while (i != tx_ring->next_to_use) {
5794 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -07005795
Alexander Duyckffed21b2017-01-17 08:37:29 -08005796 /* Free all the Tx ring sk_buffs */
John Fastabend33fdc822017-04-24 03:30:18 -07005797 if (ring_is_xdp(tx_ring))
5798 page_frag_free(tx_buffer->data);
5799 else
5800 dev_kfree_skb_any(tx_buffer->skb);
Alexander Duyckffed21b2017-01-17 08:37:29 -08005801
5802 /* unmap skb header data */
5803 dma_unmap_single(tx_ring->dev,
5804 dma_unmap_addr(tx_buffer, dma),
5805 dma_unmap_len(tx_buffer, len),
5806 DMA_TO_DEVICE);
5807
5808 /* check for eop_desc to determine the end of the packet */
5809 eop_desc = tx_buffer->next_to_watch;
5810 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5811
5812 /* unmap remaining buffers */
5813 while (tx_desc != eop_desc) {
5814 tx_buffer++;
5815 tx_desc++;
5816 i++;
5817 if (unlikely(i == tx_ring->count)) {
5818 i = 0;
5819 tx_buffer = tx_ring->tx_buffer_info;
5820 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5821 }
5822
5823 /* unmap any remaining paged data */
5824 if (dma_unmap_len(tx_buffer, len))
5825 dma_unmap_page(tx_ring->dev,
5826 dma_unmap_addr(tx_buffer, dma),
5827 dma_unmap_len(tx_buffer, len),
5828 DMA_TO_DEVICE);
5829 }
5830
5831 /* move us one more past the eop_desc for start of next pkt */
5832 tx_buffer++;
5833 i++;
5834 if (unlikely(i == tx_ring->count)) {
5835 i = 0;
5836 tx_buffer = tx_ring->tx_buffer_info;
5837 }
Auke Kok9a799d72007-09-15 14:07:45 -07005838 }
5839
Alexander Duyckffed21b2017-01-17 08:37:29 -08005840 /* reset BQL for queue */
John Fastabend33fdc822017-04-24 03:30:18 -07005841 if (!ring_is_xdp(tx_ring))
5842 netdev_tx_reset_queue(txring_txq(tx_ring));
John Fastabenddad8a3b2012-04-23 12:22:39 +00005843
Alexander Duyckffed21b2017-01-17 08:37:29 -08005844 /* reset next_to_use and next_to_clean */
Auke Kok9a799d72007-09-15 14:07:45 -07005845 tx_ring->next_to_use = 0;
5846 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005847}
5848
5849/**
Auke Kok9a799d72007-09-15 14:07:45 -07005850 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5851 * @adapter: board private structure
5852 **/
5853static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5854{
5855 int i;
5856
5857 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005858 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005859}
5860
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005861/**
5862 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5863 * @adapter: board private structure
5864 **/
5865static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5866{
5867 int i;
5868
5869 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005870 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07005871 for (i = 0; i < adapter->num_xdp_queues; i++)
5872 ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005873}
5874
Alexander Duycke4911d52011-05-11 07:18:52 +00005875static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5876{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005877 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005878 struct ixgbe_fdir_filter *filter;
5879
5880 spin_lock(&adapter->fdir_perfect_lock);
5881
Sasha Levinb67bfe02013-02-27 17:06:00 -08005882 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005883 &adapter->fdir_filter_list, fdir_node) {
5884 hlist_del(&filter->fdir_node);
5885 kfree(filter);
5886 }
5887 adapter->fdir_filter_count = 0;
5888
5889 spin_unlock(&adapter->fdir_perfect_lock);
5890}
5891
David Ahern1cd127f2016-10-17 19:15:48 -07005892static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
5893{
5894 if (netif_is_macvlan(upper)) {
5895 struct macvlan_dev *vlan = netdev_priv(upper);
5896
5897 if (vlan->fwd_priv) {
5898 netif_tx_stop_all_queues(upper);
5899 netif_carrier_off(upper);
5900 netif_tx_disable(upper);
5901 }
5902 }
5903
5904 return 0;
5905}
5906
Auke Kok9a799d72007-09-15 14:07:45 -07005907void ixgbe_down(struct ixgbe_adapter *adapter)
5908{
5909 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005910 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005911 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005912
5913 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005914 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5915 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005916
5917 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005918 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005919
Yi Zou2d39d572011-01-06 14:29:56 +00005920 /* disable all enabled rx queues */
5921 for (i = 0; i < adapter->num_rx_queues; i++)
5922 /* this call also flushes the previous write */
5923 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5924
Don Skidmore032b4322011-03-18 09:32:53 +00005925 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005926
John Fastabend11393cc2017-07-17 09:29:40 -07005927 /* synchronize_sched() needed for pending XDP buffers to drain */
5928 if (adapter->xdp_ring[0])
5929 synchronize_sched();
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005930 netif_tx_stop_all_queues(netdev);
5931
Alexander Duyck70864002011-04-27 09:13:56 +00005932 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005933 netif_carrier_off(netdev);
5934 netif_tx_disable(netdev);
5935
John Fastabend2a47fa42013-11-06 09:54:52 -08005936 /* disable any upper devices */
David Ahern1cd127f2016-10-17 19:15:48 -07005937 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5938 ixgbe_disable_macvlan, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005939
John Fastabendc0dfb902010-04-27 02:13:39 +00005940 ixgbe_irq_disable(adapter);
5941
5942 ixgbe_napi_disable_all(adapter);
5943
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005944 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5945 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005946 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5947
5948 del_timer_sync(&adapter->service_timer);
5949
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005950 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005951 /* Clear EITR Select mapping */
5952 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5953
5954 /* Mark all the VFs as inactive */
5955 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005956 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005957
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005958 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005959 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005960
Auke Kok9a799d72007-09-15 14:07:45 -07005961 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005962 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005963 }
5964
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005965 /* disable transmits in the hardware now that interrupts are off */
5966 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005967 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005968 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005969 }
John Fastabend33fdc822017-04-24 03:30:18 -07005970 for (i = 0; i < adapter->num_xdp_queues; i++) {
5971 u8 reg_idx = adapter->xdp_ring[i]->reg_idx;
5972
5973 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
5974 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005975
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005976 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005977 switch (hw->mac.type) {
5978 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005979 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005980 case ixgbe_mac_X550:
5981 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005982 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005983 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005984 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5985 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005986 break;
5987 default:
5988 break;
5989 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005990
Paul Larson6f4a0e42008-06-24 17:00:56 -07005991 if (!pci_channel_offline(adapter->pdev))
5992 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005993
Emil Tantilovec74a472012-09-20 03:33:56 +00005994 /* power down the optics for 82599 SFP+ fiber */
5995 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005996 hw->mac.ops.disable_tx_laser(hw);
5997
Auke Kok9a799d72007-09-15 14:07:45 -07005998 ixgbe_clean_all_tx_rings(adapter);
5999 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006000}
6001
Auke Kok9a799d72007-09-15 14:07:45 -07006002/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006003 * ixgbe_eee_capable - helper function to determine EEE support on X550
6004 * @adapter: board private structure
6005 */
6006static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
6007{
6008 struct ixgbe_hw *hw = &adapter->hw;
6009
6010 switch (hw->device_id) {
6011 case IXGBE_DEV_ID_X550EM_A_1G_T:
6012 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6013 if (!hw->phy.eee_speeds_supported)
6014 break;
6015 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
6016 if (!hw->phy.eee_speeds_advertised)
6017 break;
6018 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
6019 break;
6020 default:
6021 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
6022 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
6023 break;
6024 }
6025}
6026
6027/**
Auke Kok9a799d72007-09-15 14:07:45 -07006028 * ixgbe_tx_timeout - Respond to a Tx Hang
6029 * @netdev: network interface device structure
6030 **/
6031static void ixgbe_tx_timeout(struct net_device *netdev)
6032{
6033 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6034
6035 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006036 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006037}
6038
Usha Ketineni88290092016-04-26 05:00:26 -07006039#ifdef CONFIG_IXGBE_DCB
6040static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
6041{
6042 struct ixgbe_hw *hw = &adapter->hw;
6043 struct tc_configuration *tc;
6044 int j;
6045
6046 switch (hw->mac.type) {
6047 case ixgbe_mac_82598EB:
6048 case ixgbe_mac_82599EB:
6049 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
6050 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
6051 break;
6052 case ixgbe_mac_X540:
6053 case ixgbe_mac_X550:
6054 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
6055 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
6056 break;
6057 case ixgbe_mac_X550EM_x:
6058 case ixgbe_mac_x550em_a:
6059 default:
6060 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
6061 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
6062 break;
6063 }
6064
6065 /* Configure DCB traffic classes */
6066 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
6067 tc = &adapter->dcb_cfg.tc_config[j];
6068 tc->path[DCB_TX_CONFIG].bwg_id = 0;
6069 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
6070 tc->path[DCB_RX_CONFIG].bwg_id = 0;
6071 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
6072 tc->dcb_pfc = pfc_disabled;
6073 }
6074
6075 /* Initialize default user to priority mapping, UPx->TC0 */
6076 tc = &adapter->dcb_cfg.tc_config[0];
6077 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
6078 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
6079
6080 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
6081 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
6082 adapter->dcb_cfg.pfc_mode_enable = false;
6083 adapter->dcb_set_bitmap = 0x00;
6084 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
6085 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
6086 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
6087 sizeof(adapter->temp_dcb_cfg));
6088}
6089#endif
6090
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006091/**
Auke Kok9a799d72007-09-15 14:07:45 -07006092 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
6093 * @adapter: board private structure to initialize
6094 *
6095 * ixgbe_sw_init initializes the Adapter private data structure.
6096 * Fields are initialized based on PCI device information and
6097 * OS network device settings (MTU size).
6098 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07006099static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
6100 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07006101{
6102 struct ixgbe_hw *hw = &adapter->hw;
6103 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00006104 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00006105 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04006106 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006107
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006108 /* PCI config space info */
6109
6110 hw->vendor_id = pdev->vendor;
6111 hw->device_id = pdev->device;
6112 hw->revision_id = pdev->revision;
6113 hw->subsystem_vendor_id = pdev->subsystem_vendor;
6114 hw->subsystem_device_id = pdev->subsystem_device;
6115
Emil Tantilov55570b62016-10-12 12:34:25 -07006116 /* get_invariants needs the device IDs */
6117 ii->get_invariants(hw);
6118
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006119 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00006120 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00006121 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006122 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006123 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
6124 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00006125 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
6126 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006127 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
6128#ifdef CONFIG_IXGBE_DCA
6129 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
6130#endif
Usha Ketineni88290092016-04-26 05:00:26 -07006131#ifdef CONFIG_IXGBE_DCB
6132 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
6133 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6134#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006135#ifdef IXGBE_FCOE
6136 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
6137 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6138#ifdef CONFIG_IXGBE_DCB
6139 /* Default traffic class to use for FCoE */
6140 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
6141#endif /* CONFIG_IXGBE_DCB */
6142#endif /* IXGBE_FCOE */
6143
John Fastabendb82b17d2016-02-16 21:18:53 -08006144 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04006145 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
6146 GFP_KERNEL);
6147 if (!adapter->jump_tables[0])
6148 return -ENOMEM;
6149 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
6150
6151 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
6152 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08006153
Jacob Keller5d7daa32014-03-29 06:51:25 +00006154 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
6155 hw->mac.num_rar_entries,
6156 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08006157 if (!adapter->mac_table)
6158 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00006159
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07006160 if (ixgbe_init_rss_key(adapter))
6161 return -ENOMEM;
6162
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006163 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08006164 switch (hw->mac.type) {
6165 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006166 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006167
Don Skidmorebf069c92009-05-07 10:39:54 +00006168 if (hw->device_id == IXGBE_DEV_ID_82598AT)
6169 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006170
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006171 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006172 adapter->ring_feature[RING_F_FDIR].limit = 0;
6173 adapter->atr_sample_rate = 0;
6174 adapter->fdir_pballoc = 0;
6175#ifdef IXGBE_FCOE
6176 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6177 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6178#ifdef CONFIG_IXGBE_DCB
6179 adapter->fcoe.up = 0;
6180#endif /* IXGBE_DCB */
6181#endif /* IXGBE_FCOE */
6182 break;
6183 case ixgbe_mac_82599EB:
6184 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
6185 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006186 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006187 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07006188 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00006189 if (fwsm & IXGBE_FWSM_TS_ENABLED)
6190 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006191 break;
Mark Rustad49425df2016-04-01 12:18:09 -07006192 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07006193 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006194 switch (hw->device_id) {
6195 case IXGBE_DEV_ID_X550EM_A_1G_T:
6196 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6197 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6198 break;
6199 default:
6200 break;
6201 }
Emil Tantilova21d0822016-08-10 11:19:23 -07006202 /* fall through */
6203 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07006204#ifdef CONFIG_IXGBE_DCB
6205 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
6206#endif
6207#ifdef IXGBE_FCOE
6208 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6209#ifdef CONFIG_IXGBE_DCB
6210 adapter->fcoe.up = 0;
6211#endif /* IXGBE_DCB */
6212#endif /* IXGBE_FCOE */
6213 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006214 case ixgbe_mac_X550:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006215 if (hw->mac.type == ixgbe_mac_X550)
6216 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006217#ifdef CONFIG_IXGBE_DCA
6218 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
6219#endif
Mark Rustad67359c32015-06-15 11:33:25 -07006220 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006221 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08006222 default:
6223 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00006224 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08006225
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006226#ifdef IXGBE_FCOE
6227 /* FCoE support exists, always init the FCoE lock */
6228 spin_lock_init(&adapter->fcoe.lock);
6229
6230#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00006231 /* n-tuple support exists, always init our spinlock */
6232 spin_lock_init(&adapter->fdir_perfect_lock);
6233
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08006234#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07006235 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006236#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006237
6238 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00006239 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00006240 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00006241 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07006242 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
6243 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00006244 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07006245
Alexander Duyck99d74482012-05-09 08:09:25 +00006246#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08006247 if (max_vfs > 0)
6248 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 +00006249
Jacob Keller170e8542013-11-09 04:52:32 -08006250 /* assign number of SR-IOV VFs */
6251 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08006252 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Emil Tantilov5c11f002017-01-20 14:11:56 -08006253 max_vfs = 0;
Jacob Keller170e8542013-11-09 04:52:32 -08006254 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
Jacob Keller170e8542013-11-09 04:52:32 -08006255 }
6256 }
6257#endif /* CONFIG_PCI_IOV */
6258
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006259 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006260 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006261 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006262
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006263 /* set default ring sizes */
6264 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
6265 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
6266
Alexander Duyckbd198052011-06-11 01:45:08 +00006267 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00006268 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00006269
Auke Kok9a799d72007-09-15 14:07:45 -07006270 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006271 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006272 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006273 return -EIO;
6274 }
6275
John Fastabend2a47fa42013-11-06 09:54:52 -08006276 /* PF holds first pool slot */
Alexander Duyck4e039c12017-11-22 10:56:40 -08006277 set_bit(0, adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07006278 set_bit(__IXGBE_DOWN, &adapter->state);
6279
6280 return 0;
6281}
6282
6283/**
6284 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006285 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006286 *
6287 * Return 0 on success, negative on failure
6288 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006289int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006290{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006291 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006292 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006293 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07006294 int size;
6295
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006296 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006297
6298 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006299 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006300
Alexander Duyckffed21b2017-01-17 08:37:29 -08006301 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006302 if (!tx_ring->tx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006303 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006304 if (!tx_ring->tx_buffer_info)
6305 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006306
6307 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08006308 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006309 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006310
Mark Rustadca8dfe22014-07-24 06:19:24 +00006311 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006312 tx_ring->desc = dma_alloc_coherent(dev,
6313 tx_ring->size,
6314 &tx_ring->dma,
6315 GFP_KERNEL);
6316 set_dev_node(dev, orig_node);
6317 if (!tx_ring->desc)
6318 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6319 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006320 if (!tx_ring->desc)
6321 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006322
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006323 tx_ring->next_to_use = 0;
6324 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006325 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006326
6327err:
6328 vfree(tx_ring->tx_buffer_info);
6329 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006330 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006331 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006332}
6333
6334/**
Alexander Duyck69888672008-09-11 20:05:39 -07006335 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6336 * @adapter: board private structure
6337 *
6338 * If this function returns with an error, then it's possible one or
6339 * more of the rings is populated (while the rest are not). It is the
6340 * callers duty to clean those orphaned rings.
6341 *
6342 * Return 0 on success, negative on failure
6343 **/
6344static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6345{
John Fastabend33fdc822017-04-24 03:30:18 -07006346 int i, j = 0, err = 0;
Alexander Duyck69888672008-09-11 20:05:39 -07006347
6348 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006349 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006350 if (!err)
6351 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006352
Emil Tantilov396e7992010-07-01 20:05:12 +00006353 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006354 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07006355 }
John Fastabend33fdc822017-04-24 03:30:18 -07006356 for (j = 0; j < adapter->num_xdp_queues; j++) {
6357 err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
6358 if (!err)
6359 continue;
6360
6361 e_err(probe, "Allocation for Tx Queue %u failed\n", j);
6362 goto err_setup_tx;
6363 }
Alexander Duyck69888672008-09-11 20:05:39 -07006364
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006365 return 0;
6366err_setup_tx:
6367 /* rewind the index freeing the rings as we go */
John Fastabend33fdc822017-04-24 03:30:18 -07006368 while (j--)
6369 ixgbe_free_tx_resources(adapter->xdp_ring[j]);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006370 while (i--)
6371 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006372 return err;
6373}
6374
6375/**
Auke Kok9a799d72007-09-15 14:07:45 -07006376 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006377 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006378 *
6379 * Returns 0 on success, negative on failure
6380 **/
John Fastabend92470802017-04-24 03:30:17 -07006381int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
6382 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006383{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006384 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006385 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006386 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006387 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07006388
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006389 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006390
6391 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006392 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006393
Alexander Duyckffed21b2017-01-17 08:37:29 -08006394 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006395 if (!rx_ring->rx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006396 rx_ring->rx_buffer_info = vmalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006397 if (!rx_ring->rx_buffer_info)
6398 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006399
Auke Kok9a799d72007-09-15 14:07:45 -07006400 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006401 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6402 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006403
Mark Rustadca8dfe22014-07-24 06:19:24 +00006404 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006405 rx_ring->desc = dma_alloc_coherent(dev,
6406 rx_ring->size,
6407 &rx_ring->dma,
6408 GFP_KERNEL);
6409 set_dev_node(dev, orig_node);
6410 if (!rx_ring->desc)
6411 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6412 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006413 if (!rx_ring->desc)
6414 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006415
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006416 rx_ring->next_to_clean = 0;
6417 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006418
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01006419 /* XDP RX-queue info */
6420 if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev,
6421 rx_ring->queue_index) < 0)
6422 goto err;
6423
John Fastabend92470802017-04-24 03:30:17 -07006424 rx_ring->xdp_prog = adapter->xdp_prog;
6425
Auke Kok9a799d72007-09-15 14:07:45 -07006426 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006427err:
6428 vfree(rx_ring->rx_buffer_info);
6429 rx_ring->rx_buffer_info = NULL;
6430 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07006431 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006432}
6433
6434/**
Alexander Duyck69888672008-09-11 20:05:39 -07006435 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6436 * @adapter: board private structure
6437 *
6438 * If this function returns with an error, then it's possible one or
6439 * more of the rings is populated (while the rest are not). It is the
6440 * callers duty to clean those orphaned rings.
6441 *
6442 * Return 0 on success, negative on failure
6443 **/
Alexander Duyck69888672008-09-11 20:05:39 -07006444static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6445{
6446 int i, err = 0;
6447
6448 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend92470802017-04-24 03:30:17 -07006449 err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006450 if (!err)
6451 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006452
Emil Tantilov396e7992010-07-01 20:05:12 +00006453 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006454 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07006455 }
6456
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006457#ifdef IXGBE_FCOE
6458 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6459 if (!err)
6460#endif
6461 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006462err_setup_rx:
6463 /* rewind the index freeing the rings as we go */
6464 while (i--)
6465 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006466 return err;
6467}
6468
6469/**
Auke Kok9a799d72007-09-15 14:07:45 -07006470 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07006471 * @tx_ring: Tx descriptor ring for a specific queue
6472 *
6473 * Free all transmit software resources
6474 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006475void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006476{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006477 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006478
6479 vfree(tx_ring->tx_buffer_info);
6480 tx_ring->tx_buffer_info = NULL;
6481
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006482 /* if not set, then don't free */
6483 if (!tx_ring->desc)
6484 return;
6485
6486 dma_free_coherent(tx_ring->dev, tx_ring->size,
6487 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006488
6489 tx_ring->desc = NULL;
6490}
6491
6492/**
6493 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6494 * @adapter: board private structure
6495 *
6496 * Free all transmit software resources
6497 **/
6498static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6499{
6500 int i;
6501
6502 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006503 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006504 ixgbe_free_tx_resources(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07006505 for (i = 0; i < adapter->num_xdp_queues; i++)
6506 if (adapter->xdp_ring[i]->desc)
6507 ixgbe_free_tx_resources(adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006508}
6509
6510/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006511 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006512 * @rx_ring: ring to clean the resources from
6513 *
6514 * Free all receive software resources
6515 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006516void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006517{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006518 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006519
John Fastabend92470802017-04-24 03:30:17 -07006520 rx_ring->xdp_prog = NULL;
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01006521 xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
Auke Kok9a799d72007-09-15 14:07:45 -07006522 vfree(rx_ring->rx_buffer_info);
6523 rx_ring->rx_buffer_info = NULL;
6524
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006525 /* if not set, then don't free */
6526 if (!rx_ring->desc)
6527 return;
6528
6529 dma_free_coherent(rx_ring->dev, rx_ring->size,
6530 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006531
6532 rx_ring->desc = NULL;
6533}
6534
6535/**
6536 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6537 * @adapter: board private structure
6538 *
6539 * Free all receive software resources
6540 **/
6541static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6542{
6543 int i;
6544
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006545#ifdef IXGBE_FCOE
6546 ixgbe_free_fcoe_ddp_resources(adapter);
6547
6548#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006549 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006550 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006551 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006552}
6553
6554/**
Auke Kok9a799d72007-09-15 14:07:45 -07006555 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6556 * @netdev: network interface device structure
6557 * @new_mtu: new value for maximum frame size
6558 *
6559 * Returns 0 on success, negative on failure
6560 **/
6561static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6562{
6563 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck655309e2012-02-08 07:50:35 +00006564
6565 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006566 * For 82599EB we cannot allow legacy VFs to enable their receive
6567 * paths when MTU greater than 1500 is configured. So display a
6568 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006569 */
6570 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6571 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Jarod Wilson91c527a2016-10-17 15:54:05 -04006572 (new_mtu > ETH_DATA_LEN))
Alexander Duyck872844d2012-08-15 02:10:43 +00006573 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006574
Emil Tantilov396e7992010-07-01 20:05:12 +00006575 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006576
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006577 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006578 netdev->mtu = new_mtu;
6579
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006580 if (netif_running(netdev))
6581 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006582
6583 return 0;
6584}
6585
6586/**
6587 * ixgbe_open - Called when a network interface is made active
6588 * @netdev: network interface device structure
6589 *
6590 * Returns 0 on success, negative value on failure
6591 *
6592 * The open entry point is called when a network interface is made
6593 * active by the system (IFF_UP). At this point all resources needed
6594 * for transmit and receive operations are allocated, the interrupt
6595 * handler is registered with the OS, the watchdog timer is started,
6596 * and the stack is notified that the interface is ready.
6597 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006598int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006599{
6600 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006601 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006602 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006603
Auke Kok4bebfaa2008-02-11 09:26:01 -08006604 /* disallow open during test */
6605 if (test_bit(__IXGBE_TESTING, &adapter->state))
6606 return -EBUSY;
6607
Jesse Brandeburg54386462009-04-17 20:44:27 +00006608 netif_carrier_off(netdev);
6609
Auke Kok9a799d72007-09-15 14:07:45 -07006610 /* allocate transmit descriptors */
6611 err = ixgbe_setup_all_tx_resources(adapter);
6612 if (err)
6613 goto err_setup_tx;
6614
Auke Kok9a799d72007-09-15 14:07:45 -07006615 /* allocate receive descriptors */
6616 err = ixgbe_setup_all_rx_resources(adapter);
6617 if (err)
6618 goto err_setup_rx;
6619
6620 ixgbe_configure(adapter);
6621
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006622 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006623 if (err)
6624 goto err_req_irq;
6625
Alexander Duyckac802f52012-07-12 05:52:53 +00006626 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08006627 if (adapter->num_rx_pools > 1)
6628 queues = adapter->num_rx_queues_per_pool;
6629 else
6630 queues = adapter->num_tx_queues;
6631
6632 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006633 if (err)
6634 goto err_set_queues;
6635
John Fastabend2a47fa42013-11-06 09:54:52 -08006636 if (adapter->num_rx_pools > 1 &&
6637 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
6638 queues = IXGBE_MAX_L2A_QUEUES;
6639 else
6640 queues = adapter->num_rx_queues;
6641 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006642 if (err)
6643 goto err_set_queues;
6644
Jacob Keller1a71ab22012-08-25 03:54:19 +00006645 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006646
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006647 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006648
Emil Tantilova21d0822016-08-10 11:19:23 -07006649 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
Alexander Duyckb3a49552016-06-16 12:22:19 -07006650 udp_tunnel_get_rx_info(netdev);
Mark Rustad67359c32015-06-15 11:33:25 -07006651
Auke Kok9a799d72007-09-15 14:07:45 -07006652 return 0;
6653
Alexander Duyckac802f52012-07-12 05:52:53 +00006654err_set_queues:
6655 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006656err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006657 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006658 if (hw->phy.ops.set_phy_power && !adapter->wol)
6659 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006660err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006661 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006662err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006663 ixgbe_reset(adapter);
6664
6665 return err;
6666}
6667
Jacob Kellera0cccce2014-05-16 05:12:29 +00006668static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6669{
6670 ixgbe_ptp_suspend(adapter);
6671
Don Skidmore6ac74392015-06-17 17:34:31 -04006672 if (adapter->hw.phy.ops.enter_lplu) {
6673 adapter->hw.phy.reset_disable = true;
6674 ixgbe_down(adapter);
6675 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6676 adapter->hw.phy.reset_disable = false;
6677 } else {
6678 ixgbe_down(adapter);
6679 }
6680
Jacob Kellera0cccce2014-05-16 05:12:29 +00006681 ixgbe_free_irq(adapter);
6682
6683 ixgbe_free_all_tx_resources(adapter);
6684 ixgbe_free_all_rx_resources(adapter);
6685}
6686
Auke Kok9a799d72007-09-15 14:07:45 -07006687/**
6688 * ixgbe_close - Disables a network interface
6689 * @netdev: network interface device structure
6690 *
6691 * Returns 0, this is not allowed to fail
6692 *
6693 * The close entry point is called when an interface is de-activated
6694 * by the OS. The hardware is still under the drivers control, but
6695 * needs to be disabled. A global MAC reset is issued to stop the
6696 * hardware, and all transmit and receive resources are freed.
6697 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006698int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006699{
6700 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006701
Jacob Keller1a71ab22012-08-25 03:54:19 +00006702 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006703
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006704 if (netif_device_present(netdev))
6705 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006706
Alexander Duycke4911d52011-05-11 07:18:52 +00006707 ixgbe_fdir_filter_exit(adapter);
6708
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006709 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006710
6711 return 0;
6712}
6713
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006714#ifdef CONFIG_PM
6715static int ixgbe_resume(struct pci_dev *pdev)
6716{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006717 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6718 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006719 u32 err;
6720
Mark Rustad0391bbe2014-02-28 15:48:55 -08006721 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006722 pci_set_power_state(pdev, PCI_D0);
6723 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006724 /*
6725 * pci_restore_state clears dev->state_saved so call
6726 * pci_save_state to restore it.
6727 */
6728 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006729
6730 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006731 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006732 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006733 return err;
6734 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006735 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006736 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006737 pci_set_master(pdev);
6738
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006739 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006740
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006741 ixgbe_reset(adapter);
6742
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006743 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6744
Alexander Duyckac802f52012-07-12 05:52:53 +00006745 rtnl_lock();
6746 err = ixgbe_init_interrupt_scheme(adapter);
6747 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006748 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006749
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006750
6751 if (!err)
6752 netif_device_attach(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006753 rtnl_unlock();
6754
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006755 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006756}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006757#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006758
6759static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006760{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006761 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6762 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006763 struct ixgbe_hw *hw = &adapter->hw;
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006764 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006765 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006766#ifdef CONFIG_PM
6767 int retval = 0;
6768#endif
6769
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006770 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006771 netif_device_detach(netdev);
6772
Jacob Kellera0cccce2014-05-16 05:12:29 +00006773 if (netif_running(netdev))
6774 ixgbe_close_suspend(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006775
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006776 ixgbe_clear_interrupt_scheme(adapter);
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006777 rtnl_unlock();
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006778
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006779#ifdef CONFIG_PM
6780 retval = pci_save_state(pdev);
6781 if (retval)
6782 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006783
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006784#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006785 if (hw->mac.ops.stop_link_on_d3)
6786 hw->mac.ops.stop_link_on_d3(hw);
6787
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006788 if (wufc) {
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006789 u32 fctrl;
6790
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006791 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006792
Emil Tantilovec74a472012-09-20 03:33:56 +00006793 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6794 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006795 hw->mac.ops.enable_tx_laser(hw);
6796
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006797 /* enable the reception of multicast packets */
6798 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6799 fctrl |= IXGBE_FCTRL_MPE;
6800 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006801
6802 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6803 ctrl |= IXGBE_CTRL_GIO_DIS;
6804 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6805
6806 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6807 } else {
6808 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6809 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6810 }
6811
Alexander Duyckbd508172010-11-16 19:27:03 -08006812 switch (hw->mac.type) {
6813 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006814 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006815 break;
6816 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006817 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006818 case ixgbe_mac_X550:
6819 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006820 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006821 pci_wake_from_d3(pdev, !!wufc);
6822 break;
6823 default:
6824 break;
6825 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006826
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006827 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006828 if (hw->phy.ops.set_phy_power && !*enable_wake)
6829 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006830
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006831 ixgbe_release_hw_control(adapter);
6832
Mark Rustad41c62842014-03-12 00:38:35 +00006833 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6834 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006835
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006836 return 0;
6837}
6838
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006839#ifdef CONFIG_PM
6840static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6841{
6842 int retval;
6843 bool wake;
6844
6845 retval = __ixgbe_shutdown(pdev, &wake);
6846 if (retval)
6847 return retval;
6848
6849 if (wake) {
6850 pci_prepare_to_sleep(pdev);
6851 } else {
6852 pci_wake_from_d3(pdev, false);
6853 pci_set_power_state(pdev, PCI_D3hot);
6854 }
6855
6856 return 0;
6857}
6858#endif /* CONFIG_PM */
6859
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006860static void ixgbe_shutdown(struct pci_dev *pdev)
6861{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006862 bool wake;
6863
6864 __ixgbe_shutdown(pdev, &wake);
6865
6866 if (system_state == SYSTEM_POWER_OFF) {
6867 pci_wake_from_d3(pdev, wake);
6868 pci_set_power_state(pdev, PCI_D3hot);
6869 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006870}
6871
6872/**
Auke Kok9a799d72007-09-15 14:07:45 -07006873 * ixgbe_update_stats - Update the board statistics counters.
6874 * @adapter: board private structure
6875 **/
6876void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6877{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006878 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006879 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006880 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006881 u64 total_mpc = 0;
6882 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006883 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6884 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006885 u64 alloc_rx_page = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006886 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006887
Don Skidmored08935c2010-06-11 13:20:29 +00006888 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6889 test_bit(__IXGBE_RESETTING, &adapter->state))
6890 return;
6891
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006892 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006893 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006894 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006895 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006896 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6897 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006898 }
6899 adapter->rsc_total_count = rsc_count;
6900 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006901 }
6902
Alexander Duyck5b7da512010-11-16 19:26:50 -08006903 for (i = 0; i < adapter->num_rx_queues; i++) {
6904 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6905 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006906 alloc_rx_page += rx_ring->rx_stats.alloc_rx_page;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006907 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6908 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006909 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006910 bytes += rx_ring->stats.bytes;
6911 packets += rx_ring->stats.packets;
6912 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006913 adapter->non_eop_descs = non_eop_descs;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006914 adapter->alloc_rx_page = alloc_rx_page;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006915 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6916 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006917 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006918 netdev->stats.rx_bytes = bytes;
6919 netdev->stats.rx_packets = packets;
6920
6921 bytes = 0;
6922 packets = 0;
6923 /* gather some stats to the adapter struct that are per queue */
6924 for (i = 0; i < adapter->num_tx_queues; i++) {
6925 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6926 restart_queue += tx_ring->tx_stats.restart_queue;
6927 tx_busy += tx_ring->tx_stats.tx_busy;
6928 bytes += tx_ring->stats.bytes;
6929 packets += tx_ring->stats.packets;
6930 }
John Fastabend33fdc822017-04-24 03:30:18 -07006931 for (i = 0; i < adapter->num_xdp_queues; i++) {
6932 struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
6933
6934 restart_queue += xdp_ring->tx_stats.restart_queue;
6935 tx_busy += xdp_ring->tx_stats.tx_busy;
6936 bytes += xdp_ring->stats.bytes;
6937 packets += xdp_ring->stats.packets;
6938 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08006939 adapter->restart_queue = restart_queue;
6940 adapter->tx_busy = tx_busy;
6941 netdev->stats.tx_bytes = bytes;
6942 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006943
Joe Perches7ca647b2010-09-07 21:35:40 +00006944 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006945
6946 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006947 for (i = 0; i < 8; i++) {
6948 /* for packet buffers not used, the register should read 0 */
6949 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6950 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006951 hwstats->mpc[i] += mpc;
6952 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006953 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6954 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006955 switch (hw->mac.type) {
6956 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006957 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6958 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6959 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006960 hwstats->pxonrxc[i] +=
6961 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006962 break;
6963 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006964 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006965 case ixgbe_mac_X550:
6966 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006967 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006968 hwstats->pxonrxc[i] +=
6969 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006970 break;
6971 default:
6972 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006973 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006974 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006975
6976 /*16 register reads */
6977 for (i = 0; i < 16; i++) {
6978 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6979 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6980 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006981 (hw->mac.type == ixgbe_mac_X540) ||
6982 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006983 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6984 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006985 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6986 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6987 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6988 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6989 }
6990 }
6991
Joe Perches7ca647b2010-09-07 21:35:40 +00006992 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006993 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006994 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006995
John Fastabendc84d3242010-11-16 19:27:12 -08006996 ixgbe_update_xoff_received(adapter);
6997
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006998 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006999 switch (hw->mac.type) {
7000 case ixgbe_mac_82598EB:
7001 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08007002 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
7003 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
7004 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
7005 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08007006 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007007 case ixgbe_mac_X550:
7008 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07007009 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007010 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00007011 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
7012 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
7013 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
7014 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
Tony Nguyen93df9462017-05-31 04:43:47 -07007015 /* fall through */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00007016 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00007017 for (i = 0; i < 16; i++)
7018 adapter->hw_rx_no_dma_resources +=
7019 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00007020 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08007021 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00007022 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08007023 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00007024 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08007025 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00007026 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00007027 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
7028 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00007029#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00007030 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
7031 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
7032 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
7033 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
7034 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
7035 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00007036 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00007037 if (adapter->fcoe.ddp_pool) {
7038 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
7039 struct ixgbe_fcoe_ddp_pool *ddp_pool;
7040 unsigned int cpu;
7041 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00007042 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00007043 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
7044 noddp += ddp_pool->noddp;
7045 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00007046 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00007047 hwstats->fcoe_noddp = noddp;
7048 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00007049 }
Yi Zou6d455222009-05-13 13:12:16 +00007050#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08007051 break;
7052 default:
7053 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007054 }
Auke Kok9a799d72007-09-15 14:07:45 -07007055 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00007056 hwstats->bprc += bprc;
7057 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007058 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00007059 hwstats->mprc -= bprc;
7060 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
7061 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
7062 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
7063 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
7064 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
7065 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
7066 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
7067 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08007068 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00007069 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08007070 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00007071 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00007072 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
7073 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08007074 /*
7075 * 82598 errata - tx of flow control packets is included in tx counters
7076 */
7077 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00007078 hwstats->gptc -= xon_off_tot;
7079 hwstats->mptc -= xon_off_tot;
7080 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
7081 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
7082 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
7083 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
7084 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
7085 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
7086 hwstats->ptc64 -= xon_off_tot;
7087 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
7088 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
7089 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
7090 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
7091 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
7092 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07007093
7094 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00007095 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07007096
7097 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00007098 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00007099 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00007100 netdev->stats.rx_length_errors = hwstats->rlec;
7101 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00007102 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07007103}
7104
7105/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00007106 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007107 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07007108 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00007109static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07007110{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007111 struct ixgbe_hw *hw = &adapter->hw;
7112 int i;
7113
Alexander Duyckd034acf2011-04-27 09:25:34 +00007114 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
7115 return;
7116
7117 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
7118
7119 /* if interface is down do nothing */
7120 if (test_bit(__IXGBE_DOWN, &adapter->state))
7121 return;
7122
7123 /* do nothing if we are not using signature filters */
7124 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
7125 return;
7126
7127 adapter->fdir_overflow++;
7128
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007129 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
7130 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08007131 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00007132 &(adapter->tx_ring[i]->state));
John Fastabend33fdc822017-04-24 03:30:18 -07007133 for (i = 0; i < adapter->num_xdp_queues; i++)
7134 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
7135 &adapter->xdp_ring[i]->state);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007136 /* re-enable flow director interrupts */
7137 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007138 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00007139 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00007140 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007141 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007142}
7143
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007144/**
7145 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007146 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007147 *
7148 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007149 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007150 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007151 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007152 */
7153static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
7154{
Auke Kok9a799d72007-09-15 14:07:45 -07007155 struct ixgbe_hw *hw = &adapter->hw;
7156 u64 eics = 0;
7157 int i;
7158
Mark Rustad09f40ae2014-01-14 18:53:11 -08007159 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007160 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007161 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007162 test_bit(__IXGBE_RESETTING, &adapter->state))
7163 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00007164
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007165 /* Force detection of hung controller */
7166 if (netif_carrier_ok(adapter->netdev)) {
7167 for (i = 0; i < adapter->num_tx_queues; i++)
7168 set_check_for_tx_hang(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07007169 for (i = 0; i < adapter->num_xdp_queues; i++)
7170 set_check_for_tx_hang(adapter->xdp_ring[i]);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007171 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007172
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007173 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00007174 /*
7175 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007176 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00007177 * would set *both* EIMS and EICS for any bit in EIAM
7178 */
7179 IXGBE_WRITE_REG(hw, IXGBE_EICS,
7180 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007181 } else {
7182 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00007183 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007184 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00007185 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07007186 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007187 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007188 }
7189
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007190 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00007191 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00007192}
7193
7194/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007195 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007196 * @adapter: pointer to the device adapter structure
7197 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007198 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007199static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007200{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007201 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007202 u32 link_speed = adapter->link_speed;
7203 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00007204 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007205
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007206 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
7207 return;
7208
7209 if (hw->mac.ops.check_link) {
7210 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007211 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007212 /* always assume link is up, if no check link function */
7213 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
7214 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007215 }
Alexander Duyck041441d2012-04-19 17:48:48 +00007216
7217 if (adapter->ixgbe_ieee_pfc)
7218 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
7219
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007220 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00007221 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007222 ixgbe_set_rx_drop_en(adapter);
7223 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007224
7225 if (link_up ||
7226 time_after(jiffies, (adapter->link_check_timeout +
7227 IXGBE_TRY_LINK_TIMEOUT))) {
7228 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
7229 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
7230 IXGBE_WRITE_FLUSH(hw);
7231 }
7232
7233 adapter->link_up = link_up;
7234 adapter->link_speed = link_speed;
7235}
7236
Alexander Duyck107d3012012-10-02 00:17:03 +00007237static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
7238{
7239#ifdef CONFIG_IXGBE_DCB
7240 struct net_device *netdev = adapter->netdev;
7241 struct dcb_app app = {
7242 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
7243 .protocol = 0,
7244 };
7245 u8 up = 0;
7246
7247 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
7248 up = dcb_ieee_getapp_mask(netdev, &app);
7249
7250 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
7251#endif
7252}
7253
David Ahern1cd127f2016-10-17 19:15:48 -07007254static int ixgbe_enable_macvlan(struct net_device *upper, void *data)
7255{
7256 if (netif_is_macvlan(upper)) {
7257 struct macvlan_dev *vlan = netdev_priv(upper);
7258
7259 if (vlan->fwd_priv)
7260 netif_tx_wake_all_queues(upper);
7261 }
7262
7263 return 0;
7264}
7265
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007266/**
7267 * ixgbe_watchdog_link_is_up - update netif_carrier status and
7268 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007269 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007270 **/
7271static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
7272{
7273 struct net_device *netdev = adapter->netdev;
7274 struct ixgbe_hw *hw = &adapter->hw;
7275 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07007276 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007277 bool flow_rx, flow_tx;
7278
7279 /* only continue if link was previously down */
7280 if (netif_carrier_ok(netdev))
7281 return;
7282
7283 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7284
7285 switch (hw->mac.type) {
7286 case ixgbe_mac_82598EB: {
7287 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
7288 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
7289 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
7290 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
7291 }
7292 break;
7293 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007294 case ixgbe_mac_X550:
7295 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07007296 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007297 case ixgbe_mac_82599EB: {
7298 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
7299 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
7300 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
7301 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
7302 }
7303 break;
7304 default:
7305 flow_tx = false;
7306 flow_rx = false;
7307 break;
7308 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007309
Jacob Keller6cb562d2012-12-05 07:24:41 +00007310 adapter->last_rx_ptp_check = jiffies;
7311
Jacob Keller8fecf672013-06-21 08:14:32 +00007312 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007313 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007314
Mark Rustad454adb02015-07-10 14:19:22 -07007315 switch (link_speed) {
7316 case IXGBE_LINK_SPEED_10GB_FULL:
7317 speed_str = "10 Gbps";
7318 break;
7319 case IXGBE_LINK_SPEED_2_5GB_FULL:
7320 speed_str = "2.5 Gbps";
7321 break;
7322 case IXGBE_LINK_SPEED_1GB_FULL:
7323 speed_str = "1 Gbps";
7324 break;
7325 case IXGBE_LINK_SPEED_100_FULL:
7326 speed_str = "100 Mbps";
7327 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08007328 case IXGBE_LINK_SPEED_10_FULL:
7329 speed_str = "10 Mbps";
7330 break;
Mark Rustad454adb02015-07-10 14:19:22 -07007331 default:
7332 speed_str = "unknown speed";
7333 break;
7334 }
7335 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007336 ((flow_rx && flow_tx) ? "RX/TX" :
7337 (flow_rx ? "RX" :
7338 (flow_tx ? "TX" : "None"))));
7339
7340 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007341 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007342
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007343 /* enable transmits */
7344 netif_tx_wake_all_queues(adapter->netdev);
7345
7346 /* enable any upper devices */
7347 rtnl_lock();
David Ahern1cd127f2016-10-17 19:15:48 -07007348 netdev_walk_all_upper_dev_rcu(adapter->netdev,
7349 ixgbe_enable_macvlan, NULL);
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007350 rtnl_unlock();
7351
Alexander Duyck107d3012012-10-02 00:17:03 +00007352 /* update the default user priority for VFs */
7353 ixgbe_update_default_up(adapter);
7354
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007355 /* ping all the active vfs to let them know link has changed */
7356 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007357}
7358
7359/**
7360 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7361 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007362 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007363 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00007364static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007365{
7366 struct net_device *netdev = adapter->netdev;
7367 struct ixgbe_hw *hw = &adapter->hw;
7368
7369 adapter->link_up = false;
7370 adapter->link_speed = 0;
7371
7372 /* only continue if link was up previously */
7373 if (!netif_carrier_ok(netdev))
7374 return;
7375
7376 /* poll for SFP+ cable when link is down */
7377 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
7378 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
7379
Jacob Keller8fecf672013-06-21 08:14:32 +00007380 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007381 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007382
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007383 e_info(drv, "NIC Link is Down\n");
7384 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007385
7386 /* ping all the active vfs to let them know link has changed */
7387 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007388}
7389
Emil Tantilov07923c12014-08-12 07:12:08 +00007390static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
7391{
7392 int i;
7393
7394 for (i = 0; i < adapter->num_tx_queues; i++) {
7395 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
7396
7397 if (tx_ring->next_to_use != tx_ring->next_to_clean)
7398 return true;
7399 }
7400
John Fastabend33fdc822017-04-24 03:30:18 -07007401 for (i = 0; i < adapter->num_xdp_queues; i++) {
7402 struct ixgbe_ring *ring = adapter->xdp_ring[i];
7403
7404 if (ring->next_to_use != ring->next_to_clean)
7405 return true;
7406 }
7407
Emil Tantilov07923c12014-08-12 07:12:08 +00007408 return false;
7409}
7410
7411static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
7412{
7413 struct ixgbe_hw *hw = &adapter->hw;
7414 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
7415 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
7416
7417 int i, j;
7418
7419 if (!adapter->num_vfs)
7420 return false;
7421
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007422 /* resetting the PF is only needed for MAC before X550 */
7423 if (hw->mac.type >= ixgbe_mac_X550)
7424 return false;
7425
Emil Tantilov07923c12014-08-12 07:12:08 +00007426 for (i = 0; i < adapter->num_vfs; i++) {
7427 for (j = 0; j < q_per_pool; j++) {
7428 u32 h, t;
7429
7430 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
7431 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
7432
7433 if (h != t)
7434 return true;
7435 }
7436 }
7437
7438 return false;
7439}
7440
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007441/**
7442 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007443 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007444 **/
7445static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
7446{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007447 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00007448 if (ixgbe_ring_tx_pending(adapter) ||
7449 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007450 /* We've lost link, so the controller stops DMA,
7451 * but we've got queued Tx work that's never going
7452 * to get done, so reset controller to flush Tx.
7453 * (Do the reset outside of interrupt context).
7454 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00007455 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007456 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007457 }
7458 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007459}
7460
Emil Tantilov9079e412014-11-19 03:18:19 +00007461#ifdef CONFIG_PCI_IOV
Emil Tantilov9079e412014-11-19 03:18:19 +00007462static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
7463{
7464 struct ixgbe_hw *hw = &adapter->hw;
7465 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07007466 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00007467 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00007468
7469 if (!(netif_carrier_ok(adapter->netdev)))
7470 return;
7471
7472 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
7473 if (gpc) /* If incrementing then no need for the check below */
7474 return;
7475 /* Check to see if a bad DMA write target from an errant or
7476 * malicious VF has caused a PCIe error. If so then we can
7477 * issue a VFLR to the offending VF(s) and then resume without
7478 * requesting a full slot reset.
7479 */
7480
7481 if (!pdev)
7482 return;
7483
Emil Tantilov9079e412014-11-19 03:18:19 +00007484 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07007485 for (vf = 0; vf < adapter->num_vfs; ++vf) {
7486 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
7487 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00007488
Mark Rustad988d1302015-10-30 15:29:34 -07007489 if (!vfdev)
7490 continue;
7491 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
7492 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
7493 status_reg & PCI_STATUS_REC_MASTER_ABORT)
Christoph Hellwig63af8f72017-04-14 21:11:28 +02007494 pcie_flr(vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00007495 }
7496}
7497
Greg Rosea985b6c32010-11-18 03:02:52 +00007498static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
7499{
7500 u32 ssvpc;
7501
Greg Rose0584d992012-08-08 00:00:58 +00007502 /* Do not perform spoof check for 82598 or if not in IOV mode */
7503 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7504 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00007505 return;
7506
7507 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
7508
7509 /*
7510 * ssvpc register is cleared on read, if zero then no
7511 * spoofed packets in the last interval.
7512 */
7513 if (!ssvpc)
7514 return;
7515
Emil Tantilovd6ea0752012-08-08 06:28:37 +00007516 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00007517}
Emil Tantilov9079e412014-11-19 03:18:19 +00007518#else
7519static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7520{
7521}
7522
7523static void
7524ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7525{
7526}
7527#endif /* CONFIG_PCI_IOV */
7528
Greg Rosea985b6c32010-11-18 03:02:52 +00007529
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007530/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007531 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007532 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007533 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007534static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007535{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007536 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007537 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007538 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007539 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007540 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007541
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007542 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007543
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007544 if (adapter->link_up)
7545 ixgbe_watchdog_link_is_up(adapter);
7546 else
7547 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007548
Emil Tantilov9079e412014-11-19 03:18:19 +00007549 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007550 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007551 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007552
7553 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007554}
7555
Alexander Duyck70864002011-04-27 09:13:56 +00007556/**
7557 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007558 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007559 **/
7560static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7561{
7562 struct ixgbe_hw *hw = &adapter->hw;
7563 s32 err;
7564
7565 /* not searching for SFP so there is nothing to do here */
7566 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7567 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7568 return;
7569
Mark Rustad58e7cd22015-08-08 16:18:48 -07007570 if (adapter->sfp_poll_time &&
7571 time_after(adapter->sfp_poll_time, jiffies))
7572 return; /* If not yet time to poll for SFP */
7573
Alexander Duyck70864002011-04-27 09:13:56 +00007574 /* someone else is in init, wait until next service event */
7575 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7576 return;
7577
Mark Rustad58e7cd22015-08-08 16:18:48 -07007578 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7579
Alexander Duyck70864002011-04-27 09:13:56 +00007580 err = hw->phy.ops.identify_sfp(hw);
7581 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7582 goto sfp_out;
7583
7584 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7585 /* If no cable is present, then we need to reset
7586 * the next time we find a good cable. */
7587 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7588 }
7589
7590 /* exit on error */
7591 if (err)
7592 goto sfp_out;
7593
7594 /* exit if reset not needed */
7595 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7596 goto sfp_out;
7597
7598 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7599
7600 /*
7601 * A module may be identified correctly, but the EEPROM may not have
7602 * support for that module. setup_sfp() will fail in that case, so
7603 * we should not allow that module to load.
7604 */
7605 if (hw->mac.type == ixgbe_mac_82598EB)
7606 err = hw->phy.ops.reset(hw);
7607 else
7608 err = hw->mac.ops.setup_sfp(hw);
7609
7610 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7611 goto sfp_out;
7612
7613 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7614 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7615
7616sfp_out:
7617 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7618
7619 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7620 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7621 e_dev_err("failed to initialize because an unsupported "
7622 "SFP+ module type was detected.\n");
7623 e_dev_err("Reload the driver after installing a "
7624 "supported module.\n");
7625 unregister_netdev(adapter->netdev);
7626 }
7627}
7628
7629/**
7630 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007631 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007632 **/
7633static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7634{
7635 struct ixgbe_hw *hw = &adapter->hw;
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007636 u32 cap_speed;
Josh Hay3d292262012-12-15 03:28:19 +00007637 u32 speed;
7638 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007639
7640 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7641 return;
7642
7643 /* someone else is in init, wait until next service event */
7644 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7645 return;
7646
7647 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7648
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007649 hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007650
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007651 /* advertise highest capable link speed */
7652 if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL))
7653 speed = IXGBE_LINK_SPEED_10GB_FULL;
7654 else
7655 speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL |
7656 IXGBE_LINK_SPEED_1GB_FULL);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007657
Alexander Duyck70864002011-04-27 09:13:56 +00007658 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007659 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007660
7661 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7662 adapter->link_check_timeout = jiffies;
7663 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7664}
7665
7666/**
7667 * ixgbe_service_timer - Timer Call-back
7668 * @data: pointer to adapter cast into an unsigned long
7669 **/
Kees Cook26566ea2017-10-16 17:29:35 -07007670static void ixgbe_service_timer(struct timer_list *t)
Alexander Duyck70864002011-04-27 09:13:56 +00007671{
Kees Cook26566ea2017-10-16 17:29:35 -07007672 struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer);
Alexander Duyck70864002011-04-27 09:13:56 +00007673 unsigned long next_event_offset;
7674
7675 /* poll faster when waiting for link */
7676 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7677 next_event_offset = HZ / 10;
7678 else
7679 next_event_offset = HZ * 2;
7680
7681 /* Reset the timer */
7682 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7683
Emil Tantilov9079e412014-11-19 03:18:19 +00007684 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007685}
7686
Don Skidmore597f22d2015-06-09 16:52:02 -07007687static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7688{
7689 struct ixgbe_hw *hw = &adapter->hw;
7690 u32 status;
7691
7692 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7693 return;
7694
7695 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7696
7697 if (!hw->phy.ops.handle_lasi)
7698 return;
7699
7700 status = hw->phy.ops.handle_lasi(&adapter->hw);
7701 if (status != IXGBE_ERR_OVERTEMP)
7702 return;
7703
7704 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7705}
7706
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007707static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7708{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007709 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007710 return;
7711
Mark Rustad09f40ae2014-01-14 18:53:11 -08007712 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007713 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007714 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007715 test_bit(__IXGBE_RESETTING, &adapter->state))
7716 return;
7717
7718 ixgbe_dump(adapter);
7719 netdev_err(adapter->netdev, "Reset adapter\n");
7720 adapter->tx_timeout_count++;
7721
John Fastabend8f4c5c92014-01-16 02:30:05 -08007722 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007723 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007724 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007725}
7726
Alexander Duyck70864002011-04-27 09:13:56 +00007727/**
7728 * ixgbe_service_task - manages and runs subtasks
7729 * @work: pointer to work_struct containing our data
7730 **/
7731static void ixgbe_service_task(struct work_struct *work)
7732{
7733 struct ixgbe_adapter *adapter = container_of(work,
7734 struct ixgbe_adapter,
7735 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007736 if (ixgbe_removed(adapter->hw.hw_addr)) {
7737 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7738 rtnl_lock();
7739 ixgbe_down(adapter);
7740 rtnl_unlock();
7741 }
7742 ixgbe_service_event_complete(adapter);
7743 return;
7744 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007745 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007746 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007747 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007748 udp_tunnel_get_rx_info(adapter->netdev);
7749 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007750 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007751 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007752 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007753 ixgbe_sfp_detection_subtask(adapter);
7754 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007755 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007756 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007757 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007758 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007759
Jacob Keller8fecf672013-06-21 08:14:32 +00007760 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007761 ixgbe_ptp_overflow_check(adapter);
7762 ixgbe_ptp_rx_hang(adapter);
Jacob Keller622a2ef2017-05-03 10:29:04 -07007763 ixgbe_ptp_tx_hang(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007764 }
Alexander Duyck70864002011-04-27 09:13:56 +00007765
7766 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007767}
7768
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007769static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7770 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007771 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007772{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007773 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007774 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007775 union {
7776 struct iphdr *v4;
7777 struct ipv6hdr *v6;
7778 unsigned char *hdr;
7779 } ip;
7780 union {
7781 struct tcphdr *tcp;
7782 unsigned char *hdr;
7783 } l4;
7784 u32 paylen, l4_offset;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007785 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007786
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007787 if (skb->ip_summed != CHECKSUM_PARTIAL)
7788 return 0;
7789
Alexander Duyck897ab152011-05-27 05:31:47 +00007790 if (!skb_is_gso(skb))
7791 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007792
Francois Romieu2049e1f2014-03-30 03:14:27 +00007793 err = skb_cow_head(skb, 0);
7794 if (err < 0)
7795 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007796
Scott Peterson2a205252016-11-18 11:25:42 -08007797 if (eth_p_mpls(first->protocol))
7798 ip.hdr = skb_inner_network_header(skb);
7799 else
7800 ip.hdr = skb_network_header(skb);
Alexander Duyckb83e3012016-04-14 17:19:31 -04007801 l4.hdr = skb_checksum_start(skb);
7802
Alexander Duyck897ab152011-05-27 05:31:47 +00007803 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7804 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7805
Alexander Duyckb83e3012016-04-14 17:19:31 -04007806 /* initialize outer IP header fields */
7807 if (ip.v4->version == 4) {
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007808 unsigned char *csum_start = skb_checksum_start(skb);
7809 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
7810
Alexander Duyckb83e3012016-04-14 17:19:31 -04007811 /* IP header will have to cancel out any data that
7812 * is not a part of the outer IP header
7813 */
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007814 ip.v4->check = csum_fold(csum_partial(trans_start,
7815 csum_start - trans_start,
7816 0));
Alexander Duyck897ab152011-05-27 05:31:47 +00007817 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007818
7819 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007820 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7821 IXGBE_TX_FLAGS_CSUM |
7822 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007823 } else {
7824 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007825 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7826 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007827 }
7828
Alexander Duyckb83e3012016-04-14 17:19:31 -04007829 /* determine offset of inner transport header */
7830 l4_offset = l4.hdr - skb->data;
7831
7832 /* compute length of segmentation header */
7833 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7834
7835 /* remove payload length from inner checksum */
7836 paylen = skb->len - l4_offset;
7837 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007838
Alexander Duyck091a6242012-02-08 07:51:01 +00007839 /* update gso size and bytecount with header size */
7840 first->gso_segs = skb_shinfo(skb)->gso_segs;
7841 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7842
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007843 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007844 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007845 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007846
7847 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007848 vlan_macip_lens = l4.hdr - ip.hdr;
7849 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007850 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007851
7852 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007853 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007854
7855 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007856}
7857
Alexander Duyck49763de2016-01-13 07:31:11 -08007858static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7859{
7860 unsigned int offset = 0;
7861
7862 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7863
7864 return offset == skb_checksum_start_offset(skb);
7865}
7866
Alexander Duyck244e27a2012-02-08 07:51:11 +00007867static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7868 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007869{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007870 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007871 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007872 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007873
Alexander Duyck897ab152011-05-27 05:31:47 +00007874 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007875csum_failed:
7876 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7877 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007878 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007879 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007880 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007881
Alexander Duyck49763de2016-01-13 07:31:11 -08007882 switch (skb->csum_offset) {
7883 case offsetof(struct tcphdr, check):
7884 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7885 /* fall through */
7886 case offsetof(struct udphdr, check):
7887 break;
7888 case offsetof(struct sctphdr, checksum):
7889 /* validate that this is actually an SCTP request */
7890 if (((first->protocol == htons(ETH_P_IP)) &&
7891 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7892 ((first->protocol == htons(ETH_P_IPV6)) &&
7893 ixgbe_ipv6_csum_is_sctp(skb))) {
7894 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7895 break;
7896 }
7897 /* fall through */
7898 default:
7899 skb_checksum_help(skb);
7900 goto csum_failed;
7901 }
7902
7903 /* update TX checksum flag */
7904 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7905 vlan_macip_lens = skb_checksum_start_offset(skb) -
7906 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007907no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007908 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007909 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007910 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007911
Alexander Duyck49763de2016-01-13 07:31:11 -08007912 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007913}
7914
Alexander Duyck472148c2012-11-07 02:34:28 +00007915#define IXGBE_SET_FLAG(_input, _flag, _result) \
7916 ((_flag <= _result) ? \
7917 ((u32)(_input & _flag) * (_result / _flag)) : \
7918 ((u32)(_input & _flag) / (_flag / _result)))
7919
7920static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007921{
7922 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007923 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7924 IXGBE_ADVTXD_DCMD_DEXT |
7925 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007926
7927 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007928 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7929 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007930
Alexander Duyckd3d00232011-07-15 02:31:25 +00007931 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007932 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7933 IXGBE_ADVTXD_DCMD_TSE);
7934
7935 /* set timestamp bit if present */
7936 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7937 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007938
Alexander Duyck62748b72012-07-20 08:09:01 +00007939 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007940 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007941
Alexander Duyckd3d00232011-07-15 02:31:25 +00007942 return cmd_type;
7943}
7944
Alexander Duyck729739b2012-02-08 07:51:06 +00007945static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7946 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007947{
Alexander Duyck472148c2012-11-07 02:34:28 +00007948 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007949
7950 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007951 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7952 IXGBE_TX_FLAGS_CSUM,
7953 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007954
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007955 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007956 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7957 IXGBE_TX_FLAGS_IPV4,
7958 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007959
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007960 /*
7961 * Check Context must be set if Tx switch is enabled, which it
7962 * always is for case where virtual functions are running
7963 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007964 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7965 IXGBE_TX_FLAGS_CC,
7966 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007967
Alexander Duyck472148c2012-11-07 02:34:28 +00007968 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007969}
7970
Daniel Borkmann2367a172014-08-26 19:34:18 +02007971static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7972{
7973 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7974
7975 /* Herbert's original patch had:
7976 * smp_mb__after_netif_stop_queue();
7977 * but since that doesn't exist yet, just open code it.
7978 */
7979 smp_mb();
7980
7981 /* We need to check again in a case another CPU has just
7982 * made room available.
7983 */
7984 if (likely(ixgbe_desc_unused(tx_ring) < size))
7985 return -EBUSY;
7986
7987 /* A reprieve! - use start_queue because it doesn't call schedule */
7988 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7989 ++tx_ring->tx_stats.restart_queue;
7990 return 0;
7991}
7992
7993static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7994{
7995 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7996 return 0;
7997
7998 return __ixgbe_maybe_stop_tx(tx_ring, size);
7999}
8000
Alexander Duyckd3d00232011-07-15 02:31:25 +00008001#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
8002 IXGBE_TXD_CMD_RS)
8003
Jacob Keller5fef1242017-05-03 10:28:56 -07008004static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
8005 struct ixgbe_tx_buffer *first,
8006 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07008007{
Alexander Duyck729739b2012-02-08 07:51:06 +00008008 struct sk_buff *skb = first->skb;
8009 struct ixgbe_tx_buffer *tx_buffer;
8010 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00008011 struct skb_frag_struct *frag;
8012 dma_addr_t dma;
8013 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008014 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00008015 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008016 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07008017
Alexander Duyck729739b2012-02-08 07:51:06 +00008018 tx_desc = IXGBE_TX_DESC(tx_ring, i);
8019
Alexander Duyckec718252012-10-30 06:01:55 +00008020 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
8021
8022 size = skb_headlen(skb);
8023 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00008024
Alexander Duyckd3d00232011-07-15 02:31:25 +00008025#ifdef IXGBE_FCOE
8026 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00008027 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00008028 size -= sizeof(struct fcoe_crc_eof) - data_len;
8029 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00008030 } else {
8031 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00008032 }
Auke Kok9a799d72007-09-15 14:07:45 -07008033 }
8034
Alexander Duyckd3d00232011-07-15 02:31:25 +00008035#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00008036 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008037
Alexander Duyckec718252012-10-30 06:01:55 +00008038 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008039
Alexander Duyckec718252012-10-30 06:01:55 +00008040 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
8041 if (dma_mapping_error(tx_ring->dev, dma))
8042 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008043
Alexander Duyckec718252012-10-30 06:01:55 +00008044 /* record length, and DMA address */
8045 dma_unmap_len_set(tx_buffer, len, size);
8046 dma_unmap_addr_set(tx_buffer, dma, dma);
8047
8048 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8049
Alexander Duyck729739b2012-02-08 07:51:06 +00008050 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00008051 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00008052 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008053
Alexander Duyckd3d00232011-07-15 02:31:25 +00008054 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00008055 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008056 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00008057 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008058 i = 0;
8059 }
Alexander Duyckec718252012-10-30 06:01:55 +00008060 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00008061
8062 dma += IXGBE_MAX_DATA_PER_TXD;
8063 size -= IXGBE_MAX_DATA_PER_TXD;
8064
8065 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008066 }
8067
Alexander Duyck729739b2012-02-08 07:51:06 +00008068 if (likely(!data_len))
8069 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008070
Alexander Duyck472148c2012-11-07 02:34:28 +00008071 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008072
Alexander Duyck729739b2012-02-08 07:51:06 +00008073 i++;
8074 tx_desc++;
8075 if (i == tx_ring->count) {
8076 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
8077 i = 0;
8078 }
Alexander Duyckec718252012-10-30 06:01:55 +00008079 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008080
Alexander Duyckd3d00232011-07-15 02:31:25 +00008081#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00008082 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00008083#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00008084 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008085#endif
8086 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07008087
Alexander Duyck729739b2012-02-08 07:51:06 +00008088 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
8089 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07008090
Alexander Duyck729739b2012-02-08 07:51:06 +00008091 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07008092 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00008093
Alexander Duyck729739b2012-02-08 07:51:06 +00008094 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00008095 cmd_type |= size | IXGBE_TXD_CMD;
8096 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008097
Alexander Duyck091a6242012-02-08 07:51:01 +00008098 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00008099
Alexander Duyckd3d00232011-07-15 02:31:25 +00008100 /* set the timestamp */
8101 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07008102
8103 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00008104 * Force memory writes to complete before letting h/w know there
8105 * are new descriptors to fetch. (Only applicable for weak-ordered
8106 * memory model archs, such as IA-64).
8107 *
8108 * We also need this memory barrier to make certain all of the
8109 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07008110 */
8111 wmb();
8112
Alexander Duyckd3d00232011-07-15 02:31:25 +00008113 /* set next_to_watch value indicating a packet is present */
8114 first->next_to_watch = tx_desc;
8115
Alexander Duyck729739b2012-02-08 07:51:06 +00008116 i++;
8117 if (i == tx_ring->count)
8118 i = 0;
8119
8120 tx_ring->next_to_use = i;
8121
Daniel Borkmann2367a172014-08-26 19:34:18 +02008122 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
8123
8124 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00008125 writel(i, tx_ring->tail);
8126
8127 /* we need this if more than one processor can write to our tail
8128 * at a time, it synchronizes IO on IA64/Altix systems
8129 */
8130 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02008131 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02008132
Jacob Keller5fef1242017-05-03 10:28:56 -07008133 return 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008134dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00008135 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00008136
8137 /* clear dma mappings for failed tx_buffer_info map */
Alexander Duyck069db9c2017-10-19 17:07:13 -04008138 for (;;) {
8139 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckffed21b2017-01-17 08:37:29 -08008140 if (dma_unmap_len(tx_buffer, len))
8141 dma_unmap_page(tx_ring->dev,
8142 dma_unmap_addr(tx_buffer, dma),
8143 dma_unmap_len(tx_buffer, len),
8144 DMA_TO_DEVICE);
8145 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyck069db9c2017-10-19 17:07:13 -04008146 if (tx_buffer == first)
8147 break;
8148 if (i == 0)
Alexander Duyckffed21b2017-01-17 08:37:29 -08008149 i += tx_ring->count;
Alexander Duyck069db9c2017-10-19 17:07:13 -04008150 i--;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008151 }
8152
Alexander Duyckffed21b2017-01-17 08:37:29 -08008153 dev_kfree_skb_any(first->skb);
8154 first->skb = NULL;
8155
Alexander Duyckd3d00232011-07-15 02:31:25 +00008156 tx_ring->next_to_use = i;
Jacob Keller5fef1242017-05-03 10:28:56 -07008157
8158 return -1;
Auke Kok9a799d72007-09-15 14:07:45 -07008159}
8160
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008161static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00008162 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008163{
Alexander Duyck69830522011-01-06 14:29:58 +00008164 struct ixgbe_q_vector *q_vector = ring->q_vector;
8165 union ixgbe_atr_hash_dword input = { .dword = 0 };
8166 union ixgbe_atr_hash_dword common = { .dword = 0 };
8167 union {
8168 unsigned char *network;
8169 struct iphdr *ipv4;
8170 struct ipv6hdr *ipv6;
8171 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08008172 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08008173 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07008174 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00008175 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08008176 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008177
Alexander Duyck69830522011-01-06 14:29:58 +00008178 /* if ring doesn't have a interrupt vector, cannot perform ATR */
8179 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00008180 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008181
Alexander Duyck69830522011-01-06 14:29:58 +00008182 /* do nothing if sampling is disabled */
8183 if (!ring->atr_sample_rate)
8184 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008185
Alexander Duyck69830522011-01-06 14:29:58 +00008186 ring->atr_count++;
8187
Alexander Duycke2873d42016-01-25 19:39:40 -08008188 /* currently only IPv4/IPv6 with TCP is supported */
8189 if ((first->protocol != htons(ETH_P_IP)) &&
8190 (first->protocol != htons(ETH_P_IPV6)))
8191 return;
8192
Alexander Duyck69830522011-01-06 14:29:58 +00008193 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07008194 skb = first->skb;
8195 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008196 if (unlikely(hdr.network <= skb->data))
8197 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08008198 if (skb->encapsulation &&
8199 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07008200 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07008201 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00008202
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008203 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8204 VXLAN_HEADROOM))
8205 return;
8206
Alexander Duyck9f12df92016-01-25 19:36:29 -08008207 /* verify the port is recognized as VXLAN */
8208 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08008209 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08008210 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07008211
8212 if (adapter->geneve_port &&
8213 udp_hdr(skb)->dest == adapter->geneve_port)
8214 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08008215 }
8216
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008217 /* Make sure we have at least [minimum IPv4 header + TCP]
8218 * or [IPv6 header] bytes
8219 */
8220 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
8221 return;
8222
Mark Rustade19dcde2015-12-09 14:55:37 -08008223 /* Currently only IPv4/IPv6 with TCP is supported */
8224 switch (hdr.ipv4->version) {
8225 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08008226 /* access ihl as u8 to avoid unaligned access on ia64 */
8227 hlen = (hdr.network[0] & 0x0F) << 2;
8228 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08008229 break;
8230 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08008231 hlen = hdr.network - skb->data;
8232 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
8233 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08008234 break;
8235 default:
8236 return;
Mark Rustad67359c32015-06-15 11:33:25 -07008237 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008238
Alexander Duycke2873d42016-01-25 19:39:40 -08008239 if (l4_proto != IPPROTO_TCP)
8240 return;
8241
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008242 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8243 hlen + sizeof(struct tcphdr)))
8244 return;
8245
Alexander Duycke2873d42016-01-25 19:39:40 -08008246 th = (struct tcphdr *)(hdr.network + hlen);
8247
8248 /* skip this packet since the socket is closing */
8249 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00008250 return;
8251
8252 /* sample on all syn packets or once every atr sample count */
8253 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
8254 return;
8255
8256 /* reset sample count */
8257 ring->atr_count = 0;
8258
Alexander Duyck244e27a2012-02-08 07:51:11 +00008259 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00008260
8261 /*
8262 * src and dst are inverted, think how the receiver sees them
8263 *
8264 * The input is broken into two sections, a non-compressed section
8265 * containing vm_pool, vlan_id, and flow_type. The rest of the data
8266 * is XORed together and stored in the compressed dword.
8267 */
8268 input.formatted.vlan_id = vlan_id;
8269
8270 /*
8271 * since src port and flex bytes occupy the same word XOR them together
8272 * and write the value to source port portion of compressed dword
8273 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008274 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00008275 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00008276 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00008277 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00008278 common.port.dst ^= th->source;
8279
Mark Rustade19dcde2015-12-09 14:55:37 -08008280 switch (hdr.ipv4->version) {
8281 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00008282 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
8283 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08008284 break;
8285 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00008286 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
8287 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
8288 hdr.ipv6->saddr.s6_addr32[1] ^
8289 hdr.ipv6->saddr.s6_addr32[2] ^
8290 hdr.ipv6->saddr.s6_addr32[3] ^
8291 hdr.ipv6->daddr.s6_addr32[0] ^
8292 hdr.ipv6->daddr.s6_addr32[1] ^
8293 hdr.ipv6->daddr.s6_addr32[2] ^
8294 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08008295 break;
8296 default:
8297 break;
Alexander Duyck69830522011-01-06 14:29:58 +00008298 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008299
Alexander Duyck9f12df92016-01-25 19:36:29 -08008300 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07008301 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07008302
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008303 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00008304 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
8305 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008306}
8307
Jason Wangf663dd92014-01-10 16:18:26 +08008308static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01008309 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008310{
Jason Wangf663dd92014-01-10 16:18:26 +08008311 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
8312#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00008313 struct ixgbe_adapter *adapter;
8314 struct ixgbe_ring_feature *f;
8315 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08008316#endif
8317
8318 if (fwd_adapter)
8319 return skb->queue_mapping + fwd_adapter->tx_base_queue;
8320
8321#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00008322
Alexander Duyck97488bd2013-01-12 06:33:37 +00008323 /*
8324 * only execute the code below if protocol is FCoE
8325 * or FIP and we have FCoE enabled on the adapter
8326 */
8327 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00008328 case htons(ETH_P_FCOE):
8329 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00008330 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00008331
Alexander Duyck97488bd2013-01-12 06:33:37 +00008332 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8333 break;
Tony Nguyen93df9462017-05-31 04:43:47 -07008334 /* fall through */
Alexander Duyck97488bd2013-01-12 06:33:37 +00008335 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01008336 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00008337 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008338
Alexander Duyck97488bd2013-01-12 06:33:37 +00008339 f = &adapter->ring_feature[RING_F_FCOE];
8340
8341 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8342 smp_processor_id();
8343
8344 while (txq >= f->indices)
8345 txq -= f->indices;
8346
8347 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08008348#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01008349 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08008350#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008351}
8352
John Fastabend33fdc822017-04-24 03:30:18 -07008353static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
8354 struct xdp_buff *xdp)
8355{
8356 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
8357 struct ixgbe_tx_buffer *tx_buffer;
8358 union ixgbe_adv_tx_desc *tx_desc;
8359 u32 len, cmd_type;
8360 dma_addr_t dma;
8361 u16 i;
8362
8363 len = xdp->data_end - xdp->data;
8364
8365 if (unlikely(!ixgbe_desc_unused(ring)))
8366 return IXGBE_XDP_CONSUMED;
8367
8368 dma = dma_map_single(ring->dev, xdp->data, len, DMA_TO_DEVICE);
8369 if (dma_mapping_error(ring->dev, dma))
8370 return IXGBE_XDP_CONSUMED;
8371
8372 /* record the location of the first descriptor for this packet */
8373 tx_buffer = &ring->tx_buffer_info[ring->next_to_use];
8374 tx_buffer->bytecount = len;
8375 tx_buffer->gso_segs = 1;
8376 tx_buffer->protocol = 0;
8377
8378 i = ring->next_to_use;
8379 tx_desc = IXGBE_TX_DESC(ring, i);
8380
8381 dma_unmap_len_set(tx_buffer, len, len);
8382 dma_unmap_addr_set(tx_buffer, dma, dma);
8383 tx_buffer->data = xdp->data;
8384 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8385
8386 /* put descriptor type bits */
8387 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
8388 IXGBE_ADVTXD_DCMD_DEXT |
8389 IXGBE_ADVTXD_DCMD_IFCS;
8390 cmd_type |= len | IXGBE_TXD_CMD;
8391 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
8392 tx_desc->read.olinfo_status =
8393 cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT);
8394
John Fastabend7379f972017-03-28 09:47:03 -07008395 /* Avoid any potential race with xdp_xmit and cleanup */
8396 smp_wmb();
John Fastabend33fdc822017-04-24 03:30:18 -07008397
8398 /* set next_to_watch value indicating a packet is present */
8399 i++;
8400 if (i == ring->count)
8401 i = 0;
8402
8403 tx_buffer->next_to_watch = tx_desc;
8404 ring->next_to_use = i;
8405
John Fastabend33fdc822017-04-24 03:30:18 -07008406 return IXGBE_XDP_TX;
8407}
8408
Alexander Duyckfc77dc32010-11-16 19:26:51 -08008409netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00008410 struct ixgbe_adapter *adapter,
8411 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008412{
Alexander Duyckd3d00232011-07-15 02:31:25 +00008413 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00008414 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008415 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00008416 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00008417 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00008418 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00008419 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00008420
Alexander Duycka535c302011-05-27 05:31:52 +00008421 /*
8422 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00008423 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00008424 * + 2 desc gap to keep tail from touching head,
8425 * + 1 desc for context descriptor,
8426 * otherwise try next time
8427 */
Alexander Duycka535c302011-05-27 05:31:52 +00008428 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8429 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00008430
Alexander Duycka535c302011-05-27 05:31:52 +00008431 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8432 tx_ring->tx_stats.tx_busy++;
8433 return NETDEV_TX_BUSY;
8434 }
8435
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008436 /* record the location of the first descriptor for this packet */
8437 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8438 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00008439 first->bytecount = skb->len;
8440 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008441
Alexander Duyck66f32a82011-06-29 05:43:22 +00008442 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01008443 if (skb_vlan_tag_present(skb)) {
8444 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008445 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8446 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008447 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008448 struct vlan_hdr *vhdr, _vhdr;
8449 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8450 if (!vhdr)
8451 goto out_drop;
8452
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008453 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8454 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008455 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07008456 }
Toshiaki Makita02136682015-01-29 20:37:09 +09008457 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00008458
Mark Rustadd5234932014-08-09 07:02:09 +00008459 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
Jacob Keller4cc74c02017-05-03 10:29:00 -07008460 adapter->ptp_clock) {
8461 if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8462 &adapter->state)) {
8463 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8464 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00008465
Jacob Keller4cc74c02017-05-03 10:29:00 -07008466 /* schedule check for Tx timestamp */
8467 adapter->ptp_tx_skb = skb_get(skb);
8468 adapter->ptp_tx_start = jiffies;
8469 schedule_work(&adapter->ptp_tx_work);
8470 } else {
8471 adapter->tx_hwtstamp_skipped++;
8472 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008473 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008474
Jakub Kicinskiff29a862014-03-15 14:55:16 +00008475 skb_tx_timestamp(skb);
8476
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008477#ifdef CONFIG_PCI_IOV
8478 /*
8479 * Use the l2switch_enable flag - would be false if the DMA
8480 * Tx switch had been disabled.
8481 */
8482 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00008483 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008484
8485#endif
John Fastabend32701dc2011-09-27 03:51:56 +00008486 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00008487 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00008488 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8489 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008490 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00008491 tx_flags |= (skb->priority & 0x7) <<
8492 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008493 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8494 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00008495
8496 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00008497 goto out_drop;
8498 vhdr = (struct vlan_ethhdr *)skb->data;
8499 vhdr->h_vlan_TCI = htons(tx_flags >>
8500 IXGBE_TX_FLAGS_VLAN_SHIFT);
8501 } else {
8502 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8503 }
8504 }
Alexander Duycka535c302011-05-27 05:31:52 +00008505
Alexander Duyck244e27a2012-02-08 07:51:11 +00008506 /* record initial flags and protocol */
8507 first->tx_flags = tx_flags;
8508 first->protocol = protocol;
8509
Yi Zoueacd73f2009-05-13 13:11:06 +00008510#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00008511 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008512 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00008513 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00008514 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00008515 if (tso < 0)
8516 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07008517
Alexander Duyck66f32a82011-06-29 05:43:22 +00008518 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00008519 }
Auke Kok9a799d72007-09-15 14:07:45 -07008520
Auke Kok9a799d72007-09-15 14:07:45 -07008521#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008522 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008523 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07008524 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008525 else if (!tso)
8526 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008527
8528 /* add the ATR filter if ATR is on */
8529 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00008530 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008531
8532#ifdef IXGBE_FCOE
8533xmit_fcoe:
8534#endif /* IXGBE_FCOE */
Jacob Keller5fef1242017-05-03 10:28:56 -07008535 if (ixgbe_tx_map(tx_ring, first, hdr_len))
8536 goto cleanup_tx_timestamp;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008537
Auke Kok9a799d72007-09-15 14:07:45 -07008538 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00008539
8540out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008541 dev_kfree_skb_any(first->skb);
8542 first->skb = NULL;
Jacob Keller5fef1242017-05-03 10:28:56 -07008543cleanup_tx_timestamp:
8544 if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
8545 dev_kfree_skb_any(adapter->ptp_tx_skb);
8546 adapter->ptp_tx_skb = NULL;
8547 cancel_work_sync(&adapter->ptp_tx_work);
8548 clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state);
8549 }
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008550
Alexander Duyck897ab152011-05-27 05:31:47 +00008551 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07008552}
8553
John Fastabend2a47fa42013-11-06 09:54:52 -08008554static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8555 struct net_device *netdev,
8556 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008557{
8558 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008559 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07008560
Alexander Duycka50c29d2012-02-08 07:50:40 +00008561 /*
8562 * The minimum packet size for olinfo paylen is 17 so pad the skb
8563 * in order to meet this minimum size requirement.
8564 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08008565 if (skb_put_padto(skb, 17))
8566 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00008567
John Fastabend2a47fa42013-11-06 09:54:52 -08008568 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8569
Auke Kok9a799d72007-09-15 14:07:45 -07008570 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8571}
8572
John Fastabend2a47fa42013-11-06 09:54:52 -08008573static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8574 struct net_device *netdev)
8575{
8576 return __ixgbe_xmit_frame(skb, netdev, NULL);
8577}
8578
Auke Kok9a799d72007-09-15 14:07:45 -07008579/**
8580 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8581 * @netdev: network interface device structure
8582 * @p: pointer to an address structure
8583 *
8584 * Returns 0 on success, negative on failure
8585 **/
8586static int ixgbe_set_mac(struct net_device *netdev, void *p)
8587{
8588 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8589 struct ixgbe_hw *hw = &adapter->hw;
8590 struct sockaddr *addr = p;
8591
8592 if (!is_valid_ether_addr(addr->sa_data))
8593 return -EADDRNOTAVAIL;
8594
8595 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008596 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008597
Alexander Duyckc9f53e62015-10-22 16:26:30 -07008598 ixgbe_mac_set_default_filter(adapter);
8599
8600 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008601}
8602
Ben Hutchings6b73e102009-04-29 08:08:58 +00008603static int
8604ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8605{
8606 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8607 struct ixgbe_hw *hw = &adapter->hw;
8608 u16 value;
8609 int rc;
8610
8611 if (prtad != hw->phy.mdio.prtad)
8612 return -EINVAL;
8613 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8614 if (!rc)
8615 rc = value;
8616 return rc;
8617}
8618
8619static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8620 u16 addr, u16 value)
8621{
8622 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8623 struct ixgbe_hw *hw = &adapter->hw;
8624
8625 if (prtad != hw->phy.mdio.prtad)
8626 return -EINVAL;
8627 return hw->phy.ops.write_reg(hw, addr, devad, value);
8628}
8629
8630static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8631{
8632 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8633
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008634 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008635 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008636 return ixgbe_ptp_set_ts_config(adapter, req);
8637 case SIOCGHWTSTAMP:
8638 return ixgbe_ptp_get_ts_config(adapter, req);
Mark D Rustade0f06bb2016-08-31 10:34:28 -07008639 case SIOCGMIIPHY:
8640 if (!adapter->hw.phy.ops.read_reg)
8641 return -EOPNOTSUPP;
8642 /* fall through */
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008643 default:
8644 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8645 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008646}
8647
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008648/**
8649 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008650 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008651 * @netdev: network interface device structure
8652 *
8653 * Returns non-zero on failure
8654 **/
8655static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8656{
8657 int err = 0;
8658 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008659 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008660
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008661 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008662 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008663 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008664 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008665
8666 /* update SAN MAC vmdq pool selection */
8667 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008668 }
8669 return err;
8670}
8671
8672/**
8673 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008674 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008675 * @netdev: network interface device structure
8676 *
8677 * Returns non-zero on failure
8678 **/
8679static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8680{
8681 int err = 0;
8682 struct ixgbe_adapter *adapter = netdev_priv(dev);
8683 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8684
8685 if (is_valid_ether_addr(mac->san_addr)) {
8686 rtnl_lock();
8687 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8688 rtnl_unlock();
8689 }
8690 return err;
8691}
8692
Auke Kok9a799d72007-09-15 14:07:45 -07008693#ifdef CONFIG_NET_POLL_CONTROLLER
8694/*
8695 * Polling 'interrupt' - used by things like netconsole to send skbs
8696 * without having to re-enable interrupts. It's not called while
8697 * the interrupt routine is executing.
8698 */
8699static void ixgbe_netpoll(struct net_device *netdev)
8700{
8701 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008702 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008703
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008704 /* if interface is down do nothing */
8705 if (test_bit(__IXGBE_DOWN, &adapter->state))
8706 return;
8707
Alexander Duyck856f6062015-02-25 17:45:54 +00008708 /* loop through and schedule all active queues */
8709 for (i = 0; i < adapter->num_q_vectors; i++)
8710 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008711}
Auke Kok9a799d72007-09-15 14:07:45 -07008712
Alexander Duyck581330b2012-02-08 07:51:47 +00008713#endif
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008714
John Fastabend33fdc822017-04-24 03:30:18 -07008715static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
8716 struct ixgbe_ring *ring)
8717{
8718 u64 bytes, packets;
8719 unsigned int start;
8720
8721 if (ring) {
8722 do {
8723 start = u64_stats_fetch_begin_irq(&ring->syncp);
8724 packets = ring->stats.packets;
8725 bytes = ring->stats.bytes;
8726 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
8727 stats->tx_packets += packets;
8728 stats->tx_bytes += bytes;
8729 }
8730}
8731
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008732static void ixgbe_get_stats64(struct net_device *netdev,
8733 struct rtnl_link_stats64 *stats)
Eric Dumazetde1036b2010-10-20 23:00:04 +00008734{
8735 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8736 int i;
8737
Eric Dumazet1a515022010-11-16 19:26:42 -08008738 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008739 for (i = 0; i < adapter->num_rx_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008740 struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008741 u64 bytes, packets;
8742 unsigned int start;
8743
Eric Dumazet1a515022010-11-16 19:26:42 -08008744 if (ring) {
8745 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008746 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008747 packets = ring->stats.packets;
8748 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008749 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008750 stats->rx_packets += packets;
8751 stats->rx_bytes += bytes;
8752 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008753 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008754
8755 for (i = 0; i < adapter->num_tx_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008756 struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008757
John Fastabend33fdc822017-04-24 03:30:18 -07008758 ixgbe_get_ring_stats64(stats, ring);
8759 }
8760 for (i = 0; i < adapter->num_xdp_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008761 struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07008762
8763 ixgbe_get_ring_stats64(stats, ring);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008764 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008765 rcu_read_unlock();
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008766
Eric Dumazetde1036b2010-10-20 23:00:04 +00008767 /* following stats updated by ixgbe_watchdog_task() */
8768 stats->multicast = netdev->stats.multicast;
8769 stats->rx_errors = netdev->stats.rx_errors;
8770 stats->rx_length_errors = netdev->stats.rx_length_errors;
8771 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8772 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
Eric Dumazetde1036b2010-10-20 23:00:04 +00008773}
8774
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008775#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008776/**
8777 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8778 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008779 * @tc: number of traffic classes currently enabled
8780 *
8781 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8782 * 802.1Q priority maps to a packet buffer that exists.
8783 */
8784static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8785{
8786 struct ixgbe_hw *hw = &adapter->hw;
8787 u32 reg, rsave;
8788 int i;
8789
8790 /* 82598 have a static priority to TC mapping that can not
8791 * be changed so no validation is needed.
8792 */
8793 if (hw->mac.type == ixgbe_mac_82598EB)
8794 return;
8795
8796 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8797 rsave = reg;
8798
8799 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8800 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8801
8802 /* If up2tc is out of bounds default to zero */
8803 if (up2tc > tc)
8804 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8805 }
8806
8807 if (reg != rsave)
8808 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8809
8810 return;
8811}
8812
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008813/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008814 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8815 * @adapter: Pointer to adapter struct
8816 *
8817 * Populate the netdev user priority to tc map
8818 */
8819static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8820{
8821 struct net_device *dev = adapter->netdev;
8822 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8823 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8824 u8 prio;
8825
8826 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8827 u8 tc = 0;
8828
8829 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8830 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8831 else if (ets)
8832 tc = ets->prio_tc[prio];
8833
8834 netdev_set_prio_tc_map(dev, prio, tc);
8835 }
8836}
8837
Alexander Duyckcca73c52013-01-12 06:33:44 +00008838#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008839/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008840 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008841 *
8842 * @netdev: net device to configure
8843 * @tc: number of traffic classes to enable
8844 */
8845int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8846{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008847 struct ixgbe_adapter *adapter = netdev_priv(dev);
8848 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008849
John Fastabend8b1c0b22011-05-03 02:26:48 +00008850 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008851 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8852 return -EINVAL;
8853
8854 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008855 return -EINVAL;
8856
8857 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008858 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008859 * hardware is not flexible enough to do this dynamically.
8860 */
8861 if (netif_running(dev))
8862 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008863 else
8864 ixgbe_reset(adapter);
8865
John Fastabend8b1c0b22011-05-03 02:26:48 +00008866 ixgbe_clear_interrupt_scheme(adapter);
8867
Alexander Duyckcca73c52013-01-12 06:33:44 +00008868#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008869 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008870 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008871 ixgbe_set_prio_tc_map(adapter);
8872
John Fastabende7589ea2011-07-18 22:38:36 +00008873 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008874
Alexander Duyck943561d2012-05-09 22:14:44 -07008875 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8876 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008877 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008878 }
John Fastabende7589ea2011-07-18 22:38:36 +00008879 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008880 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008881
Alexander Duyck943561d2012-05-09 22:14:44 -07008882 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8883 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008884
8885 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008886
8887 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8888 adapter->dcb_cfg.pfc_mode_enable = false;
8889 }
8890
John Fastabend8b1c0b22011-05-03 02:26:48 +00008891 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008892
8893#endif /* CONFIG_IXGBE_DCB */
8894 ixgbe_init_interrupt_scheme(adapter);
8895
John Fastabend8b1c0b22011-05-03 02:26:48 +00008896 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008897 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008898
8899 return 0;
8900}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008901
John Fastabendb82b17d2016-02-16 21:18:53 -08008902static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8903 struct tc_cls_u32_offload *cls)
8904{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008905 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008906 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008907 u32 loc = cls->knode.handle & 0xfffff;
8908 int err = 0, i, j;
8909 struct ixgbe_jump_table *jump = NULL;
8910
8911 if (loc > IXGBE_MAX_HW_ENTRIES)
8912 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008913
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008914 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8915 return -EINVAL;
8916
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008917 /* Clear this filter in the link data it is associated with */
8918 if (uhtid != 0x800) {
8919 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008920 if (!jump)
8921 return -EINVAL;
8922 if (!test_bit(loc - 1, jump->child_loc_map))
8923 return -EINVAL;
8924 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008925 }
8926
8927 /* Check if the filter being deleted is a link */
8928 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8929 jump = adapter->jump_tables[i];
8930 if (jump && jump->link_hdl == hdl) {
8931 /* Delete filters in the hardware in the child hash
8932 * table associated with this link
8933 */
8934 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8935 if (!test_bit(j, jump->child_loc_map))
8936 continue;
8937 spin_lock(&adapter->fdir_perfect_lock);
8938 err = ixgbe_update_ethtool_fdir_entry(adapter,
8939 NULL,
8940 j + 1);
8941 spin_unlock(&adapter->fdir_perfect_lock);
8942 clear_bit(j, jump->child_loc_map);
8943 }
8944 /* Remove resources for this link */
8945 kfree(jump->input);
8946 kfree(jump->mask);
8947 kfree(jump);
8948 adapter->jump_tables[i] = NULL;
8949 return err;
8950 }
8951 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008952
John Fastabendb82b17d2016-02-16 21:18:53 -08008953 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008954 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008955 spin_unlock(&adapter->fdir_perfect_lock);
8956 return err;
8957}
8958
John Fastabenddb956ae2016-02-16 21:19:19 -08008959static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
John Fastabenddb956ae2016-02-16 21:19:19 -08008960 struct tc_cls_u32_offload *cls)
8961{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008962 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8963
8964 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8965 return -EINVAL;
8966
John Fastabenddb956ae2016-02-16 21:19:19 -08008967 /* This ixgbe devices do not support hash tables at the moment
8968 * so abort when given hash tables.
8969 */
8970 if (cls->hnode.divisor > 0)
8971 return -EINVAL;
8972
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008973 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008974 return 0;
8975}
8976
8977static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8978 struct tc_cls_u32_offload *cls)
8979{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008980 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8981
8982 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8983 return -EINVAL;
8984
8985 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008986 return 0;
8987}
8988
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008989#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07008990struct upper_walk_data {
8991 struct ixgbe_adapter *adapter;
8992 u64 action;
8993 int ifindex;
8994 u8 queue;
8995};
8996
8997static int get_macvlan_queue(struct net_device *upper, void *_data)
8998{
8999 if (netif_is_macvlan(upper)) {
9000 struct macvlan_dev *dfwd = netdev_priv(upper);
9001 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
9002 struct upper_walk_data *data = _data;
9003 struct ixgbe_adapter *adapter = data->adapter;
9004 int ifindex = data->ifindex;
9005
9006 if (vadapter && vadapter->netdev->ifindex == ifindex) {
9007 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
9008 data->action = data->queue;
9009 return 1;
9010 }
9011 }
9012
9013 return 0;
9014}
9015
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009016static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
9017 u8 *queue, u64 *action)
9018{
Alexander Duyck361b5342017-11-22 10:56:16 -08009019 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009020 unsigned int num_vfs = adapter->num_vfs, vf;
David Ahern1cd127f2016-10-17 19:15:48 -07009021 struct upper_walk_data data;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009022 struct net_device *upper;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009023
9024 /* redirect to a SRIOV VF */
9025 for (vf = 0; vf < num_vfs; ++vf) {
9026 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
9027 if (upper->ifindex == ifindex) {
Alexander Duyck361b5342017-11-22 10:56:16 -08009028 *queue = vf * __ALIGN_MASK(1, ~vmdq->mask);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009029 *action = vf + 1;
9030 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
9031 return 0;
9032 }
9033 }
9034
9035 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07009036 data.adapter = adapter;
9037 data.ifindex = ifindex;
9038 data.action = 0;
9039 data.queue = 0;
9040 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
9041 get_macvlan_queue, &data)) {
9042 *action = data.action;
9043 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009044
David Ahern1cd127f2016-10-17 19:15:48 -07009045 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009046 }
9047
9048 return -EINVAL;
9049}
9050
9051static int parse_tc_actions(struct ixgbe_adapter *adapter,
9052 struct tcf_exts *exts, u64 *action, u8 *queue)
9053{
9054 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07009055 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009056 int err;
9057
Jiri Pirko3bcc0ce2017-08-04 14:28:58 +02009058 if (!tcf_exts_has_actions(exts))
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009059 return -EINVAL;
9060
WANG Cong22dc13c2016-08-13 22:35:00 -07009061 tcf_exts_to_list(exts, &actions);
9062 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009063
9064 /* Drop action */
9065 if (is_tcf_gact_shot(a)) {
9066 *action = IXGBE_FDIR_DROP_QUEUE;
9067 *queue = IXGBE_FDIR_DROP_QUEUE;
9068 return 0;
9069 }
9070
9071 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03009072 if (is_tcf_mirred_egress_redirect(a)) {
Cong Wang9f8a7392017-12-05 16:17:26 -08009073 struct net_device *dev = tcf_mirred_dev(a);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009074
Cong Wang9f8a7392017-12-05 16:17:26 -08009075 if (!dev)
9076 return -EINVAL;
9077 err = handle_redirect_action(adapter, dev->ifindex, queue,
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009078 action);
9079 if (err == 0)
9080 return err;
9081 }
9082 }
9083
9084 return -EINVAL;
9085}
9086#else
9087static int parse_tc_actions(struct ixgbe_adapter *adapter,
9088 struct tcf_exts *exts, u64 *action, u8 *queue)
9089{
9090 return -EINVAL;
9091}
9092#endif /* CONFIG_NET_CLS_ACT */
9093
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009094static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
9095 union ixgbe_atr_input *mask,
9096 struct tc_cls_u32_offload *cls,
9097 struct ixgbe_mat_field *field_ptr,
9098 struct ixgbe_nexthdr *nexthdr)
9099{
9100 int i, j, off;
9101 __be32 val, m;
9102 bool found_entry = false, found_jump_field = false;
9103
9104 for (i = 0; i < cls->knode.sel->nkeys; i++) {
9105 off = cls->knode.sel->keys[i].off;
9106 val = cls->knode.sel->keys[i].val;
9107 m = cls->knode.sel->keys[i].mask;
9108
9109 for (j = 0; field_ptr[j].val; j++) {
9110 if (field_ptr[j].off == off) {
9111 field_ptr[j].val(input, mask, val, m);
9112 input->filter.formatted.flow_type |=
9113 field_ptr[j].type;
9114 found_entry = true;
9115 break;
9116 }
9117 }
9118 if (nexthdr) {
9119 if (nexthdr->off == cls->knode.sel->keys[i].off &&
9120 nexthdr->val == cls->knode.sel->keys[i].val &&
9121 nexthdr->mask == cls->knode.sel->keys[i].mask)
9122 found_jump_field = true;
9123 else
9124 continue;
9125 }
9126 }
9127
9128 if (nexthdr && !found_jump_field)
9129 return -EINVAL;
9130
9131 if (!found_entry)
9132 return 0;
9133
9134 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
9135 IXGBE_ATR_L4TYPE_MASK;
9136
9137 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
9138 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
9139
9140 return 0;
9141}
9142
John Fastabendb82b17d2016-02-16 21:18:53 -08009143static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
John Fastabendb82b17d2016-02-16 21:18:53 -08009144 struct tc_cls_u32_offload *cls)
9145{
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009146 __be16 protocol = cls->common.protocol;
John Fastabendb82b17d2016-02-16 21:18:53 -08009147 u32 loc = cls->knode.handle & 0xfffff;
9148 struct ixgbe_hw *hw = &adapter->hw;
9149 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009150 struct ixgbe_fdir_filter *input = NULL;
9151 union ixgbe_atr_input *mask = NULL;
9152 struct ixgbe_jump_table *jump = NULL;
9153 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08009154 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009155 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08009156
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009157 uhtid = TC_U32_USERHTID(cls->knode.handle);
9158 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08009159
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009160 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08009161 * L2 headers. The canonical method to match L2 frames is to use
9162 * negative values. However this is error prone at best but really
9163 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009164 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08009165 * headers when needed.
9166 */
9167 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009168 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009169
9170 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
9171 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009172 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009173 }
9174
9175 /* cls u32 is a graph starting at root node 0x800. The driver tracks
9176 * links and also the fields used to advance the parser across each
9177 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
9178 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
9179 * To add support for new nodes update ixgbe_model.h parse structures
9180 * this function _should_ be generic try not to hardcode values here.
9181 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009182 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009183 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009184 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009185 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009186 return err;
9187 if (!adapter->jump_tables[uhtid])
9188 return err;
9189 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009190 }
9191
9192 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009193 return err;
9194
9195 /* At this point we know the field_ptr is valid and need to either
9196 * build cls_u32 link or attach filter. Because adding a link to
9197 * a handle that does not exist is invalid and the same for adding
9198 * rules to handles that don't exist.
9199 */
9200
9201 if (link_uhtid) {
9202 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
9203
9204 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
9205 return err;
9206
9207 if (!test_bit(link_uhtid - 1, &adapter->tables))
9208 return err;
9209
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009210 /* Multiple filters as links to the same hash table are not
9211 * supported. To add a new filter with the same next header
9212 * but different match/jump conditions, create a new hash table
9213 * and link to it.
9214 */
9215 if (adapter->jump_tables[link_uhtid] &&
9216 (adapter->jump_tables[link_uhtid])->link_hdl) {
9217 e_err(drv, "Link filter exists for link: %x\n",
9218 link_uhtid);
9219 return err;
9220 }
9221
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009222 for (i = 0; nexthdr[i].jump; i++) {
9223 if (nexthdr[i].o != cls->knode.sel->offoff ||
9224 nexthdr[i].s != cls->knode.sel->offshift ||
9225 nexthdr[i].m != cls->knode.sel->offmask)
9226 return err;
9227
9228 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
9229 if (!jump)
9230 return -ENOMEM;
9231 input = kzalloc(sizeof(*input), GFP_KERNEL);
9232 if (!input) {
9233 err = -ENOMEM;
9234 goto free_jump;
9235 }
9236 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9237 if (!mask) {
9238 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009239 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009240 }
9241 jump->input = input;
9242 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009243 jump->link_hdl = cls->knode.handle;
9244
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009245 err = ixgbe_clsu32_build_input(input, mask, cls,
9246 field_ptr, &nexthdr[i]);
9247 if (!err) {
9248 jump->mat = nexthdr[i].jump;
9249 adapter->jump_tables[link_uhtid] = jump;
9250 break;
9251 }
9252 }
9253 return 0;
9254 }
John Fastabendb82b17d2016-02-16 21:18:53 -08009255
9256 input = kzalloc(sizeof(*input), GFP_KERNEL);
9257 if (!input)
9258 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009259 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9260 if (!mask) {
9261 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009262 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08009263 }
9264
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009265 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
9266 if ((adapter->jump_tables[uhtid])->input)
9267 memcpy(input, (adapter->jump_tables[uhtid])->input,
9268 sizeof(*input));
9269 if ((adapter->jump_tables[uhtid])->mask)
9270 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
9271 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009272
9273 /* Lookup in all child hash tables if this location is already
9274 * filled with a filter
9275 */
9276 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
9277 struct ixgbe_jump_table *link = adapter->jump_tables[i];
9278
9279 if (link && (test_bit(loc - 1, link->child_loc_map))) {
9280 e_err(drv, "Filter exists in location: %x\n",
9281 loc);
9282 err = -EINVAL;
9283 goto err_out;
9284 }
9285 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009286 }
9287 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
9288 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08009289 goto err_out;
9290
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009291 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
9292 &queue);
9293 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08009294 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08009295
John Fastabendb82b17d2016-02-16 21:18:53 -08009296 input->sw_idx = loc;
9297
9298 spin_lock(&adapter->fdir_perfect_lock);
9299
9300 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009301 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
9302 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009303 if (err)
9304 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009305 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08009306 err = -EINVAL;
9307 goto err_out_w_lock;
9308 }
9309
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009310 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009311 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
9312 input->sw_idx, queue);
9313 if (!err)
9314 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
9315 spin_unlock(&adapter->fdir_perfect_lock);
9316
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009317 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
9318 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009319
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009320 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009321 return err;
9322err_out_w_lock:
9323 spin_unlock(&adapter->fdir_perfect_lock);
9324err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009325 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009326free_input:
9327 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009328free_jump:
9329 kfree(jump);
9330 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009331}
9332
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009333static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009334 struct tc_cls_u32_offload *cls_u32)
9335{
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009336 if (cls_u32->common.chain_index)
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009337 return -EOPNOTSUPP;
9338
9339 switch (cls_u32->command) {
9340 case TC_CLSU32_NEW_KNODE:
9341 case TC_CLSU32_REPLACE_KNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009342 return ixgbe_configure_clsu32(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009343 case TC_CLSU32_DELETE_KNODE:
9344 return ixgbe_delete_clsu32(adapter, cls_u32);
9345 case TC_CLSU32_NEW_HNODE:
9346 case TC_CLSU32_REPLACE_HNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009347 return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009348 case TC_CLSU32_DELETE_HNODE:
9349 return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
9350 default:
9351 return -EOPNOTSUPP;
9352 }
9353}
9354
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009355static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
9356 void *cb_priv)
9357{
9358 struct ixgbe_adapter *adapter = cb_priv;
9359
Jiri Pirko44ae12a2017-11-01 11:47:39 +01009360 if (!tc_can_offload(adapter->netdev))
9361 return -EOPNOTSUPP;
9362
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009363 switch (type) {
9364 case TC_SETUP_CLSU32:
9365 return ixgbe_setup_tc_cls_u32(adapter, type_data);
9366 default:
9367 return -EOPNOTSUPP;
9368 }
9369}
9370
9371static int ixgbe_setup_tc_block(struct net_device *dev,
9372 struct tc_block_offload *f)
9373{
9374 struct ixgbe_adapter *adapter = netdev_priv(dev);
9375
9376 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
9377 return -EOPNOTSUPP;
9378
9379 switch (f->command) {
9380 case TC_BLOCK_BIND:
9381 return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
9382 adapter, adapter);
9383 case TC_BLOCK_UNBIND:
9384 tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
9385 adapter);
9386 return 0;
9387 default:
9388 return -EOPNOTSUPP;
9389 }
9390}
9391
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009392static int ixgbe_setup_tc_mqprio(struct net_device *dev,
9393 struct tc_mqprio_qopt *mqprio)
9394{
9395 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
9396 return ixgbe_setup_tc(dev, mqprio->num_tc);
9397}
9398
Jiri Pirko2572ac52017-08-07 10:15:17 +02009399static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02009400 void *type_data)
John Fastabende4c67342016-02-16 21:16:15 -08009401{
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009402 switch (type) {
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009403 case TC_SETUP_BLOCK:
9404 return ixgbe_setup_tc_block(dev, type_data);
Nogah Frankel575ed7d2017-11-06 07:23:42 +01009405 case TC_SETUP_QDISC_MQPRIO:
Jiri Pirkode4784c2017-08-07 10:15:32 +02009406 return ixgbe_setup_tc_mqprio(dev, type_data);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009407 default:
Jiri Pirkoa5fcf8a2017-06-06 17:00:16 +02009408 return -EOPNOTSUPP;
John Fastabendb82b17d2016-02-16 21:18:53 -08009409 }
John Fastabende4c67342016-02-16 21:16:15 -08009410}
9411
Greg Roseda36b642012-12-11 08:26:43 +00009412#ifdef CONFIG_PCI_IOV
9413void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
9414{
9415 struct net_device *netdev = adapter->netdev;
9416
9417 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00009418 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00009419 rtnl_unlock();
9420}
9421
9422#endif
Don Skidmore082757a2011-07-21 05:55:00 +00009423void ixgbe_do_reset(struct net_device *netdev)
9424{
9425 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9426
9427 if (netif_running(netdev))
9428 ixgbe_reinit_locked(adapter);
9429 else
9430 ixgbe_reset(adapter);
9431}
9432
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009433static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009434 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009435{
9436 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9437
Don Skidmore082757a2011-07-21 05:55:00 +00009438 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009439 if (!(features & NETIF_F_RXCSUM))
9440 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00009441
Alexander Duyck567d2de2012-02-11 07:18:57 +00009442 /* Turn off LRO if not RSC capable */
9443 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
9444 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009445
Alexander Duyck567d2de2012-02-11 07:18:57 +00009446 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00009447}
9448
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009449static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009450 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009451{
9452 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00009453 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00009454 bool need_reset = false;
9455
Don Skidmore082757a2011-07-21 05:55:00 +00009456 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009457 if (!(features & NETIF_F_LRO)) {
9458 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00009459 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00009460 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9461 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9462 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9463 if (adapter->rx_itr_setting == 1 ||
9464 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9465 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9466 need_reset = true;
9467 } else if ((changed ^ features) & NETIF_F_LRO) {
9468 e_info(probe, "rx-usecs set too low, "
9469 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00009470 }
9471 }
9472
9473 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08009474 * Check if Flow Director n-tuple support or hw_tc support was
9475 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00009476 */
John Fastabendb82b17d2016-02-16 21:18:53 -08009477 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00009478 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00009479 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9480 need_reset = true;
9481
Alexander Duyck567d2de2012-02-11 07:18:57 +00009482 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9483 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08009484 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00009485 /* turn off perfect filters, enable ATR and reset */
9486 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9487 need_reset = true;
9488
9489 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9490
9491 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08009492 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9493 /* We cannot enable ATR if we have 2 or more tcs */
9494 (netdev_get_num_tc(netdev) > 1) ||
9495 /* We cannot enable ATR if RSS is disabled */
9496 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9497 /* A sample rate of 0 indicates ATR disabled */
9498 (!adapter->atr_sample_rate))
9499 ; /* do nothing not supported */
9500 else /* otherwise supported and set the flag */
9501 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00009502 }
9503
Ben Greear3f2d1c02012-03-08 08:28:41 +00009504 if (changed & NETIF_F_RXALL)
9505 need_reset = true;
9506
Alexander Duyck567d2de2012-02-11 07:18:57 +00009507 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07009508
Mark Rustad67359c32015-06-15 11:33:25 -07009509 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07009510 if (features & NETIF_F_RXCSUM) {
9511 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9512 } else {
9513 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9514
9515 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9516 }
9517 }
9518
9519 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9520 if (features & NETIF_F_RXCSUM) {
9521 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9522 } else {
9523 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9524
9525 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9526 }
Mark Rustad67359c32015-06-15 11:33:25 -07009527 }
Mark Rustad67359c32015-06-15 11:33:25 -07009528
Don Skidmore082757a2011-07-21 05:55:00 +00009529 if (need_reset)
9530 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009531 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9532 NETIF_F_HW_VLAN_CTAG_FILTER))
9533 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00009534
9535 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00009536}
9537
Don Skidmore3f207802014-12-23 07:40:34 +00009538/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009539 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009540 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009541 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009542 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009543static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9544 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009545{
9546 struct ixgbe_adapter *adapter = netdev_priv(dev);
9547 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07009548 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07009549 u32 port_shift = 0;
9550 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07009551
Alexander Duyckb3a49552016-06-16 12:22:19 -07009552 if (ti->sa_family != AF_INET)
9553 return;
9554
Emil Tantilova21d0822016-08-10 11:19:23 -07009555 switch (ti->type) {
9556 case UDP_TUNNEL_TYPE_VXLAN:
9557 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9558 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009559
Emil Tantilova21d0822016-08-10 11:19:23 -07009560 if (adapter->vxlan_port == port)
9561 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009562
Emil Tantilova21d0822016-08-10 11:19:23 -07009563 if (adapter->vxlan_port) {
9564 netdev_info(dev,
9565 "VXLAN port %d set, not adding port %d\n",
9566 ntohs(adapter->vxlan_port),
9567 ntohs(port));
9568 return;
9569 }
9570
9571 adapter->vxlan_port = port;
9572 break;
9573 case UDP_TUNNEL_TYPE_GENEVE:
9574 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9575 return;
9576
9577 if (adapter->geneve_port == port)
9578 return;
9579
9580 if (adapter->geneve_port) {
9581 netdev_info(dev,
9582 "GENEVE port %d set, not adding port %d\n",
9583 ntohs(adapter->geneve_port),
9584 ntohs(port));
9585 return;
9586 }
9587
9588 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9589 adapter->geneve_port = port;
9590 break;
9591 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009592 return;
9593 }
9594
Emil Tantilova21d0822016-08-10 11:19:23 -07009595 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9596 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00009597}
9598
9599/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009600 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009601 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009602 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009603 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009604static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9605 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009606{
9607 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07009608 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00009609
Emil Tantilova21d0822016-08-10 11:19:23 -07009610 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9611 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07009612 return;
9613
9614 if (ti->sa_family != AF_INET)
9615 return;
9616
Emil Tantilova21d0822016-08-10 11:19:23 -07009617 switch (ti->type) {
9618 case UDP_TUNNEL_TYPE_VXLAN:
9619 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9620 return;
Mark Rustad67359c32015-06-15 11:33:25 -07009621
Emil Tantilova21d0822016-08-10 11:19:23 -07009622 if (adapter->vxlan_port != ti->port) {
9623 netdev_info(dev, "VXLAN port %d not found\n",
9624 ntohs(ti->port));
9625 return;
9626 }
9627
9628 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9629 break;
9630 case UDP_TUNNEL_TYPE_GENEVE:
9631 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9632 return;
9633
9634 if (adapter->geneve_port != ti->port) {
9635 netdev_info(dev, "GENEVE port %d not found\n",
9636 ntohs(ti->port));
9637 return;
9638 }
9639
9640 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9641 break;
9642 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009643 return;
9644 }
9645
Emil Tantilova21d0822016-08-10 11:19:23 -07009646 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9647 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00009648}
9649
stephen hemmingeredc7d572012-10-01 12:32:33 +00009650static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009651 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009652 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009653 u16 flags)
9654{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009655 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00009656 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009657 struct ixgbe_adapter *adapter = netdev_priv(dev);
9658 u16 pool = VMDQ_P(0);
9659
9660 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009661 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009662 }
9663
Jiri Pirkof6f64242014-11-28 14:34:15 +01009664 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009665}
9666
Don Skidmore219efe92015-04-09 22:03:22 -07009667/**
9668 * ixgbe_configure_bridge_mode - set various bridge modes
9669 * @adapter - the private structure
9670 * @mode - requested bridge mode
9671 *
9672 * Configure some settings require for various bridge modes.
9673 **/
9674static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9675 __u16 mode)
9676{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009677 struct ixgbe_hw *hw = &adapter->hw;
9678 unsigned int p, num_pools;
9679 u32 vmdctl;
9680
Don Skidmore219efe92015-04-09 22:03:22 -07009681 switch (mode) {
9682 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009683 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009684 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009685
9686 /* must enable Rx switching replication to allow multicast
9687 * packet reception on all VFs, and to enable source address
9688 * pruning.
9689 */
9690 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9691 vmdctl |= IXGBE_VT_CTL_REPLEN;
9692 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9693
9694 /* enable Rx source address pruning. Note, this requires
9695 * replication to be enabled or else it does nothing.
9696 */
9697 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9698 for (p = 0; p < num_pools; p++) {
9699 if (hw->mac.ops.set_source_address_pruning)
9700 hw->mac.ops.set_source_address_pruning(hw,
9701 true,
9702 p);
9703 }
Don Skidmore219efe92015-04-09 22:03:22 -07009704 break;
9705 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009706 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009707 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9708 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009709
9710 /* disable Rx switching replication unless we have SR-IOV
9711 * virtual functions
9712 */
9713 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9714 if (!adapter->num_vfs)
9715 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9716 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9717
9718 /* disable Rx source address pruning, since we don't expect to
9719 * be receiving external loopback of our transmitted frames.
9720 */
9721 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9722 for (p = 0; p < num_pools; p++) {
9723 if (hw->mac.ops.set_source_address_pruning)
9724 hw->mac.ops.set_source_address_pruning(hw,
9725 false,
9726 p);
9727 }
Don Skidmore219efe92015-04-09 22:03:22 -07009728 break;
9729 default:
9730 return -EINVAL;
9731 }
9732
9733 adapter->bridge_mode = mode;
9734
9735 e_info(drv, "enabling bridge mode: %s\n",
9736 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9737
9738 return 0;
9739}
9740
John Fastabend815cccb2012-10-24 08:13:09 +00009741static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009742 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009743{
9744 struct ixgbe_adapter *adapter = netdev_priv(dev);
9745 struct nlattr *attr, *br_spec;
9746 int rem;
9747
9748 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9749 return -EOPNOTSUPP;
9750
9751 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009752 if (!br_spec)
9753 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009754
9755 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009756 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009757 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009758
9759 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9760 continue;
9761
Thomas Grafb7c1a312014-11-26 13:42:17 +01009762 if (nla_len(attr) < sizeof(mode))
9763 return -EINVAL;
9764
John Fastabend815cccb2012-10-24 08:13:09 +00009765 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009766 status = ixgbe_configure_bridge_mode(adapter, mode);
9767 if (status)
9768 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009769
9770 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009771 }
9772
9773 return 0;
9774}
9775
9776static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009777 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009778 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009779{
9780 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009781
9782 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9783 return 0;
9784
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009785 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009786 adapter->bridge_mode, 0, 0, nlflags,
9787 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009788}
9789
John Fastabend2a47fa42013-11-06 09:54:52 -08009790static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9791{
9792 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
9793 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009794 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
Alexander Duyck4e039c12017-11-22 10:56:40 -08009795 int tcs = netdev_get_num_tc(pdev) ? : 1;
John Fastabend51f37732013-11-08 00:51:10 -08009796 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009797 int pool, err;
9798
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009799 /* Hardware has a limited number of available pools. Each VF, and the
9800 * PF require a pool. Check to ensure we don't attempt to use more
9801 * then the available number of pools.
9802 */
9803 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9804 return ERR_PTR(-EINVAL);
9805
John Fastabend219354d2013-11-08 00:50:32 -08009806#ifdef CONFIG_RPS
9807 if (vdev->num_rx_queues != vdev->num_tx_queues) {
9808 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
9809 vdev->name);
9810 return ERR_PTR(-EINVAL);
9811 }
9812#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08009813 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08009814 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08009815 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
9816 netdev_info(pdev,
9817 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
9818 pdev->name);
9819 return ERR_PTR(-EINVAL);
9820 }
9821
9822 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck4e039c12017-11-22 10:56:40 -08009823 adapter->num_rx_pools >= (MAX_TX_QUEUES / tcs)) ||
John Fastabend2a47fa42013-11-06 09:54:52 -08009824 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
9825 return ERR_PTR(-EBUSY);
9826
Maninder Singhbc52f952015-06-19 09:37:55 +05309827 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08009828 if (!fwd_adapter)
9829 return ERR_PTR(-ENOMEM);
9830
Alexander Duyck4e039c12017-11-22 10:56:40 -08009831 pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
9832 set_bit(pool, adapter->fwd_bitmask);
9833 limit = find_last_bit(adapter->fwd_bitmask, adapter->num_rx_pools + 1);
John Fastabend2a47fa42013-11-06 09:54:52 -08009834
9835 /* Enable VMDq flag so device will be set in VM mode */
9836 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08009837 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08009838 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08009839
9840 /* Force reinit of ring allocation with VMDQ enabled */
9841 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9842 if (err)
9843 goto fwd_add_err;
9844 fwd_adapter->pool = pool;
9845 fwd_adapter->real_adapter = adapter;
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009846
9847 if (netif_running(pdev)) {
9848 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
9849 if (err)
9850 goto fwd_add_err;
9851 netif_tx_start_all_queues(vdev);
9852 }
9853
John Fastabend2a47fa42013-11-06 09:54:52 -08009854 return fwd_adapter;
9855fwd_add_err:
9856 /* unwind counter and free adapter struct */
9857 netdev_info(pdev,
9858 "%s: dfwd hardware acceleration failed\n", vdev->name);
Alexander Duyck4e039c12017-11-22 10:56:40 -08009859 clear_bit(pool, adapter->fwd_bitmask);
John Fastabend2a47fa42013-11-06 09:54:52 -08009860 kfree(fwd_adapter);
9861 return ERR_PTR(err);
9862}
9863
9864static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9865{
9866 struct ixgbe_fwd_adapter *fwd_adapter = priv;
9867 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08009868 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009869
Alexander Duyck4e039c12017-11-22 10:56:40 -08009870 clear_bit(fwd_adapter->pool, adapter->fwd_bitmask);
John Fastabend2a47fa42013-11-06 09:54:52 -08009871
Alexander Duyck4e039c12017-11-22 10:56:40 -08009872 limit = find_last_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
John Fastabend51f37732013-11-08 00:51:10 -08009873 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009874 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
Shannon Nelsonf5a71ca2017-08-15 08:59:54 -07009875
9876 /* go back to full RSS if we're done with our VMQs */
9877 if (adapter->ring_feature[RING_F_VMDQ].limit == 1) {
9878 int rss = min_t(int, ixgbe_max_rss_indices(adapter),
9879 num_online_cpus());
9880
9881 adapter->flags &= ~IXGBE_FLAG_VMDQ_ENABLED;
9882 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
9883 adapter->ring_feature[RING_F_RSS].limit = rss;
9884 }
9885
John Fastabend2a47fa42013-11-06 09:54:52 -08009886 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
Alexander Duyck4e039c12017-11-22 10:56:40 -08009887 netdev_dbg(pdev, "pool %i:%i queues %i:%i\n",
John Fastabend2a47fa42013-11-06 09:54:52 -08009888 fwd_adapter->pool, adapter->num_rx_pools,
9889 fwd_adapter->rx_base_queue,
Alexander Duyck4e039c12017-11-22 10:56:40 -08009890 fwd_adapter->rx_base_queue +
9891 adapter->num_rx_queues_per_pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08009892 kfree(fwd_adapter);
9893}
9894
Alexander Duyckb83e3012016-04-14 17:19:31 -04009895#define IXGBE_MAX_MAC_HDR_LEN 127
9896#define IXGBE_MAX_NETWORK_HDR_LEN 511
9897
Mark Rustadf467bc02015-06-15 11:33:20 -07009898static netdev_features_t
9899ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9900 netdev_features_t features)
9901{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009902 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009903
Alexander Duyckb83e3012016-04-14 17:19:31 -04009904 /* Make certain the headers can be described by a context descriptor */
9905 mac_hdr_len = skb_network_header(skb) - skb->data;
9906 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9907 return features & ~(NETIF_F_HW_CSUM |
9908 NETIF_F_SCTP_CRC |
9909 NETIF_F_HW_VLAN_CTAG_TX |
9910 NETIF_F_TSO |
9911 NETIF_F_TSO6);
9912
9913 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9914 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9915 return features & ~(NETIF_F_HW_CSUM |
9916 NETIF_F_SCTP_CRC |
9917 NETIF_F_TSO |
9918 NETIF_F_TSO6);
9919
9920 /* We can only support IPV4 TSO in tunnels if we can mangle the
9921 * inner IP ID field, so strip TSO if MANGLEID is not supported.
9922 */
9923 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
9924 features &= ~NETIF_F_TSO;
Mark Rustadf467bc02015-06-15 11:33:20 -07009925
9926 return features;
9927}
9928
John Fastabend92470802017-04-24 03:30:17 -07009929static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
9930{
9931 int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
9932 struct ixgbe_adapter *adapter = netdev_priv(dev);
9933 struct bpf_prog *old_prog;
9934
9935 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
9936 return -EINVAL;
9937
9938 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
9939 return -EINVAL;
9940
9941 /* verify ixgbe ring attributes are sufficient for XDP */
9942 for (i = 0; i < adapter->num_rx_queues; i++) {
9943 struct ixgbe_ring *ring = adapter->rx_ring[i];
9944
9945 if (ring_is_rsc_enabled(ring))
9946 return -EINVAL;
9947
9948 if (frame_size > ixgbe_rx_bufsz(ring))
9949 return -EINVAL;
9950 }
9951
John Fastabend33fdc822017-04-24 03:30:18 -07009952 if (nr_cpu_ids > MAX_XDP_QUEUES)
9953 return -ENOMEM;
9954
John Fastabend92470802017-04-24 03:30:17 -07009955 old_prog = xchg(&adapter->xdp_prog, prog);
John Fastabend33fdc822017-04-24 03:30:18 -07009956
9957 /* If transitioning XDP modes reconfigure rings */
9958 if (!!prog != !!old_prog) {
9959 int err = ixgbe_setup_tc(dev, netdev_get_num_tc(dev));
9960
9961 if (err) {
9962 rcu_assign_pointer(adapter->xdp_prog, old_prog);
9963 return -EINVAL;
9964 }
9965 } else {
9966 for (i = 0; i < adapter->num_rx_queues; i++)
9967 xchg(&adapter->rx_ring[i]->xdp_prog, adapter->xdp_prog);
9968 }
John Fastabend92470802017-04-24 03:30:17 -07009969
9970 if (old_prog)
9971 bpf_prog_put(old_prog);
9972
9973 return 0;
9974}
9975
Jakub Kicinskif4e63522017-11-03 13:56:16 -07009976static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
John Fastabend92470802017-04-24 03:30:17 -07009977{
9978 struct ixgbe_adapter *adapter = netdev_priv(dev);
9979
9980 switch (xdp->command) {
9981 case XDP_SETUP_PROG:
9982 return ixgbe_xdp_setup(dev, xdp->prog);
9983 case XDP_QUERY_PROG:
9984 xdp->prog_attached = !!(adapter->xdp_prog);
Martin KaFai Lau47920932017-06-15 17:29:15 -07009985 xdp->prog_id = adapter->xdp_prog ?
9986 adapter->xdp_prog->aux->id : 0;
John Fastabend92470802017-04-24 03:30:17 -07009987 return 0;
9988 default:
9989 return -EINVAL;
9990 }
9991}
9992
John Fastabend64530732017-07-17 09:28:12 -07009993static int ixgbe_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp)
9994{
9995 struct ixgbe_adapter *adapter = netdev_priv(dev);
9996 struct ixgbe_ring *ring;
9997 int err;
9998
9999 if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +020010000 return -ENETDOWN;
John Fastabend64530732017-07-17 09:28:12 -070010001
10002 /* During program transitions its possible adapter->xdp_prog is assigned
10003 * but ring has not been configured yet. In this case simply abort xmit.
10004 */
10005 ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
10006 if (unlikely(!ring))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +020010007 return -ENXIO;
John Fastabend64530732017-07-17 09:28:12 -070010008
10009 err = ixgbe_xmit_xdp_ring(adapter, xdp);
10010 if (err != IXGBE_XDP_TX)
Jesper Dangaard Brouerd2cee2e2017-08-17 18:22:32 +020010011 return -ENOSPC;
John Fastabend64530732017-07-17 09:28:12 -070010012
John Fastabend11393cc2017-07-17 09:29:40 -070010013 return 0;
10014}
10015
10016static void ixgbe_xdp_flush(struct net_device *dev)
10017{
10018 struct ixgbe_adapter *adapter = netdev_priv(dev);
10019 struct ixgbe_ring *ring;
10020
10021 /* Its possible the device went down between xdp xmit and flush so
10022 * we need to ensure device is still up.
10023 */
10024 if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
10025 return;
10026
10027 ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
10028 if (unlikely(!ring))
10029 return;
10030
John Fastabend64530732017-07-17 09:28:12 -070010031 /* Force memory writes to complete before letting h/w know there
10032 * are new descriptors to fetch.
10033 */
10034 wmb();
John Fastabend64530732017-07-17 09:28:12 -070010035 writel(ring->next_to_use, ring->tail);
10036
John Fastabend11393cc2017-07-17 09:29:40 -070010037 return;
John Fastabend64530732017-07-17 09:28:12 -070010038}
10039
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010040static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +000010041 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010042 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -080010043 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -070010044 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +000010045 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010046 .ndo_validate_addr = eth_validate_addr,
10047 .ndo_set_mac_address = ixgbe_set_mac,
10048 .ndo_change_mtu = ixgbe_change_mtu,
10049 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +000010050 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010051 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
10052 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +000010053 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +000010054 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
10055 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -040010056 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +000010057 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +030010058 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +000010059 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +000010060 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +000010061 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -080010062 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010063#ifdef CONFIG_NET_POLL_CONTROLLER
10064 .ndo_poll_controller = ixgbe_netpoll,
10065#endif
Yi Zou332d4a72009-05-13 13:11:53 +000010066#ifdef IXGBE_FCOE
10067 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +000010068 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +000010069 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +000010070 .ndo_fcoe_enable = ixgbe_fcoe_enable,
10071 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +000010072 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +000010073 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +000010074#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +000010075 .ndo_set_features = ixgbe_set_features,
10076 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +000010077 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +000010078 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
10079 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -080010080 .ndo_dfwd_add_station = ixgbe_fwd_add,
10081 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -070010082 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
10083 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -070010084 .ndo_features_check = ixgbe_features_check,
Jakub Kicinskif4e63522017-11-03 13:56:16 -070010085 .ndo_bpf = ixgbe_xdp,
John Fastabend64530732017-07-17 09:28:12 -070010086 .ndo_xdp_xmit = ixgbe_xdp_xmit,
John Fastabend11393cc2017-07-17 09:29:40 -070010087 .ndo_xdp_flush = ixgbe_xdp_flush,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010088};
10089
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010090/**
Jacob Kellere027d1a2013-07-31 06:53:31 +000010091 * ixgbe_enumerate_functions - Get the number of ports this device has
10092 * @adapter: adapter structure
10093 *
10094 * This function enumerates the phsyical functions co-located on a single slot,
10095 * in order to determine how many ports a device has. This is most useful in
10096 * determining the required GT/s of PCIe bandwidth necessary for optimal
10097 * performance.
10098 **/
10099static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
10100{
Jacob Kellercaafb952014-07-19 07:17:17 +000010101 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010102 int physfns = 0;
10103
Jacob Kellerf1f96572013-08-31 02:45:38 +000010104 /* Some cards can not use the generic count PCIe functions method,
10105 * because they are behind a parent switch, so we hardcode these with
10106 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +000010107 */
Jacob Keller88189702014-07-19 07:17:16 +000010108 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +000010109 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +000010110
10111 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
10112 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +000010113 if (entry->is_virtfn)
10114 continue;
10115
10116 /* When the devices on the bus don't all match our device ID,
10117 * we can't reliably determine the correct number of
10118 * functions. This can occur if a function has been direct
10119 * attached to a virtual machine using VT-d, for example. In
10120 * this case, simply return -1 to indicate this.
10121 */
10122 if ((entry->vendor != pdev->vendor) ||
10123 (entry->device != pdev->device))
10124 return -1;
10125
10126 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010127 }
10128
10129 return physfns;
10130}
10131
10132/**
Jacob Keller8e2813f2012-04-21 06:05:40 +000010133 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -070010134 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +000010135 * @device_id: the device ID
10136 * @subdev_id: the subsystem device ID
10137 *
10138 * This function is used by probe and ethtool to determine
10139 * which devices have WoL support
10140 *
10141 **/
Emil Tantilov740234f2016-04-21 11:37:12 -070010142bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
10143 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +000010144{
10145 struct ixgbe_hw *hw = &adapter->hw;
10146 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010147
Emil Tantilov740234f2016-04-21 11:37:12 -070010148 /* WOL not supported on 82598 */
10149 if (hw->mac.type == ixgbe_mac_82598EB)
10150 return false;
10151
10152 /* check eeprom to see if WOL is enabled for X540 and newer */
10153 if (hw->mac.type >= ixgbe_mac_X540) {
10154 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
10155 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
10156 (hw->bus.func == 0)))
10157 return true;
10158 }
10159
10160 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +000010161 switch (device_id) {
10162 case IXGBE_DEV_ID_82599_SFP:
10163 /* Only these subdevices could supports WOL */
10164 switch (subdevice_id) {
10165 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010166 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
10167 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
10168 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010169 /* only support first port */
10170 if (hw->bus.func != 0)
10171 break;
Tony Nguyen93df9462017-05-31 04:43:47 -070010172 /* fall through */
Emil Tantilov5700ff22013-04-18 08:18:55 +000010173 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010174 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +000010175 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +000010176 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010177 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
10178 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
10179 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -070010180 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010181 }
10182 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010183 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -070010184 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +000010185 switch (subdevice_id) {
10186 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -070010187 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010188 }
10189 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010190 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
10191 /* All except this subdevice support WOL */
10192 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -070010193 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010194 break;
10195 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -070010196 return true;
10197 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010198 break;
10199 }
10200
Emil Tantilov740234f2016-04-21 11:37:12 -070010201 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010202}
10203
10204/**
Paul Greenwalt73834ae2017-10-27 10:32:40 -040010205 * ixgbe_set_fw_version - Set FW version
10206 * @adapter: the adapter private structure
10207 *
10208 * This function is used by probe and ethtool to determine the FW version to
10209 * format to display. The FW version is taken from the EEPROM/NVM.
10210 */
10211static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter)
10212{
10213 struct ixgbe_hw *hw = &adapter->hw;
10214 struct ixgbe_nvm_version nvm_ver;
10215
10216 ixgbe_get_oem_prod_version(hw, &nvm_ver);
10217 if (nvm_ver.oem_valid) {
10218 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10219 "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor,
10220 nvm_ver.oem_release);
10221 return;
10222 }
10223
10224 ixgbe_get_etk_id(hw, &nvm_ver);
10225 ixgbe_get_orom_version(hw, &nvm_ver);
10226
10227 if (nvm_ver.or_valid) {
10228 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10229 "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major,
10230 nvm_ver.or_build, nvm_ver.or_patch);
10231 return;
10232 }
10233
10234 /* Set ETrack ID format */
10235 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10236 "0x%08x", nvm_ver.etk_id);
10237}
10238
10239/**
Auke Kok9a799d72007-09-15 14:07:45 -070010240 * ixgbe_probe - Device Initialization Routine
10241 * @pdev: PCI device information struct
10242 * @ent: entry in ixgbe_pci_tbl
10243 *
10244 * Returns 0 on success, negative on failure
10245 *
10246 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
10247 * The OS initialization, configuring of the adapter private structure,
10248 * and a hardware reset occur.
10249 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000010250static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -070010251{
10252 struct net_device *netdev;
10253 struct ixgbe_adapter *adapter = NULL;
10254 struct ixgbe_hw *hw;
10255 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +000010256 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010257 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +000010258 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010259 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +000010260#ifdef IXGBE_FCOE
10261 u16 device_caps;
10262#endif
Don Skidmore289700db2010-12-03 03:32:58 +000010263 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -070010264
Andy Gospodarekbded64a2010-07-21 06:40:31 +000010265 /* Catch broken hardware that put the wrong VF device ID in
10266 * the PCIe SR-IOV capability.
10267 */
10268 if (pdev->is_virtfn) {
10269 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
10270 pci_name(pdev), pdev->vendor, pdev->device);
10271 return -EINVAL;
10272 }
10273
gouji-new9ce77662009-05-06 10:44:45 +000010274 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010275 if (err)
10276 return err;
10277
Russell Kingf5f2eda2013-06-10 12:47:42 +010010278 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -070010279 pci_using_dac = 1;
10280 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010281 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -070010282 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010283 dev_err(&pdev->dev,
10284 "No usable DMA configuration, aborting\n");
10285 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -070010286 }
10287 pci_using_dac = 0;
10288 }
10289
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010290 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -070010291 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +000010292 dev_err(&pdev->dev,
10293 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -070010294 goto err_pci_reg;
10295 }
10296
Frans Pop19d5afd2009-10-02 10:04:12 -070010297 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010298
Auke Kok9a799d72007-09-15 14:07:45 -070010299 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -070010300 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010301
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010302 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +000010303#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010304 /* 8 TC w/ 4 queues per TC */
10305 indices = 4 * MAX_TRAFFIC_CLASS;
10306#else
10307 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +000010308#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010309 }
John Fastabende901acd2011-04-26 07:26:08 +000010310
John Fastabendc85a2612010-02-25 23:15:21 +000010311 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -070010312 if (!netdev) {
10313 err = -ENOMEM;
10314 goto err_alloc_etherdev;
10315 }
10316
Auke Kok9a799d72007-09-15 14:07:45 -070010317 SET_NETDEV_DEV(netdev, &pdev->dev);
10318
Auke Kok9a799d72007-09-15 14:07:45 -070010319 adapter = netdev_priv(netdev);
10320
10321 adapter->netdev = netdev;
10322 adapter->pdev = pdev;
10323 hw = &adapter->hw;
10324 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +000010325 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -070010326
Jeff Kirsher05857982008-09-11 19:57:00 -070010327 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +000010328 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -080010329 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -070010330 if (!hw->hw_addr) {
10331 err = -EIO;
10332 goto err_ioremap;
10333 }
10334
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010335 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010336 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010337 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +000010338 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -070010339
Auke Kok9a799d72007-09-15 14:07:45 -070010340 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -080010341 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010342 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010343 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -070010344 if (ii->link_ops)
10345 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010346
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010347 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -080010348 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010349 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +000010350 if (ixgbe_removed(hw->hw_addr)) {
10351 err = -EIO;
10352 goto err_ioremap;
10353 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010354 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -070010355 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010356 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
10357
10358 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -080010359 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010360 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +000010361 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
10362 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
10363 hw->phy.mdio.mmds = 0;
10364 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10365 hw->phy.mdio.dev = netdev;
10366 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
10367 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010368
Auke Kok9a799d72007-09-15 14:07:45 -070010369 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -070010370 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -070010371 if (err)
10372 goto err_sw_init;
10373
Don Skidmoredbd15b82016-03-09 16:45:00 -050010374 /* Make sure the SWFW semaphore is in a valid state */
10375 if (hw->mac.ops.init_swfw_sync)
10376 hw->mac.ops.init_swfw_sync(hw);
10377
Don Skidmoree86bff02010-02-11 04:14:08 +000010378 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -080010379 switch (adapter->hw.mac.type) {
10380 case ixgbe_mac_82599EB:
10381 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010382 case ixgbe_mac_X550:
10383 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -070010384 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +000010385 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -080010386 break;
10387 default:
10388 break;
10389 }
Don Skidmoree86bff02010-02-11 04:14:08 +000010390
Don Skidmorebf069c92009-05-07 10:39:54 +000010391 /*
10392 * If there is a fan on this device and it has failed log the
10393 * failure.
10394 */
10395 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
10396 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
10397 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +000010398 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +000010399 }
10400
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +000010401 if (allow_unsupported_sfp)
10402 hw->allow_unsupported_sfp = allow_unsupported_sfp;
10403
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010404 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010405 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010406 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010407 hw->phy.reset_if_overtemp = false;
Mark Rustadb3eb4e12016-12-14 11:02:16 -080010408 ixgbe_set_eee_capable(adapter);
Mark Rustad29a8dca2015-08-08 16:17:46 -070010409 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -070010410 err = 0;
10411 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +000010412 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
10413 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010414 goto err_sw_init;
10415 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010416 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010417 goto err_sw_init;
10418 }
10419
Alexander Duyck99d74482012-05-09 08:09:25 +000010420#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +000010421 /* SR-IOV not supported on the 82598 */
10422 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
10423 goto skip_sriov;
10424 /* Mailbox */
10425 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -080010426 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -080010427 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
Emil Tantilov5c11f002017-01-20 14:11:56 -080010428 ixgbe_enable_sriov(adapter, max_vfs);
Greg Rose60a1a682012-12-11 08:26:33 +000010429skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010430
Alexander Duyck99d74482012-05-09 08:09:25 +000010431#endif
Emil Tantilov396e7992010-07-01 20:05:12 +000010432 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +000010433 NETIF_F_TSO |
10434 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +000010435 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -080010436 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010437 NETIF_F_HW_CSUM;
10438
10439#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
10440 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -070010441 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -070010442 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -040010443 NETIF_F_GSO_UDP_TUNNEL | \
10444 NETIF_F_GSO_UDP_TUNNEL_CSUM)
10445
10446 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
10447 netdev->features |= NETIF_F_GSO_PARTIAL |
10448 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -070010449
Alexander Duyck49763de2016-01-13 07:31:11 -080010450 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -080010451 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +000010452
Alexander Duyck49763de2016-01-13 07:31:11 -080010453 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -040010454 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -070010455 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010456 NETIF_F_HW_VLAN_CTAG_RX |
10457 NETIF_F_HW_VLAN_CTAG_TX |
10458 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -080010459 NETIF_F_HW_L2FW_DOFFLOAD;
10460
10461 if (hw->mac.type >= ixgbe_mac_82599EB)
10462 netdev->hw_features |= NETIF_F_NTUPLE |
10463 NETIF_F_HW_TC;
10464
Alexander Duyckb83e3012016-04-14 17:19:31 -040010465 if (pci_using_dac)
10466 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -070010467
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010468 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
10469 netdev->hw_enc_features |= netdev->vlan_features;
Scott Peterson2a205252016-11-18 11:25:42 -080010470 netdev->mpls_features |= NETIF_F_SG |
10471 NETIF_F_TSO |
10472 NETIF_F_TSO6 |
10473 NETIF_F_HW_CSUM;
10474 netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010475
Alexander Duyckb83e3012016-04-14 17:19:31 -040010476 /* set this bit last since it cannot be part of vlan_features */
10477 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
10478 NETIF_F_HW_VLAN_CTAG_RX |
10479 NETIF_F_HW_VLAN_CTAG_TX;
10480
Jiri Pirko01789342011-08-16 06:29:00 +000010481 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +000010482 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +000010483
Jarod Wilson91c527a2016-10-17 15:54:05 -040010484 /* MTU range: 68 - 9710 */
10485 netdev->min_mtu = ETH_MIN_MTU;
10486 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
10487
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -080010488#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -070010489 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
Stephen Hemminger3f40c742016-11-21 09:52:40 -080010490 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -080010491#endif
10492
Yi Zoueacd73f2009-05-13 13:11:06 +000010493#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +000010494 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010495 unsigned int fcoe_l;
10496
Yi Zoueacd73f2009-05-13 13:11:06 +000010497 if (hw->mac.ops.get_device_caps) {
10498 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +000010499 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
10500 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +000010501 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010502
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010503
10504 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
10505 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010506
Alexander Duycka58915c2012-05-25 06:38:18 +000010507 netdev->features |= NETIF_F_FSO |
10508 NETIF_F_FCOE_CRC;
10509
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010510 netdev->vlan_features |= NETIF_F_FSO |
10511 NETIF_F_FCOE_CRC |
10512 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +000010513 }
Yi Zoueacd73f2009-05-13 13:11:06 +000010514#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -070010515
Don Skidmore082757a2011-07-21 05:55:00 +000010516 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
10517 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +000010518 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +000010519 netdev->features |= NETIF_F_LRO;
10520
Auke Kok9a799d72007-09-15 14:07:45 -070010521 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010522 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010523 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010524 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010525 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010526 }
10527
Sowmini Varadhanc7374b52016-01-12 19:32:30 -080010528 eth_platform_get_mac_address(&adapter->pdev->dev,
10529 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +000010530
Auke Kok9a799d72007-09-15 14:07:45 -070010531 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -070010532
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +000010533 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010534 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010535 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010536 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010537 }
10538
Tushar Dave56768042016-01-07 14:17:03 -080010539 /* Set hw->mac.addr to permanent MAC address */
10540 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -070010541 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010542
Kees Cook26566ea2017-10-16 17:29:35 -070010543 timer_setup(&adapter->service_timer, ixgbe_service_timer, 0);
Auke Kok9a799d72007-09-15 14:07:45 -070010544
Mark Rustad58cf6632014-03-12 00:38:40 +000010545 if (ixgbe_removed(hw->hw_addr)) {
10546 err = -EIO;
10547 goto err_sw_init;
10548 }
Alexander Duyck70864002011-04-27 09:13:56 +000010549 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +000010550 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010551 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010552
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010553 err = ixgbe_init_interrupt_scheme(adapter);
10554 if (err)
10555 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010556
Liwei Songb09457e2016-12-04 22:40:44 -050010557 for (i = 0; i < adapter->num_rx_queues; i++)
10558 u64_stats_init(&adapter->rx_ring[i]->syncp);
10559 for (i = 0; i < adapter->num_tx_queues; i++)
10560 u64_stats_init(&adapter->tx_ring[i]->syncp);
John Fastabend33fdc822017-04-24 03:30:18 -070010561 for (i = 0; i < adapter->num_xdp_queues; i++)
10562 u64_stats_init(&adapter->xdp_ring[i]->syncp);
10563
Jacob Keller8e2813f2012-04-21 06:05:40 +000010564 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010565 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010566 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010567 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +000010568 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010569 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +000010570 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010571
PJ Waskiewicze8e26352009-02-27 15:45:05 +000010572 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
10573
Emil Tantilov15e52092011-09-29 05:01:29 +000010574 /* save off EEPROM version number */
Paul Greenwalt73834ae2017-10-27 10:32:40 -040010575 ixgbe_set_fw_version(adapter);
Emil Tantilov15e52092011-09-29 05:01:29 +000010576
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010577 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +000010578 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +000010579 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -040010580 else
10581 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010582
Jacob Kellere027d1a2013-07-31 06:53:31 +000010583 /* calculate the expected PCIe bandwidth required for optimal
10584 * performance. Note that some older parts will never have enough
10585 * bandwidth due to being older generation PCIe parts. We clamp these
10586 * parts to ensure no warning is displayed if it can't be fixed.
10587 */
10588 switch (hw->mac.type) {
10589 case ixgbe_mac_82598EB:
10590 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
10591 break;
10592 default:
10593 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
10594 break;
Auke Kok0c254d82008-02-11 09:25:56 -080010595 }
Jacob Kellercaafb952014-07-19 07:17:17 +000010596
10597 /* don't check link if we failed to enumerate functions */
10598 if (expected_gts > 0)
10599 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -080010600
Mark Rustad339de302014-06-06 01:57:06 +000010601 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010602 if (err)
Mark Rustad339de302014-06-06 01:57:06 +000010603 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010604 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
10605 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
10606 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +000010607 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +000010608 else
10609 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
10610 hw->mac.type, hw->phy.type, part_str);
10611
10612 e_dev_info("%pM\n", netdev->dev_addr);
10613
Auke Kok9a799d72007-09-15 14:07:45 -070010614 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010615 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010616 if (err == IXGBE_ERR_EEPROM_VERSION) {
10617 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +000010618 e_dev_warn("This device is a pre-production adapter/LOM. "
10619 "Please be aware there may be issues associated "
10620 "with your hardware. If you are experiencing "
10621 "problems please contact your Intel or hardware "
10622 "representative who provided you with this "
10623 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010624 }
Auke Kok9a799d72007-09-15 14:07:45 -070010625 strcpy(netdev->name, "eth%d");
Jeff Mahoneya09c0fc2017-06-03 18:01:17 -040010626 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010627 err = register_netdev(netdev);
10628 if (err)
10629 goto err_register;
10630
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010631
Emil Tantilovec74a472012-09-20 03:33:56 +000010632 /* power down the optics for 82599 SFP+ fiber */
10633 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +000010634 hw->mac.ops.disable_tx_laser(hw);
10635
Jesse Brandeburg54386462009-04-17 20:44:27 +000010636 /* carrier off reporting is important to ethtool even BEFORE open */
10637 netif_carrier_off(netdev);
10638
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010639#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +030010640 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010641 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010642 ixgbe_setup_dca(adapter);
10643 }
10644#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010645 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010646 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010647 for (i = 0; i < adapter->num_vfs; i++)
10648 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10649 }
10650
Jacob Keller2466dd92011-09-08 03:50:54 +000010651 /* firmware requires driver version to be 0xFFFFFFFF
10652 * since os does not support feature
10653 */
Emil Tantilov9612de92011-05-07 07:40:20 +000010654 if (hw->mac.ops.set_fw_drv_ver)
Tony Nguyencb8e0512016-10-26 16:25:18 -070010655 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10656 sizeof(ixgbe_driver_version) - 1,
10657 ixgbe_driver_version);
Emil Tantilov9612de92011-05-07 07:40:20 +000010658
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010659 /* add san mac addr to netdev */
10660 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010661
Neerav Parikhea818752012-01-04 20:23:40 +000010662 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010663
Don Skidmore12109822012-05-04 06:07:08 +000010664#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010665 if (ixgbe_sysfs_init(adapter))
10666 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +000010667#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010668
Catherine Sullivan00949162012-08-10 01:59:10 +000010669 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010670
Emil Tantilovd1a35ee2014-05-13 08:24:00 +000010671 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10672 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +000010673 hw->mac.ops.setup_link(hw,
10674 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10675 true);
10676
Auke Kok9a799d72007-09-15 14:07:45 -070010677 return 0;
10678
10679err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010680 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010681 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010682err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +000010683 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +000010684 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -080010685 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010686 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010687 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010688 kfree(adapter->rss_key);
Auke Kok9a799d72007-09-15 14:07:45 -070010689err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010690 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010691 free_netdev(netdev);
10692err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010693 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010694err_pci_reg:
10695err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010696 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010697 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010698 return err;
10699}
10700
10701/**
10702 * ixgbe_remove - Device Removal Routine
10703 * @pdev: PCI device information struct
10704 *
10705 * ixgbe_remove is called by the PCI subsystem to alert the driver
10706 * that it should release a PCI device. The could be caused by a
10707 * Hot-Plug event, or because the driver is going to be removed from
10708 * memory.
10709 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010710static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -070010711{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010712 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010713 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010714 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010715 int i;
Auke Kok9a799d72007-09-15 14:07:45 -070010716
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010717 /* if !adapter then we already cleaned up in probe */
10718 if (!adapter)
10719 return;
10720
10721 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +000010722 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010723
Mark Rustad09f40ae2014-01-14 18:53:11 -080010724 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010725 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -070010726
Jacob Keller3a6a4ed2012-05-01 05:24:58 +000010727
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010728#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010729 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10730 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10731 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -070010732 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10733 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010734 }
10735
10736#endif
Don Skidmore12109822012-05-04 06:07:08 +000010737#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010738 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +000010739#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010740
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010741 /* remove the added san mac */
10742 ixgbe_del_sanmac_netdev(netdev);
10743
Greg Roseda36b642012-12-11 08:26:43 +000010744#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -060010745 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +000010746#endif
Alex Williamson6b010e92015-07-29 14:38:21 -060010747 if (netdev->reg_state == NETREG_REGISTERED)
10748 unregister_netdev(netdev);
10749
Alexander Duyck7a921c92009-05-06 10:43:28 +000010750 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010751
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010752 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010753
Alexander Duyck2b1588c2012-03-17 02:39:16 +000010754#ifdef CONFIG_DCB
10755 kfree(adapter->ixgbe_ieee_pfc);
10756 kfree(adapter->ixgbe_ieee_ets);
10757
10758#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -080010759 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010760 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010761
Emil Tantilov849c4542010-06-03 16:53:41 +000010762 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010763
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010764 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
10765 if (adapter->jump_tables[i]) {
10766 kfree(adapter->jump_tables[i]->input);
10767 kfree(adapter->jump_tables[i]->mask);
10768 }
10769 kfree(adapter->jump_tables[i]);
10770 }
10771
Jacob Keller5d7daa32014-03-29 06:51:25 +000010772 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010773 kfree(adapter->rss_key);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010774 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010775 free_netdev(netdev);
10776
Frans Pop19d5afd2009-10-02 10:04:12 -070010777 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010778
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010779 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010780 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010781}
10782
10783/**
10784 * ixgbe_io_error_detected - called when PCI error is detected
10785 * @pdev: Pointer to PCI device
10786 * @state: The current pci connection state
10787 *
10788 * This function is called after a PCI bus error affecting
10789 * this device has been detected.
10790 */
10791static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +000010792 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -070010793{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010794 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10795 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010796
Greg Rose83c61fa2011-09-07 05:59:35 +000010797#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -080010798 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +000010799 struct pci_dev *bdev, *vfdev;
10800 u32 dw0, dw1, dw2, dw3;
10801 int vf, pos;
10802 u16 req_id, pf_func;
10803
10804 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
10805 adapter->num_vfs == 0)
10806 goto skip_bad_vf_detection;
10807
10808 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +080010809 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +000010810 bdev = bdev->bus->self;
10811
10812 if (!bdev)
10813 goto skip_bad_vf_detection;
10814
10815 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
10816 if (!pos)
10817 goto skip_bad_vf_detection;
10818
Mark Rustad14438462014-02-28 15:48:57 -080010819 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
10820 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
10821 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
10822 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
10823 if (ixgbe_removed(hw->hw_addr))
10824 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +000010825
10826 req_id = dw1 >> 16;
10827 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10828 if (!(req_id & 0x0080))
10829 goto skip_bad_vf_detection;
10830
10831 pf_func = req_id & 0x01;
10832 if ((pf_func & 1) == (pdev->devfn & 1)) {
10833 unsigned int device_id;
10834
10835 vf = (req_id & 0x7F) >> 1;
10836 e_dev_err("VF %d has caused a PCIe error\n", vf);
10837 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10838 "%8.8x\tdw3: %8.8x\n",
10839 dw0, dw1, dw2, dw3);
10840 switch (adapter->hw.mac.type) {
10841 case ixgbe_mac_82599EB:
10842 device_id = IXGBE_82599_VF_DEVICE_ID;
10843 break;
10844 case ixgbe_mac_X540:
10845 device_id = IXGBE_X540_VF_DEVICE_ID;
10846 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010847 case ixgbe_mac_X550:
10848 device_id = IXGBE_DEV_ID_X550_VF;
10849 break;
10850 case ixgbe_mac_X550EM_x:
10851 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10852 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010853 case ixgbe_mac_x550em_a:
10854 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10855 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010856 default:
10857 device_id = 0;
10858 break;
10859 }
10860
10861 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010862 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010863 while (vfdev) {
10864 if (vfdev->devfn == (req_id & 0xFF))
10865 break;
Jon Mason36e90312012-07-19 21:02:09 +000010866 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010867 device_id, vfdev);
10868 }
10869 /*
10870 * There's a slim chance the VF could have been hot plugged,
10871 * so if it is no longer present we don't need to issue the
10872 * VFLR. Just clean up the AER in that case.
10873 */
10874 if (vfdev) {
Christoph Hellwig63af8f72017-04-14 21:11:28 +020010875 pcie_flr(vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010876 /* Free device reference count */
10877 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010878 }
10879
10880 pci_cleanup_aer_uncorrect_error_status(pdev);
10881 }
10882
10883 /*
10884 * Even though the error may have occurred on the other port
10885 * we still need to increment the vf error reference count for
10886 * both ports because the I/O resume function will be called
10887 * for both of them.
10888 */
10889 adapter->vferr_refcount++;
10890
10891 return PCI_ERS_RESULT_RECOVERED;
10892
10893skip_bad_vf_detection:
10894#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010895 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10896 return PCI_ERS_RESULT_DISCONNECT;
10897
Emil Tantilovb64666a2017-09-29 10:55:42 -070010898 if (!netif_device_present(netdev))
10899 return PCI_ERS_RESULT_DISCONNECT;
10900
Mark Rustad41c62842014-03-12 00:38:35 +000010901 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010902 netif_device_detach(netdev);
10903
Mark Rustad41c62842014-03-12 00:38:35 +000010904 if (state == pci_channel_io_perm_failure) {
10905 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010906 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010907 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010908
Auke Kok9a799d72007-09-15 14:07:45 -070010909 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010910 ixgbe_close_suspend(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +000010911
10912 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10913 pci_disable_device(pdev);
10914 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010915
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010916 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010917 return PCI_ERS_RESULT_NEED_RESET;
10918}
10919
10920/**
10921 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10922 * @pdev: Pointer to PCI device
10923 *
10924 * Restart the card from scratch, as if from a cold-boot.
10925 */
10926static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10927{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010928 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010929 pci_ers_result_t result;
10930 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010931
gouji-new9ce77662009-05-06 10:44:45 +000010932 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010933 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010934 result = PCI_ERS_RESULT_DISCONNECT;
10935 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010936 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010937 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010938 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010939 pci_set_master(pdev);
10940 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010941 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010942
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010943 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010944
10945 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010946 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010947 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010948 }
Auke Kok9a799d72007-09-15 14:07:45 -070010949
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010950 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10951 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010952 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10953 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010954 /* non-fatal, continue */
10955 }
Auke Kok9a799d72007-09-15 14:07:45 -070010956
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010957 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010958}
10959
10960/**
10961 * ixgbe_io_resume - called when traffic can start flowing again.
10962 * @pdev: Pointer to PCI device
10963 *
10964 * This callback is called when the error recovery driver tells us that
10965 * its OK to resume normal operation.
10966 */
10967static void ixgbe_io_resume(struct pci_dev *pdev)
10968{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010969 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10970 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010971
Greg Rose83c61fa2011-09-07 05:59:35 +000010972#ifdef CONFIG_PCI_IOV
10973 if (adapter->vferr_refcount) {
10974 e_info(drv, "Resuming after VF err\n");
10975 adapter->vferr_refcount--;
10976 return;
10977 }
10978
10979#endif
Emil Tantilov126db132016-11-16 09:48:02 -080010980 rtnl_lock();
Alexander Duyckc7ccde02011-07-21 00:40:40 +000010981 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010982 ixgbe_open(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010983
10984 netif_device_attach(netdev);
Emil Tantilov126db132016-11-16 09:48:02 -080010985 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010986}
10987
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070010988static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070010989 .error_detected = ixgbe_io_error_detected,
10990 .slot_reset = ixgbe_io_slot_reset,
10991 .resume = ixgbe_io_resume,
10992};
10993
10994static struct pci_driver ixgbe_driver = {
10995 .name = ixgbe_driver_name,
10996 .id_table = ixgbe_pci_tbl,
10997 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010998 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070010999#ifdef CONFIG_PM
11000 .suspend = ixgbe_suspend,
11001 .resume = ixgbe_resume,
11002#endif
11003 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000011004 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070011005 .err_handler = &ixgbe_err_handler
11006};
11007
11008/**
11009 * ixgbe_init_module - Driver Registration Routine
11010 *
11011 * ixgbe_init_module is the first routine called when the driver is
11012 * loaded. All it does is register with the PCI subsystem.
11013 **/
11014static int __init ixgbe_init_module(void)
11015{
11016 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000011017 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000011018 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070011019
Mark Rustad780484d2015-10-21 17:21:10 -070011020 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
11021 if (!ixgbe_wq) {
11022 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
11023 return -ENOMEM;
11024 }
11025
Catherine Sullivan00949162012-08-10 01:59:10 +000011026 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000011027
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011028 ret = pci_register_driver(&ixgbe_driver);
11029 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000011030 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011031 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011032 return ret;
11033 }
11034
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011035#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011036 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011037#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011038
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011039 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070011040}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070011041
Auke Kok9a799d72007-09-15 14:07:45 -070011042module_init(ixgbe_init_module);
11043
11044/**
11045 * ixgbe_exit_module - Driver Exit Cleanup Routine
11046 *
11047 * ixgbe_exit_module is called just before the driver is removed
11048 * from memory.
11049 **/
11050static void __exit ixgbe_exit_module(void)
11051{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011052#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011053 dca_unregister_notify(&dca_notifier);
11054#endif
Auke Kok9a799d72007-09-15 14:07:45 -070011055 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000011056
Catherine Sullivan00949162012-08-10 01:59:10 +000011057 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070011058 if (ixgbe_wq) {
11059 destroy_workqueue(ixgbe_wq);
11060 ixgbe_wq = NULL;
11061 }
Auke Kok9a799d72007-09-15 14:07:45 -070011062}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011063
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011064#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011065static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011066 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011067{
11068 int ret_val;
11069
11070 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011071 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011072
11073 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
11074}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011075
Alexander Duyckb4533682009-03-31 21:32:42 +000011076#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000011077
Auke Kok9a799d72007-09-15 14:07:45 -070011078module_exit(ixgbe_exit_module);
11079
11080/* ixgbe_main.c */