blob: 507977994a03a338a3907af839f7e30209029f7b [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
Jacob Kellerb8e82002013-04-09 07:20:09 +0000195static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
196 u32 reg, u16 *value)
197{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000198 struct pci_dev *parent_dev;
199 struct pci_bus *parent_bus;
200
201 parent_bus = adapter->pdev->bus->parent;
202 if (!parent_bus)
203 return -1;
204
205 parent_dev = parent_bus->self;
206 if (!parent_dev)
207 return -1;
208
Yijing Wangc0798ed2013-09-04 17:30:08 +0000209 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000210 return -1;
211
Yijing Wangc0798ed2013-09-04 17:30:08 +0000212 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800213 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
214 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
215 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000216 return 0;
217}
218
219static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
220{
221 struct ixgbe_hw *hw = &adapter->hw;
222 u16 link_status = 0;
223 int err;
224
225 hw->bus.type = ixgbe_bus_type_pci_express;
226
227 /* Get the negotiated link width and speed from PCI config space of the
228 * parent, as this device is behind a switch
229 */
230 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
231
232 /* assume caller will handle error case */
233 if (err)
234 return err;
235
236 hw->bus.width = ixgbe_convert_bus_width(link_status);
237 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
238
239 return 0;
240}
241
Jacob Kellere027d1a2013-07-31 06:53:31 +0000242/**
243 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
244 * @hw: hw specific details
245 *
246 * This function is used by probe to determine whether a device's PCI-Express
247 * bandwidth details should be gathered from the parent bus instead of from the
248 * device. Used to ensure that various locations all have the correct device ID
249 * checks.
250 */
251static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
252{
253 switch (hw->device_id) {
254 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000255 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000256 return true;
257 default:
258 return false;
259 }
260}
261
262static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
263 int expected_gts)
264{
Don Skidmoref9328bc2015-06-18 13:24:06 -0400265 struct ixgbe_hw *hw = &adapter->hw;
Jacob Kellere027d1a2013-07-31 06:53:31 +0000266 int max_gts = 0;
267 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
268 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
269 struct pci_dev *pdev;
270
Don Skidmoref9328bc2015-06-18 13:24:06 -0400271 /* Some devices are not connected over PCIe and thus do not negotiate
272 * speed. These devices do not have valid bus info, and thus any report
273 * we generate may not be correct.
274 */
275 if (hw->bus.type == ixgbe_bus_type_internal)
276 return;
277
Jacob Keller56d13922015-06-10 11:44:45 -0700278 /* determine whether to use the parent device */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000279 if (ixgbe_pcie_from_parent(&adapter->hw))
280 pdev = adapter->pdev->bus->parent->self;
281 else
282 pdev = adapter->pdev;
283
284 if (pcie_get_minimum_link(pdev, &speed, &width) ||
285 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
286 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
287 return;
288 }
289
290 switch (speed) {
291 case PCIE_SPEED_2_5GT:
292 /* 8b/10b encoding reduces max throughput by 20% */
293 max_gts = 2 * width;
294 break;
295 case PCIE_SPEED_5_0GT:
296 /* 8b/10b encoding reduces max throughput by 20% */
297 max_gts = 4 * width;
298 break;
299 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000300 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000301 max_gts = 8 * width;
302 break;
303 default:
304 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
305 return;
306 }
307
308 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
309 max_gts);
310 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
311 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
312 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
313 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
314 "Unknown"),
315 width,
316 (speed == PCIE_SPEED_2_5GT ? "20%" :
317 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000318 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000319 "Unknown"));
320
321 if (max_gts < expected_gts) {
322 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
323 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
324 expected_gts);
325 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
326 }
327}
328
Alexander Duyck70864002011-04-27 09:13:56 +0000329static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
330{
331 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800332 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000333 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
Mark Rustad780484d2015-10-21 17:21:10 -0700334 queue_work(ixgbe_wq, &adapter->service_task);
Alexander Duyck70864002011-04-27 09:13:56 +0000335}
336
Mark Rustad2a1a0912014-01-14 18:53:15 -0800337static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
338{
339 struct ixgbe_adapter *adapter = hw->back;
340
341 if (!hw->hw_addr)
342 return;
343 hw->hw_addr = NULL;
344 e_dev_err("Adapter removed\n");
Mark Rustad58cf6632014-03-12 00:38:40 +0000345 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
346 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800347}
348
Mark Rustadf8e24722014-03-18 07:03:40 +0000349static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800350{
351 u32 value;
352
353 /* The following check not only optimizes a bit by not
354 * performing a read on the status register when the
355 * register just read was a status register read that
356 * returned IXGBE_FAILED_READ_REG. It also blocks any
357 * potential recursion.
358 */
359 if (reg == IXGBE_STATUS) {
360 ixgbe_remove_adapter(hw);
361 return;
362 }
363 value = ixgbe_read_reg(hw, IXGBE_STATUS);
364 if (value == IXGBE_FAILED_READ_REG)
365 ixgbe_remove_adapter(hw);
366}
367
Mark Rustadf8e24722014-03-18 07:03:40 +0000368/**
369 * ixgbe_read_reg - Read from device register
370 * @hw: hw specific details
371 * @reg: offset of register to read
372 *
373 * Returns : value read or IXGBE_FAILED_READ_REG if removed
374 *
375 * This function is used to read device registers. It checks for device
376 * removal by confirming any read that returns all ones by checking the
377 * status register value for all ones. This function avoids reading from
378 * the hardware if a removal was previously detected in which case it
379 * returns IXGBE_FAILED_READ_REG (all ones).
380 */
381u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
382{
383 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
384 u32 value;
385
386 if (ixgbe_removed(reg_addr))
387 return IXGBE_FAILED_READ_REG;
Mark Rustad2f2219b2016-04-07 10:43:50 -0700388 if (unlikely(hw->phy.nw_mng_if_sel &
Tony Nguyen48301cf2017-06-07 14:36:19 -0700389 IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE)) {
Mark Rustad2f2219b2016-04-07 10:43:50 -0700390 struct ixgbe_adapter *adapter;
391 int i;
392
393 for (i = 0; i < 200; ++i) {
394 value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
395 if (likely(!value))
396 goto writes_completed;
397 if (value == IXGBE_FAILED_READ_REG) {
398 ixgbe_remove_adapter(hw);
399 return IXGBE_FAILED_READ_REG;
400 }
401 udelay(5);
402 }
403
404 adapter = hw->back;
405 e_warn(hw, "register writes incomplete %08x\n", value);
406 }
407
408writes_completed:
Mark Rustadf8e24722014-03-18 07:03:40 +0000409 value = readl(reg_addr + reg);
410 if (unlikely(value == IXGBE_FAILED_READ_REG))
411 ixgbe_check_remove(hw, reg);
412 return value;
413}
414
Mark Rustad14438462014-02-28 15:48:57 -0800415static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
416{
417 u16 value;
418
419 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
420 if (value == IXGBE_FAILED_READ_CFG_WORD) {
421 ixgbe_remove_adapter(hw);
422 return true;
423 }
424 return false;
425}
426
427u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
428{
429 struct ixgbe_adapter *adapter = hw->back;
430 u16 value;
431
432 if (ixgbe_removed(hw->hw_addr))
433 return IXGBE_FAILED_READ_CFG_WORD;
434 pci_read_config_word(adapter->pdev, reg, &value);
435 if (value == IXGBE_FAILED_READ_CFG_WORD &&
436 ixgbe_check_cfg_remove(hw, adapter->pdev))
437 return IXGBE_FAILED_READ_CFG_WORD;
438 return value;
439}
440
441#ifdef CONFIG_PCI_IOV
442static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
443{
444 struct ixgbe_adapter *adapter = hw->back;
445 u32 value;
446
447 if (ixgbe_removed(hw->hw_addr))
448 return IXGBE_FAILED_READ_CFG_DWORD;
449 pci_read_config_dword(adapter->pdev, reg, &value);
450 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
451 ixgbe_check_cfg_remove(hw, adapter->pdev))
452 return IXGBE_FAILED_READ_CFG_DWORD;
453 return value;
454}
455#endif /* CONFIG_PCI_IOV */
456
Jacob Kellered192312014-02-22 01:23:53 +0000457void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
458{
459 struct ixgbe_adapter *adapter = hw->back;
460
461 if (ixgbe_removed(hw->hw_addr))
462 return;
463 pci_write_config_word(adapter->pdev, reg, value);
464}
465
Alexander Duyck70864002011-04-27 09:13:56 +0000466static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
467{
468 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
469
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000470 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100471 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000472 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
473}
474
Taku Izumidcd79ae2010-04-27 14:39:53 +0000475struct ixgbe_reg_info {
476 u32 ofs;
477 char *name;
478};
479
480static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
481
482 /* General Registers */
483 {IXGBE_CTRL, "CTRL"},
484 {IXGBE_STATUS, "STATUS"},
485 {IXGBE_CTRL_EXT, "CTRL_EXT"},
486
487 /* Interrupt Registers */
488 {IXGBE_EICR, "EICR"},
489
490 /* RX Registers */
491 {IXGBE_SRRCTL(0), "SRRCTL"},
492 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
493 {IXGBE_RDLEN(0), "RDLEN"},
494 {IXGBE_RDH(0), "RDH"},
495 {IXGBE_RDT(0), "RDT"},
496 {IXGBE_RXDCTL(0), "RXDCTL"},
497 {IXGBE_RDBAL(0), "RDBAL"},
498 {IXGBE_RDBAH(0), "RDBAH"},
499
500 /* TX Registers */
501 {IXGBE_TDBAL(0), "TDBAL"},
502 {IXGBE_TDBAH(0), "TDBAH"},
503 {IXGBE_TDLEN(0), "TDLEN"},
504 {IXGBE_TDH(0), "TDH"},
505 {IXGBE_TDT(0), "TDT"},
506 {IXGBE_TXDCTL(0), "TXDCTL"},
507
508 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000509 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000510};
511
512
513/*
514 * ixgbe_regdump - register printout routine
515 */
516static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
517{
Joe Perches332f2352017-01-03 07:28:11 -0800518 int i;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000519 char rname[16];
520 u32 regs[64];
521
522 switch (reginfo->ofs) {
523 case IXGBE_SRRCTL(0):
524 for (i = 0; i < 64; i++)
525 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
526 break;
527 case IXGBE_DCA_RXCTRL(0):
528 for (i = 0; i < 64; i++)
529 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
530 break;
531 case IXGBE_RDLEN(0):
532 for (i = 0; i < 64; i++)
533 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
534 break;
535 case IXGBE_RDH(0):
536 for (i = 0; i < 64; i++)
537 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
538 break;
539 case IXGBE_RDT(0):
540 for (i = 0; i < 64; i++)
541 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
542 break;
543 case IXGBE_RXDCTL(0):
544 for (i = 0; i < 64; i++)
545 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
546 break;
547 case IXGBE_RDBAL(0):
548 for (i = 0; i < 64; i++)
549 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
550 break;
551 case IXGBE_RDBAH(0):
552 for (i = 0; i < 64; i++)
553 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
554 break;
555 case IXGBE_TDBAL(0):
556 for (i = 0; i < 64; i++)
557 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
558 break;
559 case IXGBE_TDBAH(0):
560 for (i = 0; i < 64; i++)
561 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
562 break;
563 case IXGBE_TDLEN(0):
564 for (i = 0; i < 64; i++)
565 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
566 break;
567 case IXGBE_TDH(0):
568 for (i = 0; i < 64; i++)
569 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
570 break;
571 case IXGBE_TDT(0):
572 for (i = 0; i < 64; i++)
573 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
574 break;
575 case IXGBE_TXDCTL(0):
576 for (i = 0; i < 64; i++)
577 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
578 break;
579 default:
Joe Perches332f2352017-01-03 07:28:11 -0800580 pr_info("%-15s %08x\n",
581 reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000582 return;
583 }
584
Joe Perches332f2352017-01-03 07:28:11 -0800585 i = 0;
586 while (i < 64) {
587 int j;
588 char buf[9 * 8 + 1];
589 char *p = buf;
590
591 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000592 for (j = 0; j < 8; j++)
Joe Perches332f2352017-01-03 07:28:11 -0800593 p += sprintf(p, " %08x", regs[i++]);
594 pr_err("%-15s%s\n", rname, buf);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000595 }
596
597}
598
John Fastabend33fdc822017-04-24 03:30:18 -0700599static void ixgbe_print_buffer(struct ixgbe_ring *ring, int n)
600{
601 struct ixgbe_tx_buffer *tx_buffer;
602
603 tx_buffer = &ring->tx_buffer_info[ring->next_to_clean];
604 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
605 n, ring->next_to_use, ring->next_to_clean,
606 (u64)dma_unmap_addr(tx_buffer, dma),
607 dma_unmap_len(tx_buffer, len),
608 tx_buffer->next_to_watch,
609 (u64)tx_buffer->time_stamp);
610}
611
Taku Izumidcd79ae2010-04-27 14:39:53 +0000612/*
613 * ixgbe_dump - Print registers, tx-rings and rx-rings
614 */
615static void ixgbe_dump(struct ixgbe_adapter *adapter)
616{
617 struct net_device *netdev = adapter->netdev;
618 struct ixgbe_hw *hw = &adapter->hw;
619 struct ixgbe_reg_info *reginfo;
620 int n = 0;
John Fastabend33fdc822017-04-24 03:30:18 -0700621 struct ixgbe_ring *ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000622 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000623 union ixgbe_adv_tx_desc *tx_desc;
624 struct my_u0 { u64 a; u64 b; } *u0;
625 struct ixgbe_ring *rx_ring;
626 union ixgbe_adv_rx_desc *rx_desc;
627 struct ixgbe_rx_buffer *rx_buffer_info;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000628 int i = 0;
629
630 if (!netif_msg_hw(adapter))
631 return;
632
633 /* Print netdevice Info */
634 if (netdev) {
635 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000636 pr_info("Device Name state "
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100637 "trans_start\n");
638 pr_info("%-15s %016lX %016lX\n",
Joe Perchesc7689572010-09-07 21:35:17 +0000639 netdev->name,
640 netdev->state,
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100641 dev_trans_start(netdev));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000642 }
643
644 /* Print Registers */
645 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000646 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000647 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
648 reginfo->name; reginfo++) {
649 ixgbe_regdump(hw, reginfo);
650 }
651
652 /* Print TX Ring Summary */
653 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000654 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000655
656 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000657 pr_info(" %s %s %s %s\n",
658 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
659 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000660 for (n = 0; n < adapter->num_tx_queues; n++) {
John Fastabend33fdc822017-04-24 03:30:18 -0700661 ring = adapter->tx_ring[n];
662 ixgbe_print_buffer(ring, n);
663 }
664
665 for (n = 0; n < adapter->num_xdp_queues; n++) {
666 ring = adapter->xdp_ring[n];
667 ixgbe_print_buffer(ring, n);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000668 }
669
670 /* Print TX Rings */
671 if (!netif_msg_tx_done(adapter))
672 goto rx_ring_summary;
673
674 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
675
676 /* Transmit Descriptor Formats
677 *
Josh Hay39ac8682012-09-26 05:59:36 +0000678 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000679 * +--------------------------------------------------------------+
680 * 0 | Buffer Address [63:0] |
681 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000682 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000683 * +--------------------------------------------------------------+
684 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000685 *
686 * 82598 Advanced Transmit Descriptor (Write-Back Format)
687 * +--------------------------------------------------------------+
688 * 0 | RSV [63:0] |
689 * +--------------------------------------------------------------+
690 * 8 | RSV | STA | NXTSEQ |
691 * +--------------------------------------------------------------+
692 * 63 36 35 32 31 0
693 *
694 * 82599+ Advanced Transmit Descriptor
695 * +--------------------------------------------------------------+
696 * 0 | Buffer Address [63:0] |
697 * +--------------------------------------------------------------+
698 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
699 * +--------------------------------------------------------------+
700 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
701 *
702 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
703 * +--------------------------------------------------------------+
704 * 0 | RSV [63:0] |
705 * +--------------------------------------------------------------+
706 * 8 | RSV | STA | RSV |
707 * +--------------------------------------------------------------+
708 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000709 */
710
711 for (n = 0; n < adapter->num_tx_queues; n++) {
John Fastabend33fdc822017-04-24 03:30:18 -0700712 ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000713 pr_info("------------------------------------\n");
John Fastabend33fdc822017-04-24 03:30:18 -0700714 pr_info("TX QUEUE INDEX = %d\n", ring->queue_index);
Joe Perchesc7689572010-09-07 21:35:17 +0000715 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000716 pr_info("%s%s %s %s %s %s\n",
717 "T [desc] [address 63:0 ] ",
718 "[PlPOIdStDDt Ln] [bi->dma ] ",
719 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000720
John Fastabend33fdc822017-04-24 03:30:18 -0700721 for (i = 0; ring->desc && (i < ring->count); i++) {
722 tx_desc = IXGBE_TX_DESC(ring, i);
723 tx_buffer = &ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000724 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000725 if (dma_unmap_len(tx_buffer, len) > 0) {
Joe Perches332f2352017-01-03 07:28:11 -0800726 const char *ring_desc;
727
John Fastabend33fdc822017-04-24 03:30:18 -0700728 if (i == ring->next_to_use &&
729 i == ring->next_to_clean)
Joe Perches332f2352017-01-03 07:28:11 -0800730 ring_desc = " NTC/U";
John Fastabend33fdc822017-04-24 03:30:18 -0700731 else if (i == ring->next_to_use)
Joe Perches332f2352017-01-03 07:28:11 -0800732 ring_desc = " NTU";
John Fastabend33fdc822017-04-24 03:30:18 -0700733 else if (i == ring->next_to_clean)
Joe Perches332f2352017-01-03 07:28:11 -0800734 ring_desc = " NTC";
735 else
736 ring_desc = "";
737 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
Josh Hay8ad88e32012-09-26 05:59:41 +0000738 i,
739 le64_to_cpu(u0->a),
740 le64_to_cpu(u0->b),
741 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000742 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000743 tx_buffer->next_to_watch,
744 (u64)tx_buffer->time_stamp,
Joe Perches332f2352017-01-03 07:28:11 -0800745 tx_buffer->skb,
746 ring_desc);
Josh Hay8ad88e32012-09-26 05:59:41 +0000747
748 if (netif_msg_pktdata(adapter) &&
749 tx_buffer->skb)
750 print_hex_dump(KERN_INFO, "",
751 DUMP_PREFIX_ADDRESS, 16, 1,
752 tx_buffer->skb->data,
753 dma_unmap_len(tx_buffer, len),
754 true);
755 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000756 }
757 }
758
759 /* Print RX Rings Summary */
760rx_ring_summary:
761 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000762 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000763 for (n = 0; n < adapter->num_rx_queues; n++) {
764 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000765 pr_info("%5d %5X %5X\n",
766 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000767 }
768
769 /* Print RX Rings */
770 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000771 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000772
773 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
774
Josh Hay39ac8682012-09-26 05:59:36 +0000775 /* Receive Descriptor Formats
776 *
777 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000778 * 63 1 0
779 * +-----------------------------------------------------+
780 * 0 | Packet Buffer Address [63:1] |A0/NSE|
781 * +----------------------------------------------+------+
782 * 8 | Header Buffer Address [63:1] | DD |
783 * +-----------------------------------------------------+
784 *
785 *
Josh Hay39ac8682012-09-26 05:59:36 +0000786 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000787 *
788 * 63 48 47 32 31 30 21 20 16 15 4 3 0
789 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000790 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
791 * | Packet | IP | | | | Type | Type |
792 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000793 * +------------------------------------------------------+
794 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
795 * +------------------------------------------------------+
796 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000797 *
798 * 82599+ Advanced Receive Descriptor (Read) Format
799 * 63 1 0
800 * +-----------------------------------------------------+
801 * 0 | Packet Buffer Address [63:1] |A0/NSE|
802 * +----------------------------------------------+------+
803 * 8 | Header Buffer Address [63:1] | DD |
804 * +-----------------------------------------------------+
805 *
806 *
807 * 82599+ Advanced Receive Descriptor (Write-Back) Format
808 *
809 * 63 48 47 32 31 30 21 20 17 16 4 3 0
810 * +------------------------------------------------------+
811 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
812 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
813 * |/ Flow Dir Flt ID | | | | | |
814 * +------------------------------------------------------+
815 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
816 * +------------------------------------------------------+
817 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000818 */
Josh Hay39ac8682012-09-26 05:59:36 +0000819
Taku Izumidcd79ae2010-04-27 14:39:53 +0000820 for (n = 0; n < adapter->num_rx_queues; n++) {
821 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000822 pr_info("------------------------------------\n");
823 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
824 pr_info("------------------------------------\n");
Joe Perches332f2352017-01-03 07:28:11 -0800825 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000826 "R [desc] [ PktBuf A0] ",
827 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800828 "<-- Adv Rx Read format");
829 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000830 "RWB[desc] [PcsmIpSHl PtRs] ",
831 "[vl er S cks ln] ---------------- [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800832 "<-- Adv Rx Write-Back format");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000833
834 for (i = 0; i < rx_ring->count; i++) {
Joe Perches332f2352017-01-03 07:28:11 -0800835 const char *ring_desc;
836
837 if (i == rx_ring->next_to_use)
838 ring_desc = " NTU";
839 else if (i == rx_ring->next_to_clean)
840 ring_desc = " NTC";
841 else
842 ring_desc = "";
843
Taku Izumidcd79ae2010-04-27 14:39:53 +0000844 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000845 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000846 u0 = (struct my_u0 *)rx_desc;
Alexander Duyck18a8cc92017-03-02 15:01:36 -0800847 if (rx_desc->wb.upper.length) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000848 /* Descriptor Done */
Joe Perches332f2352017-01-03 07:28:11 -0800849 pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
850 i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000851 le64_to_cpu(u0->a),
852 le64_to_cpu(u0->b),
Joe Perches332f2352017-01-03 07:28:11 -0800853 rx_buffer_info->skb,
854 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000855 } else {
Joe Perches332f2352017-01-03 07:28:11 -0800856 pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
857 i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000858 le64_to_cpu(u0->a),
859 le64_to_cpu(u0->b),
860 (u64)rx_buffer_info->dma,
Joe Perches332f2352017-01-03 07:28:11 -0800861 rx_buffer_info->skb,
862 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000863
Emil Tantilov9c50c032012-07-26 01:21:24 +0000864 if (netif_msg_pktdata(adapter) &&
865 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000866 print_hex_dump(KERN_INFO, "",
867 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000868 page_address(rx_buffer_info->page) +
869 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000870 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000871 }
872 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000873 }
874 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000875}
876
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800877static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
878{
879 u32 ctrl_ext;
880
881 /* Let firmware take over control of h/w */
882 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
883 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000884 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800885}
886
887static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
888{
889 u32 ctrl_ext;
890
891 /* Let firmware know the driver has taken over */
892 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
893 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000894 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800895}
Auke Kok9a799d72007-09-15 14:07:45 -0700896
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000897/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000898 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
899 * @adapter: pointer to adapter struct
900 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
901 * @queue: queue to map the corresponding interrupt to
902 * @msix_vector: the vector to map to the corresponding queue
903 *
904 */
905static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000906 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700907{
908 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000909 struct ixgbe_hw *hw = &adapter->hw;
910 switch (hw->mac.type) {
911 case ixgbe_mac_82598EB:
912 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
913 if (direction == -1)
914 direction = 0;
915 index = (((direction * 64) + queue) >> 2) & 0x1F;
916 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
917 ivar &= ~(0xFF << (8 * (queue & 0x3)));
918 ivar |= (msix_vector << (8 * (queue & 0x3)));
919 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
920 break;
921 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800922 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000923 case ixgbe_mac_X550:
924 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700925 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000926 if (direction == -1) {
927 /* other causes */
928 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
929 index = ((queue & 1) * 8);
930 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
931 ivar &= ~(0xFF << index);
932 ivar |= (msix_vector << index);
933 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
934 break;
935 } else {
936 /* tx or rx causes */
937 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
938 index = ((16 * (queue & 1)) + (8 * direction));
939 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
940 ivar &= ~(0xFF << index);
941 ivar |= (msix_vector << index);
942 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
943 break;
944 }
945 default:
946 break;
947 }
Auke Kok9a799d72007-09-15 14:07:45 -0700948}
949
Alexander Duyckfe49f042009-06-04 16:00:09 +0000950static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000951 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000952{
953 u32 mask;
954
Alexander Duyckbd508172010-11-16 19:27:03 -0800955 switch (adapter->hw.mac.type) {
956 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000957 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
958 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800959 break;
960 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800961 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000962 case ixgbe_mac_X550:
963 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700964 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000965 mask = (qmask & 0xFFFFFFFF);
966 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
967 mask = (qmask >> 32);
968 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800969 break;
970 default:
971 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000972 }
973}
974
Alexander Duyck943561d2012-05-09 22:14:44 -0700975static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
976{
977 struct ixgbe_hw *hw = &adapter->hw;
978 struct ixgbe_hw_stats *hwstats = &adapter->stats;
979 int i;
980 u32 data;
981
982 if ((hw->fc.current_mode != ixgbe_fc_full) &&
983 (hw->fc.current_mode != ixgbe_fc_rx_pause))
984 return;
985
986 switch (hw->mac.type) {
987 case ixgbe_mac_82598EB:
988 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
989 break;
990 default:
991 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
992 }
993 hwstats->lxoffrxc += data;
994
995 /* refill credits (no tx hang) if we received xoff */
996 if (!data)
997 return;
998
999 for (i = 0; i < adapter->num_tx_queues; i++)
1000 clear_bit(__IXGBE_HANG_CHECK_ARMED,
1001 &adapter->tx_ring[i]->state);
John Fastabend33fdc822017-04-24 03:30:18 -07001002
1003 for (i = 0; i < adapter->num_xdp_queues; i++)
1004 clear_bit(__IXGBE_HANG_CHECK_ARMED,
1005 &adapter->xdp_ring[i]->state);
Alexander Duyck943561d2012-05-09 22:14:44 -07001006}
1007
John Fastabendc84d3242010-11-16 19:27:12 -08001008static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001009{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001010 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001011 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -08001012 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001013 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001014 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -07001015 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001016
Alexander Duyck943561d2012-05-09 22:14:44 -07001017 if (adapter->ixgbe_ieee_pfc)
1018 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -08001019
Alexander Duyck943561d2012-05-09 22:14:44 -07001020 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
1021 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -08001022 return;
Alexander Duyck943561d2012-05-09 22:14:44 -07001023 }
John Fastabendc84d3242010-11-16 19:27:12 -08001024
1025 /* update stats for each tc, only valid with PFC enabled */
1026 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001027 u32 pxoffrxc;
1028
John Fastabendc84d3242010-11-16 19:27:12 -08001029 switch (hw->mac.type) {
1030 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001031 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001032 break;
1033 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001034 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001035 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001036 hwstats->pxoffrxc[i] += pxoffrxc;
1037 /* Get the TC for given UP */
1038 tc = netdev_get_prio_tc_map(adapter->netdev, i);
1039 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -07001040 }
1041
John Fastabendc84d3242010-11-16 19:27:12 -08001042 /* disarm tx queues that have received xoff frames */
1043 for (i = 0; i < adapter->num_tx_queues; i++) {
1044 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -08001045
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001046 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001047 if (xoff[tc])
1048 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1049 }
John Fastabend33fdc822017-04-24 03:30:18 -07001050
1051 for (i = 0; i < adapter->num_xdp_queues; i++) {
1052 struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
1053
1054 tc = xdp_ring->dcb_tc;
1055 if (xoff[tc])
1056 clear_bit(__IXGBE_HANG_CHECK_ARMED, &xdp_ring->state);
1057 }
John Fastabendc84d3242010-11-16 19:27:12 -08001058}
1059
1060static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1061{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001062 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001063}
1064
1065static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1066{
John Fastabend2a47fa42013-11-06 09:54:52 -08001067 struct ixgbe_adapter *adapter;
1068 struct ixgbe_hw *hw;
1069 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001070
John Fastabend2a47fa42013-11-06 09:54:52 -08001071 if (ring->l2_accel_priv)
1072 adapter = ring->l2_accel_priv->real_adapter;
1073 else
1074 adapter = netdev_priv(ring->netdev);
1075
1076 hw = &adapter->hw;
1077 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1078 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001079
1080 if (head != tail)
1081 return (head < tail) ?
1082 tail - head : (tail + ring->count - head);
1083
1084 return 0;
1085}
1086
1087static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1088{
1089 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1090 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1091 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001092
1093 clear_check_for_tx_hang(tx_ring);
1094
1095 /*
1096 * Check for a hung queue, but be thorough. This verifies
1097 * that a transmit has been completed since the previous
1098 * check AND there is at least one packet pending. The
1099 * ARMED bit is set to indicate a potential hang. The
1100 * bit is cleared if a pause frame is received to remove
1101 * false hang detection due to PFC or 802.3x frames. By
1102 * requiring this to fail twice we avoid races with
1103 * pfc clearing the ARMED bit and conditions where we
1104 * run the check_tx_hang logic with a transmit completion
1105 * pending but without time to complete it yet.
1106 */
Mark Rustade90dd262014-07-22 06:51:08 +00001107 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001108 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001109 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1110 &tx_ring->state);
1111 /* update completed stats and continue */
1112 tx_ring->tx_stats.tx_done_old = tx_done;
1113 /* reset the countdown */
1114 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001115
Mark Rustade90dd262014-07-22 06:51:08 +00001116 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001117}
1118
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001119/**
1120 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1121 * @adapter: driver private struct
1122 **/
1123static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1124{
1125
1126 /* Do the reset outside of interrupt context */
1127 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
Emil Tantilov57ca2a42016-07-29 14:46:31 -07001128 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Jacob Keller12ff3f32012-12-01 07:57:17 +00001129 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001130 ixgbe_service_event_schedule(adapter);
1131 }
1132}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001133
Auke Kok9a799d72007-09-15 14:07:45 -07001134/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001135 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1136 **/
1137static int ixgbe_tx_maxrate(struct net_device *netdev,
1138 int queue_index, u32 maxrate)
1139{
1140 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1141 struct ixgbe_hw *hw = &adapter->hw;
1142 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1143
1144 if (!maxrate)
1145 return 0;
1146
1147 /* Calculate the rate factor values to set */
1148 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1149 bcnrc_val /= maxrate;
1150
1151 /* clear everything but the rate factor */
1152 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1153 IXGBE_RTTBCNRC_RF_DEC_MASK;
1154
1155 /* enable the rate scheduler */
1156 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1157
1158 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1159 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1160
1161 return 0;
1162}
1163
1164/**
Auke Kok9a799d72007-09-15 14:07:45 -07001165 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001166 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001167 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001168 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001169 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001170static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001171 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001172{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001173 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001174 struct ixgbe_tx_buffer *tx_buffer;
1175 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001176 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001177 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001178 unsigned int i = tx_ring->next_to_clean;
1179
1180 if (test_bit(__IXGBE_DOWN, &adapter->state))
1181 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001182
Alexander Duyckd3d00232011-07-15 02:31:25 +00001183 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001184 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001185 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001186
Alexander Duyck729739b2012-02-08 07:51:06 +00001187 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001188 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001189
Alexander Duyckd3d00232011-07-15 02:31:25 +00001190 /* if next_to_watch is not set then there is no work pending */
1191 if (!eop_desc)
1192 break;
1193
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001194 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001195 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001196
Alexander Duyckd3d00232011-07-15 02:31:25 +00001197 /* if DD is not set pending work has not been completed */
1198 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1199 break;
1200
Alexander Duyckd3d00232011-07-15 02:31:25 +00001201 /* clear next_to_watch to prevent false hangs */
1202 tx_buffer->next_to_watch = NULL;
1203
Alexander Duyck091a6242012-02-08 07:51:01 +00001204 /* update the statistics for this packet */
1205 total_bytes += tx_buffer->bytecount;
1206 total_packets += tx_buffer->gso_segs;
1207
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001208 /* free the skb */
John Fastabend33fdc822017-04-24 03:30:18 -07001209 if (ring_is_xdp(tx_ring))
1210 page_frag_free(tx_buffer->data);
1211 else
1212 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001213
Alexander Duyck729739b2012-02-08 07:51:06 +00001214 /* unmap skb header data */
1215 dma_unmap_single(tx_ring->dev,
1216 dma_unmap_addr(tx_buffer, dma),
1217 dma_unmap_len(tx_buffer, len),
1218 DMA_TO_DEVICE);
1219
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001220 /* clear tx_buffer data */
Alexander Duyck729739b2012-02-08 07:51:06 +00001221 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001222
Alexander Duyck729739b2012-02-08 07:51:06 +00001223 /* unmap remaining buffers */
1224 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001225 tx_buffer++;
1226 tx_desc++;
1227 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001228 if (unlikely(!i)) {
1229 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001230 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001231 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001232 }
1233
Alexander Duyck729739b2012-02-08 07:51:06 +00001234 /* unmap any remaining paged data */
1235 if (dma_unmap_len(tx_buffer, len)) {
1236 dma_unmap_page(tx_ring->dev,
1237 dma_unmap_addr(tx_buffer, dma),
1238 dma_unmap_len(tx_buffer, len),
1239 DMA_TO_DEVICE);
1240 dma_unmap_len_set(tx_buffer, len, 0);
1241 }
1242 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001243
Alexander Duyck729739b2012-02-08 07:51:06 +00001244 /* move us one more past the eop_desc for start of next pkt */
1245 tx_buffer++;
1246 tx_desc++;
1247 i++;
1248 if (unlikely(!i)) {
1249 i -= tx_ring->count;
1250 tx_buffer = tx_ring->tx_buffer_info;
1251 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1252 }
1253
1254 /* issue prefetch for next Tx descriptor */
1255 prefetch(tx_desc);
1256
1257 /* update budget accounting */
1258 budget--;
1259 } while (likely(budget));
1260
1261 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001262 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001263 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001264 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001265 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001266 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001267 q_vector->tx.total_bytes += total_bytes;
1268 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001269
John Fastabendc84d3242010-11-16 19:27:12 -08001270 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001271 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001272 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend33fdc822017-04-24 03:30:18 -07001273 e_err(drv, "Detected Tx Unit Hang %s\n"
John Fastabendc84d3242010-11-16 19:27:12 -08001274 " Tx Queue <%d>\n"
1275 " TDH, TDT <%x>, <%x>\n"
1276 " next_to_use <%x>\n"
1277 " next_to_clean <%x>\n"
1278 "tx_buffer_info[next_to_clean]\n"
1279 " time_stamp <%lx>\n"
1280 " jiffies <%lx>\n",
John Fastabend33fdc822017-04-24 03:30:18 -07001281 ring_is_xdp(tx_ring) ? "(XDP)" : "",
John Fastabendc84d3242010-11-16 19:27:12 -08001282 tx_ring->queue_index,
1283 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1284 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001285 tx_ring->next_to_use, i,
1286 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001287
John Fastabend33fdc822017-04-24 03:30:18 -07001288 if (!ring_is_xdp(tx_ring))
1289 netif_stop_subqueue(tx_ring->netdev,
1290 tx_ring->queue_index);
John Fastabendc84d3242010-11-16 19:27:12 -08001291
1292 e_info(probe,
1293 "tx hang %d detected on queue %d, resetting adapter\n",
1294 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1295
1296 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001297 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001298
1299 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001300 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001301 }
Auke Kok9a799d72007-09-15 14:07:45 -07001302
John Fastabend33fdc822017-04-24 03:30:18 -07001303 if (ring_is_xdp(tx_ring))
1304 return !!budget;
1305
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001306 netdev_tx_completed_queue(txring_txq(tx_ring),
1307 total_packets, total_bytes);
1308
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001309#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001310 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001311 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001312 /* Make sure that anybody stopping the queue after this
1313 * sees the new next_to_clean.
1314 */
1315 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001316 if (__netif_subqueue_stopped(tx_ring->netdev,
1317 tx_ring->queue_index)
1318 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1319 netif_wake_subqueue(tx_ring->netdev,
1320 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001321 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001322 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001323 }
Auke Kok9a799d72007-09-15 14:07:45 -07001324
Alexander Duyck59224552011-08-31 00:01:06 +00001325 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001326}
1327
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001328#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001329static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001330 struct ixgbe_ring *tx_ring,
1331 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001332{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001333 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001334 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001335 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001336
Mark Rustad9de76052015-08-08 16:27:41 -07001337 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1338 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1339
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001340 switch (hw->mac.type) {
1341 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001342 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001343 break;
1344 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001345 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001346 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1347 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1348 break;
1349 default:
1350 /* for unknown hardware do not write register */
1351 return;
1352 }
1353
1354 /*
1355 * We can enable relaxed ordering for reads, but not writes when
1356 * DCA is enabled. This is due to a known issue in some chipsets
1357 * which will cause the DCA tag to be cleared.
1358 */
1359 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1360 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1361 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1362
1363 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1364}
1365
1366static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1367 struct ixgbe_ring *rx_ring,
1368 int cpu)
1369{
1370 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001371 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001372 u8 reg_idx = rx_ring->reg_idx;
1373
Mark Rustad9de76052015-08-08 16:27:41 -07001374 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1375 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001376
1377 switch (hw->mac.type) {
1378 case ixgbe_mac_82599EB:
1379 case ixgbe_mac_X540:
1380 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001381 break;
1382 default:
1383 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001384 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001385
1386 /*
1387 * We can enable relaxed ordering for reads, but not writes when
1388 * DCA is enabled. This is due to a known issue in some chipsets
1389 * which will cause the DCA tag to be cleared.
1390 */
1391 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Mark Rustad9de76052015-08-08 16:27:41 -07001392 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001393 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1394
1395 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001396}
1397
1398static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1399{
1400 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001401 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001402 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001403
1404 if (q_vector->cpu == cpu)
1405 goto out_no_update;
1406
Alexander Duycka5579282012-02-08 07:50:04 +00001407 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001408 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001409
Alexander Duycka5579282012-02-08 07:50:04 +00001410 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001411 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001412
1413 q_vector->cpu = cpu;
1414out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001415 put_cpu();
1416}
1417
1418static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1419{
1420 int i;
1421
Alexander Duycke35ec122009-05-21 13:07:12 +00001422 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001423 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1424 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1425 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1426 else
1427 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1428 IXGBE_DCA_CTRL_DCA_DISABLE);
Alexander Duycke35ec122009-05-21 13:07:12 +00001429
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001430 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001431 adapter->q_vector[i]->cpu = -1;
1432 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001433 }
1434}
1435
1436static int __ixgbe_notify_dca(struct device *dev, void *data)
1437{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001438 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001439 unsigned long event = *(unsigned long *)data;
1440
Don Skidmore2a72c312011-07-20 02:27:05 +00001441 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001442 return 0;
1443
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001444 switch (event) {
1445 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001446 /* if we're already enabled, don't do it again */
1447 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1448 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001449 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001450 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001451 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1452 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001453 break;
1454 }
Tony Nguyen93df9462017-05-31 04:43:47 -07001455 /* fall through - DCA is disabled. */
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001456 case DCA_PROVIDER_REMOVE:
1457 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1458 dca_remove_requester(dev);
1459 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001460 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1461 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001462 }
1463 break;
1464 }
1465
Denis V. Lunev652f0932008-03-27 14:39:17 +03001466 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001467}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001468
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001469#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b82015-04-29 10:57:39 +08001470
1471#define IXGBE_RSS_L4_TYPES_MASK \
1472 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1473 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1474 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1475 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1476
Alexander Duyck8a0da212012-01-31 02:59:49 +00001477static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1478 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001479 struct sk_buff *skb)
1480{
Fan Du7edda4b82015-04-29 10:57:39 +08001481 u16 rss_type;
1482
1483 if (!(ring->netdev->features & NETIF_F_RXHASH))
1484 return;
1485
1486 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1487 IXGBE_RXDADV_RSSTYPE_MASK;
1488
1489 if (!rss_type)
1490 return;
1491
1492 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1493 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1494 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001495}
1496
Alexander Duyckf8003262012-03-03 02:35:52 +00001497#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001498/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001499 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001500 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001501 * @rx_desc: advanced rx descriptor
1502 *
1503 * Returns : true if it is FCoE pkt
1504 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001505static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001506 union ixgbe_adv_rx_desc *rx_desc)
1507{
1508 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1509
Alexander Duyck57efd442012-06-25 21:54:46 +00001510 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001511 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1512 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1513 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1514}
1515
Alexander Duyckf8003262012-03-03 02:35:52 +00001516#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001517/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001518 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001519 * @ring: structure containing ring specific data
1520 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001521 * @skb: skb currently being received and modified
1522 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001523static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001524 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001525 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001526{
Don Skidmore3f207802014-12-23 07:40:34 +00001527 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore3f207802014-12-23 07:40:34 +00001528 bool encap_pkt = false;
1529
Alexander Duyck8a0da212012-01-31 02:59:49 +00001530 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001531
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001532 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001533 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001534 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001535
Emil Tantilova21d0822016-08-10 11:19:23 -07001536 /* check for VXLAN and Geneve packets */
1537 if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
Don Skidmore3f207802014-12-23 07:40:34 +00001538 encap_pkt = true;
1539 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001540 }
1541
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001542 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001543 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1544 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001545 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001546 return;
1547 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001548
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001549 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001550 return;
1551
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001552 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001553 /*
1554 * 82599 errata, UDP frames with a 0 checksum can be marked as
1555 * checksum errors.
1556 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001557 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1558 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001559 return;
1560
Alexander Duyck8a0da212012-01-31 02:59:49 +00001561 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001562 return;
1563 }
1564
Auke Kok9a799d72007-09-15 14:07:45 -07001565 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001566 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001567 if (encap_pkt) {
1568 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1569 return;
1570
1571 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
Mark Rustadd4692512015-12-04 11:26:43 -08001572 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001573 return;
1574 }
1575 /* If we checked the outer header let the stack know */
1576 skb->csum_level = 1;
1577 }
Auke Kok9a799d72007-09-15 14:07:45 -07001578}
1579
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001580static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
1581{
1582 return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
1583}
1584
Alexander Duyckf990b792012-01-31 02:59:34 +00001585static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1586 struct ixgbe_rx_buffer *bi)
1587{
1588 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001589 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001590
Alexander Duyckf8003262012-03-03 02:35:52 +00001591 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001592 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001593 return true;
1594
Alexander Duyckf8003262012-03-03 02:35:52 +00001595 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001596 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1597 if (unlikely(!page)) {
1598 rx_ring->rx_stats.alloc_rx_page_failed++;
1599 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001600 }
1601
Alexander Duyckf8003262012-03-03 02:35:52 +00001602 /* map page for use */
Alexander Duyckf3213d92017-01-17 08:35:54 -08001603 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
1604 ixgbe_rx_pg_size(rx_ring),
1605 DMA_FROM_DEVICE,
1606 IXGBE_RX_DMA_ATTR);
Alexander Duyckf990b792012-01-31 02:59:34 +00001607
Alexander Duyckf8003262012-03-03 02:35:52 +00001608 /*
1609 * if mapping failed free memory back to system since
1610 * there isn't much point in holding memory we can't use
1611 */
1612 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001613 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001614
Alexander Duyckf990b792012-01-31 02:59:34 +00001615 rx_ring->rx_stats.alloc_rx_page_failed++;
1616 return false;
1617 }
1618
Alexander Duyckf8003262012-03-03 02:35:52 +00001619 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001620 bi->page = page;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001621 bi->page_offset = ixgbe_rx_offset(rx_ring);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001622 bi->pagecnt_bias = 1;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02001623 rx_ring->rx_stats.alloc_rx_page++;
Alexander Duyckf8003262012-03-03 02:35:52 +00001624
Alexander Duyckf990b792012-01-31 02:59:34 +00001625 return true;
1626}
1627
Auke Kok9a799d72007-09-15 14:07:45 -07001628/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001629 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001630 * @rx_ring: ring to place buffers on
1631 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001632 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001633void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001634{
Auke Kok9a799d72007-09-15 14:07:45 -07001635 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001636 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001637 u16 i = rx_ring->next_to_use;
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001638 u16 bufsz;
Auke Kok9a799d72007-09-15 14:07:45 -07001639
Alexander Duyckf8003262012-03-03 02:35:52 +00001640 /* nothing to do */
1641 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001642 return;
1643
Alexander Duycke4f74022012-01-31 02:59:44 +00001644 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001645 bi = &rx_ring->rx_buffer_info[i];
1646 i -= rx_ring->count;
1647
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001648 bufsz = ixgbe_rx_bufsz(rx_ring);
1649
Alexander Duyckf8003262012-03-03 02:35:52 +00001650 do {
1651 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001652 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001653
Alexander Duyckf3213d92017-01-17 08:35:54 -08001654 /* sync the buffer for use by the device */
1655 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001656 bi->page_offset, bufsz,
Alexander Duyckf3213d92017-01-17 08:35:54 -08001657 DMA_FROM_DEVICE);
1658
Alexander Duyckf8003262012-03-03 02:35:52 +00001659 /*
1660 * Refresh the desc even if buffer_addrs didn't change
1661 * because each write-back erases this info.
1662 */
1663 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001664
Alexander Duyckf990b792012-01-31 02:59:34 +00001665 rx_desc++;
1666 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001667 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001668 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001669 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001670 bi = rx_ring->rx_buffer_info;
1671 i -= rx_ring->count;
1672 }
1673
Alexander Duyckc3630cc2017-01-17 08:36:28 -08001674 /* clear the length for the next_to_use descriptor */
1675 rx_desc->wb.upper.length = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001676
1677 cleaned_count--;
1678 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001679
Alexander Duyckf990b792012-01-31 02:59:34 +00001680 i += rx_ring->count;
1681
Alexander Duyckad435ec2014-11-14 00:56:35 +00001682 if (rx_ring->next_to_use != i) {
1683 rx_ring->next_to_use = i;
1684
1685 /* update next to alloc since we have filled the ring */
1686 rx_ring->next_to_alloc = i;
1687
1688 /* Force memory writes to complete before letting h/w
1689 * know there are new descriptors to fetch. (Only
1690 * applicable for weak-ordered memory model archs,
1691 * such as IA-64).
1692 */
1693 wmb();
1694 writel(i, rx_ring->tail);
1695 }
Auke Kok9a799d72007-09-15 14:07:45 -07001696}
1697
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001698static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1699 struct sk_buff *skb)
1700{
Alexander Duyckf8003262012-03-03 02:35:52 +00001701 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001702
1703 /* set gso_size to avoid messing up TCP MSS */
1704 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1705 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001706 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001707}
1708
1709static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1710 struct sk_buff *skb)
1711{
1712 /* if append_cnt is 0 then frame is not RSC */
1713 if (!IXGBE_CB(skb)->append_cnt)
1714 return;
1715
1716 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1717 rx_ring->rx_stats.rsc_flush++;
1718
1719 ixgbe_set_rsc_gso_size(rx_ring, skb);
1720
1721 /* gso_size is computed using append_cnt so always clear it last */
1722 IXGBE_CB(skb)->append_cnt = 0;
1723}
1724
Alexander Duyck8a0da212012-01-31 02:59:49 +00001725/**
1726 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1727 * @rx_ring: rx descriptor ring packet is being transacted on
1728 * @rx_desc: pointer to the EOP Rx descriptor
1729 * @skb: pointer to current skb being populated
1730 *
1731 * This function checks the ring, descriptor, and packet information in
1732 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1733 * other fields within the skb.
1734 **/
1735static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1736 union ixgbe_adv_rx_desc *rx_desc,
1737 struct sk_buff *skb)
1738{
John Fastabend43e95f12012-05-15 06:12:17 +00001739 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001740 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001741
Alexander Duyck8a0da212012-01-31 02:59:49 +00001742 ixgbe_update_rsc_stats(rx_ring, skb);
1743
1744 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1745
1746 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1747
Mark Rustada9763f32015-10-27 09:58:07 -07001748 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1749 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001750
Patrick McHardyf6469682013-04-19 02:04:27 +00001751 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001752 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001753 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001754 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001755 }
1756
1757 skb_record_rx_queue(skb, rx_ring->queue_index);
1758
John Fastabend43e95f12012-05-15 06:12:17 +00001759 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001760}
1761
1762static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1763 struct sk_buff *skb)
1764{
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08001765 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001766}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001767
Alexander Duyckf8003262012-03-03 02:35:52 +00001768/**
1769 * ixgbe_is_non_eop - process handling of non-EOP buffers
1770 * @rx_ring: Rx ring being processed
1771 * @rx_desc: Rx descriptor for current buffer
1772 * @skb: Current socket buffer containing buffer in progress
1773 *
1774 * This function updates next to clean. If the buffer is an EOP buffer
1775 * this function exits returning false, otherwise it will place the
1776 * sk_buff in the next buffer to be chained and return true indicating
1777 * that this is in fact a non-EOP buffer.
1778 **/
1779static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1780 union ixgbe_adv_rx_desc *rx_desc,
1781 struct sk_buff *skb)
1782{
1783 u32 ntc = rx_ring->next_to_clean + 1;
1784
1785 /* fetch, update, and store next to clean */
1786 ntc = (ntc < rx_ring->count) ? ntc : 0;
1787 rx_ring->next_to_clean = ntc;
1788
1789 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1790
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001791 /* update RSC append count if present */
1792 if (ring_is_rsc_enabled(rx_ring)) {
1793 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1794 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1795
1796 if (unlikely(rsc_enabled)) {
1797 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1798
1799 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1800 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1801
1802 /* update ntc based on RSC value */
1803 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1804 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1805 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1806 }
1807 }
1808
1809 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001810 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1811 return false;
1812
Alexander Duyckf8003262012-03-03 02:35:52 +00001813 /* place skb in next buffer to be received */
1814 rx_ring->rx_buffer_info[ntc].skb = skb;
1815 rx_ring->rx_stats.non_eop_descs++;
1816
1817 return true;
1818}
1819
1820/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001821 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1822 * @rx_ring: rx descriptor ring packet is being transacted on
1823 * @skb: pointer to current skb being adjusted
1824 *
1825 * This function is an ixgbe specific version of __pskb_pull_tail. The
1826 * main difference between this version and the original function is that
1827 * this function can make several assumptions about the state of things
1828 * that allow for significant optimizations versus the standard function.
1829 * As a result we can do things like drop a frag and maintain an accurate
1830 * truesize for the skb.
1831 */
1832static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1833 struct sk_buff *skb)
1834{
1835 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1836 unsigned char *va;
1837 unsigned int pull_len;
1838
1839 /*
1840 * it is valid to use page_address instead of kmap since we are
1841 * working with pages allocated out of the lomem pool per
1842 * alloc_page(GFP_ATOMIC)
1843 */
1844 va = skb_frag_address(frag);
1845
1846 /*
1847 * we need the header to contain the greater of either ETH_HLEN or
1848 * 60 bytes if the skb->len is less than 60 for skb_pad.
1849 */
Alexander Duyck8496e3382014-09-05 19:22:18 -04001850 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001851
1852 /* align pull length to size of long to optimize memcpy performance */
1853 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1854
1855 /* update all of the pointers */
1856 skb_frag_size_sub(frag, pull_len);
1857 frag->page_offset += pull_len;
1858 skb->data_len -= pull_len;
1859 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001860}
1861
1862/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001863 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1864 * @rx_ring: rx descriptor ring packet is being transacted on
1865 * @skb: pointer to current skb being updated
1866 *
1867 * This function provides a basic DMA sync up for the first fragment of an
1868 * skb. The reason for doing this is that the first fragment cannot be
1869 * unmapped until we have reached the end of packet descriptor for a buffer
1870 * chain.
1871 */
1872static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1873 struct sk_buff *skb)
1874{
1875 /* if the page was released unmap it, else just sync our portion */
1876 if (unlikely(IXGBE_CB(skb)->page_released)) {
Alexander Duyckf3213d92017-01-17 08:35:54 -08001877 dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
1878 ixgbe_rx_pg_size(rx_ring),
1879 DMA_FROM_DEVICE,
1880 IXGBE_RX_DMA_ATTR);
Alexander Duyck42073d92012-07-20 08:08:28 +00001881 } else {
1882 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1883
1884 dma_sync_single_range_for_cpu(rx_ring->dev,
1885 IXGBE_CB(skb)->dma,
1886 frag->page_offset,
Alexander Duyckf215af82017-01-17 08:35:44 -08001887 skb_frag_size(frag),
Alexander Duyck42073d92012-07-20 08:08:28 +00001888 DMA_FROM_DEVICE);
1889 }
Alexander Duyck42073d92012-07-20 08:08:28 +00001890}
1891
1892/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001893 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1894 * @rx_ring: rx descriptor ring packet is being transacted on
1895 * @rx_desc: pointer to the EOP Rx descriptor
1896 * @skb: pointer to current skb being fixed
1897 *
John Fastabend92470802017-04-24 03:30:17 -07001898 * Check if the skb is valid in the XDP case it will be an error pointer.
1899 * Return true in this case to abort processing and advance to next
1900 * descriptor.
1901 *
Alexander Duyckf8003262012-03-03 02:35:52 +00001902 * Check for corrupted packet headers caused by senders on the local L2
1903 * embedded NIC switch not setting up their Tx Descriptors right. These
1904 * should be very rare.
1905 *
1906 * Also address the case where we are pulling data in on pages only
1907 * and as such no data is present in the skb header.
1908 *
1909 * In addition if skb is not at least 60 bytes we need to pad it so that
1910 * it is large enough to qualify as a valid Ethernet frame.
1911 *
1912 * Returns true if an error was encountered and skb was freed.
1913 **/
1914static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1915 union ixgbe_adv_rx_desc *rx_desc,
1916 struct sk_buff *skb)
1917{
Alexander Duyckf8003262012-03-03 02:35:52 +00001918 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001919
John Fastabend92470802017-04-24 03:30:17 -07001920 /* XDP packets use error pointer so abort at this point */
1921 if (IS_ERR(skb))
1922 return true;
1923
Alexander Duyckf8003262012-03-03 02:35:52 +00001924 /* verify that the packet does not have any known errors */
1925 if (unlikely(ixgbe_test_staterr(rx_desc,
1926 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1927 !(netdev->features & NETIF_F_RXALL))) {
1928 dev_kfree_skb_any(skb);
1929 return true;
1930 }
1931
Alexander Duyck19861ce2012-07-20 08:08:33 +00001932 /* place header in linear portion of buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08001933 if (!skb_headlen(skb))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001934 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001935
Alexander Duyck57efd442012-06-25 21:54:46 +00001936#ifdef IXGBE_FCOE
1937 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1938 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1939 return false;
1940
1941#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001942 /* if eth_skb_pad returns an error the skb was freed */
1943 if (eth_skb_pad(skb))
1944 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001945
1946 return false;
1947}
1948
1949/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001950 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1951 * @rx_ring: rx descriptor ring to store buffers on
1952 * @old_buff: donor buffer to have page reused
1953 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001954 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001955 **/
1956static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1957 struct ixgbe_rx_buffer *old_buff)
1958{
1959 struct ixgbe_rx_buffer *new_buff;
1960 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001961
1962 new_buff = &rx_ring->rx_buffer_info[nta];
1963
1964 /* update, and store next to alloc */
1965 nta++;
1966 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1967
Alexander Duyck3fd218762017-01-17 08:36:45 -08001968 /* Transfer page from old buffer to new buffer.
1969 * Move each member individually to avoid possible store
1970 * forwarding stalls and unnecessary copy of skb.
1971 */
1972 new_buff->dma = old_buff->dma;
1973 new_buff->page = old_buff->page;
1974 new_buff->page_offset = old_buff->page_offset;
1975 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
Alexander Duyckf8003262012-03-03 02:35:52 +00001976}
1977
Alexander Duyck18cb6522014-11-14 00:56:29 +00001978static inline bool ixgbe_page_is_reserved(struct page *page)
1979{
Michal Hocko2f064f32015-08-21 14:11:51 -07001980 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001981}
1982
Alexander Duyck3fd218762017-01-17 08:36:45 -08001983static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
Alexander Duyckf8003262012-03-03 02:35:52 +00001984{
Alexander Duyck3fd218762017-01-17 08:36:45 -08001985 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
1986 struct page *page = rx_buffer->page;
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001987
Alexander Duyck09816fb2012-07-20 08:08:23 +00001988 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001989 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001990 return false;
1991
1992#if (PAGE_SIZE < 8192)
1993 /* if we are only owner of page we can reuse it */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001994 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001995 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001996#else
Alexander Duyck3fd218762017-01-17 08:36:45 -08001997 /* The last offset is a bit aggressive in that we assume the
1998 * worst case of FCoE being enabled and using a 3K buffer.
1999 * However this should have minimal impact as the 1K extra is
2000 * still less than one buffer in size.
2001 */
2002#define IXGBE_LAST_OFFSET \
2003 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
2004 if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
Alexander Duyck09816fb2012-07-20 08:08:23 +00002005 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00002006#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00002007
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002008 /* If we have drained the page fragment pool we need to update
2009 * the pagecnt_bias and page count so that we fully restock the
2010 * number of references the driver holds.
Alexander Duyck18cb6522014-11-14 00:56:29 +00002011 */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002012 if (unlikely(!pagecnt_bias)) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002013 page_ref_add(page, USHRT_MAX);
2014 rx_buffer->pagecnt_bias = USHRT_MAX;
2015 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00002016
Alexander Duyck0549ae22012-07-20 08:08:18 +00002017 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00002018}
2019
Alexander Duyckaf43da02017-01-17 08:35:34 -08002020/**
2021 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
2022 * @rx_ring: rx descriptor ring to transact packets on
2023 * @rx_buffer: buffer containing page to add
2024 * @rx_desc: descriptor containing length of buffer written by hardware
2025 * @skb: sk_buff to place the data into
2026 *
2027 * This function will add the data contained in rx_buffer->page to the skb.
2028 * This is done either through a direct copy if the data in the buffer is
2029 * less than the skb header size, otherwise it will just attach the page as
2030 * a frag to the skb.
2031 *
2032 * The function will then update the page offset if necessary and return
2033 * true if the buffer can be reused by the adapter.
2034 **/
Alexander Duyck3fd218762017-01-17 08:36:45 -08002035static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckaf43da02017-01-17 08:35:34 -08002036 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck3fd218762017-01-17 08:36:45 -08002037 struct sk_buff *skb,
2038 unsigned int size)
Alexander Duyckaf43da02017-01-17 08:35:34 -08002039{
Alexander Duyckaf43da02017-01-17 08:35:34 -08002040#if (PAGE_SIZE < 8192)
Alexander Duyck4f4542b2017-01-17 08:36:14 -08002041 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
Alexander Duyckaf43da02017-01-17 08:35:34 -08002042#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08002043 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2044 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2045 SKB_DATA_ALIGN(size);
Alexander Duyckaf43da02017-01-17 08:35:34 -08002046#endif
Alexander Duyck3fd218762017-01-17 08:36:45 -08002047 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
Alexander Duyckaf43da02017-01-17 08:35:34 -08002048 rx_buffer->page_offset, size, truesize);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002049#if (PAGE_SIZE < 8192)
2050 rx_buffer->page_offset ^= truesize;
2051#else
2052 rx_buffer->page_offset += truesize;
2053#endif
Alexander Duyckaf43da02017-01-17 08:35:34 -08002054}
2055
Alexander Duyck3fd218762017-01-17 08:36:45 -08002056static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
2057 union ixgbe_adv_rx_desc *rx_desc,
2058 struct sk_buff **skb,
2059 const unsigned int size)
Alexander Duyck18806c92012-07-20 08:08:44 +00002060{
2061 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyck18806c92012-07-20 08:08:44 +00002062
2063 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
Alexander Duyck3fd218762017-01-17 08:36:45 -08002064 prefetchw(rx_buffer->page);
2065 *skb = rx_buffer->skb;
Alexander Duyck18806c92012-07-20 08:08:44 +00002066
Alexander Duyck3fd218762017-01-17 08:36:45 -08002067 /* Delay unmapping of the first packet. It carries the header
2068 * information, HW may still access the header after the writeback.
2069 * Only unmap it when EOP is reached
2070 */
2071 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
2072 if (!*skb)
2073 goto skip_sync;
Alexander Duyck18806c92012-07-20 08:08:44 +00002074 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002075 if (*skb)
2076 ixgbe_dma_sync_frag(rx_ring, *skb);
Alexander Duyck18806c92012-07-20 08:08:44 +00002077 }
2078
Alexander Duyck3fd218762017-01-17 08:36:45 -08002079 /* we are reusing so sync this buffer for CPU use */
2080 dma_sync_single_range_for_cpu(rx_ring->dev,
2081 rx_buffer->dma,
2082 rx_buffer->page_offset,
2083 size,
2084 DMA_FROM_DEVICE);
2085skip_sync:
2086 rx_buffer->pagecnt_bias--;
2087
2088 return rx_buffer;
2089}
2090
2091static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
2092 struct ixgbe_rx_buffer *rx_buffer,
2093 struct sk_buff *skb)
2094{
2095 if (ixgbe_can_reuse_rx_page(rx_buffer)) {
Alexander Duyck18806c92012-07-20 08:08:44 +00002096 /* hand second half of page back to the ring */
2097 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
Alexander Duyck18806c92012-07-20 08:08:44 +00002098 } else {
John Fastabend92470802017-04-24 03:30:17 -07002099 if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002100 /* the page has been released from the ring */
2101 IXGBE_CB(skb)->page_released = true;
2102 } else {
2103 /* we are not reusing the buffer so unmap it */
2104 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
2105 ixgbe_rx_pg_size(rx_ring),
2106 DMA_FROM_DEVICE,
2107 IXGBE_RX_DMA_ATTR);
2108 }
Alexander Duyck3fd218762017-01-17 08:36:45 -08002109 __page_frag_cache_drain(rx_buffer->page,
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002110 rx_buffer->pagecnt_bias);
Alexander Duyck18806c92012-07-20 08:08:44 +00002111 }
2112
Alexander Duyck3fd218762017-01-17 08:36:45 -08002113 /* clear contents of rx_buffer */
Alexander Duyck18806c92012-07-20 08:08:44 +00002114 rx_buffer->page = NULL;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002115 rx_buffer->skb = NULL;
2116}
2117
2118static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
2119 struct ixgbe_rx_buffer *rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002120 struct xdp_buff *xdp,
2121 union ixgbe_adv_rx_desc *rx_desc)
Alexander Duyck3fd218762017-01-17 08:36:45 -08002122{
John Fastabend92470802017-04-24 03:30:17 -07002123 unsigned int size = xdp->data_end - xdp->data;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002124#if (PAGE_SIZE < 8192)
2125 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2126#else
John Fastabend92470802017-04-24 03:30:17 -07002127 unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end -
2128 xdp->data_hard_start);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002129#endif
2130 struct sk_buff *skb;
2131
2132 /* prefetch first cache line of first page */
John Fastabend92470802017-04-24 03:30:17 -07002133 prefetch(xdp->data);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002134#if L1_CACHE_BYTES < 128
John Fastabend92470802017-04-24 03:30:17 -07002135 prefetch(xdp->data + L1_CACHE_BYTES);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002136#endif
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002137 /* Note, we get here by enabling legacy-rx via:
2138 *
2139 * ethtool --set-priv-flags <dev> legacy-rx on
2140 *
2141 * In this mode, we currently get 0 extra XDP headroom as
2142 * opposed to having legacy-rx off, where we process XDP
2143 * packets going to stack via ixgbe_build_skb(). The latter
2144 * provides us currently with 192 bytes of headroom.
2145 *
2146 * For ixgbe_construct_skb() mode it means that the
2147 * xdp->data_meta will always point to xdp->data, since
2148 * the helper cannot expand the head. Should this ever
2149 * change in future for legacy-rx mode on, then lets also
2150 * add xdp->data_meta handling here.
2151 */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002152
2153 /* allocate a skb to store the frags */
2154 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
2155 if (unlikely(!skb))
2156 return NULL;
2157
2158 if (size > IXGBE_RX_HDR_SIZE) {
2159 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2160 IXGBE_CB(skb)->dma = rx_buffer->dma;
2161
2162 skb_add_rx_frag(skb, 0, rx_buffer->page,
John Fastabend92470802017-04-24 03:30:17 -07002163 xdp->data - page_address(rx_buffer->page),
Alexander Duyck3fd218762017-01-17 08:36:45 -08002164 size, truesize);
2165#if (PAGE_SIZE < 8192)
2166 rx_buffer->page_offset ^= truesize;
2167#else
2168 rx_buffer->page_offset += truesize;
2169#endif
2170 } else {
John Fastabend92470802017-04-24 03:30:17 -07002171 memcpy(__skb_put(skb, size),
2172 xdp->data, ALIGN(size, sizeof(long)));
Alexander Duyck3fd218762017-01-17 08:36:45 -08002173 rx_buffer->pagecnt_bias++;
2174 }
Alexander Duyck18806c92012-07-20 08:08:44 +00002175
2176 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002177}
2178
Alexander Duyck6f429222017-01-17 08:37:13 -08002179static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
2180 struct ixgbe_rx_buffer *rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002181 struct xdp_buff *xdp,
2182 union ixgbe_adv_rx_desc *rx_desc)
Alexander Duyck6f429222017-01-17 08:37:13 -08002183{
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002184 unsigned int metasize = xdp->data - xdp->data_meta;
Alexander Duyck6f429222017-01-17 08:37:13 -08002185#if (PAGE_SIZE < 8192)
2186 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2187#else
2188 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
John Fastabend92470802017-04-24 03:30:17 -07002189 SKB_DATA_ALIGN(xdp->data_end -
2190 xdp->data_hard_start);
Alexander Duyck6f429222017-01-17 08:37:13 -08002191#endif
2192 struct sk_buff *skb;
2193
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002194 /* Prefetch first cache line of first page. If xdp->data_meta
2195 * is unused, this points extactly as xdp->data, otherwise we
2196 * likely have a consumer accessing first few bytes of meta
2197 * data, and then actual data.
2198 */
2199 prefetch(xdp->data_meta);
Alexander Duyck6f429222017-01-17 08:37:13 -08002200#if L1_CACHE_BYTES < 128
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002201 prefetch(xdp->data_meta + L1_CACHE_BYTES);
Alexander Duyck6f429222017-01-17 08:37:13 -08002202#endif
2203
John Fastabend92470802017-04-24 03:30:17 -07002204 /* build an skb to around the page buffer */
2205 skb = build_skb(xdp->data_hard_start, truesize);
Alexander Duyck6f429222017-01-17 08:37:13 -08002206 if (unlikely(!skb))
2207 return NULL;
2208
2209 /* update pointers within the skb to store the data */
John Fastabend92470802017-04-24 03:30:17 -07002210 skb_reserve(skb, xdp->data - xdp->data_hard_start);
2211 __skb_put(skb, xdp->data_end - xdp->data);
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002212 if (metasize)
2213 skb_metadata_set(skb, metasize);
Alexander Duyck6f429222017-01-17 08:37:13 -08002214
2215 /* record DMA address if this is the start of a chain of buffers */
2216 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2217 IXGBE_CB(skb)->dma = rx_buffer->dma;
2218
2219 /* update buffer offset */
2220#if (PAGE_SIZE < 8192)
2221 rx_buffer->page_offset ^= truesize;
2222#else
2223 rx_buffer->page_offset += truesize;
2224#endif
2225
2226 return skb;
2227}
2228
John Fastabend92470802017-04-24 03:30:17 -07002229#define IXGBE_XDP_PASS 0
2230#define IXGBE_XDP_CONSUMED 1
John Fastabend33fdc822017-04-24 03:30:18 -07002231#define IXGBE_XDP_TX 2
John Fastabend92470802017-04-24 03:30:17 -07002232
John Fastabend33fdc822017-04-24 03:30:18 -07002233static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
2234 struct xdp_buff *xdp);
2235
2236static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
2237 struct ixgbe_ring *rx_ring,
John Fastabend92470802017-04-24 03:30:17 -07002238 struct xdp_buff *xdp)
2239{
John Fastabend64530732017-07-17 09:28:12 -07002240 int err, result = IXGBE_XDP_PASS;
John Fastabend92470802017-04-24 03:30:17 -07002241 struct bpf_prog *xdp_prog;
2242 u32 act;
2243
2244 rcu_read_lock();
2245 xdp_prog = READ_ONCE(rx_ring->xdp_prog);
2246
2247 if (!xdp_prog)
2248 goto xdp_out;
2249
2250 act = bpf_prog_run_xdp(xdp_prog, xdp);
2251 switch (act) {
2252 case XDP_PASS:
2253 break;
John Fastabend33fdc822017-04-24 03:30:18 -07002254 case XDP_TX:
2255 result = ixgbe_xmit_xdp_ring(adapter, xdp);
2256 break;
John Fastabend64530732017-07-17 09:28:12 -07002257 case XDP_REDIRECT:
John Fastabend5acaee02017-07-17 09:28:35 -07002258 err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog);
John Fastabend64530732017-07-17 09:28:12 -07002259 if (!err)
2260 result = IXGBE_XDP_TX;
2261 else
2262 result = IXGBE_XDP_CONSUMED;
2263 break;
John Fastabend92470802017-04-24 03:30:17 -07002264 default:
2265 bpf_warn_invalid_xdp_action(act);
Tony Nguyen93df9462017-05-31 04:43:47 -07002266 /* fallthrough */
John Fastabend92470802017-04-24 03:30:17 -07002267 case XDP_ABORTED:
2268 trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
2269 /* fallthrough -- handle aborts by dropping packet */
2270 case XDP_DROP:
2271 result = IXGBE_XDP_CONSUMED;
2272 break;
2273 }
2274xdp_out:
2275 rcu_read_unlock();
2276 return ERR_PTR(-result);
2277}
2278
John Fastabend33fdc822017-04-24 03:30:18 -07002279static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
2280 struct ixgbe_rx_buffer *rx_buffer,
2281 unsigned int size)
2282{
2283#if (PAGE_SIZE < 8192)
2284 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2285
2286 rx_buffer->page_offset ^= truesize;
2287#else
2288 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2289 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2290 SKB_DATA_ALIGN(size);
2291
2292 rx_buffer->page_offset += truesize;
2293#endif
2294}
2295
Alexander Duyckf8003262012-03-03 02:35:52 +00002296/**
2297 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2298 * @q_vector: structure containing interrupt and ring information
2299 * @rx_ring: rx descriptor ring to transact packets on
2300 * @budget: Total limit on number of packets to process
2301 *
2302 * This function provides a "bounce buffer" approach to Rx interrupt
2303 * processing. The advantage to this is that on systems that have
2304 * expensive overhead for IOMMU access this provides a means of avoiding
2305 * it by maintaining the mapping of the page to the syste.
2306 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002307 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002308 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002309static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002310 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002311 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002312{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002313 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00002314 struct ixgbe_adapter *adapter = q_vector->adapter;
John Fastabend33fdc822017-04-24 03:30:18 -07002315#ifdef IXGBE_FCOE
Mark Rustad4ffdf912012-07-18 06:05:50 +00002316 int ddp_bytes;
2317 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002318#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002319 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
John Fastabend7379f972017-03-28 09:47:03 -07002320 bool xdp_xmit = false;
Auke Kok9a799d72007-09-15 14:07:45 -07002321
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002322 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002323 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002324 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyckf8003262012-03-03 02:35:52 +00002325 struct sk_buff *skb;
John Fastabend92470802017-04-24 03:30:17 -07002326 struct xdp_buff xdp;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002327 unsigned int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002328
Alexander Duyckf8003262012-03-03 02:35:52 +00002329 /* return some buffers to hardware, one at a time is too slow */
2330 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2331 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2332 cleaned_count = 0;
2333 }
Auke Kok9a799d72007-09-15 14:07:45 -07002334
Alexander Duyck18806c92012-07-20 08:08:44 +00002335 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002336 size = le16_to_cpu(rx_desc->wb.upper.length);
2337 if (!size)
Alexander Duyckf8003262012-03-03 02:35:52 +00002338 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002339
Alexander Duyck124b74c2014-12-11 15:02:28 -08002340 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002341 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002342 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002343 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002344 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002345
Alexander Duyck3fd218762017-01-17 08:36:45 -08002346 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
2347
Alexander Duyck18806c92012-07-20 08:08:44 +00002348 /* retrieve a buffer from the ring */
John Fastabend92470802017-04-24 03:30:17 -07002349 if (!skb) {
2350 xdp.data = page_address(rx_buffer->page) +
2351 rx_buffer->page_offset;
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002352 xdp.data_meta = xdp.data;
John Fastabend92470802017-04-24 03:30:17 -07002353 xdp.data_hard_start = xdp.data -
2354 ixgbe_rx_offset(rx_ring);
2355 xdp.data_end = xdp.data + size;
2356
John Fastabend33fdc822017-04-24 03:30:18 -07002357 skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
John Fastabend92470802017-04-24 03:30:17 -07002358 }
2359
2360 if (IS_ERR(skb)) {
John Fastabend7379f972017-03-28 09:47:03 -07002361 if (PTR_ERR(skb) == -IXGBE_XDP_TX) {
2362 xdp_xmit = true;
John Fastabend33fdc822017-04-24 03:30:18 -07002363 ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
John Fastabend7379f972017-03-28 09:47:03 -07002364 } else {
John Fastabend33fdc822017-04-24 03:30:18 -07002365 rx_buffer->pagecnt_bias++;
John Fastabend7379f972017-03-28 09:47:03 -07002366 }
John Fastabend92470802017-04-24 03:30:17 -07002367 total_rx_packets++;
2368 total_rx_bytes += size;
John Fastabend92470802017-04-24 03:30:17 -07002369 } else if (skb) {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002370 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
John Fastabend92470802017-04-24 03:30:17 -07002371 } else if (ring_uses_build_skb(rx_ring)) {
Alexander Duyck6f429222017-01-17 08:37:13 -08002372 skb = ixgbe_build_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002373 &xdp, rx_desc);
2374 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002375 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002376 &xdp, rx_desc);
2377 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002378
Alexander Duyck18806c92012-07-20 08:08:44 +00002379 /* exit if we failed to retrieve a buffer */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002380 if (!skb) {
2381 rx_ring->rx_stats.alloc_rx_buff_failed++;
2382 rx_buffer->pagecnt_bias++;
Alexander Duyck18806c92012-07-20 08:08:44 +00002383 break;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002384 }
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002385
Alexander Duyck3fd218762017-01-17 08:36:45 -08002386 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002387 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002388
Alexander Duyckf8003262012-03-03 02:35:52 +00002389 /* place incomplete frames back on ring for completion */
2390 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2391 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002392
Alexander Duyckf8003262012-03-03 02:35:52 +00002393 /* verify the packet layout is correct */
2394 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2395 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002396
2397 /* probably a little skewed due to removing CRC */
2398 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002399
Alexander Duyck8a0da212012-01-31 02:59:49 +00002400 /* populate checksum, timestamp, VLAN, and protocol */
2401 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2402
Yi Zou332d4a72009-05-13 13:11:53 +00002403#ifdef IXGBE_FCOE
2404 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002405 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002406 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002407 /* include DDPed FCoE data */
2408 if (ddp_bytes > 0) {
2409 if (!mss) {
2410 mss = rx_ring->netdev->mtu -
2411 sizeof(struct fcoe_hdr) -
2412 sizeof(struct fc_frame_header) -
2413 sizeof(struct fcoe_crc_eof);
2414 if (mss > 512)
2415 mss &= ~511;
2416 }
2417 total_rx_bytes += ddp_bytes;
2418 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2419 mss);
2420 }
David S. Miller823dcd22011-08-20 10:39:12 -07002421 if (!ddp_bytes) {
2422 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002423 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002424 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002425 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002426
Yi Zou332d4a72009-05-13 13:11:53 +00002427#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002428 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002429
Alexander Duyckf8003262012-03-03 02:35:52 +00002430 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002431 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002432 }
Auke Kok9a799d72007-09-15 14:07:45 -07002433
John Fastabend7379f972017-03-28 09:47:03 -07002434 if (xdp_xmit) {
2435 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
2436
2437 /* Force memory writes to complete before letting h/w
2438 * know there are new descriptors to fetch.
2439 */
2440 wmb();
2441 writel(ring->next_to_use, ring->tail);
John Fastabend11393cc2017-07-17 09:29:40 -07002442
2443 xdp_do_flush_map();
John Fastabend7379f972017-03-28 09:47:03 -07002444 }
2445
Alexander Duyckc267fc12010-11-16 19:27:00 -08002446 u64_stats_update_begin(&rx_ring->syncp);
2447 rx_ring->stats.packets += total_rx_packets;
2448 rx_ring->stats.bytes += total_rx_bytes;
2449 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002450 q_vector->rx.total_packets += total_rx_packets;
2451 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002452
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002453 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002454}
2455
Auke Kok9a799d72007-09-15 14:07:45 -07002456/**
2457 * ixgbe_configure_msix - Configure MSI-X hardware
2458 * @adapter: board private structure
2459 *
2460 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2461 * interrupts.
2462 **/
2463static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2464{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002465 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002466 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002467 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002468
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002469 /* Populate MSIX to EITR Select */
2470 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002471 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002472 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2473 }
2474
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002475 /*
2476 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002477 * corresponding register.
2478 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002479 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002480 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002481 q_vector = adapter->q_vector[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->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002484 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002485
Alexander Duycka5579282012-02-08 07:50:04 +00002486 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002487 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002488
Alexander Duyckfe49f042009-06-04 16:00:09 +00002489 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002490 }
2491
Alexander Duyckbd508172010-11-16 19:27:03 -08002492 switch (adapter->hw.mac.type) {
2493 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002494 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002495 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002496 break;
2497 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002498 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002499 case ixgbe_mac_X550:
2500 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002501 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002502 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002503 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002504 default:
2505 break;
2506 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002507 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002508
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002509 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002510 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002511 mask &= ~(IXGBE_EIMS_OTHER |
2512 IXGBE_EIMS_MAILBOX |
2513 IXGBE_EIMS_LSC);
2514
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002515 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002516}
2517
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002518enum latency_range {
2519 lowest_latency = 0,
2520 low_latency = 1,
2521 bulk_latency = 2,
2522 latency_invalid = 255
2523};
2524
2525/**
2526 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002527 * @q_vector: structure containing interrupt and ring information
2528 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002529 *
2530 * Stores a new ITR value based on packets and byte
2531 * counts during the last interrupt. The advantage of per interrupt
2532 * computation is faster updates and more accurate ITR for the current
2533 * traffic pattern. Constants in this function were computed
2534 * based on theoretical maximum wire speed and thresholds were set based
2535 * on testing data as well as attempting to minimize response time
2536 * while increasing bulk throughput.
2537 * this functionality is controlled by the InterruptThrottleRate module
2538 * parameter (see ixgbe_param.c)
2539 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002540static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2541 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002542{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002543 unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS |
2544 IXGBE_ITR_ADAPTIVE_LATENCY;
2545 unsigned int avg_wire_size, packets, bytes;
2546 unsigned long next_update = jiffies;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002547
Alexander Duyckb4ded832017-09-25 14:55:36 -07002548 /* If we don't have any rings just leave ourselves set for maximum
2549 * possible latency so we take ourselves out of the equation.
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002550 */
Alexander Duyckb4ded832017-09-25 14:55:36 -07002551 if (!ring_container->ring)
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002552 return;
2553
Alexander Duyckb4ded832017-09-25 14:55:36 -07002554 /* If we didn't update within up to 1 - 2 jiffies we can assume
2555 * that either packets are coming in so slow there hasn't been
2556 * any work, or that there is so much work that NAPI is dealing
2557 * with interrupt moderation and we don't need to do anything.
2558 */
2559 if (time_after(next_update, ring_container->next_update))
2560 goto clear_counts;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002561
Alexander Duyckb4ded832017-09-25 14:55:36 -07002562 packets = ring_container->total_packets;
2563
2564 /* We have no packets to actually measure against. This means
2565 * either one of the other queues on this vector is active or
2566 * we are a Tx queue doing TSO with too high of an interrupt rate.
2567 *
2568 * When this occurs just tick up our delay by the minimum value
2569 * and hope that this extra delay will prevent us from being called
2570 * without any work on our queue.
2571 */
2572 if (!packets) {
2573 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2574 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2575 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2576 itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY;
2577 goto clear_counts;
2578 }
2579
2580 bytes = ring_container->total_bytes;
2581
2582 /* If packets are less than 4 or bytes are less than 9000 assume
2583 * insufficient data to use bulk rate limiting approach. We are
2584 * likely latency driven.
2585 */
2586 if (packets < 4 && bytes < 9000) {
2587 itr = IXGBE_ITR_ADAPTIVE_LATENCY;
2588 goto adjust_by_size;
2589 }
2590
2591 /* Between 4 and 48 we can assume that our current interrupt delay
2592 * is only slightly too low. As such we should increase it by a small
2593 * fixed amount.
2594 */
2595 if (packets < 48) {
2596 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2597 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2598 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2599 goto clear_counts;
2600 }
2601
2602 /* Between 48 and 96 is our "goldilocks" zone where we are working
2603 * out "just right". Just report that our current ITR is good for us.
2604 */
2605 if (packets < 96) {
2606 itr = q_vector->itr >> 2;
2607 goto clear_counts;
2608 }
2609
2610 /* If packet count is 96 or greater we are likely looking at a slight
2611 * overrun of the delay we want. Try halving our delay to see if that
2612 * will cut the number of packets in half per interrupt.
2613 */
2614 if (packets < 256) {
2615 itr = q_vector->itr >> 3;
2616 if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS)
2617 itr = IXGBE_ITR_ADAPTIVE_MIN_USECS;
2618 goto clear_counts;
2619 }
2620
2621 /* The paths below assume we are dealing with a bulk ITR since number
2622 * of packets is 256 or greater. We are just going to have to compute
2623 * a value and try to bring the count under control, though for smaller
2624 * packet sizes there isn't much we can do as NAPI polling will likely
2625 * be kicking in sooner rather than later.
2626 */
2627 itr = IXGBE_ITR_ADAPTIVE_BULK;
2628
2629adjust_by_size:
2630 /* If packet counts are 256 or greater we can assume we have a gross
2631 * overestimation of what the rate should be. Instead of trying to fine
2632 * tune it just use the formula below to try and dial in an exact value
2633 * give the current packet size of the frame.
2634 */
2635 avg_wire_size = bytes / packets;
2636
2637 /* The following is a crude approximation of:
2638 * wmem_default / (size + overhead) = desired_pkts_per_int
2639 * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
2640 * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
2641 *
2642 * Assuming wmem_default is 212992 and overhead is 640 bytes per
2643 * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
2644 * formula down to
2645 *
2646 * (170 * (size + 24)) / (size + 640) = ITR
2647 *
2648 * We first do some math on the packet size and then finally bitshift
2649 * by 8 after rounding up. We also have to account for PCIe link speed
2650 * difference as ITR scales based on this.
2651 */
2652 if (avg_wire_size <= 60) {
2653 /* Start at 50k ints/sec */
2654 avg_wire_size = 5120;
2655 } else if (avg_wire_size <= 316) {
2656 /* 50K ints/sec to 16K ints/sec */
2657 avg_wire_size *= 40;
2658 avg_wire_size += 2720;
2659 } else if (avg_wire_size <= 1084) {
2660 /* 16K ints/sec to 9.2K ints/sec */
2661 avg_wire_size *= 15;
2662 avg_wire_size += 11452;
2663 } else if (avg_wire_size <= 1980) {
2664 /* 9.2K ints/sec to 8K ints/sec */
2665 avg_wire_size *= 5;
2666 avg_wire_size += 22420;
2667 } else {
2668 /* plateau at a limit of 8K ints/sec */
2669 avg_wire_size = 32256;
2670 }
2671
2672 /* If we are in low latency mode half our delay which doubles the rate
2673 * to somewhere between 100K to 16K ints/sec
2674 */
2675 if (itr & IXGBE_ITR_ADAPTIVE_LATENCY)
2676 avg_wire_size >>= 1;
2677
2678 /* Resultant value is 256 times larger than it needs to be. This
2679 * gives us room to adjust the value as needed to either increase
2680 * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
2681 *
2682 * Use addition as we have already recorded the new latency flag
2683 * for the ITR value.
2684 */
2685 switch (q_vector->adapter->link_speed) {
2686 case IXGBE_LINK_SPEED_10GB_FULL:
2687 case IXGBE_LINK_SPEED_100_FULL:
2688 default:
2689 itr += DIV_ROUND_UP(avg_wire_size,
2690 IXGBE_ITR_ADAPTIVE_MIN_INC * 256) *
2691 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002692 break;
Alexander Duyckb4ded832017-09-25 14:55:36 -07002693 case IXGBE_LINK_SPEED_2_5GB_FULL:
2694 case IXGBE_LINK_SPEED_1GB_FULL:
2695 case IXGBE_LINK_SPEED_10_FULL:
2696 itr += DIV_ROUND_UP(avg_wire_size,
2697 IXGBE_ITR_ADAPTIVE_MIN_INC * 64) *
2698 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002699 break;
2700 }
2701
Alexander Duyckb4ded832017-09-25 14:55:36 -07002702clear_counts:
2703 /* write back value */
2704 ring_container->itr = itr;
2705
2706 /* next update should occur within next jiffy */
2707 ring_container->next_update = next_update + 1;
2708
Alexander Duyckbd198052011-06-11 01:45:08 +00002709 ring_container->total_bytes = 0;
2710 ring_container->total_packets = 0;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002711}
2712
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002713/**
2714 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002715 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002716 *
2717 * This function is made to be called by ethtool and by the driver
2718 * when it needs to update EITR registers at runtime. Hardware
2719 * specific quirks/differences are taken care of here.
2720 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002721void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002722{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002723 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002724 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002725 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002726 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002727
Alexander Duyckbd508172010-11-16 19:27:03 -08002728 switch (adapter->hw.mac.type) {
2729 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002730 /* must write high and low 16 bits to reset counter */
2731 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002732 break;
2733 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002734 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002735 case ixgbe_mac_X550:
2736 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002737 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002738 /*
2739 * set the WDIS bit to not clear the timer bits and cause an
2740 * immediate assertion of the interrupt
2741 */
2742 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002743 break;
2744 default:
2745 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002746 }
2747 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2748}
2749
Alexander Duyckbd198052011-06-11 01:45:08 +00002750static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002751{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002752 u32 new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002753
Alexander Duyckbd198052011-06-11 01:45:08 +00002754 ixgbe_update_itr(q_vector, &q_vector->tx);
2755 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002756
Alexander Duyckb4ded832017-09-25 14:55:36 -07002757 /* use the smallest value of new ITR delay calculations */
2758 new_itr = min(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002759
Alexander Duyckb4ded832017-09-25 14:55:36 -07002760 /* Clear latency flag if set, shift into correct position */
2761 new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY;
2762 new_itr <<= 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002763
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002764 if (new_itr != q_vector->itr) {
Alexander Duyckbd198052011-06-11 01:45:08 +00002765 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002766 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002767
2768 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002769 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002770}
2771
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002772/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002773 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002774 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002775 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002776static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002777{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002778 struct ixgbe_hw *hw = &adapter->hw;
2779 u32 eicr = adapter->interrupt_event;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002780 s32 rc;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002781
Alexander Duyckf0f97782011-04-22 04:08:09 +00002782 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002783 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002784
Mark Rustad22cb4ff2017-04-25 13:55:25 -07002785 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
Alexander Duyckf0f97782011-04-22 04:08:09 +00002786 return;
2787
2788 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2789
Joe Perches7ca647b2010-09-07 21:35:40 +00002790 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002791 case IXGBE_DEV_ID_82599_T3_LOM:
2792 /*
2793 * Since the warning interrupt is for both ports
2794 * we don't have to check if:
2795 * - This interrupt wasn't for our port.
2796 * - We may have missed the interrupt so always have to
2797 * check if we got a LSC
2798 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002799 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002800 !(eicr & IXGBE_EICR_LSC))
2801 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002802
Alexander Duyckf0f97782011-04-22 04:08:09 +00002803 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002804 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002805 bool link_up = false;
2806
Josh Hay3d292262012-12-15 03:28:19 +00002807 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002808
Alexander Duyckf0f97782011-04-22 04:08:09 +00002809 if (link_up)
2810 return;
2811 }
2812
2813 /* Check if this is not due to overtemp */
2814 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2815 return;
2816
2817 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002818 case IXGBE_DEV_ID_X550EM_A_1G_T:
2819 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2820 rc = hw->phy.ops.check_overtemp(hw);
2821 if (rc != IXGBE_ERR_OVERTEMP)
2822 return;
2823 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002824 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002825 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2826 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002827 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002828 return;
2829 break;
2830 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002831 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002832
2833 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002834}
2835
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002836static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2837{
2838 struct ixgbe_hw *hw = &adapter->hw;
2839
2840 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002841 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002842 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002843 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002844 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002845 }
2846}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002847
Jacob Keller4f51bf72011-08-20 04:49:45 +00002848static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2849{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002850 struct ixgbe_hw *hw = &adapter->hw;
2851
Jacob Keller4f51bf72011-08-20 04:49:45 +00002852 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2853 return;
2854
2855 switch (adapter->hw.mac.type) {
2856 case ixgbe_mac_82599EB:
2857 /*
2858 * Need to check link state so complete overtemp check
2859 * on service task
2860 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002861 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2862 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002863 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2864 adapter->interrupt_event = eicr;
2865 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2866 ixgbe_service_event_schedule(adapter);
2867 return;
2868 }
2869 return;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002870 case ixgbe_mac_x550em_a:
2871 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2872 adapter->interrupt_event = eicr;
2873 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2874 ixgbe_service_event_schedule(adapter);
2875 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2876 IXGBE_EICR_GPI_SDP0_X550EM_a);
2877 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2878 IXGBE_EICR_GPI_SDP0_X550EM_a);
2879 }
2880 return;
2881 case ixgbe_mac_X550:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002882 case ixgbe_mac_X540:
2883 if (!(eicr & IXGBE_EICR_TS))
2884 return;
2885 break;
2886 default:
2887 return;
2888 }
2889
Don Skidmoref44e7512015-06-09 16:36:23 -07002890 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002891}
2892
Don Skidmore45788d22015-06-09 16:59:04 -07002893static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2894{
2895 switch (hw->mac.type) {
2896 case ixgbe_mac_82598EB:
2897 if (hw->phy.type == ixgbe_phy_nl)
2898 return true;
2899 return false;
2900 case ixgbe_mac_82599EB:
2901 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002902 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002903 switch (hw->mac.ops.get_media_type(hw)) {
2904 case ixgbe_media_type_fiber:
2905 case ixgbe_media_type_fiber_qsfp:
2906 return true;
2907 default:
2908 return false;
2909 }
2910 default:
2911 return false;
2912 }
2913}
2914
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002915static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2916{
2917 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002918 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002919
Don Skidmore4ccc6502015-09-02 13:47:54 -07002920 if (!ixgbe_is_sfp(hw))
2921 return;
2922
2923 /* Later MAC's use different SDP */
2924 if (hw->mac.type >= ixgbe_mac_X540)
2925 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2926
2927 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002928 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002929 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002930 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2931 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002932 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002933 ixgbe_service_event_schedule(adapter);
2934 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002935 }
2936
Don Skidmore4ccc6502015-09-02 13:47:54 -07002937 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2938 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002939 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002940 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002941 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2942 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2943 ixgbe_service_event_schedule(adapter);
2944 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002945 }
2946}
2947
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002948static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2949{
2950 struct ixgbe_hw *hw = &adapter->hw;
2951
2952 adapter->lsc_int++;
2953 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2954 adapter->link_check_timeout = jiffies;
2955 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2956 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002957 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002958 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002959 }
2960}
2961
Alexander Duyckfe49f042009-06-04 16:00:09 +00002962static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2963 u64 qmask)
2964{
2965 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002966 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002967
Alexander Duyckbd508172010-11-16 19:27:03 -08002968 switch (hw->mac.type) {
2969 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002970 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002971 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2972 break;
2973 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002974 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002975 case ixgbe_mac_X550:
2976 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002977 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002978 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002979 if (mask)
2980 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002981 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002982 if (mask)
2983 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2984 break;
2985 default:
2986 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002987 }
2988 /* skip the flush */
2989}
2990
2991static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002992 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002993{
2994 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002995 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002996
Alexander Duyckbd508172010-11-16 19:27:03 -08002997 switch (hw->mac.type) {
2998 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002999 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08003000 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
3001 break;
3002 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003003 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003004 case ixgbe_mac_X550:
3005 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003006 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00003007 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08003008 if (mask)
3009 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00003010 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08003011 if (mask)
3012 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
3013 break;
3014 default:
3015 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003016 }
3017 /* skip the flush */
3018}
3019
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003020/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00003021 * ixgbe_irq_enable - Enable default interrupt generation settings
3022 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003023 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00003024static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
3025 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07003026{
Don Skidmore9a900ec2015-06-09 17:15:01 -07003027 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00003028 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003029
Alexander Duyck2c4af692011-07-15 07:29:55 +00003030 /* don't reenable LSC while waiting for link */
3031 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
3032 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003033
Alexander Duyck2c4af692011-07-15 07:29:55 +00003034 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00003035 switch (adapter->hw.mac.type) {
3036 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003037 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003038 break;
3039 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003040 case ixgbe_mac_X550:
3041 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003042 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00003043 mask |= IXGBE_EIMS_TS;
3044 break;
3045 default:
3046 break;
3047 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003048 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07003049 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003050 switch (adapter->hw.mac.type) {
3051 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003052 mask |= IXGBE_EIMS_GPI_SDP1(hw);
3053 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003054 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00003055 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003056 case ixgbe_mac_X550:
3057 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003058 case ixgbe_mac_x550em_a:
3059 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07003060 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07003061 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07003062 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07003063 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
3064 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00003065 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00003066 mask |= IXGBE_EIMS_MAILBOX;
3067 break;
3068 default:
3069 break;
3070 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003071
Alexander Duyck2c4af692011-07-15 07:29:55 +00003072 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
3073 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
3074 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003075
Alexander Duyck2c4af692011-07-15 07:29:55 +00003076 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
3077 if (queues)
3078 ixgbe_irq_enable_queues(adapter, ~0);
3079 if (flush)
3080 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07003081}
3082
Alexander Duyck2c4af692011-07-15 07:29:55 +00003083static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003084{
Alexander Duyck2c4af692011-07-15 07:29:55 +00003085 struct ixgbe_adapter *adapter = data;
3086 struct ixgbe_hw *hw = &adapter->hw;
3087 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003088
Alexander Duyck2c4af692011-07-15 07:29:55 +00003089 /*
3090 * Workaround for Silicon errata. Use clear-by-write instead
3091 * of clear-by-read. Reading with EICS will return the
3092 * interrupt causes without clearing, which later be done
3093 * with the write to EICR.
3094 */
3095 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00003096
3097 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08003098 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00003099 * the bits are high when ixgbe_msix_other is called. There is a race
3100 * condition otherwise which results in possible performance loss
3101 * especially if the ixgbe_msix_other interrupt is triggering
3102 * consistently (as it would when PPS is turned on for the X540 device)
3103 */
3104 eicr &= 0xFFFF0000;
3105
Alexander Duyck2c4af692011-07-15 07:29:55 +00003106 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003107
Alexander Duyck2c4af692011-07-15 07:29:55 +00003108 if (eicr & IXGBE_EICR_LSC)
3109 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003110
Alexander Duyck2c4af692011-07-15 07:29:55 +00003111 if (eicr & IXGBE_EICR_MAILBOX)
3112 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003113
Alexander Duyck2c4af692011-07-15 07:29:55 +00003114 switch (hw->mac.type) {
3115 case ixgbe_mac_82599EB:
3116 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003117 case ixgbe_mac_X550:
3118 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003119 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07003120 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
3121 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
3122 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
3123 ixgbe_service_event_schedule(adapter);
3124 IXGBE_WRITE_REG(hw, IXGBE_EICR,
3125 IXGBE_EICR_GPI_SDP0_X540);
3126 }
Don Skidmored773ce22014-02-25 17:58:53 -08003127 if (eicr & IXGBE_EICR_ECC) {
3128 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003129 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003130 ixgbe_service_event_schedule(adapter);
3131 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3132 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003133 /* Handle Flow Director Full threshold interrupt */
3134 if (eicr & IXGBE_EICR_FLOW_DIR) {
3135 int reinit_count = 0;
3136 int i;
3137 for (i = 0; i < adapter->num_tx_queues; i++) {
3138 struct ixgbe_ring *ring = adapter->tx_ring[i];
3139 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
3140 &ring->state))
3141 reinit_count++;
3142 }
3143 if (reinit_count) {
3144 /* no more flow director interrupts until after init */
3145 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
3146 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
3147 ixgbe_service_event_schedule(adapter);
3148 }
3149 }
3150 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003151 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003152 break;
3153 default:
3154 break;
Auke Kok9a799d72007-09-15 14:07:45 -07003155 }
3156
Alexander Duyck2c4af692011-07-15 07:29:55 +00003157 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003158
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003159 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003160 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003161
Alexander Duyck2c4af692011-07-15 07:29:55 +00003162 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00003163 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00003164 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003165
Alexander Duyck2c4af692011-07-15 07:29:55 +00003166 return IRQ_HANDLED;
3167}
3168
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003169static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07003170{
3171 struct ixgbe_q_vector *q_vector = data;
3172
Auke Kok9a799d72007-09-15 14:07:45 -07003173 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003174
3175 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07003176 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003177
3178 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003179}
3180
Auke Kok9a799d72007-09-15 14:07:45 -07003181/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00003182 * ixgbe_poll - NAPI Rx polling callback
3183 * @napi: structure for representing this polling device
3184 * @budget: how many packets driver is allowed to clean
3185 *
3186 * This function is used for legacy and MSI, NAPI mode
3187 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00003188int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00003189{
3190 struct ixgbe_q_vector *q_vector =
3191 container_of(napi, struct ixgbe_q_vector, napi);
3192 struct ixgbe_adapter *adapter = q_vector->adapter;
3193 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003194 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00003195 bool clean_complete = true;
3196
3197#ifdef CONFIG_IXGBE_DCA
3198 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
3199 ixgbe_update_dca(q_vector);
3200#endif
3201
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003202 ixgbe_for_each_ring(ring, q_vector->tx) {
3203 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
3204 clean_complete = false;
3205 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003206
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08003207 /* Exit if we are called by netpoll */
3208 if (budget <= 0)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003209 return budget;
3210
Alexander Duyckeb01b972012-02-08 07:51:27 +00003211 /* attempt to distribute budget to each queue fairly, but don't allow
3212 * the budget to go below 1 because we'll exit polling */
3213 if (q_vector->rx.count > 1)
3214 per_ring_budget = max(budget/q_vector->rx.count, 1);
3215 else
3216 per_ring_budget = budget;
3217
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003218 ixgbe_for_each_ring(ring, q_vector->rx) {
3219 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
3220 per_ring_budget);
3221
3222 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003223 if (cleaned >= per_ring_budget)
3224 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003225 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003226
3227 /* If all work not completed, return budget and keep polling */
3228 if (!clean_complete)
3229 return budget;
3230
3231 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003232 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003233 if (adapter->rx_itr_setting & 1)
3234 ixgbe_set_itr(q_vector);
3235 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003236 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00003237
Paolo Abeni4b732cd2016-06-15 15:37:59 +02003238 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003239}
3240
3241/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003242 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
3243 * @adapter: board private structure
3244 *
3245 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
3246 * interrupts from the kernel.
3247 **/
3248static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
3249{
3250 struct net_device *netdev = adapter->netdev;
Tony Nguyene61e4c82017-05-12 11:38:07 -07003251 unsigned int ri = 0, ti = 0;
Alexander Duyck207867f2011-07-15 03:05:37 +00003252 int vector, err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003253
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003254 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003255 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00003256 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08003257
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003258 if (q_vector->tx.ring && q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003259 snprintf(q_vector->name, sizeof(q_vector->name),
3260 "%s-TxRx-%u", netdev->name, ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003261 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003262 } else if (q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003263 snprintf(q_vector->name, sizeof(q_vector->name),
3264 "%s-rx-%u", netdev->name, ri++);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003265 } else if (q_vector->tx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003266 snprintf(q_vector->name, sizeof(q_vector->name),
3267 "%s-tx-%u", netdev->name, ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003268 } else {
3269 /* skip this unused q_vector */
3270 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003271 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003272 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
3273 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003274 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00003275 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00003276 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003277 goto free_queue_irqs;
3278 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003279 /* If Flow Director is enabled, set interrupt affinity */
3280 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3281 /* assign the mask for this irq */
3282 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00003283 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00003284 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003285 }
3286
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003287 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00003288 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003289 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00003290 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003291 goto free_queue_irqs;
3292 }
3293
3294 return 0;
3295
3296free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00003297 while (vector) {
3298 vector--;
3299 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3300 NULL);
3301 free_irq(adapter->msix_entries[vector].vector,
3302 adapter->q_vector[vector]);
3303 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003304 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3305 pci_disable_msix(adapter->pdev);
3306 kfree(adapter->msix_entries);
3307 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003308 return err;
3309}
3310
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08003311/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003312 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07003313 * @irq: interrupt number
3314 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07003315 **/
3316static irqreturn_t ixgbe_intr(int irq, void *data)
3317{
Alexander Duycka65151ba22011-05-27 05:31:32 +00003318 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07003319 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003320 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003321 u32 eicr;
3322
Don Skidmore54037502009-02-21 15:42:56 -08003323 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00003324 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08003325 * before the read of EICR.
3326 */
3327 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3328
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003329 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003330 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003331 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003332 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003333 /*
3334 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003335 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003336 * have disabled interrupts due to EIAM
3337 * finish the workaround of silicon errata on 82598. Unmask
3338 * the interrupt that we masked before the EICR read.
3339 */
3340 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3341 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003342 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003343 }
Auke Kok9a799d72007-09-15 14:07:45 -07003344
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003345 if (eicr & IXGBE_EICR_LSC)
3346 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003347
Alexander Duyckbd508172010-11-16 19:27:03 -08003348 switch (hw->mac.type) {
3349 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003350 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003351 /* Fall through */
3352 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003353 case ixgbe_mac_X550:
3354 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003355 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003356 if (eicr & IXGBE_EICR_ECC) {
3357 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003358 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003359 ixgbe_service_event_schedule(adapter);
3360 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3361 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003362 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003363 break;
3364 default:
3365 break;
3366 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003367
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003368 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003369 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003370 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003371
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003372 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003373 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003374
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003375 /*
3376 * re-enable link(maybe) and non-queue interrupts, no flush.
3377 * ixgbe_poll will re-enable the queue interrupts
3378 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003379 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3380 ixgbe_irq_enable(adapter, false, false);
3381
Auke Kok9a799d72007-09-15 14:07:45 -07003382 return IRQ_HANDLED;
3383}
3384
3385/**
3386 * ixgbe_request_irq - initialize interrupts
3387 * @adapter: board private structure
3388 *
3389 * Attempts to configure interrupts using the best available
3390 * capabilities of the hardware and kernel.
3391 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003392static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003393{
3394 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003395 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003396
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003397 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003398 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003399 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003400 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003401 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003402 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003403 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003404 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003405
Alexander Duyckde88eee2012-02-08 07:49:59 +00003406 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003407 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003408
Auke Kok9a799d72007-09-15 14:07:45 -07003409 return err;
3410}
3411
3412static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3413{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003414 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003415
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003416 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003417 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003418 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003419 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003420
Mark Rustad1fa71252016-09-28 15:36:38 -07003421 if (!adapter->msix_entries)
3422 return;
3423
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003424 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3425 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3426 struct msix_entry *entry = &adapter->msix_entries[vector];
3427
3428 /* free only the irqs that were actually requested */
3429 if (!q_vector->rx.ring && !q_vector->tx.ring)
3430 continue;
3431
3432 /* clear the affinity_mask in the IRQ descriptor */
3433 irq_set_affinity_hint(entry->vector, NULL);
3434
3435 free_irq(entry->vector, q_vector);
3436 }
3437
Babu Moger90c6f872016-06-18 17:40:47 -07003438 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003439}
3440
3441/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003442 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3443 * @adapter: board private structure
3444 **/
3445static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3446{
Alexander Duyckbd508172010-11-16 19:27:03 -08003447 switch (adapter->hw.mac.type) {
3448 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003449 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003450 break;
3451 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003452 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003453 case ixgbe_mac_X550:
3454 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003455 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003456 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3457 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003458 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003459 break;
3460 default:
3461 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003462 }
3463 IXGBE_WRITE_FLUSH(&adapter->hw);
3464 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003465 int vector;
3466
3467 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3468 synchronize_irq(adapter->msix_entries[vector].vector);
3469
3470 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003471 } else {
3472 synchronize_irq(adapter->pdev->irq);
3473 }
3474}
3475
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003476/**
Auke Kok9a799d72007-09-15 14:07:45 -07003477 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3478 *
3479 **/
3480static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3481{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003482 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003483
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003484 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003485
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003486 ixgbe_set_ivar(adapter, 0, 0, 0);
3487 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003488
Emil Tantilov396e7992010-07-01 20:05:12 +00003489 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003490}
3491
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003492/**
3493 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3494 * @adapter: board private structure
3495 * @ring: structure containing ring specific data
3496 *
3497 * Configure the Tx descriptor ring after a reset.
3498 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003499void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3500 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003501{
3502 struct ixgbe_hw *hw = &adapter->hw;
3503 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003504 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003505 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003506 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003507
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003508 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003509 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003510 IXGBE_WRITE_FLUSH(hw);
3511
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003512 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003513 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003514 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3515 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3516 ring->count * sizeof(union ixgbe_adv_tx_desc));
3517 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3518 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003519 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003520
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003521 /*
3522 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003523 * higher than 1 when:
3524 * - ITR is 0 as it could cause false TX hangs
3525 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003526 *
3527 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3528 * to or less than the number of on chip descriptors, which is
3529 * currently 40.
3530 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003531 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003532 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003533 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003534 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003535
Alexander Duycke954b372012-02-08 07:49:38 +00003536 /*
3537 * Setting PTHRESH to 32 both improves performance
3538 * and avoids a TX hang with DFP enabled
3539 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003540 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003541 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003542
3543 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003544 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003545 ring->atr_sample_rate = adapter->atr_sample_rate;
3546 ring->atr_count = 0;
3547 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3548 } else {
3549 ring->atr_sample_rate = 0;
3550 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003551
Alexander Duyckfd786b72013-01-12 06:33:31 +00003552 /* initialize XPS */
3553 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3554 struct ixgbe_q_vector *q_vector = ring->q_vector;
3555
3556 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003557 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003558 &q_vector->affinity_mask,
3559 ring->queue_index);
3560 }
3561
John Fastabendc84d3242010-11-16 19:27:12 -08003562 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3563
Alexander Duyckffed21b2017-01-17 08:37:29 -08003564 /* reinitialize tx_buffer_info */
3565 memset(ring->tx_buffer_info, 0,
3566 sizeof(struct ixgbe_tx_buffer) * ring->count);
3567
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003568 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003569 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3570
3571 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3572 if (hw->mac.type == ixgbe_mac_82598EB &&
3573 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3574 return;
3575
3576 /* poll to verify queue is enabled */
3577 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003578 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003579 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3580 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3581 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003582 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003583}
3584
Alexander Duyck120ff942010-08-19 13:34:50 +00003585static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3586{
3587 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003588 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003589 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003590
3591 if (hw->mac.type == ixgbe_mac_82598EB)
3592 return;
3593
3594 /* disable the arbiter while setting MTQC */
3595 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3596 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3597 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3598
3599 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003600 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3601 mtqc = IXGBE_MTQC_VT_ENA;
3602 if (tcs > 4)
3603 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3604 else if (tcs > 1)
3605 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003606 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3607 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003608 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003609 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003610 mtqc |= IXGBE_MTQC_64VF;
3611 } else {
3612 if (tcs > 4)
3613 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3614 else if (tcs > 1)
3615 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3616 else
3617 mtqc = IXGBE_MTQC_64Q_1PB;
3618 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003619
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003620 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003621
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003622 /* Enable Security TX Buffer IFG for multiple pb */
3623 if (tcs) {
3624 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3625 sectx |= IXGBE_SECTX_DCB;
3626 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003627 }
3628
3629 /* re-enable the arbiter */
3630 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3631 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3632}
3633
Auke Kok9a799d72007-09-15 14:07:45 -07003634/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003635 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003636 * @adapter: board private structure
3637 *
3638 * Configure the Tx unit of the MAC after a reset.
3639 **/
3640static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3641{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003642 struct ixgbe_hw *hw = &adapter->hw;
3643 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003644 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003645
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003646 ixgbe_setup_mtqc(adapter);
3647
3648 if (hw->mac.type != ixgbe_mac_82598EB) {
3649 /* DMATXCTL.EN must be before Tx queues are enabled */
3650 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3651 dmatxctl |= IXGBE_DMATXCTL_TE;
3652 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3653 }
3654
Auke Kok9a799d72007-09-15 14:07:45 -07003655 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003656 for (i = 0; i < adapter->num_tx_queues; i++)
3657 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07003658 for (i = 0; i < adapter->num_xdp_queues; i++)
3659 ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003660}
3661
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003662static void ixgbe_enable_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
3674static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3675 struct ixgbe_ring *ring)
3676{
3677 struct ixgbe_hw *hw = &adapter->hw;
3678 u8 reg_idx = ring->reg_idx;
3679 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3680
3681 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3682
3683 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3684}
3685
3686#ifdef CONFIG_IXGBE_DCB
3687void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3688#else
3689static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3690#endif
3691{
3692 int i;
3693 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3694
3695 if (adapter->ixgbe_ieee_pfc)
3696 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3697
3698 /*
3699 * We should set the drop enable bit if:
3700 * SR-IOV is enabled
3701 * or
3702 * Number of Rx queues > 1 and flow control is disabled
3703 *
3704 * This allows us to avoid head of line blocking for security
3705 * and performance reasons.
3706 */
3707 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3708 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3709 for (i = 0; i < adapter->num_rx_queues; i++)
3710 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3711 } else {
3712 for (i = 0; i < adapter->num_rx_queues; i++)
3713 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3714 }
3715}
3716
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003717#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003718
Yi Zoua6616b42009-08-06 13:05:23 +00003719static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003720 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003721{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003722 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003723 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003724 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003725
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003726 if (hw->mac.type == ixgbe_mac_82598EB) {
3727 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3728
3729 /*
3730 * if VMDq is not active we must program one srrctl register
3731 * per RSS queue since we have enabled RDRXCTL.MVMEN
3732 */
3733 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003734 }
3735
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003736 /* configure header buffer length, needed for RSC */
3737 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003738
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003739 /* configure the packet buffer length */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003740 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3741 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3742 else
3743 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003744
3745 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003746 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003747
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003748 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003749}
3750
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003751/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003752 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003753 * @adapter: device handle
3754 *
3755 * - 82598/82599/X540: 128
3756 * - X550(non-SRIOV mode): 512
3757 * - X550(SRIOV mode): 64
3758 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003759u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003760{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003761 if (adapter->hw.mac.type < ixgbe_mac_X550)
3762 return 128;
3763 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3764 return 64;
3765 else
3766 return 512;
3767}
3768
3769/**
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003770 * ixgbe_store_key - Write the RSS key to HW
3771 * @adapter: device handle
3772 *
3773 * Write the RSS key stored in adapter.rss_key to HW.
3774 */
3775void ixgbe_store_key(struct ixgbe_adapter *adapter)
3776{
3777 struct ixgbe_hw *hw = &adapter->hw;
3778 int i;
3779
3780 for (i = 0; i < 10; i++)
3781 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3782}
3783
3784/**
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07003785 * ixgbe_init_rss_key - Initialize adapter RSS key
3786 * @adapter: device handle
3787 *
3788 * Allocates and initializes the RSS key if it is not allocated.
3789 **/
3790static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
3791{
3792 u32 *rss_key;
3793
3794 if (!adapter->rss_key) {
3795 rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
3796 if (unlikely(!rss_key))
3797 return -ENOMEM;
3798
3799 netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
3800 adapter->rss_key = rss_key;
3801 }
3802
3803 return 0;
3804}
3805
3806/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003807 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003808 * @adapter: device handle
3809 *
3810 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3811 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003812void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003813{
3814 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003815 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003816 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003817 u32 indices_multi;
3818 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003819
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003820 /* Fill out the redirection table as follows:
3821 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3822 * indices.
3823 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3824 * - X550: 8 bit wide entries containing 6 bit RSS index
3825 */
3826 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3827 indices_multi = 0x11;
3828 else
3829 indices_multi = 0x1;
3830
3831 /* Write redirection table to HW */
3832 for (i = 0; i < reta_entries; i++) {
3833 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3834 if ((i & 3) == 3) {
3835 if (i < 128)
3836 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3837 else
3838 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3839 reta);
3840 reta = 0;
3841 }
3842 }
3843}
3844
3845/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003846 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003847 * @adapter: device handle
3848 *
3849 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3850 */
3851static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3852{
3853 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3854 struct ixgbe_hw *hw = &adapter->hw;
3855 u32 vfreta = 0;
3856 unsigned int pf_pool = adapter->num_vfs;
3857
3858 /* Write redirection table to HW */
3859 for (i = 0; i < reta_entries; i++) {
3860 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3861 if ((i & 3) == 3) {
3862 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3863 vfreta);
3864 vfreta = 0;
3865 }
3866 }
3867}
3868
3869static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3870{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003871 u32 i, j;
3872 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3873 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3874
Alexander Duycke24fcf22016-09-07 20:28:24 -07003875 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003876 * make full use of any rings they may have. We will use the
3877 * PSRTYPE register to control how many rings we use within the PF.
3878 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003879 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3880 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003881
Alexander Duyck05abb122010-08-19 13:35:41 +00003882 /* Fill out hash function seeds */
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003883 ixgbe_store_key(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003884
Alexander Duyck05abb122010-08-19 13:35:41 +00003885 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003886 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3887
Don Skidmore0f9b2322014-11-18 09:35:08 +00003888 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003889 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003890 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003891
3892 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003893 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003894
3895 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003896}
3897
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003898static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003899{
3900 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003901 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3902 unsigned int pf_pool = adapter->num_vfs;
3903 int i, j;
3904
3905 /* Fill out hash function seeds */
3906 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003907 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07003908 *(adapter->rss_key + i));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003909
3910 /* Fill out the redirection table */
3911 for (i = 0, j = 0; i < 64; i++, j++) {
3912 if (j == rss_i)
3913 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003914
3915 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003916 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003917
3918 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003919}
3920
3921static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3922{
3923 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003924 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003925 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003926
3927 /* Disable indicating checksum in descriptor, enables RSS hash */
3928 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3929 rxcsum |= IXGBE_RXCSUM_PCSD;
3930 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3931
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003932 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003933 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003934 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003935 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003936 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003937
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003938 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3939 if (tcs > 4)
3940 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3941 else if (tcs > 1)
3942 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003943 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3944 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003945 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3946 else
3947 mrqc = IXGBE_MRQC_VMDQRSS64EN;
Emil Tantilove6b41c82017-04-25 11:31:06 -07003948
3949 /* Enable L3/L4 for Tx Switched packets */
3950 mrqc |= IXGBE_MRQC_L3L4TXSWEN;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003951 } else {
3952 if (tcs > 4)
3953 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3954 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003955 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3956 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003957 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003958 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003959 }
3960
Alexander Duyck05abb122010-08-19 13:35:41 +00003961 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003962 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3963 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3964 IXGBE_MRQC_RSS_FIELD_IPV6 |
3965 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003966
Alexander Duyckef6afc02012-02-08 07:51:53 +00003967 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003968 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003969 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003970 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003971
Don Skidmore0f9b2322014-11-18 09:35:08 +00003972 if ((hw->mac.type >= ixgbe_mac_X550) &&
3973 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3974 unsigned int pf_pool = adapter->num_vfs;
3975
3976 /* Enable VF RSS mode */
3977 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3978 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3979
3980 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003981 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003982 vfmrqc = IXGBE_MRQC_RSSEN;
3983 vfmrqc |= rss_field;
3984 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3985 } 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;
John Fastabend2a47fa42013-11-06 09:54:52 -08004147 u16 pool;
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
John Fastabend2a47fa42013-11-06 09:54:52 -08004164 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
4165 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
4491 if (ring->l2_accel_priv)
4492 continue;
4493 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004494 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4495 vlnctrl &= ~IXGBE_RXDCTL_VME;
4496 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4497 }
4498 break;
4499 default:
4500 break;
4501 }
4502}
4503
4504/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004505 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004506 * @adapter: driver data
4507 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004508static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004509{
4510 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004511 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004512 int i, j;
4513
4514 switch (hw->mac.type) {
4515 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004516 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4517 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004518 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4519 break;
4520 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004521 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004522 case ixgbe_mac_X550:
4523 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004524 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004525 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004526 struct ixgbe_ring *ring = adapter->rx_ring[i];
4527
4528 if (ring->l2_accel_priv)
4529 continue;
4530 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004531 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4532 vlnctrl |= IXGBE_RXDCTL_VME;
4533 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4534 }
4535 break;
4536 default:
4537 break;
4538 }
4539}
4540
Alexander Duyck16369562015-11-02 17:10:13 -08004541static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4542{
4543 struct ixgbe_hw *hw = &adapter->hw;
4544 u32 vlnctrl, i;
4545
Alexander Duyckf60439b2016-08-11 14:51:56 -07004546 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4547
Emil Tantilov691e4122016-08-22 16:17:46 -07004548 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4549 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4550 vlnctrl |= IXGBE_VLNCTRL_VFE;
4551 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4552 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004553 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004554 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4555 return;
4556 }
4557
Emil Tantilov691e4122016-08-22 16:17:46 -07004558 /* Nothing to do for 82598 */
4559 if (hw->mac.type == ixgbe_mac_82598EB)
4560 return;
4561
Alexander Duyck16369562015-11-02 17:10:13 -08004562 /* We are already in VLAN promisc, nothing to do */
4563 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4564 return;
4565
4566 /* Set flag so we don't redo unnecessary work */
4567 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4568
4569 /* Add PF to all active pools */
4570 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4571 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4572 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4573
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004574 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004575 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4576 }
4577
4578 /* Set all bits in the VLAN filter table array */
4579 for (i = hw->mac.vft_size; i--;)
4580 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4581}
4582
4583#define VFTA_BLOCK_SIZE 8
4584static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4585{
4586 struct ixgbe_hw *hw = &adapter->hw;
4587 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4588 u32 vid_start = vfta_offset * 32;
4589 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4590 u32 i, vid, word, bits;
4591
4592 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4593 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4594
4595 /* pull VLAN ID from VLVF */
4596 vid = vlvf & VLAN_VID_MASK;
4597
4598 /* only concern outselves with a certain range */
4599 if (vid < vid_start || vid >= vid_end)
4600 continue;
4601
4602 if (vlvf) {
4603 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004604 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004605
4606 /* if PF is part of this then continue */
4607 if (test_bit(vid, adapter->active_vlans))
4608 continue;
4609 }
4610
4611 /* remove PF from the pool */
4612 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004613 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004614 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4615 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4616 }
4617
4618 /* extract values from active_vlans and write back to VFTA */
4619 for (i = VFTA_BLOCK_SIZE; i--;) {
4620 vid = (vfta_offset + i) * 32;
4621 word = vid / BITS_PER_LONG;
4622 bits = vid % BITS_PER_LONG;
4623
4624 vfta[i] |= adapter->active_vlans[word] >> bits;
4625
4626 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4627 }
4628}
4629
4630static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4631{
4632 struct ixgbe_hw *hw = &adapter->hw;
4633 u32 vlnctrl, i;
4634
Alexander Duyckf60439b2016-08-11 14:51:56 -07004635 /* Set VLAN filtering to enabled */
4636 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4637 vlnctrl |= IXGBE_VLNCTRL_VFE;
4638 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4639
Emil Tantilov691e4122016-08-22 16:17:46 -07004640 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4641 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004642 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004643
4644 /* We are not in VLAN promisc, nothing to do */
4645 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4646 return;
4647
4648 /* Set flag so we don't redo unnecessary work */
4649 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4650
4651 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4652 ixgbe_scrub_vfta(adapter, i);
4653}
4654
Auke Kok9a799d72007-09-15 14:07:45 -07004655static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4656{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004657 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004658
Patrick McHardy80d5c362013-04-19 02:04:28 +00004659 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004660
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004661 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004662 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004663}
4664
4665/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004666 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4667 * @netdev: network interface device structure
4668 *
4669 * Writes multicast address list to the MTA hash table.
4670 * Returns: -ENOMEM on failure
4671 * 0 on no addresses written
4672 * X on writing X addresses to MTA
4673 **/
4674static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4675{
4676 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4677 struct ixgbe_hw *hw = &adapter->hw;
4678
4679 if (!netif_running(netdev))
4680 return 0;
4681
4682 if (hw->mac.ops.update_mc_addr_list)
4683 hw->mac.ops.update_mc_addr_list(hw, netdev);
4684 else
4685 return -ENOMEM;
4686
4687#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004688 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004689#endif
4690
4691 return netdev_mc_count(netdev);
4692}
4693
Jacob Keller5d7daa32014-03-29 06:51:25 +00004694#ifdef CONFIG_PCI_IOV
4695void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4696{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004697 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004698 struct ixgbe_hw *hw = &adapter->hw;
4699 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004700
4701 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4702 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4703
4704 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4705 hw->mac.ops.set_rar(hw, i,
4706 mac_table->addr,
4707 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004708 IXGBE_RAH_AV);
4709 else
4710 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004711 }
4712}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004713
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004714#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004715static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4716{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004717 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004718 struct ixgbe_hw *hw = &adapter->hw;
4719 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004720
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004721 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4722 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4723 continue;
4724
4725 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4726
4727 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4728 hw->mac.ops.set_rar(hw, i,
4729 mac_table->addr,
4730 mac_table->pool,
4731 IXGBE_RAH_AV);
4732 else
4733 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004734 }
4735}
4736
4737static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4738{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004739 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004740 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004741 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004742
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004743 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4744 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4745 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004746 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004747
Jacob Keller5d7daa32014-03-29 06:51:25 +00004748 ixgbe_sync_mac_table(adapter);
4749}
4750
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004751static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004752{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004753 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004754 struct ixgbe_hw *hw = &adapter->hw;
4755 int i, count = 0;
4756
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004757 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4758 /* do not count default RAR as available */
4759 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4760 continue;
4761
4762 /* only count unused and addresses that belong to us */
4763 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4764 if (mac_table->pool != pool)
4765 continue;
4766 }
4767
4768 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004769 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004770
Jacob Keller5d7daa32014-03-29 06:51:25 +00004771 return count;
4772}
4773
4774/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004775static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004776{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004777 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004778 struct ixgbe_hw *hw = &adapter->hw;
4779
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004780 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4781 mac_table->pool = VMDQ_P(0);
4782
4783 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4784
4785 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004786 IXGBE_RAH_AV);
4787}
4788
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004789int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4790 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004791{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004792 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004793 struct ixgbe_hw *hw = &adapter->hw;
4794 int i;
4795
4796 if (is_zero_ether_addr(addr))
4797 return -EINVAL;
4798
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004799 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4800 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004801 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004802
4803 ether_addr_copy(mac_table->addr, addr);
4804 mac_table->pool = pool;
4805
4806 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4807 IXGBE_MAC_STATE_IN_USE;
4808
Jacob Keller5d7daa32014-03-29 06:51:25 +00004809 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004810
Jacob Keller5d7daa32014-03-29 06:51:25 +00004811 return i;
4812 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004813
Jacob Keller5d7daa32014-03-29 06:51:25 +00004814 return -ENOMEM;
4815}
4816
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004817int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4818 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004819{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004820 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004821 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004822 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004823
4824 if (is_zero_ether_addr(addr))
4825 return -EINVAL;
4826
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004827 /* search table for addr, if found clear IN_USE flag and sync */
4828 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4829 /* we can only delete an entry if it is in use */
4830 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4831 continue;
4832 /* we only care about entries that belong to the given pool */
4833 if (mac_table->pool != pool)
4834 continue;
4835 /* we only care about a specific MAC address */
4836 if (!ether_addr_equal(addr, mac_table->addr))
4837 continue;
4838
4839 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4840 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4841
4842 ixgbe_sync_mac_table(adapter);
4843
4844 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004845 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004846
Jacob Keller5d7daa32014-03-29 06:51:25 +00004847 return -ENOMEM;
4848}
Jacob Kellerb335e752014-03-25 07:45:27 +00004849/**
Alexander Duyck28500622010-06-15 09:25:48 +00004850 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4851 * @netdev: network interface device structure
4852 *
4853 * Writes unicast address list to the RAR table.
4854 * Returns: -ENOMEM on failure/insufficient address space
4855 * 0 on no addresses written
4856 * X on writing X addresses to the RAR table
4857 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004858static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004859{
4860 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004861 int count = 0;
4862
4863 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004864 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004865 return -ENOMEM;
4866
John Fastabend95447462012-05-31 12:42:26 +00004867 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004868 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004869 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004870 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4871 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004872 count++;
4873 }
4874 }
Alexander Duyck28500622010-06-15 09:25:48 +00004875 return count;
4876}
4877
Alexander Duyck0f079d22015-10-22 16:26:36 -07004878static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4879{
4880 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4881 int ret;
4882
4883 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4884
4885 return min_t(int, ret, 0);
4886}
4887
4888static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4889{
4890 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4891
4892 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4893
4894 return 0;
4895}
4896
Alexander Duyck28500622010-06-15 09:25:48 +00004897/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004898 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004899 * @netdev: network interface device structure
4900 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004901 * The set_rx_method entry point is called whenever the unicast/multicast
4902 * address list or the network interface flags are updated. This routine is
4903 * responsible for configuring the hardware for proper unicast, multicast and
4904 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004905 **/
Greg Rose7f870472010-01-09 02:25:29 +00004906void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004907{
4908 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4909 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004910 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004911 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004912 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004913
4914 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004915 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4916
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004917 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004918 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004919 fctrl |= IXGBE_FCTRL_BAM;
4920 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4921 fctrl |= IXGBE_FCTRL_PMCF;
4922
Alexander Duyck28500622010-06-15 09:25:48 +00004923 /* clear the bits we are changing the status of */
4924 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004925 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004926 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004927 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004928 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004929 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004930 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004931 if (netdev->flags & IFF_ALLMULTI) {
4932 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004933 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004934 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004935 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004936 }
4937
4938 /*
4939 * Write addresses to available RAR registers, if there is not
4940 * sufficient space to store all the addresses then enable
4941 * unicast promiscuous mode
4942 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004943 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004944 fctrl |= IXGBE_FCTRL_UPE;
4945 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004946 }
4947
Emil Tantilovcf789592013-10-26 08:13:20 +00004948 /* Write addresses to the MTA, if the attempt fails
4949 * then we should just turn on promiscuous mode so
4950 * that we can at least receive multicast traffic
4951 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004952 count = ixgbe_write_mc_addr_list(netdev);
4953 if (count < 0) {
4954 fctrl |= IXGBE_FCTRL_MPE;
4955 vmolr |= IXGBE_VMOLR_MPE;
4956 } else if (count) {
4957 vmolr |= IXGBE_VMOLR_ROMPE;
4958 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004959
4960 if (hw->mac.type != ixgbe_mac_82598EB) {
4961 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004962 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4963 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004964 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004965 }
4966
Ben Greear3f2d1c02012-03-08 08:28:41 +00004967 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004968 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004969 /* UPE and MPE will be handled by normal PROMISC logic
4970 * in e1000e_set_rx_mode */
4971 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4972 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4973 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4974
4975 fctrl &= ~(IXGBE_FCTRL_DPF);
4976 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4977 }
4978
Auke Kok9a799d72007-09-15 14:07:45 -07004979 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004980
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004981 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004982 ixgbe_vlan_strip_enable(adapter);
4983 else
4984 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004985
4986 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4987 ixgbe_vlan_promisc_disable(adapter);
4988 else
4989 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004990}
4991
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004992static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4993{
4994 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004995
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004996 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004997 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004998}
4999
5000static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
5001{
5002 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005003
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08005004 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005005 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005006}
5007
Emil Tantilova21d0822016-08-10 11:19:23 -07005008static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07005009{
Emil Tantilova21d0822016-08-10 11:19:23 -07005010 struct ixgbe_hw *hw = &adapter->hw;
5011 u32 vxlanctrl;
5012
5013 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
5014 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
5015 return;
5016
Sabrina Dubrocaa39221c2017-07-03 13:02:55 +02005017 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask;
Emil Tantilova21d0822016-08-10 11:19:23 -07005018 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
5019
5020 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07005021 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07005022
5023 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
5024 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07005025}
5026
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005027#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005028/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08005029 * ixgbe_configure_dcb - Configure DCB hardware
5030 * @adapter: ixgbe adapter struct
5031 *
5032 * This is called by the driver on open to configure the DCB hardware.
5033 * This is also called by the gennetlink interface when reconfiguring
5034 * the DCB state.
5035 */
5036static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
5037{
5038 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00005039 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005040
Alexander Duyck67ebd792010-08-19 13:34:04 +00005041 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
5042 if (hw->mac.type == ixgbe_mac_82598EB)
5043 netif_set_gso_max_size(adapter->netdev, 65536);
5044 return;
5045 }
5046
5047 if (hw->mac.type == ixgbe_mac_82598EB)
5048 netif_set_gso_max_size(adapter->netdev, 32768);
5049
John Fastabendb1208182011-10-15 05:00:10 +00005050#ifdef IXGBE_FCOE
5051 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
5052 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
5053#endif
5054
Alexander Duyck01fa7d92010-11-16 19:26:53 -08005055 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00005056 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00005057 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5058 DCB_TX_CONFIG);
5059 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5060 DCB_RX_CONFIG);
5061 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00005062 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
5063 ixgbe_dcb_hw_ets(&adapter->hw,
5064 adapter->ixgbe_ieee_ets,
5065 max_frame);
5066 ixgbe_dcb_hw_pfc_config(&adapter->hw,
5067 adapter->ixgbe_ieee_pfc->pfc_en,
5068 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00005069 }
John Fastabend8187cd42011-02-23 05:58:08 +00005070
5071 /* Enable RSS Hash per TC */
5072 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00005073 u32 msb = 0;
5074 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005075
Alexander Duyckd411a932012-06-30 00:14:01 +00005076 while (rss_i) {
5077 msb++;
5078 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005079 }
Alexander Duyckd411a932012-06-30 00:14:01 +00005080
Alexander Duyck4ae63732012-06-22 06:46:33 +00005081 /* write msb to all 8 TCs in one write */
5082 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00005083 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005084}
John Fastabend9da712d2011-08-23 03:14:22 +00005085#endif
5086
5087/* Additional bittime to account for IXGBE framing */
5088#define IXGBE_ETH_FRAMING 20
5089
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005090/**
John Fastabend9da712d2011-08-23 03:14:22 +00005091 * ixgbe_hpbthresh - calculate high water mark for flow control
5092 *
5093 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005094 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005095 */
5096static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
5097{
5098 struct ixgbe_hw *hw = &adapter->hw;
5099 struct net_device *dev = adapter->netdev;
5100 int link, tc, kb, marker;
5101 u32 dv_id, rx_pba;
5102
5103 /* Calculate max LAN frame size */
5104 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
5105
5106#ifdef IXGBE_FCOE
5107 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00005108 if ((dev->features & NETIF_F_FCOE_MTU) &&
5109 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5110 (pb == ixgbe_fcoe_get_tc(adapter)))
5111 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005112#endif
Jacob Kellere5776622014-04-05 02:35:52 +00005113
John Fastabend9da712d2011-08-23 03:14:22 +00005114 /* Calculate delay value for device */
5115 switch (hw->mac.type) {
5116 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005117 case ixgbe_mac_X550:
5118 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005119 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005120 dv_id = IXGBE_DV_X540(link, tc);
5121 break;
5122 default:
5123 dv_id = IXGBE_DV(link, tc);
5124 break;
5125 }
5126
5127 /* Loopback switch introduces additional latency */
5128 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5129 dv_id += IXGBE_B2BT(tc);
5130
5131 /* Delay value is calculated in bit times convert to KB */
5132 kb = IXGBE_BT2KB(dv_id);
5133 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
5134
5135 marker = rx_pba - kb;
5136
5137 /* It is possible that the packet buffer is not large enough
5138 * to provide required headroom. In this case throw an error
5139 * to user and a do the best we can.
5140 */
5141 if (marker < 0) {
5142 e_warn(drv, "Packet Buffer(%i) can not provide enough"
5143 "headroom to support flow control."
5144 "Decrease MTU or number of traffic classes\n", pb);
5145 marker = tc + 1;
5146 }
5147
5148 return marker;
5149}
5150
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005151/**
John Fastabend9da712d2011-08-23 03:14:22 +00005152 * ixgbe_lpbthresh - calculate low water mark for for flow control
5153 *
5154 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005155 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005156 */
Jacob Kellere5776622014-04-05 02:35:52 +00005157static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00005158{
5159 struct ixgbe_hw *hw = &adapter->hw;
5160 struct net_device *dev = adapter->netdev;
5161 int tc;
5162 u32 dv_id;
5163
5164 /* Calculate max LAN frame size */
5165 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
5166
Jacob Kellere5776622014-04-05 02:35:52 +00005167#ifdef IXGBE_FCOE
5168 /* FCoE traffic class uses FCOE jumbo frames */
5169 if ((dev->features & NETIF_F_FCOE_MTU) &&
5170 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5171 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
5172 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
5173#endif
5174
John Fastabend9da712d2011-08-23 03:14:22 +00005175 /* Calculate delay value for device */
5176 switch (hw->mac.type) {
5177 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005178 case ixgbe_mac_X550:
5179 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005180 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005181 dv_id = IXGBE_LOW_DV_X540(tc);
5182 break;
5183 default:
5184 dv_id = IXGBE_LOW_DV(tc);
5185 break;
5186 }
5187
5188 /* Delay value is calculated in bit times convert to KB */
5189 return IXGBE_BT2KB(dv_id);
5190}
5191
5192/*
5193 * ixgbe_pbthresh_setup - calculate and setup high low water marks
5194 */
5195static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
5196{
5197 struct ixgbe_hw *hw = &adapter->hw;
5198 int num_tc = netdev_get_num_tc(adapter->netdev);
5199 int i;
5200
5201 if (!num_tc)
5202 num_tc = 1;
5203
John Fastabend9da712d2011-08-23 03:14:22 +00005204 for (i = 0; i < num_tc; i++) {
5205 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00005206 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00005207
5208 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00005209 if (hw->fc.low_water[i] > hw->fc.high_water[i])
5210 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005211 }
Jacob Kellere5776622014-04-05 02:35:52 +00005212
5213 for (; i < MAX_TRAFFIC_CLASS; i++)
5214 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005215}
John Fastabend80605c652011-05-02 12:34:10 +00005216
5217static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
5218{
John Fastabend80605c652011-05-02 12:34:10 +00005219 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00005220 int hdrm;
5221 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00005222
5223 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5224 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00005225 hdrm = 32 << adapter->fdir_pballoc;
5226 else
5227 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00005228
Alexander Duyckf7e10272011-07-21 00:40:35 +00005229 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00005230 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00005231}
5232
Alexander Duycke4911d52011-05-11 07:18:52 +00005233static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
5234{
5235 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08005236 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005237 struct ixgbe_fdir_filter *filter;
5238
5239 spin_lock(&adapter->fdir_perfect_lock);
5240
5241 if (!hlist_empty(&adapter->fdir_filter_list))
5242 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
5243
Sasha Levinb67bfe02013-02-27 17:06:00 -08005244 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005245 &adapter->fdir_filter_list, fdir_node) {
5246 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00005247 &filter->filter,
5248 filter->sw_idx,
5249 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
5250 IXGBE_FDIR_DROP_QUEUE :
5251 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00005252 }
5253
5254 spin_unlock(&adapter->fdir_perfect_lock);
5255}
5256
John Fastabend2a47fa42013-11-06 09:54:52 -08005257static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
5258 struct ixgbe_adapter *adapter)
5259{
5260 struct ixgbe_hw *hw = &adapter->hw;
5261 u32 vmolr;
5262
5263 /* No unicast promiscuous support for VMDQ devices. */
5264 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
5265 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
5266
5267 /* clear the affected bit */
5268 vmolr &= ~IXGBE_VMOLR_MPE;
5269
5270 if (dev->flags & IFF_ALLMULTI) {
5271 vmolr |= IXGBE_VMOLR_MPE;
5272 } else {
5273 vmolr |= IXGBE_VMOLR_ROMPE;
5274 hw->mac.ops.update_mc_addr_list(hw, dev);
5275 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00005276 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08005277 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
5278}
5279
John Fastabend2a47fa42013-11-06 09:54:52 -08005280static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
5281{
5282 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08005283 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08005284 struct ixgbe_hw *hw = &adapter->hw;
5285 u16 pool = vadapter->pool;
5286 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
5287 IXGBE_PSRTYPE_UDPHDR |
5288 IXGBE_PSRTYPE_IPV4HDR |
5289 IXGBE_PSRTYPE_L2HDR |
5290 IXGBE_PSRTYPE_IPV6HDR;
5291
5292 if (hw->mac.type == ixgbe_mac_82598EB)
5293 return;
5294
5295 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005296 psrtype |= 2u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08005297 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005298 psrtype |= 1u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08005299
5300 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
5301}
5302
5303/**
5304 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
5305 * @rx_ring: ring to free buffers from
5306 **/
5307static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
5308{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005309 u16 i = rx_ring->next_to_clean;
5310 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08005311
5312 /* Free all the Rx ring sk_buffs */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005313 while (i != rx_ring->next_to_alloc) {
John Fastabend2a47fa42013-11-06 09:54:52 -08005314 if (rx_buffer->skb) {
5315 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00005316 if (IXGBE_CB(skb)->page_released)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005317 dma_unmap_page_attrs(rx_ring->dev,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005318 IXGBE_CB(skb)->dma,
5319 ixgbe_rx_pg_size(rx_ring),
5320 DMA_FROM_DEVICE,
5321 IXGBE_RX_DMA_ATTR);
John Fastabend2a47fa42013-11-06 09:54:52 -08005322 dev_kfree_skb(skb);
5323 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00005324
Alexander Duyckf3213d92017-01-17 08:35:54 -08005325 /* Invalidate cache lines that may have been written to by
5326 * device so that we avoid corrupting memory.
5327 */
5328 dma_sync_single_range_for_cpu(rx_ring->dev,
5329 rx_buffer->dma,
5330 rx_buffer->page_offset,
5331 ixgbe_rx_bufsz(rx_ring),
5332 DMA_FROM_DEVICE);
5333
5334 /* free resources associated with mapping */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005335 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005336 ixgbe_rx_pg_size(rx_ring),
5337 DMA_FROM_DEVICE,
5338 IXGBE_RX_DMA_ATTR);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08005339 __page_frag_cache_drain(rx_buffer->page,
5340 rx_buffer->pagecnt_bias);
Alexander Duyck18cb6522014-11-14 00:56:29 +00005341
Alexander Duyckffed21b2017-01-17 08:37:29 -08005342 i++;
5343 rx_buffer++;
5344 if (i == rx_ring->count) {
5345 i = 0;
5346 rx_buffer = rx_ring->rx_buffer_info;
5347 }
John Fastabend2a47fa42013-11-06 09:54:52 -08005348 }
5349
John Fastabend2a47fa42013-11-06 09:54:52 -08005350 rx_ring->next_to_alloc = 0;
5351 rx_ring->next_to_clean = 0;
5352 rx_ring->next_to_use = 0;
5353}
5354
5355static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
5356 struct ixgbe_ring *rx_ring)
5357{
5358 struct ixgbe_adapter *adapter = vadapter->real_adapter;
5359 int index = rx_ring->queue_index + vadapter->rx_base_queue;
5360
5361 /* shutdown specific queue receive and wait for dma to settle */
5362 ixgbe_disable_rx_queue(adapter, rx_ring);
5363 usleep_range(10000, 20000);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005364 ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
John Fastabend2a47fa42013-11-06 09:54:52 -08005365 ixgbe_clean_rx_ring(rx_ring);
5366 rx_ring->l2_accel_priv = NULL;
5367}
5368
John Fastabendae72c8d2013-11-09 07:11:26 +00005369static int ixgbe_fwd_ring_down(struct net_device *vdev,
5370 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08005371{
5372 struct ixgbe_adapter *adapter = accel->real_adapter;
5373 unsigned int rxbase = accel->rx_base_queue;
5374 unsigned int txbase = accel->tx_base_queue;
5375 int i;
5376
5377 netif_tx_stop_all_queues(vdev);
5378
5379 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5380 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5381 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
5382 }
5383
5384 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5385 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
5386 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
5387 }
5388
5389
5390 return 0;
5391}
5392
5393static int ixgbe_fwd_ring_up(struct net_device *vdev,
5394 struct ixgbe_fwd_adapter *accel)
5395{
5396 struct ixgbe_adapter *adapter = accel->real_adapter;
5397 unsigned int rxbase, txbase, queues;
5398 int i, baseq, err = 0;
5399
5400 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
5401 return 0;
5402
5403 baseq = accel->pool * adapter->num_rx_queues_per_pool;
5404 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
5405 accel->pool, adapter->num_rx_pools,
5406 baseq, baseq + adapter->num_rx_queues_per_pool,
5407 adapter->fwd_bitmask);
5408
5409 accel->netdev = vdev;
5410 accel->rx_base_queue = rxbase = baseq;
5411 accel->tx_base_queue = txbase = baseq;
5412
5413 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5414 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5415
5416 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5417 adapter->rx_ring[rxbase + i]->netdev = vdev;
5418 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
5419 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
5420 }
5421
5422 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5423 adapter->tx_ring[txbase + i]->netdev = vdev;
5424 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
5425 }
5426
5427 queues = min_t(unsigned int,
5428 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
5429 err = netif_set_real_num_tx_queues(vdev, queues);
5430 if (err)
5431 goto fwd_queue_err;
5432
John Fastabend2a47fa42013-11-06 09:54:52 -08005433 err = netif_set_real_num_rx_queues(vdev, queues);
5434 if (err)
5435 goto fwd_queue_err;
5436
5437 if (is_valid_ether_addr(vdev->dev_addr))
5438 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
5439
5440 ixgbe_fwd_psrtype(accel);
5441 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
5442 return err;
5443fwd_queue_err:
5444 ixgbe_fwd_ring_down(vdev, accel);
5445 return err;
5446}
5447
David Ahern1cd127f2016-10-17 19:15:48 -07005448static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
5449{
5450 if (netif_is_macvlan(upper)) {
5451 struct macvlan_dev *dfwd = netdev_priv(upper);
5452 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5453
5454 if (dfwd->fwd_priv)
5455 ixgbe_fwd_ring_up(upper, vadapter);
5456 }
5457
5458 return 0;
5459}
5460
John Fastabend2a47fa42013-11-06 09:54:52 -08005461static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5462{
David Ahern1cd127f2016-10-17 19:15:48 -07005463 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5464 ixgbe_upper_dev_walk, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005465}
5466
Auke Kok9a799d72007-09-15 14:07:45 -07005467static void ixgbe_configure(struct ixgbe_adapter *adapter)
5468{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005469 struct ixgbe_hw *hw = &adapter->hw;
5470
John Fastabend80605c652011-05-02 12:34:10 +00005471 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005472#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005473 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005474#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005475 /*
5476 * We must restore virtualization before VLANs or else
5477 * the VLVF registers will not be populated
5478 */
5479 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005480
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005481 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005482 ixgbe_restore_vlan(adapter);
5483
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005484 switch (hw->mac.type) {
5485 case ixgbe_mac_82599EB:
5486 case ixgbe_mac_X540:
5487 hw->mac.ops.disable_rx_buff(hw);
5488 break;
5489 default:
5490 break;
5491 }
5492
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005493 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005494 ixgbe_init_fdir_signature_82599(&adapter->hw,
5495 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005496 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5497 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5498 adapter->fdir_pballoc);
5499 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005500 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005501
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005502 switch (hw->mac.type) {
5503 case ixgbe_mac_82599EB:
5504 case ixgbe_mac_X540:
5505 hw->mac.ops.enable_rx_buff(hw);
5506 break;
5507 default:
5508 break;
5509 }
5510
Mark Rustad9de76052015-08-08 16:27:41 -07005511#ifdef CONFIG_IXGBE_DCA
5512 /* configure DCA */
5513 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5514 ixgbe_setup_dca(adapter);
5515#endif /* CONFIG_IXGBE_DCA */
5516
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005517#ifdef IXGBE_FCOE
5518 /* configure FCoE L2 filters, redirection table, and Rx control */
5519 ixgbe_configure_fcoe(adapter);
5520
5521#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005522 ixgbe_configure_tx(adapter);
5523 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005524 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005525}
5526
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005527/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005528 * ixgbe_sfp_link_config - set up SFP+ link
5529 * @adapter: pointer to private adapter struct
5530 **/
5531static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5532{
Alexander Duyck70864002011-04-27 09:13:56 +00005533 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005534 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005535 * is that an SFP was inserted/removed after the reset
5536 * but before SFP detection was enabled. As such the best
5537 * solution is to just start searching as soon as we start
5538 */
5539 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5540 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005541
Alexander Duyck70864002011-04-27 09:13:56 +00005542 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005543 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005544}
5545
5546/**
5547 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005548 * @hw: pointer to private hardware struct
5549 *
5550 * Returns 0 on success, negative on failure
5551 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005552static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005553{
Josh Hay3d292262012-12-15 03:28:19 +00005554 u32 speed;
5555 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005556 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005557
5558 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005559 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005560
5561 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005562 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005563
Josh Hay3d292262012-12-15 03:28:19 +00005564 speed = hw->phy.autoneg_advertised;
5565 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5566 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5567 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005568 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005569 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005570
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005571 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005572 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005573
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005574 return ret;
5575}
5576
Alexander Duycka34bcff2010-08-19 13:39:20 +00005577static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005578{
Auke Kok9a799d72007-09-15 14:07:45 -07005579 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005580 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005581
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005582 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005583 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5584 IXGBE_GPIE_OCD;
5585 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005586 /*
5587 * use EIAM to auto-mask when MSI-X interrupt is asserted
5588 * this saves a register write for every interrupt
5589 */
5590 switch (hw->mac.type) {
5591 case ixgbe_mac_82598EB:
5592 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5593 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005594 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005595 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005596 case ixgbe_mac_X550:
5597 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005598 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005599 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005600 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5601 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5602 break;
5603 }
5604 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005605 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5606 * specifically only auto mask tx and rx interrupts */
5607 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005608 }
5609
Alexander Duycka34bcff2010-08-19 13:39:20 +00005610 /* XXX: to interrupt immediately for EICS writes, enable this */
5611 /* gpie |= IXGBE_GPIE_EIMEN; */
5612
5613 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5614 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005615
5616 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5617 case IXGBE_82599_VMDQ_8Q_MASK:
5618 gpie |= IXGBE_GPIE_VTMODE_16;
5619 break;
5620 case IXGBE_82599_VMDQ_4Q_MASK:
5621 gpie |= IXGBE_GPIE_VTMODE_32;
5622 break;
5623 default:
5624 gpie |= IXGBE_GPIE_VTMODE_64;
5625 break;
5626 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005627 }
5628
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005629 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005630 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5631 switch (adapter->hw.mac.type) {
5632 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005633 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005634 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005635 default:
5636 break;
5637 }
5638 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005639
Alexander Duycka34bcff2010-08-19 13:39:20 +00005640 /* Enable fan failure interrupt */
5641 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005642 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005643
Don Skidmorea023bbd2015-06-24 16:38:53 -04005644 switch (hw->mac.type) {
5645 case ixgbe_mac_82599EB:
5646 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5647 break;
5648 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005649 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005650 gpie |= IXGBE_SDP0_GPIEN_X540;
5651 break;
5652 default:
5653 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005654 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005655
5656 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5657}
5658
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005659static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005660{
5661 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005662 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005663 u32 ctrl_ext;
5664
5665 ixgbe_get_hw_control(adapter);
5666 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005667
Auke Kok9a799d72007-09-15 14:07:45 -07005668 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5669 ixgbe_configure_msix(adapter);
5670 else
5671 ixgbe_configure_msi_and_legacy(adapter);
5672
Emil Tantilovec74a472012-09-20 03:33:56 +00005673 /* enable the optics for 82599 SFP+ fiber */
5674 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005675 hw->mac.ops.enable_tx_laser(hw);
5676
Don Skidmore961fac82015-06-09 16:09:47 -07005677 if (hw->phy.ops.set_phy_power)
5678 hw->phy.ops.set_phy_power(hw, true);
5679
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005680 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005681 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005682 ixgbe_napi_enable_all(adapter);
5683
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005684 if (ixgbe_is_sfp(hw)) {
5685 ixgbe_sfp_link_config(adapter);
5686 } else {
5687 err = ixgbe_non_sfp_link_config(hw);
5688 if (err)
5689 e_err(probe, "link_config FAILED %d\n", err);
5690 }
5691
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005692 /* clear any pending interrupts, may auto mask */
5693 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005694 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005695
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005696 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005697 * If this adapter has a fan, check to see if we had a failure
5698 * before we enabled the interrupt.
5699 */
5700 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5701 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5702 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005703 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005704 }
5705
Auke Kok9a799d72007-09-15 14:07:45 -07005706 /* bring the link up in the watchdog, this could race with our first
5707 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005708 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5709 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005710 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005711
5712 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5713 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5714 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5715 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005716}
5717
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005718void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5719{
5720 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005721 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005722 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005723
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005724 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005725 usleep_range(1000, 2000);
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005726 if (adapter->hw.phy.type == ixgbe_phy_fw)
5727 ixgbe_watchdog_link_is_down(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005728 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005729 /*
5730 * If SR-IOV enabled then wait a bit before bringing the adapter
5731 * back up to give the VFs time to respond to the reset. The
5732 * two second wait is based upon the watchdog timer cycle in
5733 * the VF driver.
5734 */
5735 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5736 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005737 ixgbe_up(adapter);
5738 clear_bit(__IXGBE_RESETTING, &adapter->state);
5739}
5740
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005741void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005742{
5743 /* hardware has been reset, we need to reload some things */
5744 ixgbe_configure(adapter);
5745
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005746 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005747}
5748
5749void ixgbe_reset(struct ixgbe_adapter *adapter)
5750{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005751 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005752 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005753 int err;
5754
Mark Rustadb0483c82014-01-14 18:53:17 -08005755 if (ixgbe_removed(hw->hw_addr))
5756 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005757 /* lock SFP init bit to prevent race conditions with the watchdog */
5758 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5759 usleep_range(1000, 2000);
5760
5761 /* clear all SFP and link config related flags while holding SFP_INIT */
5762 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5763 IXGBE_FLAG2_SFP_NEEDS_RESET);
5764 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5765
Don Skidmore8ca783a2009-05-26 20:40:47 -07005766 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005767 switch (err) {
5768 case 0:
5769 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005770 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005771 break;
5772 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005773 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005774 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005775 case IXGBE_ERR_EEPROM_VERSION:
5776 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005777 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005778 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005779 "your hardware. If you are experiencing problems "
5780 "please contact your Intel or hardware "
5781 "representative who provided you with this "
5782 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005783 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005784 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005785 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005786 }
Auke Kok9a799d72007-09-15 14:07:45 -07005787
Alexander Duyck70864002011-04-27 09:13:56 +00005788 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005789
5790 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005791 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005792 __dev_uc_unsync(netdev, NULL);
5793
5794 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005795 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005796
5797 /* update SAN MAC vmdq pool selection */
5798 if (hw->mac.san_mac_rar_index)
5799 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005800
Jacob Keller8fecf672013-06-21 08:14:32 +00005801 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005802 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005803
5804 if (hw->phy.ops.set_phy_power) {
5805 if (!netif_running(adapter->netdev) && !adapter->wol)
5806 hw->phy.ops.set_phy_power(hw, false);
5807 else
5808 hw->phy.ops.set_phy_power(hw, true);
5809 }
Auke Kok9a799d72007-09-15 14:07:45 -07005810}
5811
Auke Kok9a799d72007-09-15 14:07:45 -07005812/**
Auke Kok9a799d72007-09-15 14:07:45 -07005813 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005814 * @tx_ring: ring to be cleaned
5815 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005816static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005817{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005818 u16 i = tx_ring->next_to_clean;
5819 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07005820
Alexander Duyckffed21b2017-01-17 08:37:29 -08005821 while (i != tx_ring->next_to_use) {
5822 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -07005823
Alexander Duyckffed21b2017-01-17 08:37:29 -08005824 /* Free all the Tx ring sk_buffs */
John Fastabend33fdc822017-04-24 03:30:18 -07005825 if (ring_is_xdp(tx_ring))
5826 page_frag_free(tx_buffer->data);
5827 else
5828 dev_kfree_skb_any(tx_buffer->skb);
Alexander Duyckffed21b2017-01-17 08:37:29 -08005829
5830 /* unmap skb header data */
5831 dma_unmap_single(tx_ring->dev,
5832 dma_unmap_addr(tx_buffer, dma),
5833 dma_unmap_len(tx_buffer, len),
5834 DMA_TO_DEVICE);
5835
5836 /* check for eop_desc to determine the end of the packet */
5837 eop_desc = tx_buffer->next_to_watch;
5838 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5839
5840 /* unmap remaining buffers */
5841 while (tx_desc != eop_desc) {
5842 tx_buffer++;
5843 tx_desc++;
5844 i++;
5845 if (unlikely(i == tx_ring->count)) {
5846 i = 0;
5847 tx_buffer = tx_ring->tx_buffer_info;
5848 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5849 }
5850
5851 /* unmap any remaining paged data */
5852 if (dma_unmap_len(tx_buffer, len))
5853 dma_unmap_page(tx_ring->dev,
5854 dma_unmap_addr(tx_buffer, dma),
5855 dma_unmap_len(tx_buffer, len),
5856 DMA_TO_DEVICE);
5857 }
5858
5859 /* move us one more past the eop_desc for start of next pkt */
5860 tx_buffer++;
5861 i++;
5862 if (unlikely(i == tx_ring->count)) {
5863 i = 0;
5864 tx_buffer = tx_ring->tx_buffer_info;
5865 }
Auke Kok9a799d72007-09-15 14:07:45 -07005866 }
5867
Alexander Duyckffed21b2017-01-17 08:37:29 -08005868 /* reset BQL for queue */
John Fastabend33fdc822017-04-24 03:30:18 -07005869 if (!ring_is_xdp(tx_ring))
5870 netdev_tx_reset_queue(txring_txq(tx_ring));
John Fastabenddad8a3b2012-04-23 12:22:39 +00005871
Alexander Duyckffed21b2017-01-17 08:37:29 -08005872 /* reset next_to_use and next_to_clean */
Auke Kok9a799d72007-09-15 14:07:45 -07005873 tx_ring->next_to_use = 0;
5874 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005875}
5876
5877/**
Auke Kok9a799d72007-09-15 14:07:45 -07005878 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5879 * @adapter: board private structure
5880 **/
5881static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5882{
5883 int i;
5884
5885 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005886 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005887}
5888
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005889/**
5890 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5891 * @adapter: board private structure
5892 **/
5893static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5894{
5895 int i;
5896
5897 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005898 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07005899 for (i = 0; i < adapter->num_xdp_queues; i++)
5900 ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005901}
5902
Alexander Duycke4911d52011-05-11 07:18:52 +00005903static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5904{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005905 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005906 struct ixgbe_fdir_filter *filter;
5907
5908 spin_lock(&adapter->fdir_perfect_lock);
5909
Sasha Levinb67bfe02013-02-27 17:06:00 -08005910 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005911 &adapter->fdir_filter_list, fdir_node) {
5912 hlist_del(&filter->fdir_node);
5913 kfree(filter);
5914 }
5915 adapter->fdir_filter_count = 0;
5916
5917 spin_unlock(&adapter->fdir_perfect_lock);
5918}
5919
David Ahern1cd127f2016-10-17 19:15:48 -07005920static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
5921{
5922 if (netif_is_macvlan(upper)) {
5923 struct macvlan_dev *vlan = netdev_priv(upper);
5924
5925 if (vlan->fwd_priv) {
5926 netif_tx_stop_all_queues(upper);
5927 netif_carrier_off(upper);
5928 netif_tx_disable(upper);
5929 }
5930 }
5931
5932 return 0;
5933}
5934
Auke Kok9a799d72007-09-15 14:07:45 -07005935void ixgbe_down(struct ixgbe_adapter *adapter)
5936{
5937 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005938 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005939 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005940
5941 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005942 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5943 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005944
5945 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005946 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005947
Yi Zou2d39d572011-01-06 14:29:56 +00005948 /* disable all enabled rx queues */
5949 for (i = 0; i < adapter->num_rx_queues; i++)
5950 /* this call also flushes the previous write */
5951 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5952
Don Skidmore032b4322011-03-18 09:32:53 +00005953 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005954
John Fastabend11393cc2017-07-17 09:29:40 -07005955 /* synchronize_sched() needed for pending XDP buffers to drain */
5956 if (adapter->xdp_ring[0])
5957 synchronize_sched();
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005958 netif_tx_stop_all_queues(netdev);
5959
Alexander Duyck70864002011-04-27 09:13:56 +00005960 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005961 netif_carrier_off(netdev);
5962 netif_tx_disable(netdev);
5963
John Fastabend2a47fa42013-11-06 09:54:52 -08005964 /* disable any upper devices */
David Ahern1cd127f2016-10-17 19:15:48 -07005965 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5966 ixgbe_disable_macvlan, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005967
John Fastabendc0dfb902010-04-27 02:13:39 +00005968 ixgbe_irq_disable(adapter);
5969
5970 ixgbe_napi_disable_all(adapter);
5971
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005972 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5973 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005974 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5975
5976 del_timer_sync(&adapter->service_timer);
5977
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005978 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005979 /* Clear EITR Select mapping */
5980 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5981
5982 /* Mark all the VFs as inactive */
5983 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005984 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005985
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005986 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005987 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005988
Auke Kok9a799d72007-09-15 14:07:45 -07005989 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005990 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005991 }
5992
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005993 /* disable transmits in the hardware now that interrupts are off */
5994 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005995 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005996 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005997 }
John Fastabend33fdc822017-04-24 03:30:18 -07005998 for (i = 0; i < adapter->num_xdp_queues; i++) {
5999 u8 reg_idx = adapter->xdp_ring[i]->reg_idx;
6000
6001 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
6002 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00006003
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006004 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08006005 switch (hw->mac.type) {
6006 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006007 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006008 case ixgbe_mac_X550:
6009 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006010 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00006011 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00006012 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
6013 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08006014 break;
6015 default:
6016 break;
6017 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07006018
Paul Larson6f4a0e42008-06-24 17:00:56 -07006019 if (!pci_channel_offline(adapter->pdev))
6020 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00006021
Emil Tantilovec74a472012-09-20 03:33:56 +00006022 /* power down the optics for 82599 SFP+ fiber */
6023 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00006024 hw->mac.ops.disable_tx_laser(hw);
6025
Auke Kok9a799d72007-09-15 14:07:45 -07006026 ixgbe_clean_all_tx_rings(adapter);
6027 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006028}
6029
Auke Kok9a799d72007-09-15 14:07:45 -07006030/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006031 * ixgbe_eee_capable - helper function to determine EEE support on X550
6032 * @adapter: board private structure
6033 */
6034static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
6035{
6036 struct ixgbe_hw *hw = &adapter->hw;
6037
6038 switch (hw->device_id) {
6039 case IXGBE_DEV_ID_X550EM_A_1G_T:
6040 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6041 if (!hw->phy.eee_speeds_supported)
6042 break;
6043 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
6044 if (!hw->phy.eee_speeds_advertised)
6045 break;
6046 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
6047 break;
6048 default:
6049 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
6050 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
6051 break;
6052 }
6053}
6054
6055/**
Auke Kok9a799d72007-09-15 14:07:45 -07006056 * ixgbe_tx_timeout - Respond to a Tx Hang
6057 * @netdev: network interface device structure
6058 **/
6059static void ixgbe_tx_timeout(struct net_device *netdev)
6060{
6061 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6062
6063 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006064 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006065}
6066
Usha Ketineni88290092016-04-26 05:00:26 -07006067#ifdef CONFIG_IXGBE_DCB
6068static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
6069{
6070 struct ixgbe_hw *hw = &adapter->hw;
6071 struct tc_configuration *tc;
6072 int j;
6073
6074 switch (hw->mac.type) {
6075 case ixgbe_mac_82598EB:
6076 case ixgbe_mac_82599EB:
6077 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
6078 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
6079 break;
6080 case ixgbe_mac_X540:
6081 case ixgbe_mac_X550:
6082 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
6083 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
6084 break;
6085 case ixgbe_mac_X550EM_x:
6086 case ixgbe_mac_x550em_a:
6087 default:
6088 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
6089 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
6090 break;
6091 }
6092
6093 /* Configure DCB traffic classes */
6094 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
6095 tc = &adapter->dcb_cfg.tc_config[j];
6096 tc->path[DCB_TX_CONFIG].bwg_id = 0;
6097 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
6098 tc->path[DCB_RX_CONFIG].bwg_id = 0;
6099 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
6100 tc->dcb_pfc = pfc_disabled;
6101 }
6102
6103 /* Initialize default user to priority mapping, UPx->TC0 */
6104 tc = &adapter->dcb_cfg.tc_config[0];
6105 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
6106 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
6107
6108 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
6109 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
6110 adapter->dcb_cfg.pfc_mode_enable = false;
6111 adapter->dcb_set_bitmap = 0x00;
6112 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
6113 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
6114 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
6115 sizeof(adapter->temp_dcb_cfg));
6116}
6117#endif
6118
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006119/**
Auke Kok9a799d72007-09-15 14:07:45 -07006120 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
6121 * @adapter: board private structure to initialize
6122 *
6123 * ixgbe_sw_init initializes the Adapter private data structure.
6124 * Fields are initialized based on PCI device information and
6125 * OS network device settings (MTU size).
6126 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07006127static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
6128 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07006129{
6130 struct ixgbe_hw *hw = &adapter->hw;
6131 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00006132 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00006133 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04006134 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006135
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006136 /* PCI config space info */
6137
6138 hw->vendor_id = pdev->vendor;
6139 hw->device_id = pdev->device;
6140 hw->revision_id = pdev->revision;
6141 hw->subsystem_vendor_id = pdev->subsystem_vendor;
6142 hw->subsystem_device_id = pdev->subsystem_device;
6143
Emil Tantilov55570b62016-10-12 12:34:25 -07006144 /* get_invariants needs the device IDs */
6145 ii->get_invariants(hw);
6146
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006147 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00006148 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00006149 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006150 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006151 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
6152 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00006153 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
6154 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006155 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
6156#ifdef CONFIG_IXGBE_DCA
6157 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
6158#endif
Usha Ketineni88290092016-04-26 05:00:26 -07006159#ifdef CONFIG_IXGBE_DCB
6160 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
6161 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6162#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006163#ifdef IXGBE_FCOE
6164 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
6165 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6166#ifdef CONFIG_IXGBE_DCB
6167 /* Default traffic class to use for FCoE */
6168 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
6169#endif /* CONFIG_IXGBE_DCB */
6170#endif /* IXGBE_FCOE */
6171
John Fastabendb82b17d2016-02-16 21:18:53 -08006172 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04006173 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
6174 GFP_KERNEL);
6175 if (!adapter->jump_tables[0])
6176 return -ENOMEM;
6177 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
6178
6179 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
6180 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08006181
Jacob Keller5d7daa32014-03-29 06:51:25 +00006182 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
6183 hw->mac.num_rar_entries,
6184 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08006185 if (!adapter->mac_table)
6186 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00006187
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07006188 if (ixgbe_init_rss_key(adapter))
6189 return -ENOMEM;
6190
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006191 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08006192 switch (hw->mac.type) {
6193 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006194 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006195
Don Skidmorebf069c92009-05-07 10:39:54 +00006196 if (hw->device_id == IXGBE_DEV_ID_82598AT)
6197 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006198
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006199 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006200 adapter->ring_feature[RING_F_FDIR].limit = 0;
6201 adapter->atr_sample_rate = 0;
6202 adapter->fdir_pballoc = 0;
6203#ifdef IXGBE_FCOE
6204 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6205 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6206#ifdef CONFIG_IXGBE_DCB
6207 adapter->fcoe.up = 0;
6208#endif /* IXGBE_DCB */
6209#endif /* IXGBE_FCOE */
6210 break;
6211 case ixgbe_mac_82599EB:
6212 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
6213 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006214 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006215 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07006216 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00006217 if (fwsm & IXGBE_FWSM_TS_ENABLED)
6218 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006219 break;
Mark Rustad49425df2016-04-01 12:18:09 -07006220 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07006221 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006222 switch (hw->device_id) {
6223 case IXGBE_DEV_ID_X550EM_A_1G_T:
6224 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6225 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6226 break;
6227 default:
6228 break;
6229 }
Emil Tantilova21d0822016-08-10 11:19:23 -07006230 /* fall through */
6231 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07006232#ifdef CONFIG_IXGBE_DCB
6233 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
6234#endif
6235#ifdef IXGBE_FCOE
6236 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6237#ifdef CONFIG_IXGBE_DCB
6238 adapter->fcoe.up = 0;
6239#endif /* IXGBE_DCB */
6240#endif /* IXGBE_FCOE */
6241 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006242 case ixgbe_mac_X550:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006243 if (hw->mac.type == ixgbe_mac_X550)
6244 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006245#ifdef CONFIG_IXGBE_DCA
6246 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
6247#endif
Mark Rustad67359c32015-06-15 11:33:25 -07006248 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006249 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08006250 default:
6251 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00006252 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08006253
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006254#ifdef IXGBE_FCOE
6255 /* FCoE support exists, always init the FCoE lock */
6256 spin_lock_init(&adapter->fcoe.lock);
6257
6258#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00006259 /* n-tuple support exists, always init our spinlock */
6260 spin_lock_init(&adapter->fdir_perfect_lock);
6261
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08006262#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07006263 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006264#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006265
6266 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00006267 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00006268 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00006269 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07006270 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
6271 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00006272 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07006273
Alexander Duyck99d74482012-05-09 08:09:25 +00006274#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08006275 if (max_vfs > 0)
6276 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 +00006277
Jacob Keller170e8542013-11-09 04:52:32 -08006278 /* assign number of SR-IOV VFs */
6279 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08006280 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Emil Tantilov5c11f002017-01-20 14:11:56 -08006281 max_vfs = 0;
Jacob Keller170e8542013-11-09 04:52:32 -08006282 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
Jacob Keller170e8542013-11-09 04:52:32 -08006283 }
6284 }
6285#endif /* CONFIG_PCI_IOV */
6286
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006287 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006288 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006289 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006290
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006291 /* set default ring sizes */
6292 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
6293 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
6294
Alexander Duyckbd198052011-06-11 01:45:08 +00006295 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00006296 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00006297
Auke Kok9a799d72007-09-15 14:07:45 -07006298 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006299 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006300 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006301 return -EIO;
6302 }
6303
John Fastabend2a47fa42013-11-06 09:54:52 -08006304 /* PF holds first pool slot */
6305 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07006306 set_bit(__IXGBE_DOWN, &adapter->state);
6307
6308 return 0;
6309}
6310
6311/**
6312 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006313 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006314 *
6315 * Return 0 on success, negative on failure
6316 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006317int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006318{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006319 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006320 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006321 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07006322 int size;
6323
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006324 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006325
6326 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006327 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006328
Alexander Duyckffed21b2017-01-17 08:37:29 -08006329 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006330 if (!tx_ring->tx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006331 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006332 if (!tx_ring->tx_buffer_info)
6333 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006334
6335 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08006336 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006337 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006338
Mark Rustadca8dfe22014-07-24 06:19:24 +00006339 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006340 tx_ring->desc = dma_alloc_coherent(dev,
6341 tx_ring->size,
6342 &tx_ring->dma,
6343 GFP_KERNEL);
6344 set_dev_node(dev, orig_node);
6345 if (!tx_ring->desc)
6346 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6347 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006348 if (!tx_ring->desc)
6349 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006350
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006351 tx_ring->next_to_use = 0;
6352 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006353 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006354
6355err:
6356 vfree(tx_ring->tx_buffer_info);
6357 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006358 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006359 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006360}
6361
6362/**
Alexander Duyck69888672008-09-11 20:05:39 -07006363 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6364 * @adapter: board private structure
6365 *
6366 * If this function returns with an error, then it's possible one or
6367 * more of the rings is populated (while the rest are not). It is the
6368 * callers duty to clean those orphaned rings.
6369 *
6370 * Return 0 on success, negative on failure
6371 **/
6372static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6373{
John Fastabend33fdc822017-04-24 03:30:18 -07006374 int i, j = 0, err = 0;
Alexander Duyck69888672008-09-11 20:05:39 -07006375
6376 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006377 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006378 if (!err)
6379 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006380
Emil Tantilov396e7992010-07-01 20:05:12 +00006381 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006382 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07006383 }
John Fastabend33fdc822017-04-24 03:30:18 -07006384 for (j = 0; j < adapter->num_xdp_queues; j++) {
6385 err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
6386 if (!err)
6387 continue;
6388
6389 e_err(probe, "Allocation for Tx Queue %u failed\n", j);
6390 goto err_setup_tx;
6391 }
Alexander Duyck69888672008-09-11 20:05:39 -07006392
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006393 return 0;
6394err_setup_tx:
6395 /* rewind the index freeing the rings as we go */
John Fastabend33fdc822017-04-24 03:30:18 -07006396 while (j--)
6397 ixgbe_free_tx_resources(adapter->xdp_ring[j]);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006398 while (i--)
6399 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006400 return err;
6401}
6402
6403/**
Auke Kok9a799d72007-09-15 14:07:45 -07006404 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006405 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006406 *
6407 * Returns 0 on success, negative on failure
6408 **/
John Fastabend92470802017-04-24 03:30:17 -07006409int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
6410 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006411{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006412 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006413 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006414 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006415 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07006416
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006417 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006418
6419 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006420 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006421
Alexander Duyckffed21b2017-01-17 08:37:29 -08006422 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006423 if (!rx_ring->rx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006424 rx_ring->rx_buffer_info = vmalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006425 if (!rx_ring->rx_buffer_info)
6426 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006427
Auke Kok9a799d72007-09-15 14:07:45 -07006428 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006429 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6430 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006431
Mark Rustadca8dfe22014-07-24 06:19:24 +00006432 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006433 rx_ring->desc = dma_alloc_coherent(dev,
6434 rx_ring->size,
6435 &rx_ring->dma,
6436 GFP_KERNEL);
6437 set_dev_node(dev, orig_node);
6438 if (!rx_ring->desc)
6439 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6440 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006441 if (!rx_ring->desc)
6442 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006443
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006444 rx_ring->next_to_clean = 0;
6445 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006446
John Fastabend92470802017-04-24 03:30:17 -07006447 rx_ring->xdp_prog = adapter->xdp_prog;
6448
Auke Kok9a799d72007-09-15 14:07:45 -07006449 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006450err:
6451 vfree(rx_ring->rx_buffer_info);
6452 rx_ring->rx_buffer_info = NULL;
6453 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07006454 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006455}
6456
6457/**
Alexander Duyck69888672008-09-11 20:05:39 -07006458 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6459 * @adapter: board private structure
6460 *
6461 * If this function returns with an error, then it's possible one or
6462 * more of the rings is populated (while the rest are not). It is the
6463 * callers duty to clean those orphaned rings.
6464 *
6465 * Return 0 on success, negative on failure
6466 **/
Alexander Duyck69888672008-09-11 20:05:39 -07006467static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6468{
6469 int i, err = 0;
6470
6471 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend92470802017-04-24 03:30:17 -07006472 err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006473 if (!err)
6474 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006475
Emil Tantilov396e7992010-07-01 20:05:12 +00006476 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006477 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07006478 }
6479
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006480#ifdef IXGBE_FCOE
6481 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6482 if (!err)
6483#endif
6484 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006485err_setup_rx:
6486 /* rewind the index freeing the rings as we go */
6487 while (i--)
6488 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006489 return err;
6490}
6491
6492/**
Auke Kok9a799d72007-09-15 14:07:45 -07006493 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07006494 * @tx_ring: Tx descriptor ring for a specific queue
6495 *
6496 * Free all transmit software resources
6497 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006498void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006499{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006500 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006501
6502 vfree(tx_ring->tx_buffer_info);
6503 tx_ring->tx_buffer_info = NULL;
6504
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006505 /* if not set, then don't free */
6506 if (!tx_ring->desc)
6507 return;
6508
6509 dma_free_coherent(tx_ring->dev, tx_ring->size,
6510 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006511
6512 tx_ring->desc = NULL;
6513}
6514
6515/**
6516 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6517 * @adapter: board private structure
6518 *
6519 * Free all transmit software resources
6520 **/
6521static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6522{
6523 int i;
6524
6525 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006526 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006527 ixgbe_free_tx_resources(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07006528 for (i = 0; i < adapter->num_xdp_queues; i++)
6529 if (adapter->xdp_ring[i]->desc)
6530 ixgbe_free_tx_resources(adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006531}
6532
6533/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006534 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006535 * @rx_ring: ring to clean the resources from
6536 *
6537 * Free all receive software resources
6538 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006539void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006540{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006541 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006542
John Fastabend92470802017-04-24 03:30:17 -07006543 rx_ring->xdp_prog = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07006544 vfree(rx_ring->rx_buffer_info);
6545 rx_ring->rx_buffer_info = NULL;
6546
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006547 /* if not set, then don't free */
6548 if (!rx_ring->desc)
6549 return;
6550
6551 dma_free_coherent(rx_ring->dev, rx_ring->size,
6552 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006553
6554 rx_ring->desc = NULL;
6555}
6556
6557/**
6558 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6559 * @adapter: board private structure
6560 *
6561 * Free all receive software resources
6562 **/
6563static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6564{
6565 int i;
6566
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006567#ifdef IXGBE_FCOE
6568 ixgbe_free_fcoe_ddp_resources(adapter);
6569
6570#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006571 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006572 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006573 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006574}
6575
6576/**
Auke Kok9a799d72007-09-15 14:07:45 -07006577 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6578 * @netdev: network interface device structure
6579 * @new_mtu: new value for maximum frame size
6580 *
6581 * Returns 0 on success, negative on failure
6582 **/
6583static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6584{
6585 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck655309e2012-02-08 07:50:35 +00006586
6587 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006588 * For 82599EB we cannot allow legacy VFs to enable their receive
6589 * paths when MTU greater than 1500 is configured. So display a
6590 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006591 */
6592 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6593 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Jarod Wilson91c527a2016-10-17 15:54:05 -04006594 (new_mtu > ETH_DATA_LEN))
Alexander Duyck872844d2012-08-15 02:10:43 +00006595 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006596
Emil Tantilov396e7992010-07-01 20:05:12 +00006597 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006598
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006599 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006600 netdev->mtu = new_mtu;
6601
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006602 if (netif_running(netdev))
6603 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006604
6605 return 0;
6606}
6607
6608/**
6609 * ixgbe_open - Called when a network interface is made active
6610 * @netdev: network interface device structure
6611 *
6612 * Returns 0 on success, negative value on failure
6613 *
6614 * The open entry point is called when a network interface is made
6615 * active by the system (IFF_UP). At this point all resources needed
6616 * for transmit and receive operations are allocated, the interrupt
6617 * handler is registered with the OS, the watchdog timer is started,
6618 * and the stack is notified that the interface is ready.
6619 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006620int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006621{
6622 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006623 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006624 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006625
Auke Kok4bebfaa2008-02-11 09:26:01 -08006626 /* disallow open during test */
6627 if (test_bit(__IXGBE_TESTING, &adapter->state))
6628 return -EBUSY;
6629
Jesse Brandeburg54386462009-04-17 20:44:27 +00006630 netif_carrier_off(netdev);
6631
Auke Kok9a799d72007-09-15 14:07:45 -07006632 /* allocate transmit descriptors */
6633 err = ixgbe_setup_all_tx_resources(adapter);
6634 if (err)
6635 goto err_setup_tx;
6636
Auke Kok9a799d72007-09-15 14:07:45 -07006637 /* allocate receive descriptors */
6638 err = ixgbe_setup_all_rx_resources(adapter);
6639 if (err)
6640 goto err_setup_rx;
6641
6642 ixgbe_configure(adapter);
6643
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006644 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006645 if (err)
6646 goto err_req_irq;
6647
Alexander Duyckac802f52012-07-12 05:52:53 +00006648 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08006649 if (adapter->num_rx_pools > 1)
6650 queues = adapter->num_rx_queues_per_pool;
6651 else
6652 queues = adapter->num_tx_queues;
6653
6654 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006655 if (err)
6656 goto err_set_queues;
6657
John Fastabend2a47fa42013-11-06 09:54:52 -08006658 if (adapter->num_rx_pools > 1 &&
6659 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
6660 queues = IXGBE_MAX_L2A_QUEUES;
6661 else
6662 queues = adapter->num_rx_queues;
6663 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006664 if (err)
6665 goto err_set_queues;
6666
Jacob Keller1a71ab22012-08-25 03:54:19 +00006667 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006668
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006669 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006670
Emil Tantilova21d0822016-08-10 11:19:23 -07006671 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
Alexander Duyckb3a49552016-06-16 12:22:19 -07006672 udp_tunnel_get_rx_info(netdev);
Mark Rustad67359c32015-06-15 11:33:25 -07006673
Auke Kok9a799d72007-09-15 14:07:45 -07006674 return 0;
6675
Alexander Duyckac802f52012-07-12 05:52:53 +00006676err_set_queues:
6677 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006678err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006679 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006680 if (hw->phy.ops.set_phy_power && !adapter->wol)
6681 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006682err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006683 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006684err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006685 ixgbe_reset(adapter);
6686
6687 return err;
6688}
6689
Jacob Kellera0cccce2014-05-16 05:12:29 +00006690static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6691{
6692 ixgbe_ptp_suspend(adapter);
6693
Don Skidmore6ac74392015-06-17 17:34:31 -04006694 if (adapter->hw.phy.ops.enter_lplu) {
6695 adapter->hw.phy.reset_disable = true;
6696 ixgbe_down(adapter);
6697 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6698 adapter->hw.phy.reset_disable = false;
6699 } else {
6700 ixgbe_down(adapter);
6701 }
6702
Jacob Kellera0cccce2014-05-16 05:12:29 +00006703 ixgbe_free_irq(adapter);
6704
6705 ixgbe_free_all_tx_resources(adapter);
6706 ixgbe_free_all_rx_resources(adapter);
6707}
6708
Auke Kok9a799d72007-09-15 14:07:45 -07006709/**
6710 * ixgbe_close - Disables a network interface
6711 * @netdev: network interface device structure
6712 *
6713 * Returns 0, this is not allowed to fail
6714 *
6715 * The close entry point is called when an interface is de-activated
6716 * by the OS. The hardware is still under the drivers control, but
6717 * needs to be disabled. A global MAC reset is issued to stop the
6718 * hardware, and all transmit and receive resources are freed.
6719 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006720int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006721{
6722 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006723
Jacob Keller1a71ab22012-08-25 03:54:19 +00006724 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006725
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006726 if (netif_device_present(netdev))
6727 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006728
Alexander Duycke4911d52011-05-11 07:18:52 +00006729 ixgbe_fdir_filter_exit(adapter);
6730
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006731 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006732
6733 return 0;
6734}
6735
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006736#ifdef CONFIG_PM
6737static int ixgbe_resume(struct pci_dev *pdev)
6738{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006739 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6740 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006741 u32 err;
6742
Mark Rustad0391bbe2014-02-28 15:48:55 -08006743 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006744 pci_set_power_state(pdev, PCI_D0);
6745 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006746 /*
6747 * pci_restore_state clears dev->state_saved so call
6748 * pci_save_state to restore it.
6749 */
6750 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006751
6752 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006753 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006754 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006755 return err;
6756 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006757 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006758 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006759 pci_set_master(pdev);
6760
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006761 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006762
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006763 ixgbe_reset(adapter);
6764
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006765 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6766
Alexander Duyckac802f52012-07-12 05:52:53 +00006767 rtnl_lock();
6768 err = ixgbe_init_interrupt_scheme(adapter);
6769 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006770 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006771
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006772
6773 if (!err)
6774 netif_device_attach(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006775 rtnl_unlock();
6776
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006777 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006778}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006779#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006780
6781static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006782{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006783 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6784 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006785 struct ixgbe_hw *hw = &adapter->hw;
6786 u32 ctrl, fctrl;
6787 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006788#ifdef CONFIG_PM
6789 int retval = 0;
6790#endif
6791
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006792 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006793 netif_device_detach(netdev);
6794
Jacob Kellera0cccce2014-05-16 05:12:29 +00006795 if (netif_running(netdev))
6796 ixgbe_close_suspend(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006797
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006798 ixgbe_clear_interrupt_scheme(adapter);
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006799 rtnl_unlock();
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006800
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006801#ifdef CONFIG_PM
6802 retval = pci_save_state(pdev);
6803 if (retval)
6804 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006805
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006806#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006807 if (hw->mac.ops.stop_link_on_d3)
6808 hw->mac.ops.stop_link_on_d3(hw);
6809
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006810 if (wufc) {
6811 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006812
Emil Tantilovec74a472012-09-20 03:33:56 +00006813 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6814 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006815 hw->mac.ops.enable_tx_laser(hw);
6816
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006817 /* turn on all-multi mode if wake on multicast is enabled */
6818 if (wufc & IXGBE_WUFC_MC) {
6819 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6820 fctrl |= IXGBE_FCTRL_MPE;
6821 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
6822 }
6823
6824 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6825 ctrl |= IXGBE_CTRL_GIO_DIS;
6826 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6827
6828 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6829 } else {
6830 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6831 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6832 }
6833
Alexander Duyckbd508172010-11-16 19:27:03 -08006834 switch (hw->mac.type) {
6835 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006836 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006837 break;
6838 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006839 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006840 case ixgbe_mac_X550:
6841 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006842 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006843 pci_wake_from_d3(pdev, !!wufc);
6844 break;
6845 default:
6846 break;
6847 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006848
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006849 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006850 if (hw->phy.ops.set_phy_power && !*enable_wake)
6851 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006852
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006853 ixgbe_release_hw_control(adapter);
6854
Mark Rustad41c62842014-03-12 00:38:35 +00006855 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6856 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006857
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006858 return 0;
6859}
6860
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006861#ifdef CONFIG_PM
6862static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6863{
6864 int retval;
6865 bool wake;
6866
6867 retval = __ixgbe_shutdown(pdev, &wake);
6868 if (retval)
6869 return retval;
6870
6871 if (wake) {
6872 pci_prepare_to_sleep(pdev);
6873 } else {
6874 pci_wake_from_d3(pdev, false);
6875 pci_set_power_state(pdev, PCI_D3hot);
6876 }
6877
6878 return 0;
6879}
6880#endif /* CONFIG_PM */
6881
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006882static void ixgbe_shutdown(struct pci_dev *pdev)
6883{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006884 bool wake;
6885
6886 __ixgbe_shutdown(pdev, &wake);
6887
6888 if (system_state == SYSTEM_POWER_OFF) {
6889 pci_wake_from_d3(pdev, wake);
6890 pci_set_power_state(pdev, PCI_D3hot);
6891 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006892}
6893
6894/**
Auke Kok9a799d72007-09-15 14:07:45 -07006895 * ixgbe_update_stats - Update the board statistics counters.
6896 * @adapter: board private structure
6897 **/
6898void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6899{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006900 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006901 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006902 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006903 u64 total_mpc = 0;
6904 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006905 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6906 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006907 u64 alloc_rx_page = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006908 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006909
Don Skidmored08935c2010-06-11 13:20:29 +00006910 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6911 test_bit(__IXGBE_RESETTING, &adapter->state))
6912 return;
6913
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006914 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006915 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006916 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006917 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006918 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6919 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006920 }
6921 adapter->rsc_total_count = rsc_count;
6922 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006923 }
6924
Alexander Duyck5b7da512010-11-16 19:26:50 -08006925 for (i = 0; i < adapter->num_rx_queues; i++) {
6926 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6927 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006928 alloc_rx_page += rx_ring->rx_stats.alloc_rx_page;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006929 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6930 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006931 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006932 bytes += rx_ring->stats.bytes;
6933 packets += rx_ring->stats.packets;
6934 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006935 adapter->non_eop_descs = non_eop_descs;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006936 adapter->alloc_rx_page = alloc_rx_page;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006937 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6938 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006939 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006940 netdev->stats.rx_bytes = bytes;
6941 netdev->stats.rx_packets = packets;
6942
6943 bytes = 0;
6944 packets = 0;
6945 /* gather some stats to the adapter struct that are per queue */
6946 for (i = 0; i < adapter->num_tx_queues; i++) {
6947 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6948 restart_queue += tx_ring->tx_stats.restart_queue;
6949 tx_busy += tx_ring->tx_stats.tx_busy;
6950 bytes += tx_ring->stats.bytes;
6951 packets += tx_ring->stats.packets;
6952 }
John Fastabend33fdc822017-04-24 03:30:18 -07006953 for (i = 0; i < adapter->num_xdp_queues; i++) {
6954 struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
6955
6956 restart_queue += xdp_ring->tx_stats.restart_queue;
6957 tx_busy += xdp_ring->tx_stats.tx_busy;
6958 bytes += xdp_ring->stats.bytes;
6959 packets += xdp_ring->stats.packets;
6960 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08006961 adapter->restart_queue = restart_queue;
6962 adapter->tx_busy = tx_busy;
6963 netdev->stats.tx_bytes = bytes;
6964 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006965
Joe Perches7ca647b2010-09-07 21:35:40 +00006966 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006967
6968 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006969 for (i = 0; i < 8; i++) {
6970 /* for packet buffers not used, the register should read 0 */
6971 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6972 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006973 hwstats->mpc[i] += mpc;
6974 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006975 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6976 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006977 switch (hw->mac.type) {
6978 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006979 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6980 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6981 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006982 hwstats->pxonrxc[i] +=
6983 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006984 break;
6985 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006986 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006987 case ixgbe_mac_X550:
6988 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006989 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006990 hwstats->pxonrxc[i] +=
6991 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006992 break;
6993 default:
6994 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006995 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006996 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006997
6998 /*16 register reads */
6999 for (i = 0; i < 16; i++) {
7000 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
7001 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
7002 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007003 (hw->mac.type == ixgbe_mac_X540) ||
7004 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07007005 (hw->mac.type == ixgbe_mac_X550EM_x) ||
7006 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00007007 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
7008 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
7009 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
7010 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
7011 }
7012 }
7013
Joe Perches7ca647b2010-09-07 21:35:40 +00007014 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08007015 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00007016 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07007017
John Fastabendc84d3242010-11-16 19:27:12 -08007018 ixgbe_update_xoff_received(adapter);
7019
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08007020 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08007021 switch (hw->mac.type) {
7022 case ixgbe_mac_82598EB:
7023 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08007024 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
7025 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
7026 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
7027 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08007028 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007029 case ixgbe_mac_X550:
7030 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07007031 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007032 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00007033 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
7034 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
7035 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
7036 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
Tony Nguyen93df9462017-05-31 04:43:47 -07007037 /* fall through */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00007038 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00007039 for (i = 0; i < 16; i++)
7040 adapter->hw_rx_no_dma_resources +=
7041 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00007042 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08007043 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00007044 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08007045 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00007046 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08007047 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00007048 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00007049 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
7050 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00007051#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00007052 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
7053 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
7054 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
7055 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
7056 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
7057 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00007058 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00007059 if (adapter->fcoe.ddp_pool) {
7060 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
7061 struct ixgbe_fcoe_ddp_pool *ddp_pool;
7062 unsigned int cpu;
7063 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00007064 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00007065 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
7066 noddp += ddp_pool->noddp;
7067 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00007068 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00007069 hwstats->fcoe_noddp = noddp;
7070 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00007071 }
Yi Zou6d455222009-05-13 13:12:16 +00007072#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08007073 break;
7074 default:
7075 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007076 }
Auke Kok9a799d72007-09-15 14:07:45 -07007077 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00007078 hwstats->bprc += bprc;
7079 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007080 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00007081 hwstats->mprc -= bprc;
7082 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
7083 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
7084 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
7085 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
7086 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
7087 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
7088 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
7089 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08007090 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00007091 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08007092 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00007093 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00007094 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
7095 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08007096 /*
7097 * 82598 errata - tx of flow control packets is included in tx counters
7098 */
7099 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00007100 hwstats->gptc -= xon_off_tot;
7101 hwstats->mptc -= xon_off_tot;
7102 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
7103 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
7104 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
7105 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
7106 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
7107 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
7108 hwstats->ptc64 -= xon_off_tot;
7109 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
7110 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
7111 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
7112 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
7113 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
7114 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07007115
7116 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00007117 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07007118
7119 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00007120 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00007121 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00007122 netdev->stats.rx_length_errors = hwstats->rlec;
7123 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00007124 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07007125}
7126
7127/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00007128 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007129 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07007130 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00007131static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07007132{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007133 struct ixgbe_hw *hw = &adapter->hw;
7134 int i;
7135
Alexander Duyckd034acf2011-04-27 09:25:34 +00007136 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
7137 return;
7138
7139 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
7140
7141 /* if interface is down do nothing */
7142 if (test_bit(__IXGBE_DOWN, &adapter->state))
7143 return;
7144
7145 /* do nothing if we are not using signature filters */
7146 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
7147 return;
7148
7149 adapter->fdir_overflow++;
7150
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007151 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
7152 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08007153 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00007154 &(adapter->tx_ring[i]->state));
John Fastabend33fdc822017-04-24 03:30:18 -07007155 for (i = 0; i < adapter->num_xdp_queues; i++)
7156 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
7157 &adapter->xdp_ring[i]->state);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007158 /* re-enable flow director interrupts */
7159 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007160 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00007161 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00007162 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007163 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007164}
7165
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007166/**
7167 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007168 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007169 *
7170 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007171 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007172 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007173 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007174 */
7175static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
7176{
Auke Kok9a799d72007-09-15 14:07:45 -07007177 struct ixgbe_hw *hw = &adapter->hw;
7178 u64 eics = 0;
7179 int i;
7180
Mark Rustad09f40ae2014-01-14 18:53:11 -08007181 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007182 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007183 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007184 test_bit(__IXGBE_RESETTING, &adapter->state))
7185 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00007186
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007187 /* Force detection of hung controller */
7188 if (netif_carrier_ok(adapter->netdev)) {
7189 for (i = 0; i < adapter->num_tx_queues; i++)
7190 set_check_for_tx_hang(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07007191 for (i = 0; i < adapter->num_xdp_queues; i++)
7192 set_check_for_tx_hang(adapter->xdp_ring[i]);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007193 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007194
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007195 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00007196 /*
7197 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007198 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00007199 * would set *both* EIMS and EICS for any bit in EIAM
7200 */
7201 IXGBE_WRITE_REG(hw, IXGBE_EICS,
7202 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007203 } else {
7204 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00007205 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007206 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00007207 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07007208 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007209 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007210 }
7211
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007212 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00007213 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00007214}
7215
7216/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007217 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007218 * @adapter: pointer to the device adapter structure
7219 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007220 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007221static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007222{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007223 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007224 u32 link_speed = adapter->link_speed;
7225 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00007226 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007227
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007228 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
7229 return;
7230
7231 if (hw->mac.ops.check_link) {
7232 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007233 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007234 /* always assume link is up, if no check link function */
7235 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
7236 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007237 }
Alexander Duyck041441d2012-04-19 17:48:48 +00007238
7239 if (adapter->ixgbe_ieee_pfc)
7240 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
7241
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007242 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00007243 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007244 ixgbe_set_rx_drop_en(adapter);
7245 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007246
7247 if (link_up ||
7248 time_after(jiffies, (adapter->link_check_timeout +
7249 IXGBE_TRY_LINK_TIMEOUT))) {
7250 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
7251 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
7252 IXGBE_WRITE_FLUSH(hw);
7253 }
7254
7255 adapter->link_up = link_up;
7256 adapter->link_speed = link_speed;
7257}
7258
Alexander Duyck107d3012012-10-02 00:17:03 +00007259static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
7260{
7261#ifdef CONFIG_IXGBE_DCB
7262 struct net_device *netdev = adapter->netdev;
7263 struct dcb_app app = {
7264 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
7265 .protocol = 0,
7266 };
7267 u8 up = 0;
7268
7269 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
7270 up = dcb_ieee_getapp_mask(netdev, &app);
7271
7272 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
7273#endif
7274}
7275
David Ahern1cd127f2016-10-17 19:15:48 -07007276static int ixgbe_enable_macvlan(struct net_device *upper, void *data)
7277{
7278 if (netif_is_macvlan(upper)) {
7279 struct macvlan_dev *vlan = netdev_priv(upper);
7280
7281 if (vlan->fwd_priv)
7282 netif_tx_wake_all_queues(upper);
7283 }
7284
7285 return 0;
7286}
7287
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007288/**
7289 * ixgbe_watchdog_link_is_up - update netif_carrier status and
7290 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007291 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007292 **/
7293static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
7294{
7295 struct net_device *netdev = adapter->netdev;
7296 struct ixgbe_hw *hw = &adapter->hw;
7297 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07007298 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007299 bool flow_rx, flow_tx;
7300
7301 /* only continue if link was previously down */
7302 if (netif_carrier_ok(netdev))
7303 return;
7304
7305 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7306
7307 switch (hw->mac.type) {
7308 case ixgbe_mac_82598EB: {
7309 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
7310 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
7311 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
7312 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
7313 }
7314 break;
7315 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007316 case ixgbe_mac_X550:
7317 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07007318 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007319 case ixgbe_mac_82599EB: {
7320 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
7321 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
7322 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
7323 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
7324 }
7325 break;
7326 default:
7327 flow_tx = false;
7328 flow_rx = false;
7329 break;
7330 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007331
Jacob Keller6cb562d2012-12-05 07:24:41 +00007332 adapter->last_rx_ptp_check = jiffies;
7333
Jacob Keller8fecf672013-06-21 08:14:32 +00007334 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007335 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007336
Mark Rustad454adb02015-07-10 14:19:22 -07007337 switch (link_speed) {
7338 case IXGBE_LINK_SPEED_10GB_FULL:
7339 speed_str = "10 Gbps";
7340 break;
7341 case IXGBE_LINK_SPEED_2_5GB_FULL:
7342 speed_str = "2.5 Gbps";
7343 break;
7344 case IXGBE_LINK_SPEED_1GB_FULL:
7345 speed_str = "1 Gbps";
7346 break;
7347 case IXGBE_LINK_SPEED_100_FULL:
7348 speed_str = "100 Mbps";
7349 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08007350 case IXGBE_LINK_SPEED_10_FULL:
7351 speed_str = "10 Mbps";
7352 break;
Mark Rustad454adb02015-07-10 14:19:22 -07007353 default:
7354 speed_str = "unknown speed";
7355 break;
7356 }
7357 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007358 ((flow_rx && flow_tx) ? "RX/TX" :
7359 (flow_rx ? "RX" :
7360 (flow_tx ? "TX" : "None"))));
7361
7362 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007363 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007364
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007365 /* enable transmits */
7366 netif_tx_wake_all_queues(adapter->netdev);
7367
7368 /* enable any upper devices */
7369 rtnl_lock();
David Ahern1cd127f2016-10-17 19:15:48 -07007370 netdev_walk_all_upper_dev_rcu(adapter->netdev,
7371 ixgbe_enable_macvlan, NULL);
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007372 rtnl_unlock();
7373
Alexander Duyck107d3012012-10-02 00:17:03 +00007374 /* update the default user priority for VFs */
7375 ixgbe_update_default_up(adapter);
7376
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007377 /* ping all the active vfs to let them know link has changed */
7378 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007379}
7380
7381/**
7382 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7383 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007384 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007385 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00007386static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007387{
7388 struct net_device *netdev = adapter->netdev;
7389 struct ixgbe_hw *hw = &adapter->hw;
7390
7391 adapter->link_up = false;
7392 adapter->link_speed = 0;
7393
7394 /* only continue if link was up previously */
7395 if (!netif_carrier_ok(netdev))
7396 return;
7397
7398 /* poll for SFP+ cable when link is down */
7399 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
7400 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
7401
Jacob Keller8fecf672013-06-21 08:14:32 +00007402 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007403 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007404
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007405 e_info(drv, "NIC Link is Down\n");
7406 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007407
7408 /* ping all the active vfs to let them know link has changed */
7409 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007410}
7411
Emil Tantilov07923c12014-08-12 07:12:08 +00007412static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
7413{
7414 int i;
7415
7416 for (i = 0; i < adapter->num_tx_queues; i++) {
7417 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
7418
7419 if (tx_ring->next_to_use != tx_ring->next_to_clean)
7420 return true;
7421 }
7422
John Fastabend33fdc822017-04-24 03:30:18 -07007423 for (i = 0; i < adapter->num_xdp_queues; i++) {
7424 struct ixgbe_ring *ring = adapter->xdp_ring[i];
7425
7426 if (ring->next_to_use != ring->next_to_clean)
7427 return true;
7428 }
7429
Emil Tantilov07923c12014-08-12 07:12:08 +00007430 return false;
7431}
7432
7433static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
7434{
7435 struct ixgbe_hw *hw = &adapter->hw;
7436 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
7437 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
7438
7439 int i, j;
7440
7441 if (!adapter->num_vfs)
7442 return false;
7443
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007444 /* resetting the PF is only needed for MAC before X550 */
7445 if (hw->mac.type >= ixgbe_mac_X550)
7446 return false;
7447
Emil Tantilov07923c12014-08-12 07:12:08 +00007448 for (i = 0; i < adapter->num_vfs; i++) {
7449 for (j = 0; j < q_per_pool; j++) {
7450 u32 h, t;
7451
7452 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
7453 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
7454
7455 if (h != t)
7456 return true;
7457 }
7458 }
7459
7460 return false;
7461}
7462
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007463/**
7464 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007465 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007466 **/
7467static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
7468{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007469 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00007470 if (ixgbe_ring_tx_pending(adapter) ||
7471 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007472 /* We've lost link, so the controller stops DMA,
7473 * but we've got queued Tx work that's never going
7474 * to get done, so reset controller to flush Tx.
7475 * (Do the reset outside of interrupt context).
7476 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00007477 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007478 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007479 }
7480 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007481}
7482
Emil Tantilov9079e412014-11-19 03:18:19 +00007483#ifdef CONFIG_PCI_IOV
Emil Tantilov9079e412014-11-19 03:18:19 +00007484static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
7485{
7486 struct ixgbe_hw *hw = &adapter->hw;
7487 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07007488 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00007489 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00007490
7491 if (!(netif_carrier_ok(adapter->netdev)))
7492 return;
7493
7494 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
7495 if (gpc) /* If incrementing then no need for the check below */
7496 return;
7497 /* Check to see if a bad DMA write target from an errant or
7498 * malicious VF has caused a PCIe error. If so then we can
7499 * issue a VFLR to the offending VF(s) and then resume without
7500 * requesting a full slot reset.
7501 */
7502
7503 if (!pdev)
7504 return;
7505
Emil Tantilov9079e412014-11-19 03:18:19 +00007506 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07007507 for (vf = 0; vf < adapter->num_vfs; ++vf) {
7508 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
7509 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00007510
Mark Rustad988d1302015-10-30 15:29:34 -07007511 if (!vfdev)
7512 continue;
7513 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
7514 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
7515 status_reg & PCI_STATUS_REC_MASTER_ABORT)
Christoph Hellwig63af8f72017-04-14 21:11:28 +02007516 pcie_flr(vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00007517 }
7518}
7519
Greg Rosea985b6c32010-11-18 03:02:52 +00007520static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
7521{
7522 u32 ssvpc;
7523
Greg Rose0584d992012-08-08 00:00:58 +00007524 /* Do not perform spoof check for 82598 or if not in IOV mode */
7525 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7526 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00007527 return;
7528
7529 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
7530
7531 /*
7532 * ssvpc register is cleared on read, if zero then no
7533 * spoofed packets in the last interval.
7534 */
7535 if (!ssvpc)
7536 return;
7537
Emil Tantilovd6ea0752012-08-08 06:28:37 +00007538 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00007539}
Emil Tantilov9079e412014-11-19 03:18:19 +00007540#else
7541static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7542{
7543}
7544
7545static void
7546ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7547{
7548}
7549#endif /* CONFIG_PCI_IOV */
7550
Greg Rosea985b6c32010-11-18 03:02:52 +00007551
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007552/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007553 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007554 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007555 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007556static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007557{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007558 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007559 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007560 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007561 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007562 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007563
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007564 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007565
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007566 if (adapter->link_up)
7567 ixgbe_watchdog_link_is_up(adapter);
7568 else
7569 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007570
Emil Tantilov9079e412014-11-19 03:18:19 +00007571 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007572 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007573 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007574
7575 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007576}
7577
Alexander Duyck70864002011-04-27 09:13:56 +00007578/**
7579 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007580 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007581 **/
7582static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7583{
7584 struct ixgbe_hw *hw = &adapter->hw;
7585 s32 err;
7586
7587 /* not searching for SFP so there is nothing to do here */
7588 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7589 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7590 return;
7591
Mark Rustad58e7cd22015-08-08 16:18:48 -07007592 if (adapter->sfp_poll_time &&
7593 time_after(adapter->sfp_poll_time, jiffies))
7594 return; /* If not yet time to poll for SFP */
7595
Alexander Duyck70864002011-04-27 09:13:56 +00007596 /* someone else is in init, wait until next service event */
7597 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7598 return;
7599
Mark Rustad58e7cd22015-08-08 16:18:48 -07007600 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7601
Alexander Duyck70864002011-04-27 09:13:56 +00007602 err = hw->phy.ops.identify_sfp(hw);
7603 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7604 goto sfp_out;
7605
7606 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7607 /* If no cable is present, then we need to reset
7608 * the next time we find a good cable. */
7609 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7610 }
7611
7612 /* exit on error */
7613 if (err)
7614 goto sfp_out;
7615
7616 /* exit if reset not needed */
7617 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7618 goto sfp_out;
7619
7620 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7621
7622 /*
7623 * A module may be identified correctly, but the EEPROM may not have
7624 * support for that module. setup_sfp() will fail in that case, so
7625 * we should not allow that module to load.
7626 */
7627 if (hw->mac.type == ixgbe_mac_82598EB)
7628 err = hw->phy.ops.reset(hw);
7629 else
7630 err = hw->mac.ops.setup_sfp(hw);
7631
7632 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7633 goto sfp_out;
7634
7635 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7636 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7637
7638sfp_out:
7639 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7640
7641 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7642 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7643 e_dev_err("failed to initialize because an unsupported "
7644 "SFP+ module type was detected.\n");
7645 e_dev_err("Reload the driver after installing a "
7646 "supported module.\n");
7647 unregister_netdev(adapter->netdev);
7648 }
7649}
7650
7651/**
7652 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007653 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007654 **/
7655static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7656{
7657 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00007658 u32 speed;
7659 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007660
7661 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7662 return;
7663
7664 /* someone else is in init, wait until next service event */
7665 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7666 return;
7667
7668 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7669
Josh Hay3d292262012-12-15 03:28:19 +00007670 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00007671 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00007672 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007673
7674 /* setup the highest link when no autoneg */
7675 if (!autoneg) {
7676 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
7677 speed = IXGBE_LINK_SPEED_10GB_FULL;
7678 }
7679 }
7680
Alexander Duyck70864002011-04-27 09:13:56 +00007681 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007682 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007683
7684 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7685 adapter->link_check_timeout = jiffies;
7686 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7687}
7688
7689/**
7690 * ixgbe_service_timer - Timer Call-back
7691 * @data: pointer to adapter cast into an unsigned long
7692 **/
Kees Cook26566ea2017-10-16 17:29:35 -07007693static void ixgbe_service_timer(struct timer_list *t)
Alexander Duyck70864002011-04-27 09:13:56 +00007694{
Kees Cook26566ea2017-10-16 17:29:35 -07007695 struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer);
Alexander Duyck70864002011-04-27 09:13:56 +00007696 unsigned long next_event_offset;
7697
7698 /* poll faster when waiting for link */
7699 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7700 next_event_offset = HZ / 10;
7701 else
7702 next_event_offset = HZ * 2;
7703
7704 /* Reset the timer */
7705 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7706
Emil Tantilov9079e412014-11-19 03:18:19 +00007707 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007708}
7709
Don Skidmore597f22d2015-06-09 16:52:02 -07007710static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7711{
7712 struct ixgbe_hw *hw = &adapter->hw;
7713 u32 status;
7714
7715 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7716 return;
7717
7718 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7719
7720 if (!hw->phy.ops.handle_lasi)
7721 return;
7722
7723 status = hw->phy.ops.handle_lasi(&adapter->hw);
7724 if (status != IXGBE_ERR_OVERTEMP)
7725 return;
7726
7727 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7728}
7729
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007730static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7731{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007732 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007733 return;
7734
Mark Rustad09f40ae2014-01-14 18:53:11 -08007735 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007736 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007737 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007738 test_bit(__IXGBE_RESETTING, &adapter->state))
7739 return;
7740
7741 ixgbe_dump(adapter);
7742 netdev_err(adapter->netdev, "Reset adapter\n");
7743 adapter->tx_timeout_count++;
7744
John Fastabend8f4c5c92014-01-16 02:30:05 -08007745 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007746 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007747 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007748}
7749
Alexander Duyck70864002011-04-27 09:13:56 +00007750/**
7751 * ixgbe_service_task - manages and runs subtasks
7752 * @work: pointer to work_struct containing our data
7753 **/
7754static void ixgbe_service_task(struct work_struct *work)
7755{
7756 struct ixgbe_adapter *adapter = container_of(work,
7757 struct ixgbe_adapter,
7758 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007759 if (ixgbe_removed(adapter->hw.hw_addr)) {
7760 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7761 rtnl_lock();
7762 ixgbe_down(adapter);
7763 rtnl_unlock();
7764 }
7765 ixgbe_service_event_complete(adapter);
7766 return;
7767 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007768 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007769 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007770 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007771 udp_tunnel_get_rx_info(adapter->netdev);
7772 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007773 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007774 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007775 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007776 ixgbe_sfp_detection_subtask(adapter);
7777 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007778 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007779 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007780 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007781 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007782
Jacob Keller8fecf672013-06-21 08:14:32 +00007783 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007784 ixgbe_ptp_overflow_check(adapter);
7785 ixgbe_ptp_rx_hang(adapter);
Jacob Keller622a2ef2017-05-03 10:29:04 -07007786 ixgbe_ptp_tx_hang(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007787 }
Alexander Duyck70864002011-04-27 09:13:56 +00007788
7789 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007790}
7791
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007792static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7793 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007794 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007795{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007796 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007797 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007798 union {
7799 struct iphdr *v4;
7800 struct ipv6hdr *v6;
7801 unsigned char *hdr;
7802 } ip;
7803 union {
7804 struct tcphdr *tcp;
7805 unsigned char *hdr;
7806 } l4;
7807 u32 paylen, l4_offset;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007808 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007809
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007810 if (skb->ip_summed != CHECKSUM_PARTIAL)
7811 return 0;
7812
Alexander Duyck897ab152011-05-27 05:31:47 +00007813 if (!skb_is_gso(skb))
7814 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007815
Francois Romieu2049e1f2014-03-30 03:14:27 +00007816 err = skb_cow_head(skb, 0);
7817 if (err < 0)
7818 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007819
Scott Peterson2a205252016-11-18 11:25:42 -08007820 if (eth_p_mpls(first->protocol))
7821 ip.hdr = skb_inner_network_header(skb);
7822 else
7823 ip.hdr = skb_network_header(skb);
Alexander Duyckb83e3012016-04-14 17:19:31 -04007824 l4.hdr = skb_checksum_start(skb);
7825
Alexander Duyck897ab152011-05-27 05:31:47 +00007826 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7827 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7828
Alexander Duyckb83e3012016-04-14 17:19:31 -04007829 /* initialize outer IP header fields */
7830 if (ip.v4->version == 4) {
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007831 unsigned char *csum_start = skb_checksum_start(skb);
7832 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
7833
Alexander Duyckb83e3012016-04-14 17:19:31 -04007834 /* IP header will have to cancel out any data that
7835 * is not a part of the outer IP header
7836 */
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007837 ip.v4->check = csum_fold(csum_partial(trans_start,
7838 csum_start - trans_start,
7839 0));
Alexander Duyck897ab152011-05-27 05:31:47 +00007840 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007841
7842 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007843 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7844 IXGBE_TX_FLAGS_CSUM |
7845 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007846 } else {
7847 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007848 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7849 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007850 }
7851
Alexander Duyckb83e3012016-04-14 17:19:31 -04007852 /* determine offset of inner transport header */
7853 l4_offset = l4.hdr - skb->data;
7854
7855 /* compute length of segmentation header */
7856 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7857
7858 /* remove payload length from inner checksum */
7859 paylen = skb->len - l4_offset;
7860 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007861
Alexander Duyck091a6242012-02-08 07:51:01 +00007862 /* update gso size and bytecount with header size */
7863 first->gso_segs = skb_shinfo(skb)->gso_segs;
7864 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7865
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007866 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007867 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007868 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007869
7870 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007871 vlan_macip_lens = l4.hdr - ip.hdr;
7872 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007873 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007874
7875 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007876 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007877
7878 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007879}
7880
Alexander Duyck49763de2016-01-13 07:31:11 -08007881static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7882{
7883 unsigned int offset = 0;
7884
7885 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7886
7887 return offset == skb_checksum_start_offset(skb);
7888}
7889
Alexander Duyck244e27a2012-02-08 07:51:11 +00007890static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7891 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007892{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007893 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007894 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007895 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007896
Alexander Duyck897ab152011-05-27 05:31:47 +00007897 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007898csum_failed:
7899 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7900 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007901 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007902 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007903 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007904
Alexander Duyck49763de2016-01-13 07:31:11 -08007905 switch (skb->csum_offset) {
7906 case offsetof(struct tcphdr, check):
7907 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7908 /* fall through */
7909 case offsetof(struct udphdr, check):
7910 break;
7911 case offsetof(struct sctphdr, checksum):
7912 /* validate that this is actually an SCTP request */
7913 if (((first->protocol == htons(ETH_P_IP)) &&
7914 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7915 ((first->protocol == htons(ETH_P_IPV6)) &&
7916 ixgbe_ipv6_csum_is_sctp(skb))) {
7917 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7918 break;
7919 }
7920 /* fall through */
7921 default:
7922 skb_checksum_help(skb);
7923 goto csum_failed;
7924 }
7925
7926 /* update TX checksum flag */
7927 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7928 vlan_macip_lens = skb_checksum_start_offset(skb) -
7929 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007930no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007931 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007932 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007933 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007934
Alexander Duyck49763de2016-01-13 07:31:11 -08007935 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007936}
7937
Alexander Duyck472148c2012-11-07 02:34:28 +00007938#define IXGBE_SET_FLAG(_input, _flag, _result) \
7939 ((_flag <= _result) ? \
7940 ((u32)(_input & _flag) * (_result / _flag)) : \
7941 ((u32)(_input & _flag) / (_flag / _result)))
7942
7943static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007944{
7945 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007946 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7947 IXGBE_ADVTXD_DCMD_DEXT |
7948 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007949
7950 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007951 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7952 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007953
Alexander Duyckd3d00232011-07-15 02:31:25 +00007954 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007955 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7956 IXGBE_ADVTXD_DCMD_TSE);
7957
7958 /* set timestamp bit if present */
7959 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7960 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007961
Alexander Duyck62748b72012-07-20 08:09:01 +00007962 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007963 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007964
Alexander Duyckd3d00232011-07-15 02:31:25 +00007965 return cmd_type;
7966}
7967
Alexander Duyck729739b2012-02-08 07:51:06 +00007968static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7969 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007970{
Alexander Duyck472148c2012-11-07 02:34:28 +00007971 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007972
7973 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007974 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7975 IXGBE_TX_FLAGS_CSUM,
7976 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007977
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007978 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007979 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7980 IXGBE_TX_FLAGS_IPV4,
7981 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007982
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007983 /*
7984 * Check Context must be set if Tx switch is enabled, which it
7985 * always is for case where virtual functions are running
7986 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007987 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7988 IXGBE_TX_FLAGS_CC,
7989 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007990
Alexander Duyck472148c2012-11-07 02:34:28 +00007991 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007992}
7993
Daniel Borkmann2367a172014-08-26 19:34:18 +02007994static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7995{
7996 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7997
7998 /* Herbert's original patch had:
7999 * smp_mb__after_netif_stop_queue();
8000 * but since that doesn't exist yet, just open code it.
8001 */
8002 smp_mb();
8003
8004 /* We need to check again in a case another CPU has just
8005 * made room available.
8006 */
8007 if (likely(ixgbe_desc_unused(tx_ring) < size))
8008 return -EBUSY;
8009
8010 /* A reprieve! - use start_queue because it doesn't call schedule */
8011 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
8012 ++tx_ring->tx_stats.restart_queue;
8013 return 0;
8014}
8015
8016static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
8017{
8018 if (likely(ixgbe_desc_unused(tx_ring) >= size))
8019 return 0;
8020
8021 return __ixgbe_maybe_stop_tx(tx_ring, size);
8022}
8023
Alexander Duyckd3d00232011-07-15 02:31:25 +00008024#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
8025 IXGBE_TXD_CMD_RS)
8026
Jacob Keller5fef1242017-05-03 10:28:56 -07008027static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
8028 struct ixgbe_tx_buffer *first,
8029 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07008030{
Alexander Duyck729739b2012-02-08 07:51:06 +00008031 struct sk_buff *skb = first->skb;
8032 struct ixgbe_tx_buffer *tx_buffer;
8033 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00008034 struct skb_frag_struct *frag;
8035 dma_addr_t dma;
8036 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008037 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00008038 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008039 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07008040
Alexander Duyck729739b2012-02-08 07:51:06 +00008041 tx_desc = IXGBE_TX_DESC(tx_ring, i);
8042
Alexander Duyckec718252012-10-30 06:01:55 +00008043 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
8044
8045 size = skb_headlen(skb);
8046 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00008047
Alexander Duyckd3d00232011-07-15 02:31:25 +00008048#ifdef IXGBE_FCOE
8049 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00008050 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00008051 size -= sizeof(struct fcoe_crc_eof) - data_len;
8052 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00008053 } else {
8054 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00008055 }
Auke Kok9a799d72007-09-15 14:07:45 -07008056 }
8057
Alexander Duyckd3d00232011-07-15 02:31:25 +00008058#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00008059 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008060
Alexander Duyckec718252012-10-30 06:01:55 +00008061 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008062
Alexander Duyckec718252012-10-30 06:01:55 +00008063 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
8064 if (dma_mapping_error(tx_ring->dev, dma))
8065 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008066
Alexander Duyckec718252012-10-30 06:01:55 +00008067 /* record length, and DMA address */
8068 dma_unmap_len_set(tx_buffer, len, size);
8069 dma_unmap_addr_set(tx_buffer, dma, dma);
8070
8071 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8072
Alexander Duyck729739b2012-02-08 07:51:06 +00008073 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00008074 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00008075 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008076
Alexander Duyckd3d00232011-07-15 02:31:25 +00008077 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00008078 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008079 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00008080 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008081 i = 0;
8082 }
Alexander Duyckec718252012-10-30 06:01:55 +00008083 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00008084
8085 dma += IXGBE_MAX_DATA_PER_TXD;
8086 size -= IXGBE_MAX_DATA_PER_TXD;
8087
8088 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008089 }
8090
Alexander Duyck729739b2012-02-08 07:51:06 +00008091 if (likely(!data_len))
8092 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008093
Alexander Duyck472148c2012-11-07 02:34:28 +00008094 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008095
Alexander Duyck729739b2012-02-08 07:51:06 +00008096 i++;
8097 tx_desc++;
8098 if (i == tx_ring->count) {
8099 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
8100 i = 0;
8101 }
Alexander Duyckec718252012-10-30 06:01:55 +00008102 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008103
Alexander Duyckd3d00232011-07-15 02:31:25 +00008104#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00008105 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00008106#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00008107 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008108#endif
8109 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07008110
Alexander Duyck729739b2012-02-08 07:51:06 +00008111 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
8112 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07008113
Alexander Duyck729739b2012-02-08 07:51:06 +00008114 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07008115 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00008116
Alexander Duyck729739b2012-02-08 07:51:06 +00008117 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00008118 cmd_type |= size | IXGBE_TXD_CMD;
8119 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008120
Alexander Duyck091a6242012-02-08 07:51:01 +00008121 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00008122
Alexander Duyckd3d00232011-07-15 02:31:25 +00008123 /* set the timestamp */
8124 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07008125
8126 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00008127 * Force memory writes to complete before letting h/w know there
8128 * are new descriptors to fetch. (Only applicable for weak-ordered
8129 * memory model archs, such as IA-64).
8130 *
8131 * We also need this memory barrier to make certain all of the
8132 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07008133 */
8134 wmb();
8135
Alexander Duyckd3d00232011-07-15 02:31:25 +00008136 /* set next_to_watch value indicating a packet is present */
8137 first->next_to_watch = tx_desc;
8138
Alexander Duyck729739b2012-02-08 07:51:06 +00008139 i++;
8140 if (i == tx_ring->count)
8141 i = 0;
8142
8143 tx_ring->next_to_use = i;
8144
Daniel Borkmann2367a172014-08-26 19:34:18 +02008145 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
8146
8147 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00008148 writel(i, tx_ring->tail);
8149
8150 /* we need this if more than one processor can write to our tail
8151 * at a time, it synchronizes IO on IA64/Altix systems
8152 */
8153 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02008154 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02008155
Jacob Keller5fef1242017-05-03 10:28:56 -07008156 return 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008157dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00008158 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00008159
8160 /* clear dma mappings for failed tx_buffer_info map */
Alexander Duyck069db9c2017-10-19 17:07:13 -04008161 for (;;) {
8162 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckffed21b2017-01-17 08:37:29 -08008163 if (dma_unmap_len(tx_buffer, len))
8164 dma_unmap_page(tx_ring->dev,
8165 dma_unmap_addr(tx_buffer, dma),
8166 dma_unmap_len(tx_buffer, len),
8167 DMA_TO_DEVICE);
8168 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyck069db9c2017-10-19 17:07:13 -04008169 if (tx_buffer == first)
8170 break;
8171 if (i == 0)
Alexander Duyckffed21b2017-01-17 08:37:29 -08008172 i += tx_ring->count;
Alexander Duyck069db9c2017-10-19 17:07:13 -04008173 i--;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008174 }
8175
Alexander Duyckffed21b2017-01-17 08:37:29 -08008176 dev_kfree_skb_any(first->skb);
8177 first->skb = NULL;
8178
Alexander Duyckd3d00232011-07-15 02:31:25 +00008179 tx_ring->next_to_use = i;
Jacob Keller5fef1242017-05-03 10:28:56 -07008180
8181 return -1;
Auke Kok9a799d72007-09-15 14:07:45 -07008182}
8183
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008184static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00008185 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008186{
Alexander Duyck69830522011-01-06 14:29:58 +00008187 struct ixgbe_q_vector *q_vector = ring->q_vector;
8188 union ixgbe_atr_hash_dword input = { .dword = 0 };
8189 union ixgbe_atr_hash_dword common = { .dword = 0 };
8190 union {
8191 unsigned char *network;
8192 struct iphdr *ipv4;
8193 struct ipv6hdr *ipv6;
8194 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08008195 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08008196 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07008197 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00008198 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08008199 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008200
Alexander Duyck69830522011-01-06 14:29:58 +00008201 /* if ring doesn't have a interrupt vector, cannot perform ATR */
8202 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00008203 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008204
Alexander Duyck69830522011-01-06 14:29:58 +00008205 /* do nothing if sampling is disabled */
8206 if (!ring->atr_sample_rate)
8207 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008208
Alexander Duyck69830522011-01-06 14:29:58 +00008209 ring->atr_count++;
8210
Alexander Duycke2873d42016-01-25 19:39:40 -08008211 /* currently only IPv4/IPv6 with TCP is supported */
8212 if ((first->protocol != htons(ETH_P_IP)) &&
8213 (first->protocol != htons(ETH_P_IPV6)))
8214 return;
8215
Alexander Duyck69830522011-01-06 14:29:58 +00008216 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07008217 skb = first->skb;
8218 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008219 if (unlikely(hdr.network <= skb->data))
8220 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08008221 if (skb->encapsulation &&
8222 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07008223 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07008224 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00008225
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008226 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8227 VXLAN_HEADROOM))
8228 return;
8229
Alexander Duyck9f12df92016-01-25 19:36:29 -08008230 /* verify the port is recognized as VXLAN */
8231 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08008232 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08008233 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07008234
8235 if (adapter->geneve_port &&
8236 udp_hdr(skb)->dest == adapter->geneve_port)
8237 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08008238 }
8239
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008240 /* Make sure we have at least [minimum IPv4 header + TCP]
8241 * or [IPv6 header] bytes
8242 */
8243 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
8244 return;
8245
Mark Rustade19dcde2015-12-09 14:55:37 -08008246 /* Currently only IPv4/IPv6 with TCP is supported */
8247 switch (hdr.ipv4->version) {
8248 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08008249 /* access ihl as u8 to avoid unaligned access on ia64 */
8250 hlen = (hdr.network[0] & 0x0F) << 2;
8251 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08008252 break;
8253 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08008254 hlen = hdr.network - skb->data;
8255 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
8256 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08008257 break;
8258 default:
8259 return;
Mark Rustad67359c32015-06-15 11:33:25 -07008260 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008261
Alexander Duycke2873d42016-01-25 19:39:40 -08008262 if (l4_proto != IPPROTO_TCP)
8263 return;
8264
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008265 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8266 hlen + sizeof(struct tcphdr)))
8267 return;
8268
Alexander Duycke2873d42016-01-25 19:39:40 -08008269 th = (struct tcphdr *)(hdr.network + hlen);
8270
8271 /* skip this packet since the socket is closing */
8272 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00008273 return;
8274
8275 /* sample on all syn packets or once every atr sample count */
8276 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
8277 return;
8278
8279 /* reset sample count */
8280 ring->atr_count = 0;
8281
Alexander Duyck244e27a2012-02-08 07:51:11 +00008282 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00008283
8284 /*
8285 * src and dst are inverted, think how the receiver sees them
8286 *
8287 * The input is broken into two sections, a non-compressed section
8288 * containing vm_pool, vlan_id, and flow_type. The rest of the data
8289 * is XORed together and stored in the compressed dword.
8290 */
8291 input.formatted.vlan_id = vlan_id;
8292
8293 /*
8294 * since src port and flex bytes occupy the same word XOR them together
8295 * and write the value to source port portion of compressed dword
8296 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008297 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00008298 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00008299 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00008300 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00008301 common.port.dst ^= th->source;
8302
Mark Rustade19dcde2015-12-09 14:55:37 -08008303 switch (hdr.ipv4->version) {
8304 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00008305 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
8306 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08008307 break;
8308 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00008309 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
8310 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
8311 hdr.ipv6->saddr.s6_addr32[1] ^
8312 hdr.ipv6->saddr.s6_addr32[2] ^
8313 hdr.ipv6->saddr.s6_addr32[3] ^
8314 hdr.ipv6->daddr.s6_addr32[0] ^
8315 hdr.ipv6->daddr.s6_addr32[1] ^
8316 hdr.ipv6->daddr.s6_addr32[2] ^
8317 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08008318 break;
8319 default:
8320 break;
Alexander Duyck69830522011-01-06 14:29:58 +00008321 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008322
Alexander Duyck9f12df92016-01-25 19:36:29 -08008323 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07008324 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07008325
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008326 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00008327 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
8328 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008329}
8330
Jason Wangf663dd92014-01-10 16:18:26 +08008331static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01008332 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008333{
Jason Wangf663dd92014-01-10 16:18:26 +08008334 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
8335#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00008336 struct ixgbe_adapter *adapter;
8337 struct ixgbe_ring_feature *f;
8338 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08008339#endif
8340
8341 if (fwd_adapter)
8342 return skb->queue_mapping + fwd_adapter->tx_base_queue;
8343
8344#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00008345
Alexander Duyck97488bd2013-01-12 06:33:37 +00008346 /*
8347 * only execute the code below if protocol is FCoE
8348 * or FIP and we have FCoE enabled on the adapter
8349 */
8350 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00008351 case htons(ETH_P_FCOE):
8352 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00008353 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00008354
Alexander Duyck97488bd2013-01-12 06:33:37 +00008355 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8356 break;
Tony Nguyen93df9462017-05-31 04:43:47 -07008357 /* fall through */
Alexander Duyck97488bd2013-01-12 06:33:37 +00008358 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01008359 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00008360 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008361
Alexander Duyck97488bd2013-01-12 06:33:37 +00008362 f = &adapter->ring_feature[RING_F_FCOE];
8363
8364 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8365 smp_processor_id();
8366
8367 while (txq >= f->indices)
8368 txq -= f->indices;
8369
8370 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08008371#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01008372 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08008373#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008374}
8375
John Fastabend33fdc822017-04-24 03:30:18 -07008376static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
8377 struct xdp_buff *xdp)
8378{
8379 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
8380 struct ixgbe_tx_buffer *tx_buffer;
8381 union ixgbe_adv_tx_desc *tx_desc;
8382 u32 len, cmd_type;
8383 dma_addr_t dma;
8384 u16 i;
8385
8386 len = xdp->data_end - xdp->data;
8387
8388 if (unlikely(!ixgbe_desc_unused(ring)))
8389 return IXGBE_XDP_CONSUMED;
8390
8391 dma = dma_map_single(ring->dev, xdp->data, len, DMA_TO_DEVICE);
8392 if (dma_mapping_error(ring->dev, dma))
8393 return IXGBE_XDP_CONSUMED;
8394
8395 /* record the location of the first descriptor for this packet */
8396 tx_buffer = &ring->tx_buffer_info[ring->next_to_use];
8397 tx_buffer->bytecount = len;
8398 tx_buffer->gso_segs = 1;
8399 tx_buffer->protocol = 0;
8400
8401 i = ring->next_to_use;
8402 tx_desc = IXGBE_TX_DESC(ring, i);
8403
8404 dma_unmap_len_set(tx_buffer, len, len);
8405 dma_unmap_addr_set(tx_buffer, dma, dma);
8406 tx_buffer->data = xdp->data;
8407 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8408
8409 /* put descriptor type bits */
8410 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
8411 IXGBE_ADVTXD_DCMD_DEXT |
8412 IXGBE_ADVTXD_DCMD_IFCS;
8413 cmd_type |= len | IXGBE_TXD_CMD;
8414 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
8415 tx_desc->read.olinfo_status =
8416 cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT);
8417
John Fastabend7379f972017-03-28 09:47:03 -07008418 /* Avoid any potential race with xdp_xmit and cleanup */
8419 smp_wmb();
John Fastabend33fdc822017-04-24 03:30:18 -07008420
8421 /* set next_to_watch value indicating a packet is present */
8422 i++;
8423 if (i == ring->count)
8424 i = 0;
8425
8426 tx_buffer->next_to_watch = tx_desc;
8427 ring->next_to_use = i;
8428
John Fastabend33fdc822017-04-24 03:30:18 -07008429 return IXGBE_XDP_TX;
8430}
8431
Alexander Duyckfc77dc32010-11-16 19:26:51 -08008432netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00008433 struct ixgbe_adapter *adapter,
8434 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008435{
Alexander Duyckd3d00232011-07-15 02:31:25 +00008436 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00008437 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008438 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00008439 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00008440 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00008441 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00008442 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00008443
Alexander Duycka535c302011-05-27 05:31:52 +00008444 /*
8445 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00008446 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00008447 * + 2 desc gap to keep tail from touching head,
8448 * + 1 desc for context descriptor,
8449 * otherwise try next time
8450 */
Alexander Duycka535c302011-05-27 05:31:52 +00008451 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8452 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00008453
Alexander Duycka535c302011-05-27 05:31:52 +00008454 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8455 tx_ring->tx_stats.tx_busy++;
8456 return NETDEV_TX_BUSY;
8457 }
8458
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008459 /* record the location of the first descriptor for this packet */
8460 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8461 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00008462 first->bytecount = skb->len;
8463 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008464
Alexander Duyck66f32a82011-06-29 05:43:22 +00008465 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01008466 if (skb_vlan_tag_present(skb)) {
8467 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008468 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8469 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008470 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008471 struct vlan_hdr *vhdr, _vhdr;
8472 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8473 if (!vhdr)
8474 goto out_drop;
8475
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008476 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8477 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008478 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07008479 }
Toshiaki Makita02136682015-01-29 20:37:09 +09008480 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00008481
Mark Rustadd5234932014-08-09 07:02:09 +00008482 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
Jacob Keller4cc74c02017-05-03 10:29:00 -07008483 adapter->ptp_clock) {
8484 if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8485 &adapter->state)) {
8486 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8487 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00008488
Jacob Keller4cc74c02017-05-03 10:29:00 -07008489 /* schedule check for Tx timestamp */
8490 adapter->ptp_tx_skb = skb_get(skb);
8491 adapter->ptp_tx_start = jiffies;
8492 schedule_work(&adapter->ptp_tx_work);
8493 } else {
8494 adapter->tx_hwtstamp_skipped++;
8495 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008496 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008497
Jakub Kicinskiff29a862014-03-15 14:55:16 +00008498 skb_tx_timestamp(skb);
8499
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008500#ifdef CONFIG_PCI_IOV
8501 /*
8502 * Use the l2switch_enable flag - would be false if the DMA
8503 * Tx switch had been disabled.
8504 */
8505 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00008506 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008507
8508#endif
John Fastabend32701dc2011-09-27 03:51:56 +00008509 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00008510 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00008511 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8512 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008513 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00008514 tx_flags |= (skb->priority & 0x7) <<
8515 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008516 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8517 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00008518
8519 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00008520 goto out_drop;
8521 vhdr = (struct vlan_ethhdr *)skb->data;
8522 vhdr->h_vlan_TCI = htons(tx_flags >>
8523 IXGBE_TX_FLAGS_VLAN_SHIFT);
8524 } else {
8525 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8526 }
8527 }
Alexander Duycka535c302011-05-27 05:31:52 +00008528
Alexander Duyck244e27a2012-02-08 07:51:11 +00008529 /* record initial flags and protocol */
8530 first->tx_flags = tx_flags;
8531 first->protocol = protocol;
8532
Yi Zoueacd73f2009-05-13 13:11:06 +00008533#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00008534 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008535 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00008536 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00008537 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00008538 if (tso < 0)
8539 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07008540
Alexander Duyck66f32a82011-06-29 05:43:22 +00008541 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00008542 }
Auke Kok9a799d72007-09-15 14:07:45 -07008543
Auke Kok9a799d72007-09-15 14:07:45 -07008544#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008545 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008546 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07008547 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008548 else if (!tso)
8549 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008550
8551 /* add the ATR filter if ATR is on */
8552 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00008553 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008554
8555#ifdef IXGBE_FCOE
8556xmit_fcoe:
8557#endif /* IXGBE_FCOE */
Jacob Keller5fef1242017-05-03 10:28:56 -07008558 if (ixgbe_tx_map(tx_ring, first, hdr_len))
8559 goto cleanup_tx_timestamp;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008560
Auke Kok9a799d72007-09-15 14:07:45 -07008561 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00008562
8563out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008564 dev_kfree_skb_any(first->skb);
8565 first->skb = NULL;
Jacob Keller5fef1242017-05-03 10:28:56 -07008566cleanup_tx_timestamp:
8567 if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
8568 dev_kfree_skb_any(adapter->ptp_tx_skb);
8569 adapter->ptp_tx_skb = NULL;
8570 cancel_work_sync(&adapter->ptp_tx_work);
8571 clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state);
8572 }
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008573
Alexander Duyck897ab152011-05-27 05:31:47 +00008574 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07008575}
8576
John Fastabend2a47fa42013-11-06 09:54:52 -08008577static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8578 struct net_device *netdev,
8579 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008580{
8581 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008582 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07008583
Alexander Duycka50c29d2012-02-08 07:50:40 +00008584 /*
8585 * The minimum packet size for olinfo paylen is 17 so pad the skb
8586 * in order to meet this minimum size requirement.
8587 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08008588 if (skb_put_padto(skb, 17))
8589 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00008590
John Fastabend2a47fa42013-11-06 09:54:52 -08008591 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8592
Auke Kok9a799d72007-09-15 14:07:45 -07008593 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8594}
8595
John Fastabend2a47fa42013-11-06 09:54:52 -08008596static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8597 struct net_device *netdev)
8598{
8599 return __ixgbe_xmit_frame(skb, netdev, NULL);
8600}
8601
Auke Kok9a799d72007-09-15 14:07:45 -07008602/**
8603 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8604 * @netdev: network interface device structure
8605 * @p: pointer to an address structure
8606 *
8607 * Returns 0 on success, negative on failure
8608 **/
8609static int ixgbe_set_mac(struct net_device *netdev, void *p)
8610{
8611 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8612 struct ixgbe_hw *hw = &adapter->hw;
8613 struct sockaddr *addr = p;
8614
8615 if (!is_valid_ether_addr(addr->sa_data))
8616 return -EADDRNOTAVAIL;
8617
8618 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008619 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008620
Alexander Duyckc9f53e62015-10-22 16:26:30 -07008621 ixgbe_mac_set_default_filter(adapter);
8622
8623 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008624}
8625
Ben Hutchings6b73e102009-04-29 08:08:58 +00008626static int
8627ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8628{
8629 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8630 struct ixgbe_hw *hw = &adapter->hw;
8631 u16 value;
8632 int rc;
8633
8634 if (prtad != hw->phy.mdio.prtad)
8635 return -EINVAL;
8636 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8637 if (!rc)
8638 rc = value;
8639 return rc;
8640}
8641
8642static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8643 u16 addr, u16 value)
8644{
8645 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8646 struct ixgbe_hw *hw = &adapter->hw;
8647
8648 if (prtad != hw->phy.mdio.prtad)
8649 return -EINVAL;
8650 return hw->phy.ops.write_reg(hw, addr, devad, value);
8651}
8652
8653static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8654{
8655 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8656
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008657 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008658 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008659 return ixgbe_ptp_set_ts_config(adapter, req);
8660 case SIOCGHWTSTAMP:
8661 return ixgbe_ptp_get_ts_config(adapter, req);
Mark D Rustade0f06bb2016-08-31 10:34:28 -07008662 case SIOCGMIIPHY:
8663 if (!adapter->hw.phy.ops.read_reg)
8664 return -EOPNOTSUPP;
8665 /* fall through */
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008666 default:
8667 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8668 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008669}
8670
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008671/**
8672 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008673 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008674 * @netdev: network interface device structure
8675 *
8676 * Returns non-zero on failure
8677 **/
8678static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8679{
8680 int err = 0;
8681 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008682 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008683
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008684 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008685 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008686 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008687 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008688
8689 /* update SAN MAC vmdq pool selection */
8690 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008691 }
8692 return err;
8693}
8694
8695/**
8696 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008697 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008698 * @netdev: network interface device structure
8699 *
8700 * Returns non-zero on failure
8701 **/
8702static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8703{
8704 int err = 0;
8705 struct ixgbe_adapter *adapter = netdev_priv(dev);
8706 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8707
8708 if (is_valid_ether_addr(mac->san_addr)) {
8709 rtnl_lock();
8710 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8711 rtnl_unlock();
8712 }
8713 return err;
8714}
8715
Auke Kok9a799d72007-09-15 14:07:45 -07008716#ifdef CONFIG_NET_POLL_CONTROLLER
8717/*
8718 * Polling 'interrupt' - used by things like netconsole to send skbs
8719 * without having to re-enable interrupts. It's not called while
8720 * the interrupt routine is executing.
8721 */
8722static void ixgbe_netpoll(struct net_device *netdev)
8723{
8724 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008725 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008726
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008727 /* if interface is down do nothing */
8728 if (test_bit(__IXGBE_DOWN, &adapter->state))
8729 return;
8730
Alexander Duyck856f6062015-02-25 17:45:54 +00008731 /* loop through and schedule all active queues */
8732 for (i = 0; i < adapter->num_q_vectors; i++)
8733 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008734}
Auke Kok9a799d72007-09-15 14:07:45 -07008735
Alexander Duyck581330b2012-02-08 07:51:47 +00008736#endif
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008737
John Fastabend33fdc822017-04-24 03:30:18 -07008738static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
8739 struct ixgbe_ring *ring)
8740{
8741 u64 bytes, packets;
8742 unsigned int start;
8743
8744 if (ring) {
8745 do {
8746 start = u64_stats_fetch_begin_irq(&ring->syncp);
8747 packets = ring->stats.packets;
8748 bytes = ring->stats.bytes;
8749 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
8750 stats->tx_packets += packets;
8751 stats->tx_bytes += bytes;
8752 }
8753}
8754
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008755static void ixgbe_get_stats64(struct net_device *netdev,
8756 struct rtnl_link_stats64 *stats)
Eric Dumazetde1036b2010-10-20 23:00:04 +00008757{
8758 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8759 int i;
8760
Eric Dumazet1a515022010-11-16 19:26:42 -08008761 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008762 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08008763 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008764 u64 bytes, packets;
8765 unsigned int start;
8766
Eric Dumazet1a515022010-11-16 19:26:42 -08008767 if (ring) {
8768 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008769 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008770 packets = ring->stats.packets;
8771 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008772 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008773 stats->rx_packets += packets;
8774 stats->rx_bytes += bytes;
8775 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008776 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008777
8778 for (i = 0; i < adapter->num_tx_queues; i++) {
8779 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008780
John Fastabend33fdc822017-04-24 03:30:18 -07008781 ixgbe_get_ring_stats64(stats, ring);
8782 }
8783 for (i = 0; i < adapter->num_xdp_queues; i++) {
8784 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->xdp_ring[i]);
8785
8786 ixgbe_get_ring_stats64(stats, ring);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008787 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008788 rcu_read_unlock();
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008789
Eric Dumazetde1036b2010-10-20 23:00:04 +00008790 /* following stats updated by ixgbe_watchdog_task() */
8791 stats->multicast = netdev->stats.multicast;
8792 stats->rx_errors = netdev->stats.rx_errors;
8793 stats->rx_length_errors = netdev->stats.rx_length_errors;
8794 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8795 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
Eric Dumazetde1036b2010-10-20 23:00:04 +00008796}
8797
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008798#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008799/**
8800 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8801 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008802 * @tc: number of traffic classes currently enabled
8803 *
8804 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8805 * 802.1Q priority maps to a packet buffer that exists.
8806 */
8807static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8808{
8809 struct ixgbe_hw *hw = &adapter->hw;
8810 u32 reg, rsave;
8811 int i;
8812
8813 /* 82598 have a static priority to TC mapping that can not
8814 * be changed so no validation is needed.
8815 */
8816 if (hw->mac.type == ixgbe_mac_82598EB)
8817 return;
8818
8819 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8820 rsave = reg;
8821
8822 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8823 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8824
8825 /* If up2tc is out of bounds default to zero */
8826 if (up2tc > tc)
8827 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8828 }
8829
8830 if (reg != rsave)
8831 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8832
8833 return;
8834}
8835
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008836/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008837 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8838 * @adapter: Pointer to adapter struct
8839 *
8840 * Populate the netdev user priority to tc map
8841 */
8842static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8843{
8844 struct net_device *dev = adapter->netdev;
8845 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8846 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8847 u8 prio;
8848
8849 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8850 u8 tc = 0;
8851
8852 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8853 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8854 else if (ets)
8855 tc = ets->prio_tc[prio];
8856
8857 netdev_set_prio_tc_map(dev, prio, tc);
8858 }
8859}
8860
Alexander Duyckcca73c52013-01-12 06:33:44 +00008861#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008862/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008863 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008864 *
8865 * @netdev: net device to configure
8866 * @tc: number of traffic classes to enable
8867 */
8868int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8869{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008870 struct ixgbe_adapter *adapter = netdev_priv(dev);
8871 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08008872 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008873
John Fastabend8b1c0b22011-05-03 02:26:48 +00008874 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008875 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8876 return -EINVAL;
8877
8878 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008879 return -EINVAL;
8880
John Fastabend2a47fa42013-11-06 09:54:52 -08008881 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
8882 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
8883 return -EBUSY;
8884
John Fastabend8b1c0b22011-05-03 02:26:48 +00008885 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008886 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008887 * hardware is not flexible enough to do this dynamically.
8888 */
8889 if (netif_running(dev))
8890 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008891 else
8892 ixgbe_reset(adapter);
8893
John Fastabend8b1c0b22011-05-03 02:26:48 +00008894 ixgbe_clear_interrupt_scheme(adapter);
8895
Alexander Duyckcca73c52013-01-12 06:33:44 +00008896#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008897 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008898 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008899 ixgbe_set_prio_tc_map(adapter);
8900
John Fastabende7589ea2011-07-18 22:38:36 +00008901 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008902
Alexander Duyck943561d2012-05-09 22:14:44 -07008903 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8904 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008905 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008906 }
John Fastabende7589ea2011-07-18 22:38:36 +00008907 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008908 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008909
Alexander Duyck943561d2012-05-09 22:14:44 -07008910 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8911 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008912
8913 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008914
8915 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8916 adapter->dcb_cfg.pfc_mode_enable = false;
8917 }
8918
John Fastabend8b1c0b22011-05-03 02:26:48 +00008919 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008920
8921#endif /* CONFIG_IXGBE_DCB */
8922 ixgbe_init_interrupt_scheme(adapter);
8923
John Fastabend8b1c0b22011-05-03 02:26:48 +00008924 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008925 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008926
8927 return 0;
8928}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008929
John Fastabendb82b17d2016-02-16 21:18:53 -08008930static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8931 struct tc_cls_u32_offload *cls)
8932{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008933 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008934 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008935 u32 loc = cls->knode.handle & 0xfffff;
8936 int err = 0, i, j;
8937 struct ixgbe_jump_table *jump = NULL;
8938
8939 if (loc > IXGBE_MAX_HW_ENTRIES)
8940 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008941
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008942 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8943 return -EINVAL;
8944
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008945 /* Clear this filter in the link data it is associated with */
8946 if (uhtid != 0x800) {
8947 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008948 if (!jump)
8949 return -EINVAL;
8950 if (!test_bit(loc - 1, jump->child_loc_map))
8951 return -EINVAL;
8952 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008953 }
8954
8955 /* Check if the filter being deleted is a link */
8956 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8957 jump = adapter->jump_tables[i];
8958 if (jump && jump->link_hdl == hdl) {
8959 /* Delete filters in the hardware in the child hash
8960 * table associated with this link
8961 */
8962 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8963 if (!test_bit(j, jump->child_loc_map))
8964 continue;
8965 spin_lock(&adapter->fdir_perfect_lock);
8966 err = ixgbe_update_ethtool_fdir_entry(adapter,
8967 NULL,
8968 j + 1);
8969 spin_unlock(&adapter->fdir_perfect_lock);
8970 clear_bit(j, jump->child_loc_map);
8971 }
8972 /* Remove resources for this link */
8973 kfree(jump->input);
8974 kfree(jump->mask);
8975 kfree(jump);
8976 adapter->jump_tables[i] = NULL;
8977 return err;
8978 }
8979 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008980
John Fastabendb82b17d2016-02-16 21:18:53 -08008981 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008982 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008983 spin_unlock(&adapter->fdir_perfect_lock);
8984 return err;
8985}
8986
John Fastabenddb956ae2016-02-16 21:19:19 -08008987static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
John Fastabenddb956ae2016-02-16 21:19:19 -08008988 struct tc_cls_u32_offload *cls)
8989{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008990 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8991
8992 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8993 return -EINVAL;
8994
John Fastabenddb956ae2016-02-16 21:19:19 -08008995 /* This ixgbe devices do not support hash tables at the moment
8996 * so abort when given hash tables.
8997 */
8998 if (cls->hnode.divisor > 0)
8999 return -EINVAL;
9000
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009001 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08009002 return 0;
9003}
9004
9005static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
9006 struct tc_cls_u32_offload *cls)
9007{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009008 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
9009
9010 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
9011 return -EINVAL;
9012
9013 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08009014 return 0;
9015}
9016
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009017#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07009018struct upper_walk_data {
9019 struct ixgbe_adapter *adapter;
9020 u64 action;
9021 int ifindex;
9022 u8 queue;
9023};
9024
9025static int get_macvlan_queue(struct net_device *upper, void *_data)
9026{
9027 if (netif_is_macvlan(upper)) {
9028 struct macvlan_dev *dfwd = netdev_priv(upper);
9029 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
9030 struct upper_walk_data *data = _data;
9031 struct ixgbe_adapter *adapter = data->adapter;
9032 int ifindex = data->ifindex;
9033
9034 if (vadapter && vadapter->netdev->ifindex == ifindex) {
9035 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
9036 data->action = data->queue;
9037 return 1;
9038 }
9039 }
9040
9041 return 0;
9042}
9043
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009044static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
9045 u8 *queue, u64 *action)
9046{
9047 unsigned int num_vfs = adapter->num_vfs, vf;
David Ahern1cd127f2016-10-17 19:15:48 -07009048 struct upper_walk_data data;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009049 struct net_device *upper;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009050
9051 /* redirect to a SRIOV VF */
9052 for (vf = 0; vf < num_vfs; ++vf) {
9053 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
9054 if (upper->ifindex == ifindex) {
9055 if (adapter->num_rx_pools > 1)
9056 *queue = vf * 2;
9057 else
9058 *queue = vf * adapter->num_rx_queues_per_pool;
9059
9060 *action = vf + 1;
9061 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
9062 return 0;
9063 }
9064 }
9065
9066 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07009067 data.adapter = adapter;
9068 data.ifindex = ifindex;
9069 data.action = 0;
9070 data.queue = 0;
9071 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
9072 get_macvlan_queue, &data)) {
9073 *action = data.action;
9074 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009075
David Ahern1cd127f2016-10-17 19:15:48 -07009076 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009077 }
9078
9079 return -EINVAL;
9080}
9081
9082static int parse_tc_actions(struct ixgbe_adapter *adapter,
9083 struct tcf_exts *exts, u64 *action, u8 *queue)
9084{
9085 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07009086 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009087 int err;
9088
Jiri Pirko3bcc0ce2017-08-04 14:28:58 +02009089 if (!tcf_exts_has_actions(exts))
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009090 return -EINVAL;
9091
WANG Cong22dc13c2016-08-13 22:35:00 -07009092 tcf_exts_to_list(exts, &actions);
9093 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009094
9095 /* Drop action */
9096 if (is_tcf_gact_shot(a)) {
9097 *action = IXGBE_FDIR_DROP_QUEUE;
9098 *queue = IXGBE_FDIR_DROP_QUEUE;
9099 return 0;
9100 }
9101
9102 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03009103 if (is_tcf_mirred_egress_redirect(a)) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009104 int ifindex = tcf_mirred_ifindex(a);
9105
9106 err = handle_redirect_action(adapter, ifindex, queue,
9107 action);
9108 if (err == 0)
9109 return err;
9110 }
9111 }
9112
9113 return -EINVAL;
9114}
9115#else
9116static int parse_tc_actions(struct ixgbe_adapter *adapter,
9117 struct tcf_exts *exts, u64 *action, u8 *queue)
9118{
9119 return -EINVAL;
9120}
9121#endif /* CONFIG_NET_CLS_ACT */
9122
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009123static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
9124 union ixgbe_atr_input *mask,
9125 struct tc_cls_u32_offload *cls,
9126 struct ixgbe_mat_field *field_ptr,
9127 struct ixgbe_nexthdr *nexthdr)
9128{
9129 int i, j, off;
9130 __be32 val, m;
9131 bool found_entry = false, found_jump_field = false;
9132
9133 for (i = 0; i < cls->knode.sel->nkeys; i++) {
9134 off = cls->knode.sel->keys[i].off;
9135 val = cls->knode.sel->keys[i].val;
9136 m = cls->knode.sel->keys[i].mask;
9137
9138 for (j = 0; field_ptr[j].val; j++) {
9139 if (field_ptr[j].off == off) {
9140 field_ptr[j].val(input, mask, val, m);
9141 input->filter.formatted.flow_type |=
9142 field_ptr[j].type;
9143 found_entry = true;
9144 break;
9145 }
9146 }
9147 if (nexthdr) {
9148 if (nexthdr->off == cls->knode.sel->keys[i].off &&
9149 nexthdr->val == cls->knode.sel->keys[i].val &&
9150 nexthdr->mask == cls->knode.sel->keys[i].mask)
9151 found_jump_field = true;
9152 else
9153 continue;
9154 }
9155 }
9156
9157 if (nexthdr && !found_jump_field)
9158 return -EINVAL;
9159
9160 if (!found_entry)
9161 return 0;
9162
9163 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
9164 IXGBE_ATR_L4TYPE_MASK;
9165
9166 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
9167 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
9168
9169 return 0;
9170}
9171
John Fastabendb82b17d2016-02-16 21:18:53 -08009172static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
John Fastabendb82b17d2016-02-16 21:18:53 -08009173 struct tc_cls_u32_offload *cls)
9174{
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009175 __be16 protocol = cls->common.protocol;
John Fastabendb82b17d2016-02-16 21:18:53 -08009176 u32 loc = cls->knode.handle & 0xfffff;
9177 struct ixgbe_hw *hw = &adapter->hw;
9178 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009179 struct ixgbe_fdir_filter *input = NULL;
9180 union ixgbe_atr_input *mask = NULL;
9181 struct ixgbe_jump_table *jump = NULL;
9182 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08009183 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009184 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08009185
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009186 uhtid = TC_U32_USERHTID(cls->knode.handle);
9187 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08009188
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009189 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08009190 * L2 headers. The canonical method to match L2 frames is to use
9191 * negative values. However this is error prone at best but really
9192 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009193 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08009194 * headers when needed.
9195 */
9196 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009197 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009198
9199 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
9200 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009201 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009202 }
9203
9204 /* cls u32 is a graph starting at root node 0x800. The driver tracks
9205 * links and also the fields used to advance the parser across each
9206 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
9207 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
9208 * To add support for new nodes update ixgbe_model.h parse structures
9209 * this function _should_ be generic try not to hardcode values here.
9210 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009211 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009212 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009213 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009214 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009215 return err;
9216 if (!adapter->jump_tables[uhtid])
9217 return err;
9218 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009219 }
9220
9221 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009222 return err;
9223
9224 /* At this point we know the field_ptr is valid and need to either
9225 * build cls_u32 link or attach filter. Because adding a link to
9226 * a handle that does not exist is invalid and the same for adding
9227 * rules to handles that don't exist.
9228 */
9229
9230 if (link_uhtid) {
9231 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
9232
9233 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
9234 return err;
9235
9236 if (!test_bit(link_uhtid - 1, &adapter->tables))
9237 return err;
9238
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009239 /* Multiple filters as links to the same hash table are not
9240 * supported. To add a new filter with the same next header
9241 * but different match/jump conditions, create a new hash table
9242 * and link to it.
9243 */
9244 if (adapter->jump_tables[link_uhtid] &&
9245 (adapter->jump_tables[link_uhtid])->link_hdl) {
9246 e_err(drv, "Link filter exists for link: %x\n",
9247 link_uhtid);
9248 return err;
9249 }
9250
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009251 for (i = 0; nexthdr[i].jump; i++) {
9252 if (nexthdr[i].o != cls->knode.sel->offoff ||
9253 nexthdr[i].s != cls->knode.sel->offshift ||
9254 nexthdr[i].m != cls->knode.sel->offmask)
9255 return err;
9256
9257 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
9258 if (!jump)
9259 return -ENOMEM;
9260 input = kzalloc(sizeof(*input), GFP_KERNEL);
9261 if (!input) {
9262 err = -ENOMEM;
9263 goto free_jump;
9264 }
9265 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9266 if (!mask) {
9267 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009268 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009269 }
9270 jump->input = input;
9271 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009272 jump->link_hdl = cls->knode.handle;
9273
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009274 err = ixgbe_clsu32_build_input(input, mask, cls,
9275 field_ptr, &nexthdr[i]);
9276 if (!err) {
9277 jump->mat = nexthdr[i].jump;
9278 adapter->jump_tables[link_uhtid] = jump;
9279 break;
9280 }
9281 }
9282 return 0;
9283 }
John Fastabendb82b17d2016-02-16 21:18:53 -08009284
9285 input = kzalloc(sizeof(*input), GFP_KERNEL);
9286 if (!input)
9287 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009288 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9289 if (!mask) {
9290 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009291 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08009292 }
9293
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009294 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
9295 if ((adapter->jump_tables[uhtid])->input)
9296 memcpy(input, (adapter->jump_tables[uhtid])->input,
9297 sizeof(*input));
9298 if ((adapter->jump_tables[uhtid])->mask)
9299 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
9300 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009301
9302 /* Lookup in all child hash tables if this location is already
9303 * filled with a filter
9304 */
9305 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
9306 struct ixgbe_jump_table *link = adapter->jump_tables[i];
9307
9308 if (link && (test_bit(loc - 1, link->child_loc_map))) {
9309 e_err(drv, "Filter exists in location: %x\n",
9310 loc);
9311 err = -EINVAL;
9312 goto err_out;
9313 }
9314 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009315 }
9316 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
9317 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08009318 goto err_out;
9319
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009320 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
9321 &queue);
9322 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08009323 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08009324
John Fastabendb82b17d2016-02-16 21:18:53 -08009325 input->sw_idx = loc;
9326
9327 spin_lock(&adapter->fdir_perfect_lock);
9328
9329 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009330 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
9331 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009332 if (err)
9333 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009334 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08009335 err = -EINVAL;
9336 goto err_out_w_lock;
9337 }
9338
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009339 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009340 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
9341 input->sw_idx, queue);
9342 if (!err)
9343 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
9344 spin_unlock(&adapter->fdir_perfect_lock);
9345
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009346 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
9347 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009348
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009349 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009350 return err;
9351err_out_w_lock:
9352 spin_unlock(&adapter->fdir_perfect_lock);
9353err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009354 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009355free_input:
9356 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009357free_jump:
9358 kfree(jump);
9359 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009360}
9361
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009362static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009363 struct tc_cls_u32_offload *cls_u32)
9364{
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009365 if (cls_u32->common.chain_index)
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009366 return -EOPNOTSUPP;
9367
9368 switch (cls_u32->command) {
9369 case TC_CLSU32_NEW_KNODE:
9370 case TC_CLSU32_REPLACE_KNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009371 return ixgbe_configure_clsu32(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009372 case TC_CLSU32_DELETE_KNODE:
9373 return ixgbe_delete_clsu32(adapter, cls_u32);
9374 case TC_CLSU32_NEW_HNODE:
9375 case TC_CLSU32_REPLACE_HNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009376 return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009377 case TC_CLSU32_DELETE_HNODE:
9378 return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
9379 default:
9380 return -EOPNOTSUPP;
9381 }
9382}
9383
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009384static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
9385 void *cb_priv)
9386{
9387 struct ixgbe_adapter *adapter = cb_priv;
9388
Jiri Pirko44ae12a2017-11-01 11:47:39 +01009389 if (!tc_can_offload(adapter->netdev))
9390 return -EOPNOTSUPP;
9391
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009392 switch (type) {
9393 case TC_SETUP_CLSU32:
9394 return ixgbe_setup_tc_cls_u32(adapter, type_data);
9395 default:
9396 return -EOPNOTSUPP;
9397 }
9398}
9399
9400static int ixgbe_setup_tc_block(struct net_device *dev,
9401 struct tc_block_offload *f)
9402{
9403 struct ixgbe_adapter *adapter = netdev_priv(dev);
9404
9405 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
9406 return -EOPNOTSUPP;
9407
9408 switch (f->command) {
9409 case TC_BLOCK_BIND:
9410 return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
9411 adapter, adapter);
9412 case TC_BLOCK_UNBIND:
9413 tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
9414 adapter);
9415 return 0;
9416 default:
9417 return -EOPNOTSUPP;
9418 }
9419}
9420
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009421static int ixgbe_setup_tc_mqprio(struct net_device *dev,
9422 struct tc_mqprio_qopt *mqprio)
9423{
9424 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
9425 return ixgbe_setup_tc(dev, mqprio->num_tc);
9426}
9427
Jiri Pirko2572ac52017-08-07 10:15:17 +02009428static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02009429 void *type_data)
John Fastabende4c67342016-02-16 21:16:15 -08009430{
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009431 switch (type) {
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009432 case TC_SETUP_BLOCK:
9433 return ixgbe_setup_tc_block(dev, type_data);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009434 case TC_SETUP_MQPRIO:
Jiri Pirkode4784c2017-08-07 10:15:32 +02009435 return ixgbe_setup_tc_mqprio(dev, type_data);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009436 default:
Jiri Pirkoa5fcf8a2017-06-06 17:00:16 +02009437 return -EOPNOTSUPP;
John Fastabendb82b17d2016-02-16 21:18:53 -08009438 }
John Fastabende4c67342016-02-16 21:16:15 -08009439}
9440
Greg Roseda36b642012-12-11 08:26:43 +00009441#ifdef CONFIG_PCI_IOV
9442void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
9443{
9444 struct net_device *netdev = adapter->netdev;
9445
9446 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00009447 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00009448 rtnl_unlock();
9449}
9450
9451#endif
Don Skidmore082757a2011-07-21 05:55:00 +00009452void ixgbe_do_reset(struct net_device *netdev)
9453{
9454 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9455
9456 if (netif_running(netdev))
9457 ixgbe_reinit_locked(adapter);
9458 else
9459 ixgbe_reset(adapter);
9460}
9461
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009462static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009463 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009464{
9465 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9466
Don Skidmore082757a2011-07-21 05:55:00 +00009467 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009468 if (!(features & NETIF_F_RXCSUM))
9469 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00009470
Alexander Duyck567d2de2012-02-11 07:18:57 +00009471 /* Turn off LRO if not RSC capable */
9472 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
9473 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009474
Alexander Duyck567d2de2012-02-11 07:18:57 +00009475 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00009476}
9477
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009478static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009479 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009480{
9481 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00009482 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00009483 bool need_reset = false;
9484
Don Skidmore082757a2011-07-21 05:55:00 +00009485 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009486 if (!(features & NETIF_F_LRO)) {
9487 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00009488 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00009489 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9490 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9491 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9492 if (adapter->rx_itr_setting == 1 ||
9493 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9494 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9495 need_reset = true;
9496 } else if ((changed ^ features) & NETIF_F_LRO) {
9497 e_info(probe, "rx-usecs set too low, "
9498 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00009499 }
9500 }
9501
9502 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08009503 * Check if Flow Director n-tuple support or hw_tc support was
9504 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00009505 */
John Fastabendb82b17d2016-02-16 21:18:53 -08009506 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00009507 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00009508 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9509 need_reset = true;
9510
Alexander Duyck567d2de2012-02-11 07:18:57 +00009511 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9512 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08009513 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00009514 /* turn off perfect filters, enable ATR and reset */
9515 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9516 need_reset = true;
9517
9518 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9519
9520 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08009521 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9522 /* We cannot enable ATR if we have 2 or more tcs */
9523 (netdev_get_num_tc(netdev) > 1) ||
9524 /* We cannot enable ATR if RSS is disabled */
9525 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9526 /* A sample rate of 0 indicates ATR disabled */
9527 (!adapter->atr_sample_rate))
9528 ; /* do nothing not supported */
9529 else /* otherwise supported and set the flag */
9530 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00009531 }
9532
Ben Greear3f2d1c02012-03-08 08:28:41 +00009533 if (changed & NETIF_F_RXALL)
9534 need_reset = true;
9535
Alexander Duyck567d2de2012-02-11 07:18:57 +00009536 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07009537
Mark Rustad67359c32015-06-15 11:33:25 -07009538 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07009539 if (features & NETIF_F_RXCSUM) {
9540 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9541 } else {
9542 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9543
9544 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9545 }
9546 }
9547
9548 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9549 if (features & NETIF_F_RXCSUM) {
9550 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9551 } else {
9552 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9553
9554 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9555 }
Mark Rustad67359c32015-06-15 11:33:25 -07009556 }
Mark Rustad67359c32015-06-15 11:33:25 -07009557
Don Skidmore082757a2011-07-21 05:55:00 +00009558 if (need_reset)
9559 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009560 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9561 NETIF_F_HW_VLAN_CTAG_FILTER))
9562 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00009563
9564 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00009565}
9566
Don Skidmore3f207802014-12-23 07:40:34 +00009567/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009568 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009569 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009570 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009571 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009572static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9573 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009574{
9575 struct ixgbe_adapter *adapter = netdev_priv(dev);
9576 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07009577 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07009578 u32 port_shift = 0;
9579 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07009580
Alexander Duyckb3a49552016-06-16 12:22:19 -07009581 if (ti->sa_family != AF_INET)
9582 return;
9583
Emil Tantilova21d0822016-08-10 11:19:23 -07009584 switch (ti->type) {
9585 case UDP_TUNNEL_TYPE_VXLAN:
9586 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9587 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009588
Emil Tantilova21d0822016-08-10 11:19:23 -07009589 if (adapter->vxlan_port == port)
9590 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009591
Emil Tantilova21d0822016-08-10 11:19:23 -07009592 if (adapter->vxlan_port) {
9593 netdev_info(dev,
9594 "VXLAN port %d set, not adding port %d\n",
9595 ntohs(adapter->vxlan_port),
9596 ntohs(port));
9597 return;
9598 }
9599
9600 adapter->vxlan_port = port;
9601 break;
9602 case UDP_TUNNEL_TYPE_GENEVE:
9603 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9604 return;
9605
9606 if (adapter->geneve_port == port)
9607 return;
9608
9609 if (adapter->geneve_port) {
9610 netdev_info(dev,
9611 "GENEVE port %d set, not adding port %d\n",
9612 ntohs(adapter->geneve_port),
9613 ntohs(port));
9614 return;
9615 }
9616
9617 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9618 adapter->geneve_port = port;
9619 break;
9620 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009621 return;
9622 }
9623
Emil Tantilova21d0822016-08-10 11:19:23 -07009624 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9625 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00009626}
9627
9628/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009629 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009630 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009631 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009632 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009633static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9634 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009635{
9636 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07009637 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00009638
Emil Tantilova21d0822016-08-10 11:19:23 -07009639 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9640 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07009641 return;
9642
9643 if (ti->sa_family != AF_INET)
9644 return;
9645
Emil Tantilova21d0822016-08-10 11:19:23 -07009646 switch (ti->type) {
9647 case UDP_TUNNEL_TYPE_VXLAN:
9648 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9649 return;
Mark Rustad67359c32015-06-15 11:33:25 -07009650
Emil Tantilova21d0822016-08-10 11:19:23 -07009651 if (adapter->vxlan_port != ti->port) {
9652 netdev_info(dev, "VXLAN port %d not found\n",
9653 ntohs(ti->port));
9654 return;
9655 }
9656
9657 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9658 break;
9659 case UDP_TUNNEL_TYPE_GENEVE:
9660 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9661 return;
9662
9663 if (adapter->geneve_port != ti->port) {
9664 netdev_info(dev, "GENEVE port %d not found\n",
9665 ntohs(ti->port));
9666 return;
9667 }
9668
9669 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9670 break;
9671 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009672 return;
9673 }
9674
Emil Tantilova21d0822016-08-10 11:19:23 -07009675 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9676 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00009677}
9678
stephen hemmingeredc7d572012-10-01 12:32:33 +00009679static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009680 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009681 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009682 u16 flags)
9683{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009684 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00009685 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009686 struct ixgbe_adapter *adapter = netdev_priv(dev);
9687 u16 pool = VMDQ_P(0);
9688
9689 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009690 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009691 }
9692
Jiri Pirkof6f64242014-11-28 14:34:15 +01009693 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009694}
9695
Don Skidmore219efe92015-04-09 22:03:22 -07009696/**
9697 * ixgbe_configure_bridge_mode - set various bridge modes
9698 * @adapter - the private structure
9699 * @mode - requested bridge mode
9700 *
9701 * Configure some settings require for various bridge modes.
9702 **/
9703static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9704 __u16 mode)
9705{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009706 struct ixgbe_hw *hw = &adapter->hw;
9707 unsigned int p, num_pools;
9708 u32 vmdctl;
9709
Don Skidmore219efe92015-04-09 22:03:22 -07009710 switch (mode) {
9711 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009712 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009713 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009714
9715 /* must enable Rx switching replication to allow multicast
9716 * packet reception on all VFs, and to enable source address
9717 * pruning.
9718 */
9719 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9720 vmdctl |= IXGBE_VT_CTL_REPLEN;
9721 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9722
9723 /* enable Rx source address pruning. Note, this requires
9724 * replication to be enabled or else it does nothing.
9725 */
9726 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9727 for (p = 0; p < num_pools; p++) {
9728 if (hw->mac.ops.set_source_address_pruning)
9729 hw->mac.ops.set_source_address_pruning(hw,
9730 true,
9731 p);
9732 }
Don Skidmore219efe92015-04-09 22:03:22 -07009733 break;
9734 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009735 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009736 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9737 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009738
9739 /* disable Rx switching replication unless we have SR-IOV
9740 * virtual functions
9741 */
9742 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9743 if (!adapter->num_vfs)
9744 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9745 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9746
9747 /* disable Rx source address pruning, since we don't expect to
9748 * be receiving external loopback of our transmitted frames.
9749 */
9750 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9751 for (p = 0; p < num_pools; p++) {
9752 if (hw->mac.ops.set_source_address_pruning)
9753 hw->mac.ops.set_source_address_pruning(hw,
9754 false,
9755 p);
9756 }
Don Skidmore219efe92015-04-09 22:03:22 -07009757 break;
9758 default:
9759 return -EINVAL;
9760 }
9761
9762 adapter->bridge_mode = mode;
9763
9764 e_info(drv, "enabling bridge mode: %s\n",
9765 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9766
9767 return 0;
9768}
9769
John Fastabend815cccb2012-10-24 08:13:09 +00009770static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009771 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009772{
9773 struct ixgbe_adapter *adapter = netdev_priv(dev);
9774 struct nlattr *attr, *br_spec;
9775 int rem;
9776
9777 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9778 return -EOPNOTSUPP;
9779
9780 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009781 if (!br_spec)
9782 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009783
9784 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009785 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009786 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009787
9788 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9789 continue;
9790
Thomas Grafb7c1a312014-11-26 13:42:17 +01009791 if (nla_len(attr) < sizeof(mode))
9792 return -EINVAL;
9793
John Fastabend815cccb2012-10-24 08:13:09 +00009794 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009795 status = ixgbe_configure_bridge_mode(adapter, mode);
9796 if (status)
9797 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009798
9799 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009800 }
9801
9802 return 0;
9803}
9804
9805static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009806 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009807 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009808{
9809 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009810
9811 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9812 return 0;
9813
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009814 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009815 adapter->bridge_mode, 0, 0, nlflags,
9816 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009817}
9818
John Fastabend2a47fa42013-11-06 09:54:52 -08009819static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9820{
9821 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
9822 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009823 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08009824 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009825 int pool, err;
9826
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009827 /* Hardware has a limited number of available pools. Each VF, and the
9828 * PF require a pool. Check to ensure we don't attempt to use more
9829 * then the available number of pools.
9830 */
9831 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9832 return ERR_PTR(-EINVAL);
9833
John Fastabend219354d2013-11-08 00:50:32 -08009834#ifdef CONFIG_RPS
9835 if (vdev->num_rx_queues != vdev->num_tx_queues) {
9836 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
9837 vdev->name);
9838 return ERR_PTR(-EINVAL);
9839 }
9840#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08009841 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08009842 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08009843 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
9844 netdev_info(pdev,
9845 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
9846 pdev->name);
9847 return ERR_PTR(-EINVAL);
9848 }
9849
9850 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
9851 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
9852 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
9853 return ERR_PTR(-EBUSY);
9854
Maninder Singhbc52f952015-06-19 09:37:55 +05309855 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08009856 if (!fwd_adapter)
9857 return ERR_PTR(-ENOMEM);
9858
9859 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
9860 adapter->num_rx_pools++;
9861 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08009862 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08009863
9864 /* Enable VMDq flag so device will be set in VM mode */
9865 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08009866 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08009867 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08009868
9869 /* Force reinit of ring allocation with VMDQ enabled */
9870 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9871 if (err)
9872 goto fwd_add_err;
9873 fwd_adapter->pool = pool;
9874 fwd_adapter->real_adapter = adapter;
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009875
9876 if (netif_running(pdev)) {
9877 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
9878 if (err)
9879 goto fwd_add_err;
9880 netif_tx_start_all_queues(vdev);
9881 }
9882
John Fastabend2a47fa42013-11-06 09:54:52 -08009883 return fwd_adapter;
9884fwd_add_err:
9885 /* unwind counter and free adapter struct */
9886 netdev_info(pdev,
9887 "%s: dfwd hardware acceleration failed\n", vdev->name);
9888 clear_bit(pool, &adapter->fwd_bitmask);
9889 adapter->num_rx_pools--;
9890 kfree(fwd_adapter);
9891 return ERR_PTR(err);
9892}
9893
9894static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9895{
9896 struct ixgbe_fwd_adapter *fwd_adapter = priv;
9897 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08009898 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009899
9900 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
9901 adapter->num_rx_pools--;
9902
John Fastabend51f37732013-11-08 00:51:10 -08009903 limit = find_last_bit(&adapter->fwd_bitmask, 32);
9904 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009905 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
Shannon Nelsonf5a71ca2017-08-15 08:59:54 -07009906
9907 /* go back to full RSS if we're done with our VMQs */
9908 if (adapter->ring_feature[RING_F_VMDQ].limit == 1) {
9909 int rss = min_t(int, ixgbe_max_rss_indices(adapter),
9910 num_online_cpus());
9911
9912 adapter->flags &= ~IXGBE_FLAG_VMDQ_ENABLED;
9913 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
9914 adapter->ring_feature[RING_F_RSS].limit = rss;
9915 }
9916
John Fastabend2a47fa42013-11-06 09:54:52 -08009917 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9918 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
9919 fwd_adapter->pool, adapter->num_rx_pools,
9920 fwd_adapter->rx_base_queue,
9921 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
9922 adapter->fwd_bitmask);
9923 kfree(fwd_adapter);
9924}
9925
Alexander Duyckb83e3012016-04-14 17:19:31 -04009926#define IXGBE_MAX_MAC_HDR_LEN 127
9927#define IXGBE_MAX_NETWORK_HDR_LEN 511
9928
Mark Rustadf467bc02015-06-15 11:33:20 -07009929static netdev_features_t
9930ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9931 netdev_features_t features)
9932{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009933 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009934
Alexander Duyckb83e3012016-04-14 17:19:31 -04009935 /* Make certain the headers can be described by a context descriptor */
9936 mac_hdr_len = skb_network_header(skb) - skb->data;
9937 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9938 return features & ~(NETIF_F_HW_CSUM |
9939 NETIF_F_SCTP_CRC |
9940 NETIF_F_HW_VLAN_CTAG_TX |
9941 NETIF_F_TSO |
9942 NETIF_F_TSO6);
9943
9944 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9945 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9946 return features & ~(NETIF_F_HW_CSUM |
9947 NETIF_F_SCTP_CRC |
9948 NETIF_F_TSO |
9949 NETIF_F_TSO6);
9950
9951 /* We can only support IPV4 TSO in tunnels if we can mangle the
9952 * inner IP ID field, so strip TSO if MANGLEID is not supported.
9953 */
9954 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
9955 features &= ~NETIF_F_TSO;
Mark Rustadf467bc02015-06-15 11:33:20 -07009956
9957 return features;
9958}
9959
John Fastabend92470802017-04-24 03:30:17 -07009960static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
9961{
9962 int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
9963 struct ixgbe_adapter *adapter = netdev_priv(dev);
9964 struct bpf_prog *old_prog;
9965
9966 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
9967 return -EINVAL;
9968
9969 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
9970 return -EINVAL;
9971
9972 /* verify ixgbe ring attributes are sufficient for XDP */
9973 for (i = 0; i < adapter->num_rx_queues; i++) {
9974 struct ixgbe_ring *ring = adapter->rx_ring[i];
9975
9976 if (ring_is_rsc_enabled(ring))
9977 return -EINVAL;
9978
9979 if (frame_size > ixgbe_rx_bufsz(ring))
9980 return -EINVAL;
9981 }
9982
John Fastabend33fdc822017-04-24 03:30:18 -07009983 if (nr_cpu_ids > MAX_XDP_QUEUES)
9984 return -ENOMEM;
9985
John Fastabend92470802017-04-24 03:30:17 -07009986 old_prog = xchg(&adapter->xdp_prog, prog);
John Fastabend33fdc822017-04-24 03:30:18 -07009987
9988 /* If transitioning XDP modes reconfigure rings */
9989 if (!!prog != !!old_prog) {
9990 int err = ixgbe_setup_tc(dev, netdev_get_num_tc(dev));
9991
9992 if (err) {
9993 rcu_assign_pointer(adapter->xdp_prog, old_prog);
9994 return -EINVAL;
9995 }
9996 } else {
9997 for (i = 0; i < adapter->num_rx_queues; i++)
9998 xchg(&adapter->rx_ring[i]->xdp_prog, adapter->xdp_prog);
9999 }
John Fastabend92470802017-04-24 03:30:17 -070010000
10001 if (old_prog)
10002 bpf_prog_put(old_prog);
10003
10004 return 0;
10005}
10006
10007static int ixgbe_xdp(struct net_device *dev, struct netdev_xdp *xdp)
10008{
10009 struct ixgbe_adapter *adapter = netdev_priv(dev);
10010
10011 switch (xdp->command) {
10012 case XDP_SETUP_PROG:
10013 return ixgbe_xdp_setup(dev, xdp->prog);
10014 case XDP_QUERY_PROG:
10015 xdp->prog_attached = !!(adapter->xdp_prog);
Martin KaFai Lau47920932017-06-15 17:29:15 -070010016 xdp->prog_id = adapter->xdp_prog ?
10017 adapter->xdp_prog->aux->id : 0;
John Fastabend92470802017-04-24 03:30:17 -070010018 return 0;
10019 default:
10020 return -EINVAL;
10021 }
10022}
10023
John Fastabend64530732017-07-17 09:28:12 -070010024static int ixgbe_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp)
10025{
10026 struct ixgbe_adapter *adapter = netdev_priv(dev);
10027 struct ixgbe_ring *ring;
10028 int err;
10029
10030 if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +020010031 return -ENETDOWN;
John Fastabend64530732017-07-17 09:28:12 -070010032
10033 /* During program transitions its possible adapter->xdp_prog is assigned
10034 * but ring has not been configured yet. In this case simply abort xmit.
10035 */
10036 ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
10037 if (unlikely(!ring))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +020010038 return -ENXIO;
John Fastabend64530732017-07-17 09:28:12 -070010039
10040 err = ixgbe_xmit_xdp_ring(adapter, xdp);
10041 if (err != IXGBE_XDP_TX)
Jesper Dangaard Brouerd2cee2e2017-08-17 18:22:32 +020010042 return -ENOSPC;
John Fastabend64530732017-07-17 09:28:12 -070010043
John Fastabend11393cc2017-07-17 09:29:40 -070010044 return 0;
10045}
10046
10047static void ixgbe_xdp_flush(struct net_device *dev)
10048{
10049 struct ixgbe_adapter *adapter = netdev_priv(dev);
10050 struct ixgbe_ring *ring;
10051
10052 /* Its possible the device went down between xdp xmit and flush so
10053 * we need to ensure device is still up.
10054 */
10055 if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
10056 return;
10057
10058 ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
10059 if (unlikely(!ring))
10060 return;
10061
John Fastabend64530732017-07-17 09:28:12 -070010062 /* Force memory writes to complete before letting h/w know there
10063 * are new descriptors to fetch.
10064 */
10065 wmb();
John Fastabend64530732017-07-17 09:28:12 -070010066 writel(ring->next_to_use, ring->tail);
10067
John Fastabend11393cc2017-07-17 09:29:40 -070010068 return;
John Fastabend64530732017-07-17 09:28:12 -070010069}
10070
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010071static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +000010072 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010073 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -080010074 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -070010075 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +000010076 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010077 .ndo_validate_addr = eth_validate_addr,
10078 .ndo_set_mac_address = ixgbe_set_mac,
10079 .ndo_change_mtu = ixgbe_change_mtu,
10080 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +000010081 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010082 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
10083 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +000010084 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +000010085 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
10086 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -040010087 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +000010088 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +030010089 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +000010090 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +000010091 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +000010092 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -080010093 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010094#ifdef CONFIG_NET_POLL_CONTROLLER
10095 .ndo_poll_controller = ixgbe_netpoll,
10096#endif
Yi Zou332d4a72009-05-13 13:11:53 +000010097#ifdef IXGBE_FCOE
10098 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +000010099 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +000010100 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +000010101 .ndo_fcoe_enable = ixgbe_fcoe_enable,
10102 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +000010103 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +000010104 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +000010105#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +000010106 .ndo_set_features = ixgbe_set_features,
10107 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +000010108 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +000010109 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
10110 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -080010111 .ndo_dfwd_add_station = ixgbe_fwd_add,
10112 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -070010113 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
10114 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -070010115 .ndo_features_check = ixgbe_features_check,
John Fastabend92470802017-04-24 03:30:17 -070010116 .ndo_xdp = ixgbe_xdp,
John Fastabend64530732017-07-17 09:28:12 -070010117 .ndo_xdp_xmit = ixgbe_xdp_xmit,
John Fastabend11393cc2017-07-17 09:29:40 -070010118 .ndo_xdp_flush = ixgbe_xdp_flush,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010119};
10120
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010121/**
Jacob Kellere027d1a2013-07-31 06:53:31 +000010122 * ixgbe_enumerate_functions - Get the number of ports this device has
10123 * @adapter: adapter structure
10124 *
10125 * This function enumerates the phsyical functions co-located on a single slot,
10126 * in order to determine how many ports a device has. This is most useful in
10127 * determining the required GT/s of PCIe bandwidth necessary for optimal
10128 * performance.
10129 **/
10130static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
10131{
Jacob Kellercaafb952014-07-19 07:17:17 +000010132 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010133 int physfns = 0;
10134
Jacob Kellerf1f96572013-08-31 02:45:38 +000010135 /* Some cards can not use the generic count PCIe functions method,
10136 * because they are behind a parent switch, so we hardcode these with
10137 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +000010138 */
Jacob Keller88189702014-07-19 07:17:16 +000010139 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +000010140 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +000010141
10142 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
10143 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +000010144 if (entry->is_virtfn)
10145 continue;
10146
10147 /* When the devices on the bus don't all match our device ID,
10148 * we can't reliably determine the correct number of
10149 * functions. This can occur if a function has been direct
10150 * attached to a virtual machine using VT-d, for example. In
10151 * this case, simply return -1 to indicate this.
10152 */
10153 if ((entry->vendor != pdev->vendor) ||
10154 (entry->device != pdev->device))
10155 return -1;
10156
10157 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010158 }
10159
10160 return physfns;
10161}
10162
10163/**
Jacob Keller8e2813f2012-04-21 06:05:40 +000010164 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -070010165 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +000010166 * @device_id: the device ID
10167 * @subdev_id: the subsystem device ID
10168 *
10169 * This function is used by probe and ethtool to determine
10170 * which devices have WoL support
10171 *
10172 **/
Emil Tantilov740234f2016-04-21 11:37:12 -070010173bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
10174 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +000010175{
10176 struct ixgbe_hw *hw = &adapter->hw;
10177 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010178
Emil Tantilov740234f2016-04-21 11:37:12 -070010179 /* WOL not supported on 82598 */
10180 if (hw->mac.type == ixgbe_mac_82598EB)
10181 return false;
10182
10183 /* check eeprom to see if WOL is enabled for X540 and newer */
10184 if (hw->mac.type >= ixgbe_mac_X540) {
10185 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
10186 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
10187 (hw->bus.func == 0)))
10188 return true;
10189 }
10190
10191 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +000010192 switch (device_id) {
10193 case IXGBE_DEV_ID_82599_SFP:
10194 /* Only these subdevices could supports WOL */
10195 switch (subdevice_id) {
10196 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010197 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
10198 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
10199 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010200 /* only support first port */
10201 if (hw->bus.func != 0)
10202 break;
Tony Nguyen93df9462017-05-31 04:43:47 -070010203 /* fall through */
Emil Tantilov5700ff22013-04-18 08:18:55 +000010204 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010205 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +000010206 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +000010207 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010208 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
10209 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
10210 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -070010211 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010212 }
10213 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010214 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -070010215 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +000010216 switch (subdevice_id) {
10217 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -070010218 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010219 }
10220 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010221 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
10222 /* All except this subdevice support WOL */
10223 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -070010224 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010225 break;
10226 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -070010227 return true;
10228 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010229 break;
10230 }
10231
Emil Tantilov740234f2016-04-21 11:37:12 -070010232 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010233}
10234
10235/**
Auke Kok9a799d72007-09-15 14:07:45 -070010236 * ixgbe_probe - Device Initialization Routine
10237 * @pdev: PCI device information struct
10238 * @ent: entry in ixgbe_pci_tbl
10239 *
10240 * Returns 0 on success, negative on failure
10241 *
10242 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
10243 * The OS initialization, configuring of the adapter private structure,
10244 * and a hardware reset occur.
10245 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000010246static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -070010247{
10248 struct net_device *netdev;
10249 struct ixgbe_adapter *adapter = NULL;
10250 struct ixgbe_hw *hw;
10251 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +000010252 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010253 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +000010254 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010255 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +000010256#ifdef IXGBE_FCOE
10257 u16 device_caps;
10258#endif
Don Skidmore289700db2010-12-03 03:32:58 +000010259 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -070010260
Andy Gospodarekbded64a2010-07-21 06:40:31 +000010261 /* Catch broken hardware that put the wrong VF device ID in
10262 * the PCIe SR-IOV capability.
10263 */
10264 if (pdev->is_virtfn) {
10265 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
10266 pci_name(pdev), pdev->vendor, pdev->device);
10267 return -EINVAL;
10268 }
10269
gouji-new9ce77662009-05-06 10:44:45 +000010270 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010271 if (err)
10272 return err;
10273
Russell Kingf5f2eda2013-06-10 12:47:42 +010010274 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -070010275 pci_using_dac = 1;
10276 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010277 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -070010278 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010279 dev_err(&pdev->dev,
10280 "No usable DMA configuration, aborting\n");
10281 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -070010282 }
10283 pci_using_dac = 0;
10284 }
10285
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010286 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -070010287 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +000010288 dev_err(&pdev->dev,
10289 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -070010290 goto err_pci_reg;
10291 }
10292
Frans Pop19d5afd2009-10-02 10:04:12 -070010293 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010294
Auke Kok9a799d72007-09-15 14:07:45 -070010295 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -070010296 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010297
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010298 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +000010299#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010300 /* 8 TC w/ 4 queues per TC */
10301 indices = 4 * MAX_TRAFFIC_CLASS;
10302#else
10303 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +000010304#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010305 }
John Fastabende901acd2011-04-26 07:26:08 +000010306
John Fastabendc85a2612010-02-25 23:15:21 +000010307 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -070010308 if (!netdev) {
10309 err = -ENOMEM;
10310 goto err_alloc_etherdev;
10311 }
10312
Auke Kok9a799d72007-09-15 14:07:45 -070010313 SET_NETDEV_DEV(netdev, &pdev->dev);
10314
Auke Kok9a799d72007-09-15 14:07:45 -070010315 adapter = netdev_priv(netdev);
10316
10317 adapter->netdev = netdev;
10318 adapter->pdev = pdev;
10319 hw = &adapter->hw;
10320 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +000010321 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -070010322
Jeff Kirsher05857982008-09-11 19:57:00 -070010323 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +000010324 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -080010325 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -070010326 if (!hw->hw_addr) {
10327 err = -EIO;
10328 goto err_ioremap;
10329 }
10330
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010331 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010332 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010333 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +000010334 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -070010335
Auke Kok9a799d72007-09-15 14:07:45 -070010336 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -080010337 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010338 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010339 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -070010340 if (ii->link_ops)
10341 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010342
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010343 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -080010344 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010345 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +000010346 if (ixgbe_removed(hw->hw_addr)) {
10347 err = -EIO;
10348 goto err_ioremap;
10349 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010350 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -070010351 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010352 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
10353
10354 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -080010355 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010356 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +000010357 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
10358 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
10359 hw->phy.mdio.mmds = 0;
10360 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10361 hw->phy.mdio.dev = netdev;
10362 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
10363 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010364
Auke Kok9a799d72007-09-15 14:07:45 -070010365 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -070010366 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -070010367 if (err)
10368 goto err_sw_init;
10369
Don Skidmoredbd15b82016-03-09 16:45:00 -050010370 /* Make sure the SWFW semaphore is in a valid state */
10371 if (hw->mac.ops.init_swfw_sync)
10372 hw->mac.ops.init_swfw_sync(hw);
10373
Don Skidmoree86bff02010-02-11 04:14:08 +000010374 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -080010375 switch (adapter->hw.mac.type) {
10376 case ixgbe_mac_82599EB:
10377 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010378 case ixgbe_mac_X550:
10379 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -070010380 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +000010381 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -080010382 break;
10383 default:
10384 break;
10385 }
Don Skidmoree86bff02010-02-11 04:14:08 +000010386
Don Skidmorebf069c92009-05-07 10:39:54 +000010387 /*
10388 * If there is a fan on this device and it has failed log the
10389 * failure.
10390 */
10391 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
10392 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
10393 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +000010394 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +000010395 }
10396
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +000010397 if (allow_unsupported_sfp)
10398 hw->allow_unsupported_sfp = allow_unsupported_sfp;
10399
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010400 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010401 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010402 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010403 hw->phy.reset_if_overtemp = false;
Mark Rustadb3eb4e12016-12-14 11:02:16 -080010404 ixgbe_set_eee_capable(adapter);
Mark Rustad29a8dca2015-08-08 16:17:46 -070010405 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -070010406 err = 0;
10407 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +000010408 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
10409 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010410 goto err_sw_init;
10411 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010412 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010413 goto err_sw_init;
10414 }
10415
Alexander Duyck99d74482012-05-09 08:09:25 +000010416#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +000010417 /* SR-IOV not supported on the 82598 */
10418 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
10419 goto skip_sriov;
10420 /* Mailbox */
10421 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -080010422 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -080010423 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
Emil Tantilov5c11f002017-01-20 14:11:56 -080010424 ixgbe_enable_sriov(adapter, max_vfs);
Greg Rose60a1a682012-12-11 08:26:33 +000010425skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010426
Alexander Duyck99d74482012-05-09 08:09:25 +000010427#endif
Emil Tantilov396e7992010-07-01 20:05:12 +000010428 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +000010429 NETIF_F_TSO |
10430 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +000010431 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -080010432 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010433 NETIF_F_HW_CSUM;
10434
10435#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
10436 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -070010437 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -070010438 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -040010439 NETIF_F_GSO_UDP_TUNNEL | \
10440 NETIF_F_GSO_UDP_TUNNEL_CSUM)
10441
10442 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
10443 netdev->features |= NETIF_F_GSO_PARTIAL |
10444 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -070010445
Alexander Duyck49763de2016-01-13 07:31:11 -080010446 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -080010447 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +000010448
Alexander Duyck49763de2016-01-13 07:31:11 -080010449 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -040010450 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -070010451 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010452 NETIF_F_HW_VLAN_CTAG_RX |
10453 NETIF_F_HW_VLAN_CTAG_TX |
10454 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -080010455 NETIF_F_HW_L2FW_DOFFLOAD;
10456
10457 if (hw->mac.type >= ixgbe_mac_82599EB)
10458 netdev->hw_features |= NETIF_F_NTUPLE |
10459 NETIF_F_HW_TC;
10460
Alexander Duyckb83e3012016-04-14 17:19:31 -040010461 if (pci_using_dac)
10462 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -070010463
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010464 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
10465 netdev->hw_enc_features |= netdev->vlan_features;
Scott Peterson2a205252016-11-18 11:25:42 -080010466 netdev->mpls_features |= NETIF_F_SG |
10467 NETIF_F_TSO |
10468 NETIF_F_TSO6 |
10469 NETIF_F_HW_CSUM;
10470 netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010471
Alexander Duyckb83e3012016-04-14 17:19:31 -040010472 /* set this bit last since it cannot be part of vlan_features */
10473 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
10474 NETIF_F_HW_VLAN_CTAG_RX |
10475 NETIF_F_HW_VLAN_CTAG_TX;
10476
Jiri Pirko01789342011-08-16 06:29:00 +000010477 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +000010478 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +000010479
Jarod Wilson91c527a2016-10-17 15:54:05 -040010480 /* MTU range: 68 - 9710 */
10481 netdev->min_mtu = ETH_MIN_MTU;
10482 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
10483
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -080010484#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -070010485 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
Stephen Hemminger3f40c742016-11-21 09:52:40 -080010486 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -080010487#endif
10488
Yi Zoueacd73f2009-05-13 13:11:06 +000010489#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +000010490 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010491 unsigned int fcoe_l;
10492
Yi Zoueacd73f2009-05-13 13:11:06 +000010493 if (hw->mac.ops.get_device_caps) {
10494 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +000010495 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
10496 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +000010497 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010498
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010499
10500 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
10501 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010502
Alexander Duycka58915c2012-05-25 06:38:18 +000010503 netdev->features |= NETIF_F_FSO |
10504 NETIF_F_FCOE_CRC;
10505
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010506 netdev->vlan_features |= NETIF_F_FSO |
10507 NETIF_F_FCOE_CRC |
10508 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +000010509 }
Yi Zoueacd73f2009-05-13 13:11:06 +000010510#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -070010511
Don Skidmore082757a2011-07-21 05:55:00 +000010512 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
10513 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +000010514 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +000010515 netdev->features |= NETIF_F_LRO;
10516
Auke Kok9a799d72007-09-15 14:07:45 -070010517 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010518 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010519 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010520 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010521 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010522 }
10523
Sowmini Varadhanc7374b52016-01-12 19:32:30 -080010524 eth_platform_get_mac_address(&adapter->pdev->dev,
10525 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +000010526
Auke Kok9a799d72007-09-15 14:07:45 -070010527 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -070010528
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +000010529 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010530 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010531 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010532 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010533 }
10534
Tushar Dave56768042016-01-07 14:17:03 -080010535 /* Set hw->mac.addr to permanent MAC address */
10536 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -070010537 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010538
Kees Cook26566ea2017-10-16 17:29:35 -070010539 timer_setup(&adapter->service_timer, ixgbe_service_timer, 0);
Auke Kok9a799d72007-09-15 14:07:45 -070010540
Mark Rustad58cf6632014-03-12 00:38:40 +000010541 if (ixgbe_removed(hw->hw_addr)) {
10542 err = -EIO;
10543 goto err_sw_init;
10544 }
Alexander Duyck70864002011-04-27 09:13:56 +000010545 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +000010546 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010547 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010548
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010549 err = ixgbe_init_interrupt_scheme(adapter);
10550 if (err)
10551 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010552
Liwei Songb09457e2016-12-04 22:40:44 -050010553 for (i = 0; i < adapter->num_rx_queues; i++)
10554 u64_stats_init(&adapter->rx_ring[i]->syncp);
10555 for (i = 0; i < adapter->num_tx_queues; i++)
10556 u64_stats_init(&adapter->tx_ring[i]->syncp);
John Fastabend33fdc822017-04-24 03:30:18 -070010557 for (i = 0; i < adapter->num_xdp_queues; i++)
10558 u64_stats_init(&adapter->xdp_ring[i]->syncp);
10559
Jacob Keller8e2813f2012-04-21 06:05:40 +000010560 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010561 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010562 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010563 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +000010564 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010565 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +000010566 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010567
PJ Waskiewicze8e26352009-02-27 15:45:05 +000010568 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
10569
Emil Tantilov15e52092011-09-29 05:01:29 +000010570 /* save off EEPROM version number */
10571 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
10572 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
10573
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010574 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +000010575 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +000010576 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -040010577 else
10578 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010579
Jacob Kellere027d1a2013-07-31 06:53:31 +000010580 /* calculate the expected PCIe bandwidth required for optimal
10581 * performance. Note that some older parts will never have enough
10582 * bandwidth due to being older generation PCIe parts. We clamp these
10583 * parts to ensure no warning is displayed if it can't be fixed.
10584 */
10585 switch (hw->mac.type) {
10586 case ixgbe_mac_82598EB:
10587 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
10588 break;
10589 default:
10590 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
10591 break;
Auke Kok0c254d82008-02-11 09:25:56 -080010592 }
Jacob Kellercaafb952014-07-19 07:17:17 +000010593
10594 /* don't check link if we failed to enumerate functions */
10595 if (expected_gts > 0)
10596 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -080010597
Mark Rustad339de302014-06-06 01:57:06 +000010598 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010599 if (err)
Mark Rustad339de302014-06-06 01:57:06 +000010600 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010601 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
10602 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
10603 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +000010604 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +000010605 else
10606 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
10607 hw->mac.type, hw->phy.type, part_str);
10608
10609 e_dev_info("%pM\n", netdev->dev_addr);
10610
Auke Kok9a799d72007-09-15 14:07:45 -070010611 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010612 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010613 if (err == IXGBE_ERR_EEPROM_VERSION) {
10614 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +000010615 e_dev_warn("This device is a pre-production adapter/LOM. "
10616 "Please be aware there may be issues associated "
10617 "with your hardware. If you are experiencing "
10618 "problems please contact your Intel or hardware "
10619 "representative who provided you with this "
10620 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010621 }
Auke Kok9a799d72007-09-15 14:07:45 -070010622 strcpy(netdev->name, "eth%d");
Jeff Mahoneya09c0fc2017-06-03 18:01:17 -040010623 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010624 err = register_netdev(netdev);
10625 if (err)
10626 goto err_register;
10627
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010628
Emil Tantilovec74a472012-09-20 03:33:56 +000010629 /* power down the optics for 82599 SFP+ fiber */
10630 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +000010631 hw->mac.ops.disable_tx_laser(hw);
10632
Jesse Brandeburg54386462009-04-17 20:44:27 +000010633 /* carrier off reporting is important to ethtool even BEFORE open */
10634 netif_carrier_off(netdev);
10635
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010636#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +030010637 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010638 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010639 ixgbe_setup_dca(adapter);
10640 }
10641#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010642 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010643 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010644 for (i = 0; i < adapter->num_vfs; i++)
10645 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10646 }
10647
Jacob Keller2466dd92011-09-08 03:50:54 +000010648 /* firmware requires driver version to be 0xFFFFFFFF
10649 * since os does not support feature
10650 */
Emil Tantilov9612de92011-05-07 07:40:20 +000010651 if (hw->mac.ops.set_fw_drv_ver)
Tony Nguyencb8e0512016-10-26 16:25:18 -070010652 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10653 sizeof(ixgbe_driver_version) - 1,
10654 ixgbe_driver_version);
Emil Tantilov9612de92011-05-07 07:40:20 +000010655
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010656 /* add san mac addr to netdev */
10657 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010658
Neerav Parikhea818752012-01-04 20:23:40 +000010659 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010660
Don Skidmore12109822012-05-04 06:07:08 +000010661#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010662 if (ixgbe_sysfs_init(adapter))
10663 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +000010664#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010665
Catherine Sullivan00949162012-08-10 01:59:10 +000010666 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010667
Emil Tantilovd1a35ee2014-05-13 08:24:00 +000010668 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10669 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +000010670 hw->mac.ops.setup_link(hw,
10671 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10672 true);
10673
Auke Kok9a799d72007-09-15 14:07:45 -070010674 return 0;
10675
10676err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010677 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010678 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010679err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +000010680 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +000010681 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -080010682 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010683 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010684 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010685 kfree(adapter->rss_key);
Auke Kok9a799d72007-09-15 14:07:45 -070010686err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010687 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010688 free_netdev(netdev);
10689err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010690 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010691err_pci_reg:
10692err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010693 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010694 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010695 return err;
10696}
10697
10698/**
10699 * ixgbe_remove - Device Removal Routine
10700 * @pdev: PCI device information struct
10701 *
10702 * ixgbe_remove is called by the PCI subsystem to alert the driver
10703 * that it should release a PCI device. The could be caused by a
10704 * Hot-Plug event, or because the driver is going to be removed from
10705 * memory.
10706 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010707static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -070010708{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010709 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010710 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010711 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010712 int i;
Auke Kok9a799d72007-09-15 14:07:45 -070010713
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010714 /* if !adapter then we already cleaned up in probe */
10715 if (!adapter)
10716 return;
10717
10718 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +000010719 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010720
Mark Rustad09f40ae2014-01-14 18:53:11 -080010721 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010722 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -070010723
Jacob Keller3a6a4ed2012-05-01 05:24:58 +000010724
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010725#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010726 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10727 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10728 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -070010729 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10730 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010731 }
10732
10733#endif
Don Skidmore12109822012-05-04 06:07:08 +000010734#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010735 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +000010736#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010737
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010738 /* remove the added san mac */
10739 ixgbe_del_sanmac_netdev(netdev);
10740
Greg Roseda36b642012-12-11 08:26:43 +000010741#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -060010742 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +000010743#endif
Alex Williamson6b010e92015-07-29 14:38:21 -060010744 if (netdev->reg_state == NETREG_REGISTERED)
10745 unregister_netdev(netdev);
10746
Alexander Duyck7a921c92009-05-06 10:43:28 +000010747 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010748
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010749 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010750
Alexander Duyck2b1588c2012-03-17 02:39:16 +000010751#ifdef CONFIG_DCB
10752 kfree(adapter->ixgbe_ieee_pfc);
10753 kfree(adapter->ixgbe_ieee_ets);
10754
10755#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -080010756 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010757 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010758
Emil Tantilov849c4542010-06-03 16:53:41 +000010759 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010760
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010761 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
10762 if (adapter->jump_tables[i]) {
10763 kfree(adapter->jump_tables[i]->input);
10764 kfree(adapter->jump_tables[i]->mask);
10765 }
10766 kfree(adapter->jump_tables[i]);
10767 }
10768
Jacob Keller5d7daa32014-03-29 06:51:25 +000010769 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010770 kfree(adapter->rss_key);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010771 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010772 free_netdev(netdev);
10773
Frans Pop19d5afd2009-10-02 10:04:12 -070010774 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010775
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010776 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010777 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010778}
10779
10780/**
10781 * ixgbe_io_error_detected - called when PCI error is detected
10782 * @pdev: Pointer to PCI device
10783 * @state: The current pci connection state
10784 *
10785 * This function is called after a PCI bus error affecting
10786 * this device has been detected.
10787 */
10788static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +000010789 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -070010790{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010791 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10792 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010793
Greg Rose83c61fa2011-09-07 05:59:35 +000010794#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -080010795 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +000010796 struct pci_dev *bdev, *vfdev;
10797 u32 dw0, dw1, dw2, dw3;
10798 int vf, pos;
10799 u16 req_id, pf_func;
10800
10801 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
10802 adapter->num_vfs == 0)
10803 goto skip_bad_vf_detection;
10804
10805 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +080010806 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +000010807 bdev = bdev->bus->self;
10808
10809 if (!bdev)
10810 goto skip_bad_vf_detection;
10811
10812 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
10813 if (!pos)
10814 goto skip_bad_vf_detection;
10815
Mark Rustad14438462014-02-28 15:48:57 -080010816 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
10817 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
10818 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
10819 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
10820 if (ixgbe_removed(hw->hw_addr))
10821 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +000010822
10823 req_id = dw1 >> 16;
10824 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10825 if (!(req_id & 0x0080))
10826 goto skip_bad_vf_detection;
10827
10828 pf_func = req_id & 0x01;
10829 if ((pf_func & 1) == (pdev->devfn & 1)) {
10830 unsigned int device_id;
10831
10832 vf = (req_id & 0x7F) >> 1;
10833 e_dev_err("VF %d has caused a PCIe error\n", vf);
10834 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10835 "%8.8x\tdw3: %8.8x\n",
10836 dw0, dw1, dw2, dw3);
10837 switch (adapter->hw.mac.type) {
10838 case ixgbe_mac_82599EB:
10839 device_id = IXGBE_82599_VF_DEVICE_ID;
10840 break;
10841 case ixgbe_mac_X540:
10842 device_id = IXGBE_X540_VF_DEVICE_ID;
10843 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010844 case ixgbe_mac_X550:
10845 device_id = IXGBE_DEV_ID_X550_VF;
10846 break;
10847 case ixgbe_mac_X550EM_x:
10848 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10849 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010850 case ixgbe_mac_x550em_a:
10851 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10852 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010853 default:
10854 device_id = 0;
10855 break;
10856 }
10857
10858 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010859 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010860 while (vfdev) {
10861 if (vfdev->devfn == (req_id & 0xFF))
10862 break;
Jon Mason36e90312012-07-19 21:02:09 +000010863 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010864 device_id, vfdev);
10865 }
10866 /*
10867 * There's a slim chance the VF could have been hot plugged,
10868 * so if it is no longer present we don't need to issue the
10869 * VFLR. Just clean up the AER in that case.
10870 */
10871 if (vfdev) {
Christoph Hellwig63af8f72017-04-14 21:11:28 +020010872 pcie_flr(vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010873 /* Free device reference count */
10874 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010875 }
10876
10877 pci_cleanup_aer_uncorrect_error_status(pdev);
10878 }
10879
10880 /*
10881 * Even though the error may have occurred on the other port
10882 * we still need to increment the vf error reference count for
10883 * both ports because the I/O resume function will be called
10884 * for both of them.
10885 */
10886 adapter->vferr_refcount++;
10887
10888 return PCI_ERS_RESULT_RECOVERED;
10889
10890skip_bad_vf_detection:
10891#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010892 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10893 return PCI_ERS_RESULT_DISCONNECT;
10894
Emil Tantilovb64666a2017-09-29 10:55:42 -070010895 if (!netif_device_present(netdev))
10896 return PCI_ERS_RESULT_DISCONNECT;
10897
Mark Rustad41c62842014-03-12 00:38:35 +000010898 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010899 netif_device_detach(netdev);
10900
Mark Rustad41c62842014-03-12 00:38:35 +000010901 if (state == pci_channel_io_perm_failure) {
10902 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010903 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010904 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010905
Auke Kok9a799d72007-09-15 14:07:45 -070010906 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010907 ixgbe_close_suspend(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +000010908
10909 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10910 pci_disable_device(pdev);
10911 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010912
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010913 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010914 return PCI_ERS_RESULT_NEED_RESET;
10915}
10916
10917/**
10918 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10919 * @pdev: Pointer to PCI device
10920 *
10921 * Restart the card from scratch, as if from a cold-boot.
10922 */
10923static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10924{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010925 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010926 pci_ers_result_t result;
10927 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010928
gouji-new9ce77662009-05-06 10:44:45 +000010929 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010930 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010931 result = PCI_ERS_RESULT_DISCONNECT;
10932 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010933 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010934 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010935 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010936 pci_set_master(pdev);
10937 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010938 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010939
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010940 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010941
10942 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010943 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010944 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010945 }
Auke Kok9a799d72007-09-15 14:07:45 -070010946
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010947 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10948 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010949 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10950 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010951 /* non-fatal, continue */
10952 }
Auke Kok9a799d72007-09-15 14:07:45 -070010953
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010954 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010955}
10956
10957/**
10958 * ixgbe_io_resume - called when traffic can start flowing again.
10959 * @pdev: Pointer to PCI device
10960 *
10961 * This callback is called when the error recovery driver tells us that
10962 * its OK to resume normal operation.
10963 */
10964static void ixgbe_io_resume(struct pci_dev *pdev)
10965{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010966 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10967 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010968
Greg Rose83c61fa2011-09-07 05:59:35 +000010969#ifdef CONFIG_PCI_IOV
10970 if (adapter->vferr_refcount) {
10971 e_info(drv, "Resuming after VF err\n");
10972 adapter->vferr_refcount--;
10973 return;
10974 }
10975
10976#endif
Emil Tantilov126db132016-11-16 09:48:02 -080010977 rtnl_lock();
Alexander Duyckc7ccde02011-07-21 00:40:40 +000010978 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010979 ixgbe_open(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010980
10981 netif_device_attach(netdev);
Emil Tantilov126db132016-11-16 09:48:02 -080010982 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010983}
10984
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070010985static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070010986 .error_detected = ixgbe_io_error_detected,
10987 .slot_reset = ixgbe_io_slot_reset,
10988 .resume = ixgbe_io_resume,
10989};
10990
10991static struct pci_driver ixgbe_driver = {
10992 .name = ixgbe_driver_name,
10993 .id_table = ixgbe_pci_tbl,
10994 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010995 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070010996#ifdef CONFIG_PM
10997 .suspend = ixgbe_suspend,
10998 .resume = ixgbe_resume,
10999#endif
11000 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000011001 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070011002 .err_handler = &ixgbe_err_handler
11003};
11004
11005/**
11006 * ixgbe_init_module - Driver Registration Routine
11007 *
11008 * ixgbe_init_module is the first routine called when the driver is
11009 * loaded. All it does is register with the PCI subsystem.
11010 **/
11011static int __init ixgbe_init_module(void)
11012{
11013 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000011014 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000011015 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070011016
Mark Rustad780484d2015-10-21 17:21:10 -070011017 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
11018 if (!ixgbe_wq) {
11019 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
11020 return -ENOMEM;
11021 }
11022
Catherine Sullivan00949162012-08-10 01:59:10 +000011023 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000011024
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011025 ret = pci_register_driver(&ixgbe_driver);
11026 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000011027 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011028 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011029 return ret;
11030 }
11031
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011032#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011033 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011034#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011035
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011036 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070011037}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070011038
Auke Kok9a799d72007-09-15 14:07:45 -070011039module_init(ixgbe_init_module);
11040
11041/**
11042 * ixgbe_exit_module - Driver Exit Cleanup Routine
11043 *
11044 * ixgbe_exit_module is called just before the driver is removed
11045 * from memory.
11046 **/
11047static void __exit ixgbe_exit_module(void)
11048{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011049#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011050 dca_unregister_notify(&dca_notifier);
11051#endif
Auke Kok9a799d72007-09-15 14:07:45 -070011052 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000011053
Catherine Sullivan00949162012-08-10 01:59:10 +000011054 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070011055 if (ixgbe_wq) {
11056 destroy_workqueue(ixgbe_wq);
11057 ixgbe_wq = NULL;
11058 }
Auke Kok9a799d72007-09-15 14:07:45 -070011059}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011060
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011061#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011062static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011063 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011064{
11065 int ret_val;
11066
11067 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011068 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011069
11070 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
11071}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011072
Alexander Duyckb4533682009-03-31 21:32:42 +000011073#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000011074
Auke Kok9a799d72007-09-15 14:07:45 -070011075module_exit(ixgbe_exit_module);
11076
11077/* ixgbe_main.c */