blob: 952663744fc7f49fb97e1a329bd01107bcc1e32c [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{
Mark Rutland6aa7de02017-10-23 14:07:29 -0700383 u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
Mark Rustadf8e24722014-03-18 07:03:40 +0000384 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 */
Brian King0a9a17e2017-11-17 11:05:43 -06001195 smp_rmb();
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;
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01002321 struct xdp_buff xdp;
2322
2323 xdp.rxq = &rx_ring->xdp_rxq;
Auke Kok9a799d72007-09-15 14:07:45 -07002324
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002325 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002326 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002327 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyckf8003262012-03-03 02:35:52 +00002328 struct sk_buff *skb;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002329 unsigned int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002330
Alexander Duyckf8003262012-03-03 02:35:52 +00002331 /* return some buffers to hardware, one at a time is too slow */
2332 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2333 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2334 cleaned_count = 0;
2335 }
Auke Kok9a799d72007-09-15 14:07:45 -07002336
Alexander Duyck18806c92012-07-20 08:08:44 +00002337 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002338 size = le16_to_cpu(rx_desc->wb.upper.length);
2339 if (!size)
Alexander Duyckf8003262012-03-03 02:35:52 +00002340 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002341
Alexander Duyck124b74c2014-12-11 15:02:28 -08002342 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002343 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002344 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002345 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002346 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002347
Alexander Duyck3fd218762017-01-17 08:36:45 -08002348 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
2349
Alexander Duyck18806c92012-07-20 08:08:44 +00002350 /* retrieve a buffer from the ring */
John Fastabend92470802017-04-24 03:30:17 -07002351 if (!skb) {
2352 xdp.data = page_address(rx_buffer->page) +
2353 rx_buffer->page_offset;
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002354 xdp.data_meta = xdp.data;
John Fastabend92470802017-04-24 03:30:17 -07002355 xdp.data_hard_start = xdp.data -
2356 ixgbe_rx_offset(rx_ring);
2357 xdp.data_end = xdp.data + size;
2358
John Fastabend33fdc822017-04-24 03:30:18 -07002359 skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
John Fastabend92470802017-04-24 03:30:17 -07002360 }
2361
2362 if (IS_ERR(skb)) {
John Fastabend7379f972017-03-28 09:47:03 -07002363 if (PTR_ERR(skb) == -IXGBE_XDP_TX) {
2364 xdp_xmit = true;
John Fastabend33fdc822017-04-24 03:30:18 -07002365 ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
John Fastabend7379f972017-03-28 09:47:03 -07002366 } else {
John Fastabend33fdc822017-04-24 03:30:18 -07002367 rx_buffer->pagecnt_bias++;
John Fastabend7379f972017-03-28 09:47:03 -07002368 }
John Fastabend92470802017-04-24 03:30:17 -07002369 total_rx_packets++;
2370 total_rx_bytes += size;
John Fastabend92470802017-04-24 03:30:17 -07002371 } else if (skb) {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002372 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
John Fastabend92470802017-04-24 03:30:17 -07002373 } else if (ring_uses_build_skb(rx_ring)) {
Alexander Duyck6f429222017-01-17 08:37:13 -08002374 skb = ixgbe_build_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002375 &xdp, rx_desc);
2376 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002377 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002378 &xdp, rx_desc);
2379 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002380
Alexander Duyck18806c92012-07-20 08:08:44 +00002381 /* exit if we failed to retrieve a buffer */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002382 if (!skb) {
2383 rx_ring->rx_stats.alloc_rx_buff_failed++;
2384 rx_buffer->pagecnt_bias++;
Alexander Duyck18806c92012-07-20 08:08:44 +00002385 break;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002386 }
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002387
Alexander Duyck3fd218762017-01-17 08:36:45 -08002388 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002389 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002390
Alexander Duyckf8003262012-03-03 02:35:52 +00002391 /* place incomplete frames back on ring for completion */
2392 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2393 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002394
Alexander Duyckf8003262012-03-03 02:35:52 +00002395 /* verify the packet layout is correct */
2396 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2397 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002398
2399 /* probably a little skewed due to removing CRC */
2400 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002401
Alexander Duyck8a0da212012-01-31 02:59:49 +00002402 /* populate checksum, timestamp, VLAN, and protocol */
2403 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2404
Yi Zou332d4a72009-05-13 13:11:53 +00002405#ifdef IXGBE_FCOE
2406 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002407 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002408 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002409 /* include DDPed FCoE data */
2410 if (ddp_bytes > 0) {
2411 if (!mss) {
2412 mss = rx_ring->netdev->mtu -
2413 sizeof(struct fcoe_hdr) -
2414 sizeof(struct fc_frame_header) -
2415 sizeof(struct fcoe_crc_eof);
2416 if (mss > 512)
2417 mss &= ~511;
2418 }
2419 total_rx_bytes += ddp_bytes;
2420 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2421 mss);
2422 }
David S. Miller823dcd22011-08-20 10:39:12 -07002423 if (!ddp_bytes) {
2424 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002425 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002426 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002427 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002428
Yi Zou332d4a72009-05-13 13:11:53 +00002429#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002430 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002431
Alexander Duyckf8003262012-03-03 02:35:52 +00002432 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002433 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002434 }
Auke Kok9a799d72007-09-15 14:07:45 -07002435
John Fastabend7379f972017-03-28 09:47:03 -07002436 if (xdp_xmit) {
2437 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
2438
2439 /* Force memory writes to complete before letting h/w
2440 * know there are new descriptors to fetch.
2441 */
2442 wmb();
2443 writel(ring->next_to_use, ring->tail);
John Fastabend11393cc2017-07-17 09:29:40 -07002444
2445 xdp_do_flush_map();
John Fastabend7379f972017-03-28 09:47:03 -07002446 }
2447
Alexander Duyckc267fc12010-11-16 19:27:00 -08002448 u64_stats_update_begin(&rx_ring->syncp);
2449 rx_ring->stats.packets += total_rx_packets;
2450 rx_ring->stats.bytes += total_rx_bytes;
2451 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002452 q_vector->rx.total_packets += total_rx_packets;
2453 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002454
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002455 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002456}
2457
Auke Kok9a799d72007-09-15 14:07:45 -07002458/**
2459 * ixgbe_configure_msix - Configure MSI-X hardware
2460 * @adapter: board private structure
2461 *
2462 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2463 * interrupts.
2464 **/
2465static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2466{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002467 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002468 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002469 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002470
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002471 /* Populate MSIX to EITR Select */
2472 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002473 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002474 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2475 }
2476
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002477 /*
2478 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002479 * corresponding register.
2480 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002481 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002482 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002483 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002484
Alexander Duycka5579282012-02-08 07:50:04 +00002485 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002486 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002487
Alexander Duycka5579282012-02-08 07:50:04 +00002488 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002489 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002490
Alexander Duyckfe49f042009-06-04 16:00:09 +00002491 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002492 }
2493
Alexander Duyckbd508172010-11-16 19:27:03 -08002494 switch (adapter->hw.mac.type) {
2495 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002496 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002497 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002498 break;
2499 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002500 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002501 case ixgbe_mac_X550:
2502 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002503 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002504 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002505 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002506 default:
2507 break;
2508 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002509 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002510
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002511 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002512 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002513 mask &= ~(IXGBE_EIMS_OTHER |
2514 IXGBE_EIMS_MAILBOX |
2515 IXGBE_EIMS_LSC);
2516
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002517 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002518}
2519
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002520/**
2521 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002522 * @q_vector: structure containing interrupt and ring information
2523 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002524 *
2525 * Stores a new ITR value based on packets and byte
2526 * counts during the last interrupt. The advantage of per interrupt
2527 * computation is faster updates and more accurate ITR for the current
2528 * traffic pattern. Constants in this function were computed
2529 * based on theoretical maximum wire speed and thresholds were set based
2530 * on testing data as well as attempting to minimize response time
2531 * while increasing bulk throughput.
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002532 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002533static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2534 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002535{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002536 unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS |
2537 IXGBE_ITR_ADAPTIVE_LATENCY;
2538 unsigned int avg_wire_size, packets, bytes;
2539 unsigned long next_update = jiffies;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002540
Alexander Duyckb4ded832017-09-25 14:55:36 -07002541 /* If we don't have any rings just leave ourselves set for maximum
2542 * possible latency so we take ourselves out of the equation.
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002543 */
Alexander Duyckb4ded832017-09-25 14:55:36 -07002544 if (!ring_container->ring)
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002545 return;
2546
Alexander Duyckb4ded832017-09-25 14:55:36 -07002547 /* If we didn't update within up to 1 - 2 jiffies we can assume
2548 * that either packets are coming in so slow there hasn't been
2549 * any work, or that there is so much work that NAPI is dealing
2550 * with interrupt moderation and we don't need to do anything.
2551 */
2552 if (time_after(next_update, ring_container->next_update))
2553 goto clear_counts;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002554
Alexander Duyckb4ded832017-09-25 14:55:36 -07002555 packets = ring_container->total_packets;
2556
2557 /* We have no packets to actually measure against. This means
2558 * either one of the other queues on this vector is active or
2559 * we are a Tx queue doing TSO with too high of an interrupt rate.
2560 *
2561 * When this occurs just tick up our delay by the minimum value
2562 * and hope that this extra delay will prevent us from being called
2563 * without any work on our queue.
2564 */
2565 if (!packets) {
2566 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2567 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2568 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2569 itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY;
2570 goto clear_counts;
2571 }
2572
2573 bytes = ring_container->total_bytes;
2574
2575 /* If packets are less than 4 or bytes are less than 9000 assume
2576 * insufficient data to use bulk rate limiting approach. We are
2577 * likely latency driven.
2578 */
2579 if (packets < 4 && bytes < 9000) {
2580 itr = IXGBE_ITR_ADAPTIVE_LATENCY;
2581 goto adjust_by_size;
2582 }
2583
2584 /* Between 4 and 48 we can assume that our current interrupt delay
2585 * is only slightly too low. As such we should increase it by a small
2586 * fixed amount.
2587 */
2588 if (packets < 48) {
2589 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2590 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2591 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2592 goto clear_counts;
2593 }
2594
2595 /* Between 48 and 96 is our "goldilocks" zone where we are working
2596 * out "just right". Just report that our current ITR is good for us.
2597 */
2598 if (packets < 96) {
2599 itr = q_vector->itr >> 2;
2600 goto clear_counts;
2601 }
2602
2603 /* If packet count is 96 or greater we are likely looking at a slight
2604 * overrun of the delay we want. Try halving our delay to see if that
2605 * will cut the number of packets in half per interrupt.
2606 */
2607 if (packets < 256) {
2608 itr = q_vector->itr >> 3;
2609 if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS)
2610 itr = IXGBE_ITR_ADAPTIVE_MIN_USECS;
2611 goto clear_counts;
2612 }
2613
2614 /* The paths below assume we are dealing with a bulk ITR since number
2615 * of packets is 256 or greater. We are just going to have to compute
2616 * a value and try to bring the count under control, though for smaller
2617 * packet sizes there isn't much we can do as NAPI polling will likely
2618 * be kicking in sooner rather than later.
2619 */
2620 itr = IXGBE_ITR_ADAPTIVE_BULK;
2621
2622adjust_by_size:
2623 /* If packet counts are 256 or greater we can assume we have a gross
2624 * overestimation of what the rate should be. Instead of trying to fine
2625 * tune it just use the formula below to try and dial in an exact value
2626 * give the current packet size of the frame.
2627 */
2628 avg_wire_size = bytes / packets;
2629
2630 /* The following is a crude approximation of:
2631 * wmem_default / (size + overhead) = desired_pkts_per_int
2632 * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
2633 * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
2634 *
2635 * Assuming wmem_default is 212992 and overhead is 640 bytes per
2636 * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
2637 * formula down to
2638 *
2639 * (170 * (size + 24)) / (size + 640) = ITR
2640 *
2641 * We first do some math on the packet size and then finally bitshift
2642 * by 8 after rounding up. We also have to account for PCIe link speed
2643 * difference as ITR scales based on this.
2644 */
2645 if (avg_wire_size <= 60) {
2646 /* Start at 50k ints/sec */
2647 avg_wire_size = 5120;
2648 } else if (avg_wire_size <= 316) {
2649 /* 50K ints/sec to 16K ints/sec */
2650 avg_wire_size *= 40;
2651 avg_wire_size += 2720;
2652 } else if (avg_wire_size <= 1084) {
2653 /* 16K ints/sec to 9.2K ints/sec */
2654 avg_wire_size *= 15;
2655 avg_wire_size += 11452;
2656 } else if (avg_wire_size <= 1980) {
2657 /* 9.2K ints/sec to 8K ints/sec */
2658 avg_wire_size *= 5;
2659 avg_wire_size += 22420;
2660 } else {
2661 /* plateau at a limit of 8K ints/sec */
2662 avg_wire_size = 32256;
2663 }
2664
2665 /* If we are in low latency mode half our delay which doubles the rate
2666 * to somewhere between 100K to 16K ints/sec
2667 */
2668 if (itr & IXGBE_ITR_ADAPTIVE_LATENCY)
2669 avg_wire_size >>= 1;
2670
2671 /* Resultant value is 256 times larger than it needs to be. This
2672 * gives us room to adjust the value as needed to either increase
2673 * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
2674 *
2675 * Use addition as we have already recorded the new latency flag
2676 * for the ITR value.
2677 */
2678 switch (q_vector->adapter->link_speed) {
2679 case IXGBE_LINK_SPEED_10GB_FULL:
2680 case IXGBE_LINK_SPEED_100_FULL:
2681 default:
2682 itr += DIV_ROUND_UP(avg_wire_size,
2683 IXGBE_ITR_ADAPTIVE_MIN_INC * 256) *
2684 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002685 break;
Alexander Duyckb4ded832017-09-25 14:55:36 -07002686 case IXGBE_LINK_SPEED_2_5GB_FULL:
2687 case IXGBE_LINK_SPEED_1GB_FULL:
2688 case IXGBE_LINK_SPEED_10_FULL:
2689 itr += DIV_ROUND_UP(avg_wire_size,
2690 IXGBE_ITR_ADAPTIVE_MIN_INC * 64) *
2691 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002692 break;
2693 }
2694
Alexander Duyckb4ded832017-09-25 14:55:36 -07002695clear_counts:
2696 /* write back value */
2697 ring_container->itr = itr;
2698
2699 /* next update should occur within next jiffy */
2700 ring_container->next_update = next_update + 1;
2701
Alexander Duyckbd198052011-06-11 01:45:08 +00002702 ring_container->total_bytes = 0;
2703 ring_container->total_packets = 0;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002704}
2705
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002706/**
2707 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002708 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002709 *
2710 * This function is made to be called by ethtool and by the driver
2711 * when it needs to update EITR registers at runtime. Hardware
2712 * specific quirks/differences are taken care of here.
2713 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002714void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002715{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002716 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002717 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002718 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002719 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002720
Alexander Duyckbd508172010-11-16 19:27:03 -08002721 switch (adapter->hw.mac.type) {
2722 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002723 /* must write high and low 16 bits to reset counter */
2724 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002725 break;
2726 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002727 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002728 case ixgbe_mac_X550:
2729 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002730 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002731 /*
2732 * set the WDIS bit to not clear the timer bits and cause an
2733 * immediate assertion of the interrupt
2734 */
2735 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002736 break;
2737 default:
2738 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002739 }
2740 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2741}
2742
Alexander Duyckbd198052011-06-11 01:45:08 +00002743static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002744{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002745 u32 new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002746
Alexander Duyckbd198052011-06-11 01:45:08 +00002747 ixgbe_update_itr(q_vector, &q_vector->tx);
2748 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002749
Alexander Duyckb4ded832017-09-25 14:55:36 -07002750 /* use the smallest value of new ITR delay calculations */
2751 new_itr = min(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002752
Alexander Duyckb4ded832017-09-25 14:55:36 -07002753 /* Clear latency flag if set, shift into correct position */
2754 new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY;
2755 new_itr <<= 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002756
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002757 if (new_itr != q_vector->itr) {
Alexander Duyckbd198052011-06-11 01:45:08 +00002758 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002759 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002760
2761 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002762 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002763}
2764
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002765/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002766 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002767 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002768 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002769static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002770{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002771 struct ixgbe_hw *hw = &adapter->hw;
2772 u32 eicr = adapter->interrupt_event;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002773 s32 rc;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002774
Alexander Duyckf0f97782011-04-22 04:08:09 +00002775 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002776 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002777
Mark Rustad22cb4ff2017-04-25 13:55:25 -07002778 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
Alexander Duyckf0f97782011-04-22 04:08:09 +00002779 return;
2780
2781 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2782
Joe Perches7ca647b2010-09-07 21:35:40 +00002783 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002784 case IXGBE_DEV_ID_82599_T3_LOM:
2785 /*
2786 * Since the warning interrupt is for both ports
2787 * we don't have to check if:
2788 * - This interrupt wasn't for our port.
2789 * - We may have missed the interrupt so always have to
2790 * check if we got a LSC
2791 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002792 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002793 !(eicr & IXGBE_EICR_LSC))
2794 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002795
Alexander Duyckf0f97782011-04-22 04:08:09 +00002796 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002797 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002798 bool link_up = false;
2799
Josh Hay3d292262012-12-15 03:28:19 +00002800 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002801
Alexander Duyckf0f97782011-04-22 04:08:09 +00002802 if (link_up)
2803 return;
2804 }
2805
2806 /* Check if this is not due to overtemp */
2807 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2808 return;
2809
2810 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002811 case IXGBE_DEV_ID_X550EM_A_1G_T:
2812 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2813 rc = hw->phy.ops.check_overtemp(hw);
2814 if (rc != IXGBE_ERR_OVERTEMP)
2815 return;
2816 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002817 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002818 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2819 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002820 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002821 return;
2822 break;
2823 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002824 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002825
2826 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002827}
2828
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002829static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2830{
2831 struct ixgbe_hw *hw = &adapter->hw;
2832
2833 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002834 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002835 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002836 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002837 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002838 }
2839}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002840
Jacob Keller4f51bf72011-08-20 04:49:45 +00002841static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2842{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002843 struct ixgbe_hw *hw = &adapter->hw;
2844
Jacob Keller4f51bf72011-08-20 04:49:45 +00002845 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2846 return;
2847
2848 switch (adapter->hw.mac.type) {
2849 case ixgbe_mac_82599EB:
2850 /*
2851 * Need to check link state so complete overtemp check
2852 * on service task
2853 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002854 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2855 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002856 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2857 adapter->interrupt_event = eicr;
2858 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2859 ixgbe_service_event_schedule(adapter);
2860 return;
2861 }
2862 return;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002863 case ixgbe_mac_x550em_a:
2864 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2865 adapter->interrupt_event = eicr;
2866 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2867 ixgbe_service_event_schedule(adapter);
2868 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2869 IXGBE_EICR_GPI_SDP0_X550EM_a);
2870 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2871 IXGBE_EICR_GPI_SDP0_X550EM_a);
2872 }
2873 return;
2874 case ixgbe_mac_X550:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002875 case ixgbe_mac_X540:
2876 if (!(eicr & IXGBE_EICR_TS))
2877 return;
2878 break;
2879 default:
2880 return;
2881 }
2882
Don Skidmoref44e7512015-06-09 16:36:23 -07002883 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002884}
2885
Don Skidmore45788d22015-06-09 16:59:04 -07002886static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2887{
2888 switch (hw->mac.type) {
2889 case ixgbe_mac_82598EB:
2890 if (hw->phy.type == ixgbe_phy_nl)
2891 return true;
2892 return false;
2893 case ixgbe_mac_82599EB:
2894 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002895 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002896 switch (hw->mac.ops.get_media_type(hw)) {
2897 case ixgbe_media_type_fiber:
2898 case ixgbe_media_type_fiber_qsfp:
2899 return true;
2900 default:
2901 return false;
2902 }
2903 default:
2904 return false;
2905 }
2906}
2907
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002908static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2909{
2910 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002911 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002912
Don Skidmore4ccc6502015-09-02 13:47:54 -07002913 if (!ixgbe_is_sfp(hw))
2914 return;
2915
2916 /* Later MAC's use different SDP */
2917 if (hw->mac.type >= ixgbe_mac_X540)
2918 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2919
2920 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002921 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002922 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002923 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2924 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002925 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002926 ixgbe_service_event_schedule(adapter);
2927 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002928 }
2929
Don Skidmore4ccc6502015-09-02 13:47:54 -07002930 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2931 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002932 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002933 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002934 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2935 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2936 ixgbe_service_event_schedule(adapter);
2937 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002938 }
2939}
2940
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002941static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2942{
2943 struct ixgbe_hw *hw = &adapter->hw;
2944
2945 adapter->lsc_int++;
2946 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2947 adapter->link_check_timeout = jiffies;
2948 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2949 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002950 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002951 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002952 }
2953}
2954
Alexander Duyckfe49f042009-06-04 16:00:09 +00002955static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2956 u64 qmask)
2957{
2958 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002959 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002960
Alexander Duyckbd508172010-11-16 19:27:03 -08002961 switch (hw->mac.type) {
2962 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002963 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002964 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2965 break;
2966 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002967 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002968 case ixgbe_mac_X550:
2969 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002970 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002971 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002972 if (mask)
2973 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002974 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002975 if (mask)
2976 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2977 break;
2978 default:
2979 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002980 }
2981 /* skip the flush */
2982}
2983
2984static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002985 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002986{
2987 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002988 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002989
Alexander Duyckbd508172010-11-16 19:27:03 -08002990 switch (hw->mac.type) {
2991 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002992 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002993 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2994 break;
2995 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002996 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002997 case ixgbe_mac_X550:
2998 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002999 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00003000 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08003001 if (mask)
3002 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00003003 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08003004 if (mask)
3005 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
3006 break;
3007 default:
3008 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003009 }
3010 /* skip the flush */
3011}
3012
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003013/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00003014 * ixgbe_irq_enable - Enable default interrupt generation settings
3015 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003016 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00003017static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
3018 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07003019{
Don Skidmore9a900ec2015-06-09 17:15:01 -07003020 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00003021 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003022
Alexander Duyck2c4af692011-07-15 07:29:55 +00003023 /* don't reenable LSC while waiting for link */
3024 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
3025 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003026
Alexander Duyck2c4af692011-07-15 07:29:55 +00003027 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00003028 switch (adapter->hw.mac.type) {
3029 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003030 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003031 break;
3032 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003033 case ixgbe_mac_X550:
3034 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003035 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00003036 mask |= IXGBE_EIMS_TS;
3037 break;
3038 default:
3039 break;
3040 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003041 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07003042 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003043 switch (adapter->hw.mac.type) {
3044 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003045 mask |= IXGBE_EIMS_GPI_SDP1(hw);
3046 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003047 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00003048 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003049 case ixgbe_mac_X550:
3050 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003051 case ixgbe_mac_x550em_a:
3052 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07003053 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07003054 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07003055 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07003056 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
3057 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00003058 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00003059 mask |= IXGBE_EIMS_MAILBOX;
3060 break;
3061 default:
3062 break;
3063 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003064
Alexander Duyck2c4af692011-07-15 07:29:55 +00003065 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
3066 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
3067 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003068
Alexander Duyck2c4af692011-07-15 07:29:55 +00003069 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
3070 if (queues)
3071 ixgbe_irq_enable_queues(adapter, ~0);
3072 if (flush)
3073 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07003074}
3075
Alexander Duyck2c4af692011-07-15 07:29:55 +00003076static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003077{
Alexander Duyck2c4af692011-07-15 07:29:55 +00003078 struct ixgbe_adapter *adapter = data;
3079 struct ixgbe_hw *hw = &adapter->hw;
3080 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003081
Alexander Duyck2c4af692011-07-15 07:29:55 +00003082 /*
3083 * Workaround for Silicon errata. Use clear-by-write instead
3084 * of clear-by-read. Reading with EICS will return the
3085 * interrupt causes without clearing, which later be done
3086 * with the write to EICR.
3087 */
3088 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00003089
3090 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08003091 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00003092 * the bits are high when ixgbe_msix_other is called. There is a race
3093 * condition otherwise which results in possible performance loss
3094 * especially if the ixgbe_msix_other interrupt is triggering
3095 * consistently (as it would when PPS is turned on for the X540 device)
3096 */
3097 eicr &= 0xFFFF0000;
3098
Alexander Duyck2c4af692011-07-15 07:29:55 +00003099 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003100
Alexander Duyck2c4af692011-07-15 07:29:55 +00003101 if (eicr & IXGBE_EICR_LSC)
3102 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003103
Alexander Duyck2c4af692011-07-15 07:29:55 +00003104 if (eicr & IXGBE_EICR_MAILBOX)
3105 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003106
Alexander Duyck2c4af692011-07-15 07:29:55 +00003107 switch (hw->mac.type) {
3108 case ixgbe_mac_82599EB:
3109 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003110 case ixgbe_mac_X550:
3111 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003112 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07003113 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
3114 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
3115 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
3116 ixgbe_service_event_schedule(adapter);
3117 IXGBE_WRITE_REG(hw, IXGBE_EICR,
3118 IXGBE_EICR_GPI_SDP0_X540);
3119 }
Don Skidmored773ce22014-02-25 17:58:53 -08003120 if (eicr & IXGBE_EICR_ECC) {
3121 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003122 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003123 ixgbe_service_event_schedule(adapter);
3124 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3125 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003126 /* Handle Flow Director Full threshold interrupt */
3127 if (eicr & IXGBE_EICR_FLOW_DIR) {
3128 int reinit_count = 0;
3129 int i;
3130 for (i = 0; i < adapter->num_tx_queues; i++) {
3131 struct ixgbe_ring *ring = adapter->tx_ring[i];
3132 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
3133 &ring->state))
3134 reinit_count++;
3135 }
3136 if (reinit_count) {
3137 /* no more flow director interrupts until after init */
3138 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
3139 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
3140 ixgbe_service_event_schedule(adapter);
3141 }
3142 }
3143 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003144 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003145 break;
3146 default:
3147 break;
Auke Kok9a799d72007-09-15 14:07:45 -07003148 }
3149
Alexander Duyck2c4af692011-07-15 07:29:55 +00003150 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003151
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003152 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003153 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003154
Alexander Duyck2c4af692011-07-15 07:29:55 +00003155 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00003156 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00003157 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003158
Alexander Duyck2c4af692011-07-15 07:29:55 +00003159 return IRQ_HANDLED;
3160}
3161
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003162static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07003163{
3164 struct ixgbe_q_vector *q_vector = data;
3165
Auke Kok9a799d72007-09-15 14:07:45 -07003166 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003167
3168 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07003169 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003170
3171 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003172}
3173
Auke Kok9a799d72007-09-15 14:07:45 -07003174/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00003175 * ixgbe_poll - NAPI Rx polling callback
3176 * @napi: structure for representing this polling device
3177 * @budget: how many packets driver is allowed to clean
3178 *
3179 * This function is used for legacy and MSI, NAPI mode
3180 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00003181int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00003182{
3183 struct ixgbe_q_vector *q_vector =
3184 container_of(napi, struct ixgbe_q_vector, napi);
3185 struct ixgbe_adapter *adapter = q_vector->adapter;
3186 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003187 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00003188 bool clean_complete = true;
3189
3190#ifdef CONFIG_IXGBE_DCA
3191 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
3192 ixgbe_update_dca(q_vector);
3193#endif
3194
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003195 ixgbe_for_each_ring(ring, q_vector->tx) {
3196 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
3197 clean_complete = false;
3198 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003199
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08003200 /* Exit if we are called by netpoll */
3201 if (budget <= 0)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003202 return budget;
3203
Alexander Duyckeb01b972012-02-08 07:51:27 +00003204 /* attempt to distribute budget to each queue fairly, but don't allow
3205 * the budget to go below 1 because we'll exit polling */
3206 if (q_vector->rx.count > 1)
3207 per_ring_budget = max(budget/q_vector->rx.count, 1);
3208 else
3209 per_ring_budget = budget;
3210
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003211 ixgbe_for_each_ring(ring, q_vector->rx) {
3212 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
3213 per_ring_budget);
3214
3215 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003216 if (cleaned >= per_ring_budget)
3217 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003218 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003219
3220 /* If all work not completed, return budget and keep polling */
3221 if (!clean_complete)
3222 return budget;
3223
3224 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003225 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003226 if (adapter->rx_itr_setting & 1)
3227 ixgbe_set_itr(q_vector);
3228 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003229 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00003230
Paolo Abeni4b732cd2016-06-15 15:37:59 +02003231 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003232}
3233
3234/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003235 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
3236 * @adapter: board private structure
3237 *
3238 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
3239 * interrupts from the kernel.
3240 **/
3241static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
3242{
3243 struct net_device *netdev = adapter->netdev;
Tony Nguyene61e4c82017-05-12 11:38:07 -07003244 unsigned int ri = 0, ti = 0;
Alexander Duyck207867f2011-07-15 03:05:37 +00003245 int vector, err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003246
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003247 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003248 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00003249 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08003250
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003251 if (q_vector->tx.ring && q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003252 snprintf(q_vector->name, sizeof(q_vector->name),
3253 "%s-TxRx-%u", netdev->name, ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003254 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003255 } else if (q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003256 snprintf(q_vector->name, sizeof(q_vector->name),
3257 "%s-rx-%u", netdev->name, ri++);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003258 } else if (q_vector->tx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003259 snprintf(q_vector->name, sizeof(q_vector->name),
3260 "%s-tx-%u", netdev->name, ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003261 } else {
3262 /* skip this unused q_vector */
3263 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003264 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003265 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
3266 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003267 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00003268 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00003269 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003270 goto free_queue_irqs;
3271 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003272 /* If Flow Director is enabled, set interrupt affinity */
3273 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3274 /* assign the mask for this irq */
3275 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00003276 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00003277 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003278 }
3279
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003280 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00003281 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003282 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00003283 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003284 goto free_queue_irqs;
3285 }
3286
3287 return 0;
3288
3289free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00003290 while (vector) {
3291 vector--;
3292 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3293 NULL);
3294 free_irq(adapter->msix_entries[vector].vector,
3295 adapter->q_vector[vector]);
3296 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003297 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3298 pci_disable_msix(adapter->pdev);
3299 kfree(adapter->msix_entries);
3300 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003301 return err;
3302}
3303
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08003304/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003305 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07003306 * @irq: interrupt number
3307 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07003308 **/
3309static irqreturn_t ixgbe_intr(int irq, void *data)
3310{
Alexander Duycka65151ba22011-05-27 05:31:32 +00003311 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07003312 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003313 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003314 u32 eicr;
3315
Don Skidmore54037502009-02-21 15:42:56 -08003316 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00003317 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08003318 * before the read of EICR.
3319 */
3320 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3321
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003322 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003323 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003324 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003325 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003326 /*
3327 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003328 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003329 * have disabled interrupts due to EIAM
3330 * finish the workaround of silicon errata on 82598. Unmask
3331 * the interrupt that we masked before the EICR read.
3332 */
3333 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3334 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003335 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003336 }
Auke Kok9a799d72007-09-15 14:07:45 -07003337
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003338 if (eicr & IXGBE_EICR_LSC)
3339 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003340
Alexander Duyckbd508172010-11-16 19:27:03 -08003341 switch (hw->mac.type) {
3342 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003343 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003344 /* Fall through */
3345 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003346 case ixgbe_mac_X550:
3347 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003348 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003349 if (eicr & IXGBE_EICR_ECC) {
3350 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003351 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003352 ixgbe_service_event_schedule(adapter);
3353 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3354 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003355 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003356 break;
3357 default:
3358 break;
3359 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003360
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003361 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003362 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003363 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003364
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003365 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003366 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003367
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003368 /*
3369 * re-enable link(maybe) and non-queue interrupts, no flush.
3370 * ixgbe_poll will re-enable the queue interrupts
3371 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003372 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3373 ixgbe_irq_enable(adapter, false, false);
3374
Auke Kok9a799d72007-09-15 14:07:45 -07003375 return IRQ_HANDLED;
3376}
3377
3378/**
3379 * ixgbe_request_irq - initialize interrupts
3380 * @adapter: board private structure
3381 *
3382 * Attempts to configure interrupts using the best available
3383 * capabilities of the hardware and kernel.
3384 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003385static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003386{
3387 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003388 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003389
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003390 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003391 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003392 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003393 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003394 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003395 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003396 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003397 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003398
Alexander Duyckde88eee2012-02-08 07:49:59 +00003399 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003400 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003401
Auke Kok9a799d72007-09-15 14:07:45 -07003402 return err;
3403}
3404
3405static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3406{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003407 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003408
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003409 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003410 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003411 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003412 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003413
Mark Rustad1fa71252016-09-28 15:36:38 -07003414 if (!adapter->msix_entries)
3415 return;
3416
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003417 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3418 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3419 struct msix_entry *entry = &adapter->msix_entries[vector];
3420
3421 /* free only the irqs that were actually requested */
3422 if (!q_vector->rx.ring && !q_vector->tx.ring)
3423 continue;
3424
3425 /* clear the affinity_mask in the IRQ descriptor */
3426 irq_set_affinity_hint(entry->vector, NULL);
3427
3428 free_irq(entry->vector, q_vector);
3429 }
3430
Babu Moger90c6f872016-06-18 17:40:47 -07003431 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003432}
3433
3434/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003435 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3436 * @adapter: board private structure
3437 **/
3438static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3439{
Alexander Duyckbd508172010-11-16 19:27:03 -08003440 switch (adapter->hw.mac.type) {
3441 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003442 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003443 break;
3444 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003445 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003446 case ixgbe_mac_X550:
3447 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003448 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003449 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3450 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003451 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003452 break;
3453 default:
3454 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003455 }
3456 IXGBE_WRITE_FLUSH(&adapter->hw);
3457 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003458 int vector;
3459
3460 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3461 synchronize_irq(adapter->msix_entries[vector].vector);
3462
3463 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003464 } else {
3465 synchronize_irq(adapter->pdev->irq);
3466 }
3467}
3468
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003469/**
Auke Kok9a799d72007-09-15 14:07:45 -07003470 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3471 *
3472 **/
3473static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3474{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003475 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003476
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003477 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003478
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003479 ixgbe_set_ivar(adapter, 0, 0, 0);
3480 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003481
Emil Tantilov396e7992010-07-01 20:05:12 +00003482 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003483}
3484
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003485/**
3486 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3487 * @adapter: board private structure
3488 * @ring: structure containing ring specific data
3489 *
3490 * Configure the Tx descriptor ring after a reset.
3491 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003492void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3493 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003494{
3495 struct ixgbe_hw *hw = &adapter->hw;
3496 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003497 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003498 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003499 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003500
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003501 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003502 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003503 IXGBE_WRITE_FLUSH(hw);
3504
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003505 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003506 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003507 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3508 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3509 ring->count * sizeof(union ixgbe_adv_tx_desc));
3510 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3511 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003512 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003513
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003514 /*
3515 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003516 * higher than 1 when:
3517 * - ITR is 0 as it could cause false TX hangs
3518 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003519 *
3520 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3521 * to or less than the number of on chip descriptors, which is
3522 * currently 40.
3523 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003524 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003525 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003526 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003527 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003528
Alexander Duycke954b372012-02-08 07:49:38 +00003529 /*
3530 * Setting PTHRESH to 32 both improves performance
3531 * and avoids a TX hang with DFP enabled
3532 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003533 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003534 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003535
3536 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003537 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003538 ring->atr_sample_rate = adapter->atr_sample_rate;
3539 ring->atr_count = 0;
3540 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3541 } else {
3542 ring->atr_sample_rate = 0;
3543 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003544
Alexander Duyckfd786b72013-01-12 06:33:31 +00003545 /* initialize XPS */
3546 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3547 struct ixgbe_q_vector *q_vector = ring->q_vector;
3548
3549 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003550 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003551 &q_vector->affinity_mask,
3552 ring->queue_index);
3553 }
3554
John Fastabendc84d3242010-11-16 19:27:12 -08003555 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3556
Alexander Duyckffed21b2017-01-17 08:37:29 -08003557 /* reinitialize tx_buffer_info */
3558 memset(ring->tx_buffer_info, 0,
3559 sizeof(struct ixgbe_tx_buffer) * ring->count);
3560
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003561 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003562 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3563
3564 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3565 if (hw->mac.type == ixgbe_mac_82598EB &&
3566 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3567 return;
3568
3569 /* poll to verify queue is enabled */
3570 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003571 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003572 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3573 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3574 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003575 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003576}
3577
Alexander Duyck120ff942010-08-19 13:34:50 +00003578static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3579{
3580 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003581 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003582 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003583
3584 if (hw->mac.type == ixgbe_mac_82598EB)
3585 return;
3586
3587 /* disable the arbiter while setting MTQC */
3588 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3589 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3590 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3591
3592 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003593 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3594 mtqc = IXGBE_MTQC_VT_ENA;
3595 if (tcs > 4)
3596 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3597 else if (tcs > 1)
3598 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003599 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3600 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003601 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003602 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003603 mtqc |= IXGBE_MTQC_64VF;
3604 } else {
3605 if (tcs > 4)
3606 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3607 else if (tcs > 1)
3608 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3609 else
3610 mtqc = IXGBE_MTQC_64Q_1PB;
3611 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003612
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003613 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003614
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003615 /* Enable Security TX Buffer IFG for multiple pb */
3616 if (tcs) {
3617 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3618 sectx |= IXGBE_SECTX_DCB;
3619 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003620 }
3621
3622 /* re-enable the arbiter */
3623 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3624 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3625}
3626
Auke Kok9a799d72007-09-15 14:07:45 -07003627/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003628 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003629 * @adapter: board private structure
3630 *
3631 * Configure the Tx unit of the MAC after a reset.
3632 **/
3633static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3634{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003635 struct ixgbe_hw *hw = &adapter->hw;
3636 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003637 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003638
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003639 ixgbe_setup_mtqc(adapter);
3640
3641 if (hw->mac.type != ixgbe_mac_82598EB) {
3642 /* DMATXCTL.EN must be before Tx queues are enabled */
3643 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3644 dmatxctl |= IXGBE_DMATXCTL_TE;
3645 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3646 }
3647
Auke Kok9a799d72007-09-15 14:07:45 -07003648 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003649 for (i = 0; i < adapter->num_tx_queues; i++)
3650 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07003651 for (i = 0; i < adapter->num_xdp_queues; i++)
3652 ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003653}
3654
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003655static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3656 struct ixgbe_ring *ring)
3657{
3658 struct ixgbe_hw *hw = &adapter->hw;
3659 u8 reg_idx = ring->reg_idx;
3660 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3661
3662 srrctl |= IXGBE_SRRCTL_DROP_EN;
3663
3664 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3665}
3666
3667static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3668 struct ixgbe_ring *ring)
3669{
3670 struct ixgbe_hw *hw = &adapter->hw;
3671 u8 reg_idx = ring->reg_idx;
3672 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3673
3674 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3675
3676 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3677}
3678
3679#ifdef CONFIG_IXGBE_DCB
3680void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3681#else
3682static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3683#endif
3684{
3685 int i;
3686 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3687
3688 if (adapter->ixgbe_ieee_pfc)
3689 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3690
3691 /*
3692 * We should set the drop enable bit if:
3693 * SR-IOV is enabled
3694 * or
3695 * Number of Rx queues > 1 and flow control is disabled
3696 *
3697 * This allows us to avoid head of line blocking for security
3698 * and performance reasons.
3699 */
3700 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3701 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3702 for (i = 0; i < adapter->num_rx_queues; i++)
3703 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3704 } else {
3705 for (i = 0; i < adapter->num_rx_queues; i++)
3706 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3707 }
3708}
3709
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003710#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003711
Yi Zoua6616b42009-08-06 13:05:23 +00003712static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003713 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003714{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003715 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003716 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003717 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003718
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003719 if (hw->mac.type == ixgbe_mac_82598EB) {
3720 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3721
3722 /*
3723 * if VMDq is not active we must program one srrctl register
3724 * per RSS queue since we have enabled RDRXCTL.MVMEN
3725 */
3726 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003727 }
3728
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003729 /* configure header buffer length, needed for RSC */
3730 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003731
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003732 /* configure the packet buffer length */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003733 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3734 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3735 else
3736 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003737
3738 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003739 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003740
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003741 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003742}
3743
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003744/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003745 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003746 * @adapter: device handle
3747 *
3748 * - 82598/82599/X540: 128
3749 * - X550(non-SRIOV mode): 512
3750 * - X550(SRIOV mode): 64
3751 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003752u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003753{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003754 if (adapter->hw.mac.type < ixgbe_mac_X550)
3755 return 128;
3756 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3757 return 64;
3758 else
3759 return 512;
3760}
3761
3762/**
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003763 * ixgbe_store_key - Write the RSS key to HW
3764 * @adapter: device handle
3765 *
3766 * Write the RSS key stored in adapter.rss_key to HW.
3767 */
3768void ixgbe_store_key(struct ixgbe_adapter *adapter)
3769{
3770 struct ixgbe_hw *hw = &adapter->hw;
3771 int i;
3772
3773 for (i = 0; i < 10; i++)
3774 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3775}
3776
3777/**
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07003778 * ixgbe_init_rss_key - Initialize adapter RSS key
3779 * @adapter: device handle
3780 *
3781 * Allocates and initializes the RSS key if it is not allocated.
3782 **/
3783static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
3784{
3785 u32 *rss_key;
3786
3787 if (!adapter->rss_key) {
3788 rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
3789 if (unlikely(!rss_key))
3790 return -ENOMEM;
3791
3792 netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
3793 adapter->rss_key = rss_key;
3794 }
3795
3796 return 0;
3797}
3798
3799/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003800 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003801 * @adapter: device handle
3802 *
3803 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3804 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003805void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003806{
3807 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003808 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003809 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003810 u32 indices_multi;
3811 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003812
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003813 /* Fill out the redirection table as follows:
3814 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3815 * indices.
3816 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3817 * - X550: 8 bit wide entries containing 6 bit RSS index
3818 */
3819 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3820 indices_multi = 0x11;
3821 else
3822 indices_multi = 0x1;
3823
3824 /* Write redirection table to HW */
3825 for (i = 0; i < reta_entries; i++) {
3826 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3827 if ((i & 3) == 3) {
3828 if (i < 128)
3829 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3830 else
3831 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3832 reta);
3833 reta = 0;
3834 }
3835 }
3836}
3837
3838/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003839 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003840 * @adapter: device handle
3841 *
3842 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3843 */
3844static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3845{
3846 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3847 struct ixgbe_hw *hw = &adapter->hw;
3848 u32 vfreta = 0;
3849 unsigned int pf_pool = adapter->num_vfs;
3850
3851 /* Write redirection table to HW */
3852 for (i = 0; i < reta_entries; i++) {
3853 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3854 if ((i & 3) == 3) {
3855 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3856 vfreta);
3857 vfreta = 0;
3858 }
3859 }
3860}
3861
3862static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3863{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003864 u32 i, j;
3865 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3866 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3867
Alexander Duycke24fcf22016-09-07 20:28:24 -07003868 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003869 * make full use of any rings they may have. We will use the
3870 * PSRTYPE register to control how many rings we use within the PF.
3871 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003872 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3873 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003874
Alexander Duyck05abb122010-08-19 13:35:41 +00003875 /* Fill out hash function seeds */
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003876 ixgbe_store_key(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003877
Alexander Duyck05abb122010-08-19 13:35:41 +00003878 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003879 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3880
Don Skidmore0f9b2322014-11-18 09:35:08 +00003881 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003882 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003883 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003884
3885 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003886 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003887
3888 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003889}
3890
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003891static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003892{
3893 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003894 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3895 unsigned int pf_pool = adapter->num_vfs;
3896 int i, j;
3897
3898 /* Fill out hash function seeds */
3899 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003900 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07003901 *(adapter->rss_key + i));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003902
3903 /* Fill out the redirection table */
3904 for (i = 0, j = 0; i < 64; i++, j++) {
3905 if (j == rss_i)
3906 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003907
3908 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003909 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003910
3911 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003912}
3913
3914static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3915{
3916 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003917 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003918 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003919
3920 /* Disable indicating checksum in descriptor, enables RSS hash */
3921 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3922 rxcsum |= IXGBE_RXCSUM_PCSD;
3923 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3924
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003925 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003926 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003927 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003928 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003929 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003930
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003931 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3932 if (tcs > 4)
3933 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3934 else if (tcs > 1)
3935 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003936 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3937 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003938 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3939 else
3940 mrqc = IXGBE_MRQC_VMDQRSS64EN;
Emil Tantilove6b41c82017-04-25 11:31:06 -07003941
3942 /* Enable L3/L4 for Tx Switched packets */
3943 mrqc |= IXGBE_MRQC_L3L4TXSWEN;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003944 } else {
3945 if (tcs > 4)
3946 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3947 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003948 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3949 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003950 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003951 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003952 }
3953
Alexander Duyck05abb122010-08-19 13:35:41 +00003954 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003955 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3956 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3957 IXGBE_MRQC_RSS_FIELD_IPV6 |
3958 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003959
Alexander Duyckef6afc02012-02-08 07:51:53 +00003960 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003961 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003962 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003963 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003964
Don Skidmore0f9b2322014-11-18 09:35:08 +00003965 if ((hw->mac.type >= ixgbe_mac_X550) &&
3966 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3967 unsigned int pf_pool = adapter->num_vfs;
3968
3969 /* Enable VF RSS mode */
3970 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3971 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3972
3973 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003974 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003975 vfmrqc = IXGBE_MRQC_RSSEN;
3976 vfmrqc |= rss_field;
3977 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3978 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003979 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003980 mrqc |= rss_field;
3981 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3982 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003983}
3984
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003985/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003986 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3987 * @adapter: address of board private structure
3988 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003989 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003990static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003991 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003992{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003993 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003994 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003995 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003996
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003997 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003998 return;
3999
Alexander Duyck73670962010-08-19 13:38:34 +00004000 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00004001 rscctrl |= IXGBE_RSCCTL_RSCEN;
4002 /*
4003 * we must limit the number of descriptors so that the
4004 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00004005 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00004006 */
Alexander Duyckf8003262012-03-03 02:35:52 +00004007 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00004008 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00004009}
4010
Alexander Duyck9e10e042010-08-19 13:40:06 +00004011#define IXGBE_MAX_RX_DESC_POLL 10
4012static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
4013 struct ixgbe_ring *ring)
4014{
4015 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004016 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
4017 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004018 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004019
Mark Rustadb0483c82014-01-14 18:53:17 -08004020 if (ixgbe_removed(hw->hw_addr))
4021 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004022 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
4023 if (hw->mac.type == ixgbe_mac_82598EB &&
4024 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
4025 return;
4026
4027 do {
Don Skidmore032b4322011-03-18 09:32:53 +00004028 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004029 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4030 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
4031
4032 if (!wait_loop) {
4033 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
4034 "the polling period\n", reg_idx);
4035 }
4036}
4037
Yi Zou2d39d572011-01-06 14:29:56 +00004038void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
4039 struct ixgbe_ring *ring)
4040{
4041 struct ixgbe_hw *hw = &adapter->hw;
4042 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
4043 u32 rxdctl;
4044 u8 reg_idx = ring->reg_idx;
4045
Mark Rustadb0483c82014-01-14 18:53:17 -08004046 if (ixgbe_removed(hw->hw_addr))
4047 return;
Yi Zou2d39d572011-01-06 14:29:56 +00004048 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4049 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
4050
4051 /* write value back with RXDCTL.ENABLE bit cleared */
4052 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4053
4054 if (hw->mac.type == ixgbe_mac_82598EB &&
4055 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
4056 return;
4057
4058 /* the hardware may take up to 100us to really disable the rx queue */
4059 do {
4060 udelay(10);
4061 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4062 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
4063
4064 if (!wait_loop) {
4065 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
4066 "the polling period\n", reg_idx);
4067 }
4068}
4069
Alexander Duyck84418e32010-08-19 13:40:54 +00004070void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
4071 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00004072{
4073 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc3630cc2017-01-17 08:36:28 -08004074 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyckacd37172010-08-19 13:36:05 +00004075 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004076 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004077 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00004078
Alexander Duyck9e10e042010-08-19 13:40:06 +00004079 /* disable queue to avoid issues while updating state */
4080 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00004081 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004082
Alexander Duyckacd37172010-08-19 13:36:05 +00004083 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
4084 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
4085 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
4086 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08004087 /* Force flushing of IXGBE_RDLEN to prevent MDD */
4088 IXGBE_WRITE_FLUSH(hw);
4089
Alexander Duyckacd37172010-08-19 13:36:05 +00004090 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
4091 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08004092 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004093
4094 ixgbe_configure_srrctl(adapter, ring);
4095 ixgbe_configure_rscctl(adapter, ring);
4096
4097 if (hw->mac.type == ixgbe_mac_82598EB) {
4098 /*
4099 * enable cache line friendly hardware writes:
4100 * PTHRESH=32 descriptors (half the internal cache),
4101 * this also removes ugly rx_no_buffer_count increment
4102 * HTHRESH=4 descriptors (to minimize latency on fetch)
4103 * WTHRESH=8 burst writeback up to two cache lines
4104 */
4105 rxdctl &= ~0x3FFFFF;
4106 rxdctl |= 0x080420;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004107#if (PAGE_SIZE < 8192)
4108 } else {
4109 rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
4110 IXGBE_RXDCTL_RLPML_EN);
4111
4112 /* Limit the maximum frame size so we don't overrun the skb */
4113 if (ring_uses_build_skb(ring) &&
4114 !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
Alexander Duyck541ea692017-03-02 15:01:05 -08004115 rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004116 IXGBE_RXDCTL_RLPML_EN;
4117#endif
Alexander Duyck9e10e042010-08-19 13:40:06 +00004118 }
4119
Alexander Duyckffed21b2017-01-17 08:37:29 -08004120 /* initialize rx_buffer_info */
4121 memset(ring->rx_buffer_info, 0,
4122 sizeof(struct ixgbe_rx_buffer) * ring->count);
4123
Alexander Duyckc3630cc2017-01-17 08:36:28 -08004124 /* initialize Rx descriptor 0 */
4125 rx_desc = IXGBE_RX_DESC(ring, 0);
4126 rx_desc->wb.upper.length = 0;
4127
Alexander Duyck9e10e042010-08-19 13:40:06 +00004128 /* enable receive descriptor ring */
4129 rxdctl |= IXGBE_RXDCTL_ENABLE;
4130 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4131
4132 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00004133 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00004134}
4135
Alexander Duyck48654522010-08-19 13:36:27 +00004136static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
4137{
4138 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004139 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08004140 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00004141
4142 /* PSRTYPE must be initialized in non 82598 adapters */
4143 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004144 IXGBE_PSRTYPE_UDPHDR |
4145 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00004146 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004147 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00004148
4149 if (hw->mac.type == ixgbe_mac_82598EB)
4150 return;
4151
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004152 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004153 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004154 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004155 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00004156
John Fastabend2a47fa42013-11-06 09:54:52 -08004157 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
4158 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00004159}
4160
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004161static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
4162{
4163 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004164 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004165 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00004166 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004167
4168 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
4169 return;
4170
4171 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00004172 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
4173 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004174 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004175 vmdctl |= IXGBE_VT_CTL_REPLEN;
4176 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004177
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004178 vf_shift = VMDQ_P(0) % 32;
4179 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004180
4181 /* Enable only the PF's pool for Tx/Rx */
Emil Tantilov11f2b492016-05-04 15:01:27 -07004182 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004183 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
Emil Tantilov11f2b492016-05-04 15:01:27 -07004184 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004185 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07004186 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00004187 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004188
4189 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004190 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004191
Alexander Duyck16369562015-11-02 17:10:13 -08004192 /* clear VLAN promisc flag so VFTA will be updated if necessary */
4193 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4194
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004195 /*
4196 * Set up VF register offsets for selected VT Mode,
4197 * i.e. 32 or 64 VFs for SR-IOV
4198 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00004199 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4200 case IXGBE_82599_VMDQ_8Q_MASK:
4201 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
4202 break;
4203 case IXGBE_82599_VMDQ_4Q_MASK:
4204 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
4205 break;
4206 default:
4207 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
4208 break;
4209 }
4210
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004211 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
4212
Greg Rosede4c7f62011-09-29 05:57:33 +00004213 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07004214 /* configure spoof checking */
4215 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
4216 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03004217
4218 /* Enable/Disable RSS query feature */
4219 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
4220 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00004221 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004222}
4223
Alexander Duyck477de6e2010-08-19 13:38:11 +00004224static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004225{
Auke Kok9a799d72007-09-15 14:07:45 -07004226 struct ixgbe_hw *hw = &adapter->hw;
4227 struct net_device *netdev = adapter->netdev;
4228 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004229 struct ixgbe_ring *rx_ring;
4230 int i;
4231 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00004232
Alexander Duyck477de6e2010-08-19 13:38:11 +00004233#ifdef IXGBE_FCOE
4234 /* adjust max frame to be able to do baby jumbo for FCoE */
4235 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
4236 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
4237 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4238
4239#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00004240
4241 /* adjust max frame to be at least the size of a standard frame */
4242 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
4243 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
4244
Alexander Duyck477de6e2010-08-19 13:38:11 +00004245 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
4246 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
4247 mhadd &= ~IXGBE_MHADD_MFS_MASK;
4248 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
4249
4250 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07004251 }
4252
Auke Kok9a799d72007-09-15 14:07:45 -07004253 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004254 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
4255 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07004256 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4257
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004258 /*
4259 * Setup the HW Rx Head and Tail Descriptor Pointers and
4260 * the Base and Length of the Rx Descriptor Ring
4261 */
Auke Kok9a799d72007-09-15 14:07:45 -07004262 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004263 rx_ring = adapter->rx_ring[i];
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004264
4265 clear_ring_rsc_enabled(rx_ring);
4266 clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004267 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004268
Alexander Duyck7d637bc2010-11-16 19:26:56 -08004269 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4270 set_ring_rsc_enabled(rx_ring);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004271
4272 if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
4273 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004274
Alexander Duyck6f429222017-01-17 08:37:13 -08004275 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004276 if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
4277 continue;
4278
4279 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
4280
4281#if (PAGE_SIZE < 8192)
4282 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4283 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4284
Alexander Duyck541ea692017-03-02 15:01:05 -08004285 if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
4286 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004287 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4288#endif
Alexander Duyck477de6e2010-08-19 13:38:11 +00004289 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00004290}
4291
Alexander Duyck73670962010-08-19 13:38:34 +00004292static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
4293{
4294 struct ixgbe_hw *hw = &adapter->hw;
4295 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
4296
4297 switch (hw->mac.type) {
4298 case ixgbe_mac_82598EB:
4299 /*
4300 * For VMDq support of different descriptor types or
4301 * buffer sizes through the use of multiple SRRCTL
4302 * registers, RDRXCTL.MVMEN must be set to 1
4303 *
4304 * also, the manual doesn't mention it clearly but DCA hints
4305 * will only use queue 0's tags unless this bit is set. Side
4306 * effects of setting this bit are only that SRRCTL must be
4307 * fully programmed [0..15]
4308 */
4309 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
4310 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07004311 case ixgbe_mac_X550:
4312 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004313 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07004314 if (adapter->num_vfs)
4315 rdrxctl |= IXGBE_RDRXCTL_PSP;
Tony Nguyen93df9462017-05-31 04:43:47 -07004316 /* fall through */
Alexander Duyck73670962010-08-19 13:38:34 +00004317 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004318 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00004319 /* Disable RSC for ACK packets */
4320 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
4321 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
4322 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
4323 /* hardware requires some bits to be set by default */
4324 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
4325 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
4326 break;
4327 default:
4328 /* We should do nothing since we don't know this hardware */
4329 return;
4330 }
4331
4332 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
4333}
4334
Alexander Duyck477de6e2010-08-19 13:38:11 +00004335/**
4336 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4337 * @adapter: board private structure
4338 *
4339 * Configure the Rx unit of the MAC after a reset.
4340 **/
4341static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
4342{
4343 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004344 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004345 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004346
4347 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07004348 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004349
4350 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00004351 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004352
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004353 /* RSC Setup */
4354 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4355 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
4356 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
4357 rfctl |= IXGBE_RFCTL_RSC_DIS;
Emil Tantilova21d0822016-08-10 11:19:23 -07004358
4359 /* disable NFS filtering */
4360 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004361 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
4362
Alexander Duyck9e10e042010-08-19 13:40:06 +00004363 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004364 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004365
Alexander Duyck477de6e2010-08-19 13:38:11 +00004366 /* set_rx_buffer_len must be called before ring initialization */
4367 ixgbe_set_rx_buffer_len(adapter);
4368
4369 /*
4370 * Setup the HW Rx Head and Tail Descriptor Pointers and
4371 * the Base and Length of the Rx Descriptor Ring
4372 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00004373 for (i = 0; i < adapter->num_rx_queues; i++)
4374 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004375
Don Skidmore1f9ac572015-03-13 13:54:30 -07004376 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004377 /* disable drop enable for 82598 parts */
4378 if (hw->mac.type == ixgbe_mac_82598EB)
4379 rxctrl |= IXGBE_RXCTRL_DMBYPS;
4380
4381 /* enable all receives */
4382 rxctrl |= IXGBE_RXCTRL_RXEN;
4383 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004384}
4385
Patrick McHardy80d5c362013-04-19 02:04:28 +00004386static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
4387 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004388{
4389 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004390 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004391
4392 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004393 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4394 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
4395
Jesse Grossf62bbb52010-10-20 13:56:10 +00004396 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004397
4398 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004399}
4400
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004401static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
4402{
4403 u32 vlvf;
4404 int idx;
4405
4406 /* short cut the special case */
4407 if (vlan == 0)
4408 return 0;
4409
4410 /* Search for the vlan id in the VLVF entries */
4411 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
4412 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
4413 if ((vlvf & VLAN_VID_MASK) == vlan)
4414 break;
4415 }
4416
4417 return idx;
4418}
4419
4420void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
4421{
4422 struct ixgbe_hw *hw = &adapter->hw;
4423 u32 bits, word;
4424 int idx;
4425
4426 idx = ixgbe_find_vlvf_entry(hw, vid);
4427 if (!idx)
4428 return;
4429
4430 /* See if any other pools are set for this VLAN filter
4431 * entry other than the PF.
4432 */
4433 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004434 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004435 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4436
4437 /* Disable the filter so this falls into the default pool. */
4438 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4439 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4440 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4441 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4442 }
4443}
4444
Patrick McHardy80d5c362013-04-19 02:04:28 +00004445static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4446 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004447{
4448 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004449 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004450
Auke Kok9a799d72007-09-15 14:07:45 -07004451 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004452 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004453 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4454
Jesse Grossf62bbb52010-10-20 13:56:10 +00004455 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004456
4457 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004458}
4459
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004460/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004461 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4462 * @adapter: driver data
4463 */
4464static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4465{
4466 struct ixgbe_hw *hw = &adapter->hw;
4467 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004468 int i, j;
4469
4470 switch (hw->mac.type) {
4471 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004472 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4473 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004474 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4475 break;
4476 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004477 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004478 case ixgbe_mac_X550:
4479 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004480 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004481 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004482 struct ixgbe_ring *ring = adapter->rx_ring[i];
4483
4484 if (ring->l2_accel_priv)
4485 continue;
4486 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004487 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4488 vlnctrl &= ~IXGBE_RXDCTL_VME;
4489 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4490 }
4491 break;
4492 default:
4493 break;
4494 }
4495}
4496
4497/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004498 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004499 * @adapter: driver data
4500 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004501static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004502{
4503 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004504 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004505 int i, j;
4506
4507 switch (hw->mac.type) {
4508 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004509 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4510 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004511 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4512 break;
4513 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004514 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004515 case ixgbe_mac_X550:
4516 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004517 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004518 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004519 struct ixgbe_ring *ring = adapter->rx_ring[i];
4520
4521 if (ring->l2_accel_priv)
4522 continue;
4523 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004524 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4525 vlnctrl |= IXGBE_RXDCTL_VME;
4526 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4527 }
4528 break;
4529 default:
4530 break;
4531 }
4532}
4533
Alexander Duyck16369562015-11-02 17:10:13 -08004534static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4535{
4536 struct ixgbe_hw *hw = &adapter->hw;
4537 u32 vlnctrl, i;
4538
Alexander Duyckf60439b2016-08-11 14:51:56 -07004539 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4540
Emil Tantilov691e4122016-08-22 16:17:46 -07004541 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4542 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4543 vlnctrl |= IXGBE_VLNCTRL_VFE;
4544 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4545 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004546 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004547 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4548 return;
4549 }
4550
Emil Tantilov691e4122016-08-22 16:17:46 -07004551 /* Nothing to do for 82598 */
4552 if (hw->mac.type == ixgbe_mac_82598EB)
4553 return;
4554
Alexander Duyck16369562015-11-02 17:10:13 -08004555 /* We are already in VLAN promisc, nothing to do */
4556 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4557 return;
4558
4559 /* Set flag so we don't redo unnecessary work */
4560 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4561
4562 /* Add PF to all active pools */
4563 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4564 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4565 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4566
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004567 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004568 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4569 }
4570
4571 /* Set all bits in the VLAN filter table array */
4572 for (i = hw->mac.vft_size; i--;)
4573 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4574}
4575
4576#define VFTA_BLOCK_SIZE 8
4577static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4578{
4579 struct ixgbe_hw *hw = &adapter->hw;
4580 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4581 u32 vid_start = vfta_offset * 32;
4582 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4583 u32 i, vid, word, bits;
4584
4585 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4586 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4587
4588 /* pull VLAN ID from VLVF */
4589 vid = vlvf & VLAN_VID_MASK;
4590
4591 /* only concern outselves with a certain range */
4592 if (vid < vid_start || vid >= vid_end)
4593 continue;
4594
4595 if (vlvf) {
4596 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004597 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004598
4599 /* if PF is part of this then continue */
4600 if (test_bit(vid, adapter->active_vlans))
4601 continue;
4602 }
4603
4604 /* remove PF from the pool */
4605 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004606 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004607 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4608 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4609 }
4610
4611 /* extract values from active_vlans and write back to VFTA */
4612 for (i = VFTA_BLOCK_SIZE; i--;) {
4613 vid = (vfta_offset + i) * 32;
4614 word = vid / BITS_PER_LONG;
4615 bits = vid % BITS_PER_LONG;
4616
4617 vfta[i] |= adapter->active_vlans[word] >> bits;
4618
4619 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4620 }
4621}
4622
4623static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4624{
4625 struct ixgbe_hw *hw = &adapter->hw;
4626 u32 vlnctrl, i;
4627
Alexander Duyckf60439b2016-08-11 14:51:56 -07004628 /* Set VLAN filtering to enabled */
4629 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4630 vlnctrl |= IXGBE_VLNCTRL_VFE;
4631 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4632
Emil Tantilov691e4122016-08-22 16:17:46 -07004633 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4634 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004635 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004636
4637 /* We are not in VLAN promisc, nothing to do */
4638 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4639 return;
4640
4641 /* Set flag so we don't redo unnecessary work */
4642 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4643
4644 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4645 ixgbe_scrub_vfta(adapter, i);
4646}
4647
Auke Kok9a799d72007-09-15 14:07:45 -07004648static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4649{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004650 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004651
Patrick McHardy80d5c362013-04-19 02:04:28 +00004652 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004653
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004654 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004655 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004656}
4657
4658/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004659 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4660 * @netdev: network interface device structure
4661 *
4662 * Writes multicast address list to the MTA hash table.
4663 * Returns: -ENOMEM on failure
4664 * 0 on no addresses written
4665 * X on writing X addresses to MTA
4666 **/
4667static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4668{
4669 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4670 struct ixgbe_hw *hw = &adapter->hw;
4671
4672 if (!netif_running(netdev))
4673 return 0;
4674
4675 if (hw->mac.ops.update_mc_addr_list)
4676 hw->mac.ops.update_mc_addr_list(hw, netdev);
4677 else
4678 return -ENOMEM;
4679
4680#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004681 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004682#endif
4683
4684 return netdev_mc_count(netdev);
4685}
4686
Jacob Keller5d7daa32014-03-29 06:51:25 +00004687#ifdef CONFIG_PCI_IOV
4688void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4689{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004690 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004691 struct ixgbe_hw *hw = &adapter->hw;
4692 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004693
4694 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4695 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4696
4697 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4698 hw->mac.ops.set_rar(hw, i,
4699 mac_table->addr,
4700 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004701 IXGBE_RAH_AV);
4702 else
4703 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004704 }
4705}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004706
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004707#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004708static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4709{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004710 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004711 struct ixgbe_hw *hw = &adapter->hw;
4712 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004713
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004714 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4715 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4716 continue;
4717
4718 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4719
4720 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4721 hw->mac.ops.set_rar(hw, i,
4722 mac_table->addr,
4723 mac_table->pool,
4724 IXGBE_RAH_AV);
4725 else
4726 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004727 }
4728}
4729
4730static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4731{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004732 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004733 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004734 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004735
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004736 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4737 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4738 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004739 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004740
Jacob Keller5d7daa32014-03-29 06:51:25 +00004741 ixgbe_sync_mac_table(adapter);
4742}
4743
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004744static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004745{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004746 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004747 struct ixgbe_hw *hw = &adapter->hw;
4748 int i, count = 0;
4749
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004750 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4751 /* do not count default RAR as available */
4752 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4753 continue;
4754
4755 /* only count unused and addresses that belong to us */
4756 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4757 if (mac_table->pool != pool)
4758 continue;
4759 }
4760
4761 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004762 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004763
Jacob Keller5d7daa32014-03-29 06:51:25 +00004764 return count;
4765}
4766
4767/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004768static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004769{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004770 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004771 struct ixgbe_hw *hw = &adapter->hw;
4772
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004773 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4774 mac_table->pool = VMDQ_P(0);
4775
4776 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4777
4778 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004779 IXGBE_RAH_AV);
4780}
4781
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004782int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4783 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004784{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004785 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004786 struct ixgbe_hw *hw = &adapter->hw;
4787 int i;
4788
4789 if (is_zero_ether_addr(addr))
4790 return -EINVAL;
4791
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004792 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4793 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004794 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004795
4796 ether_addr_copy(mac_table->addr, addr);
4797 mac_table->pool = pool;
4798
4799 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4800 IXGBE_MAC_STATE_IN_USE;
4801
Jacob Keller5d7daa32014-03-29 06:51:25 +00004802 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004803
Jacob Keller5d7daa32014-03-29 06:51:25 +00004804 return i;
4805 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004806
Jacob Keller5d7daa32014-03-29 06:51:25 +00004807 return -ENOMEM;
4808}
4809
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004810int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4811 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004812{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004813 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004814 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004815 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004816
4817 if (is_zero_ether_addr(addr))
4818 return -EINVAL;
4819
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004820 /* search table for addr, if found clear IN_USE flag and sync */
4821 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4822 /* we can only delete an entry if it is in use */
4823 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4824 continue;
4825 /* we only care about entries that belong to the given pool */
4826 if (mac_table->pool != pool)
4827 continue;
4828 /* we only care about a specific MAC address */
4829 if (!ether_addr_equal(addr, mac_table->addr))
4830 continue;
4831
4832 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4833 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4834
4835 ixgbe_sync_mac_table(adapter);
4836
4837 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004838 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004839
Jacob Keller5d7daa32014-03-29 06:51:25 +00004840 return -ENOMEM;
4841}
Jacob Kellerb335e752014-03-25 07:45:27 +00004842/**
Alexander Duyck28500622010-06-15 09:25:48 +00004843 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4844 * @netdev: network interface device structure
4845 *
4846 * Writes unicast address list to the RAR table.
4847 * Returns: -ENOMEM on failure/insufficient address space
4848 * 0 on no addresses written
4849 * X on writing X addresses to the RAR table
4850 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004851static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004852{
4853 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004854 int count = 0;
4855
4856 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004857 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004858 return -ENOMEM;
4859
John Fastabend95447462012-05-31 12:42:26 +00004860 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004861 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004862 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004863 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4864 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004865 count++;
4866 }
4867 }
Alexander Duyck28500622010-06-15 09:25:48 +00004868 return count;
4869}
4870
Alexander Duyck0f079d22015-10-22 16:26:36 -07004871static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4872{
4873 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4874 int ret;
4875
4876 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4877
4878 return min_t(int, ret, 0);
4879}
4880
4881static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4882{
4883 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4884
4885 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4886
4887 return 0;
4888}
4889
Alexander Duyck28500622010-06-15 09:25:48 +00004890/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004891 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004892 * @netdev: network interface device structure
4893 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004894 * The set_rx_method entry point is called whenever the unicast/multicast
4895 * address list or the network interface flags are updated. This routine is
4896 * responsible for configuring the hardware for proper unicast, multicast and
4897 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004898 **/
Greg Rose7f870472010-01-09 02:25:29 +00004899void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004900{
4901 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4902 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004903 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004904 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004905 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004906
4907 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004908 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4909
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004910 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004911 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004912 fctrl |= IXGBE_FCTRL_BAM;
4913 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4914 fctrl |= IXGBE_FCTRL_PMCF;
4915
Alexander Duyck28500622010-06-15 09:25:48 +00004916 /* clear the bits we are changing the status of */
4917 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004918 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004919 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004920 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004921 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004922 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004923 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004924 if (netdev->flags & IFF_ALLMULTI) {
4925 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004926 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004927 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004928 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004929 }
4930
4931 /*
4932 * Write addresses to available RAR registers, if there is not
4933 * sufficient space to store all the addresses then enable
4934 * unicast promiscuous mode
4935 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004936 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004937 fctrl |= IXGBE_FCTRL_UPE;
4938 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004939 }
4940
Emil Tantilovcf789592013-10-26 08:13:20 +00004941 /* Write addresses to the MTA, if the attempt fails
4942 * then we should just turn on promiscuous mode so
4943 * that we can at least receive multicast traffic
4944 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004945 count = ixgbe_write_mc_addr_list(netdev);
4946 if (count < 0) {
4947 fctrl |= IXGBE_FCTRL_MPE;
4948 vmolr |= IXGBE_VMOLR_MPE;
4949 } else if (count) {
4950 vmolr |= IXGBE_VMOLR_ROMPE;
4951 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004952
4953 if (hw->mac.type != ixgbe_mac_82598EB) {
4954 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004955 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4956 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004957 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004958 }
4959
Ben Greear3f2d1c02012-03-08 08:28:41 +00004960 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004961 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004962 /* UPE and MPE will be handled by normal PROMISC logic
4963 * in e1000e_set_rx_mode */
4964 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4965 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4966 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4967
4968 fctrl &= ~(IXGBE_FCTRL_DPF);
4969 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4970 }
4971
Auke Kok9a799d72007-09-15 14:07:45 -07004972 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004973
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004974 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004975 ixgbe_vlan_strip_enable(adapter);
4976 else
4977 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004978
4979 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4980 ixgbe_vlan_promisc_disable(adapter);
4981 else
4982 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004983}
4984
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004985static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4986{
4987 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004988
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004989 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004990 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004991}
4992
4993static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4994{
4995 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004996
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004997 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004998 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004999}
5000
Emil Tantilova21d0822016-08-10 11:19:23 -07005001static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07005002{
Emil Tantilova21d0822016-08-10 11:19:23 -07005003 struct ixgbe_hw *hw = &adapter->hw;
5004 u32 vxlanctrl;
5005
5006 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
5007 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
5008 return;
5009
Sabrina Dubrocaa39221c2017-07-03 13:02:55 +02005010 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask;
Emil Tantilova21d0822016-08-10 11:19:23 -07005011 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
5012
5013 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07005014 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07005015
5016 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
5017 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07005018}
5019
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005020#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005021/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08005022 * ixgbe_configure_dcb - Configure DCB hardware
5023 * @adapter: ixgbe adapter struct
5024 *
5025 * This is called by the driver on open to configure the DCB hardware.
5026 * This is also called by the gennetlink interface when reconfiguring
5027 * the DCB state.
5028 */
5029static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
5030{
5031 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00005032 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005033
Alexander Duyck67ebd792010-08-19 13:34:04 +00005034 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
5035 if (hw->mac.type == ixgbe_mac_82598EB)
5036 netif_set_gso_max_size(adapter->netdev, 65536);
5037 return;
5038 }
5039
5040 if (hw->mac.type == ixgbe_mac_82598EB)
5041 netif_set_gso_max_size(adapter->netdev, 32768);
5042
John Fastabendb1208182011-10-15 05:00:10 +00005043#ifdef IXGBE_FCOE
5044 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
5045 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
5046#endif
5047
Alexander Duyck01fa7d92010-11-16 19:26:53 -08005048 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00005049 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00005050 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5051 DCB_TX_CONFIG);
5052 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5053 DCB_RX_CONFIG);
5054 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00005055 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
5056 ixgbe_dcb_hw_ets(&adapter->hw,
5057 adapter->ixgbe_ieee_ets,
5058 max_frame);
5059 ixgbe_dcb_hw_pfc_config(&adapter->hw,
5060 adapter->ixgbe_ieee_pfc->pfc_en,
5061 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00005062 }
John Fastabend8187cd42011-02-23 05:58:08 +00005063
5064 /* Enable RSS Hash per TC */
5065 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00005066 u32 msb = 0;
5067 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005068
Alexander Duyckd411a932012-06-30 00:14:01 +00005069 while (rss_i) {
5070 msb++;
5071 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005072 }
Alexander Duyckd411a932012-06-30 00:14:01 +00005073
Alexander Duyck4ae63732012-06-22 06:46:33 +00005074 /* write msb to all 8 TCs in one write */
5075 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00005076 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005077}
John Fastabend9da712d2011-08-23 03:14:22 +00005078#endif
5079
5080/* Additional bittime to account for IXGBE framing */
5081#define IXGBE_ETH_FRAMING 20
5082
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005083/**
John Fastabend9da712d2011-08-23 03:14:22 +00005084 * ixgbe_hpbthresh - calculate high water mark for flow control
5085 *
5086 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005087 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005088 */
5089static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
5090{
5091 struct ixgbe_hw *hw = &adapter->hw;
5092 struct net_device *dev = adapter->netdev;
5093 int link, tc, kb, marker;
5094 u32 dv_id, rx_pba;
5095
5096 /* Calculate max LAN frame size */
5097 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
5098
5099#ifdef IXGBE_FCOE
5100 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00005101 if ((dev->features & NETIF_F_FCOE_MTU) &&
5102 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5103 (pb == ixgbe_fcoe_get_tc(adapter)))
5104 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005105#endif
Jacob Kellere5776622014-04-05 02:35:52 +00005106
John Fastabend9da712d2011-08-23 03:14:22 +00005107 /* Calculate delay value for device */
5108 switch (hw->mac.type) {
5109 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005110 case ixgbe_mac_X550:
5111 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005112 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005113 dv_id = IXGBE_DV_X540(link, tc);
5114 break;
5115 default:
5116 dv_id = IXGBE_DV(link, tc);
5117 break;
5118 }
5119
5120 /* Loopback switch introduces additional latency */
5121 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5122 dv_id += IXGBE_B2BT(tc);
5123
5124 /* Delay value is calculated in bit times convert to KB */
5125 kb = IXGBE_BT2KB(dv_id);
5126 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
5127
5128 marker = rx_pba - kb;
5129
5130 /* It is possible that the packet buffer is not large enough
5131 * to provide required headroom. In this case throw an error
5132 * to user and a do the best we can.
5133 */
5134 if (marker < 0) {
5135 e_warn(drv, "Packet Buffer(%i) can not provide enough"
5136 "headroom to support flow control."
5137 "Decrease MTU or number of traffic classes\n", pb);
5138 marker = tc + 1;
5139 }
5140
5141 return marker;
5142}
5143
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005144/**
John Fastabend9da712d2011-08-23 03:14:22 +00005145 * ixgbe_lpbthresh - calculate low water mark for for flow control
5146 *
5147 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005148 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005149 */
Jacob Kellere5776622014-04-05 02:35:52 +00005150static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00005151{
5152 struct ixgbe_hw *hw = &adapter->hw;
5153 struct net_device *dev = adapter->netdev;
5154 int tc;
5155 u32 dv_id;
5156
5157 /* Calculate max LAN frame size */
5158 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
5159
Jacob Kellere5776622014-04-05 02:35:52 +00005160#ifdef IXGBE_FCOE
5161 /* FCoE traffic class uses FCOE jumbo frames */
5162 if ((dev->features & NETIF_F_FCOE_MTU) &&
5163 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5164 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
5165 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
5166#endif
5167
John Fastabend9da712d2011-08-23 03:14:22 +00005168 /* Calculate delay value for device */
5169 switch (hw->mac.type) {
5170 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005171 case ixgbe_mac_X550:
5172 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005173 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005174 dv_id = IXGBE_LOW_DV_X540(tc);
5175 break;
5176 default:
5177 dv_id = IXGBE_LOW_DV(tc);
5178 break;
5179 }
5180
5181 /* Delay value is calculated in bit times convert to KB */
5182 return IXGBE_BT2KB(dv_id);
5183}
5184
5185/*
5186 * ixgbe_pbthresh_setup - calculate and setup high low water marks
5187 */
5188static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
5189{
5190 struct ixgbe_hw *hw = &adapter->hw;
5191 int num_tc = netdev_get_num_tc(adapter->netdev);
5192 int i;
5193
5194 if (!num_tc)
5195 num_tc = 1;
5196
John Fastabend9da712d2011-08-23 03:14:22 +00005197 for (i = 0; i < num_tc; i++) {
5198 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00005199 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00005200
5201 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00005202 if (hw->fc.low_water[i] > hw->fc.high_water[i])
5203 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005204 }
Jacob Kellere5776622014-04-05 02:35:52 +00005205
5206 for (; i < MAX_TRAFFIC_CLASS; i++)
5207 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005208}
John Fastabend80605c652011-05-02 12:34:10 +00005209
5210static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
5211{
John Fastabend80605c652011-05-02 12:34:10 +00005212 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00005213 int hdrm;
5214 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00005215
5216 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5217 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00005218 hdrm = 32 << adapter->fdir_pballoc;
5219 else
5220 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00005221
Alexander Duyckf7e10272011-07-21 00:40:35 +00005222 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00005223 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00005224}
5225
Alexander Duycke4911d52011-05-11 07:18:52 +00005226static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
5227{
5228 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08005229 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005230 struct ixgbe_fdir_filter *filter;
5231
5232 spin_lock(&adapter->fdir_perfect_lock);
5233
5234 if (!hlist_empty(&adapter->fdir_filter_list))
5235 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
5236
Sasha Levinb67bfe02013-02-27 17:06:00 -08005237 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005238 &adapter->fdir_filter_list, fdir_node) {
5239 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00005240 &filter->filter,
5241 filter->sw_idx,
5242 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
5243 IXGBE_FDIR_DROP_QUEUE :
5244 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00005245 }
5246
5247 spin_unlock(&adapter->fdir_perfect_lock);
5248}
5249
John Fastabend2a47fa42013-11-06 09:54:52 -08005250static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
5251 struct ixgbe_adapter *adapter)
5252{
5253 struct ixgbe_hw *hw = &adapter->hw;
5254 u32 vmolr;
5255
5256 /* No unicast promiscuous support for VMDQ devices. */
5257 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
5258 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
5259
5260 /* clear the affected bit */
5261 vmolr &= ~IXGBE_VMOLR_MPE;
5262
5263 if (dev->flags & IFF_ALLMULTI) {
5264 vmolr |= IXGBE_VMOLR_MPE;
5265 } else {
5266 vmolr |= IXGBE_VMOLR_ROMPE;
5267 hw->mac.ops.update_mc_addr_list(hw, dev);
5268 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00005269 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08005270 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
5271}
5272
John Fastabend2a47fa42013-11-06 09:54:52 -08005273static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
5274{
5275 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08005276 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08005277 struct ixgbe_hw *hw = &adapter->hw;
5278 u16 pool = vadapter->pool;
5279 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
5280 IXGBE_PSRTYPE_UDPHDR |
5281 IXGBE_PSRTYPE_IPV4HDR |
5282 IXGBE_PSRTYPE_L2HDR |
5283 IXGBE_PSRTYPE_IPV6HDR;
5284
5285 if (hw->mac.type == ixgbe_mac_82598EB)
5286 return;
5287
5288 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005289 psrtype |= 2u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08005290 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005291 psrtype |= 1u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08005292
5293 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
5294}
5295
5296/**
5297 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
5298 * @rx_ring: ring to free buffers from
5299 **/
5300static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
5301{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005302 u16 i = rx_ring->next_to_clean;
5303 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08005304
5305 /* Free all the Rx ring sk_buffs */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005306 while (i != rx_ring->next_to_alloc) {
John Fastabend2a47fa42013-11-06 09:54:52 -08005307 if (rx_buffer->skb) {
5308 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00005309 if (IXGBE_CB(skb)->page_released)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005310 dma_unmap_page_attrs(rx_ring->dev,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005311 IXGBE_CB(skb)->dma,
5312 ixgbe_rx_pg_size(rx_ring),
5313 DMA_FROM_DEVICE,
5314 IXGBE_RX_DMA_ATTR);
John Fastabend2a47fa42013-11-06 09:54:52 -08005315 dev_kfree_skb(skb);
5316 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00005317
Alexander Duyckf3213d92017-01-17 08:35:54 -08005318 /* Invalidate cache lines that may have been written to by
5319 * device so that we avoid corrupting memory.
5320 */
5321 dma_sync_single_range_for_cpu(rx_ring->dev,
5322 rx_buffer->dma,
5323 rx_buffer->page_offset,
5324 ixgbe_rx_bufsz(rx_ring),
5325 DMA_FROM_DEVICE);
5326
5327 /* free resources associated with mapping */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005328 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005329 ixgbe_rx_pg_size(rx_ring),
5330 DMA_FROM_DEVICE,
5331 IXGBE_RX_DMA_ATTR);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08005332 __page_frag_cache_drain(rx_buffer->page,
5333 rx_buffer->pagecnt_bias);
Alexander Duyck18cb6522014-11-14 00:56:29 +00005334
Alexander Duyckffed21b2017-01-17 08:37:29 -08005335 i++;
5336 rx_buffer++;
5337 if (i == rx_ring->count) {
5338 i = 0;
5339 rx_buffer = rx_ring->rx_buffer_info;
5340 }
John Fastabend2a47fa42013-11-06 09:54:52 -08005341 }
5342
John Fastabend2a47fa42013-11-06 09:54:52 -08005343 rx_ring->next_to_alloc = 0;
5344 rx_ring->next_to_clean = 0;
5345 rx_ring->next_to_use = 0;
5346}
5347
5348static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
5349 struct ixgbe_ring *rx_ring)
5350{
5351 struct ixgbe_adapter *adapter = vadapter->real_adapter;
5352 int index = rx_ring->queue_index + vadapter->rx_base_queue;
5353
5354 /* shutdown specific queue receive and wait for dma to settle */
5355 ixgbe_disable_rx_queue(adapter, rx_ring);
5356 usleep_range(10000, 20000);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005357 ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
John Fastabend2a47fa42013-11-06 09:54:52 -08005358 ixgbe_clean_rx_ring(rx_ring);
5359 rx_ring->l2_accel_priv = NULL;
5360}
5361
John Fastabendae72c8d2013-11-09 07:11:26 +00005362static int ixgbe_fwd_ring_down(struct net_device *vdev,
5363 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08005364{
5365 struct ixgbe_adapter *adapter = accel->real_adapter;
5366 unsigned int rxbase = accel->rx_base_queue;
5367 unsigned int txbase = accel->tx_base_queue;
5368 int i;
5369
5370 netif_tx_stop_all_queues(vdev);
5371
5372 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5373 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5374 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
5375 }
5376
5377 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5378 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
5379 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
5380 }
5381
5382
5383 return 0;
5384}
5385
5386static int ixgbe_fwd_ring_up(struct net_device *vdev,
5387 struct ixgbe_fwd_adapter *accel)
5388{
5389 struct ixgbe_adapter *adapter = accel->real_adapter;
5390 unsigned int rxbase, txbase, queues;
5391 int i, baseq, err = 0;
5392
5393 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
5394 return 0;
5395
5396 baseq = accel->pool * adapter->num_rx_queues_per_pool;
5397 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
5398 accel->pool, adapter->num_rx_pools,
5399 baseq, baseq + adapter->num_rx_queues_per_pool,
5400 adapter->fwd_bitmask);
5401
5402 accel->netdev = vdev;
5403 accel->rx_base_queue = rxbase = baseq;
5404 accel->tx_base_queue = txbase = baseq;
5405
5406 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5407 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5408
5409 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5410 adapter->rx_ring[rxbase + i]->netdev = vdev;
5411 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
5412 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
5413 }
5414
5415 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5416 adapter->tx_ring[txbase + i]->netdev = vdev;
5417 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
5418 }
5419
5420 queues = min_t(unsigned int,
5421 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
5422 err = netif_set_real_num_tx_queues(vdev, queues);
5423 if (err)
5424 goto fwd_queue_err;
5425
John Fastabend2a47fa42013-11-06 09:54:52 -08005426 err = netif_set_real_num_rx_queues(vdev, queues);
5427 if (err)
5428 goto fwd_queue_err;
5429
5430 if (is_valid_ether_addr(vdev->dev_addr))
Alexander Duyck361b5342017-11-22 10:56:16 -08005431 ixgbe_add_mac_filter(adapter, vdev->dev_addr,
5432 VMDQ_P(accel->pool));
John Fastabend2a47fa42013-11-06 09:54:52 -08005433
5434 ixgbe_fwd_psrtype(accel);
Alexander Duyck361b5342017-11-22 10:56:16 -08005435 ixgbe_macvlan_set_rx_mode(vdev, VMDQ_P(accel->pool), adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005436 return err;
5437fwd_queue_err:
5438 ixgbe_fwd_ring_down(vdev, accel);
5439 return err;
5440}
5441
David Ahern1cd127f2016-10-17 19:15:48 -07005442static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
5443{
5444 if (netif_is_macvlan(upper)) {
5445 struct macvlan_dev *dfwd = netdev_priv(upper);
5446 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5447
5448 if (dfwd->fwd_priv)
5449 ixgbe_fwd_ring_up(upper, vadapter);
5450 }
5451
5452 return 0;
5453}
5454
John Fastabend2a47fa42013-11-06 09:54:52 -08005455static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5456{
David Ahern1cd127f2016-10-17 19:15:48 -07005457 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5458 ixgbe_upper_dev_walk, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005459}
5460
Auke Kok9a799d72007-09-15 14:07:45 -07005461static void ixgbe_configure(struct ixgbe_adapter *adapter)
5462{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005463 struct ixgbe_hw *hw = &adapter->hw;
5464
John Fastabend80605c652011-05-02 12:34:10 +00005465 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005466#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005467 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005468#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005469 /*
5470 * We must restore virtualization before VLANs or else
5471 * the VLVF registers will not be populated
5472 */
5473 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005474
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005475 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005476 ixgbe_restore_vlan(adapter);
5477
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005478 switch (hw->mac.type) {
5479 case ixgbe_mac_82599EB:
5480 case ixgbe_mac_X540:
5481 hw->mac.ops.disable_rx_buff(hw);
5482 break;
5483 default:
5484 break;
5485 }
5486
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005487 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005488 ixgbe_init_fdir_signature_82599(&adapter->hw,
5489 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005490 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5491 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5492 adapter->fdir_pballoc);
5493 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005494 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005495
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005496 switch (hw->mac.type) {
5497 case ixgbe_mac_82599EB:
5498 case ixgbe_mac_X540:
5499 hw->mac.ops.enable_rx_buff(hw);
5500 break;
5501 default:
5502 break;
5503 }
5504
Mark Rustad9de76052015-08-08 16:27:41 -07005505#ifdef CONFIG_IXGBE_DCA
5506 /* configure DCA */
5507 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5508 ixgbe_setup_dca(adapter);
5509#endif /* CONFIG_IXGBE_DCA */
5510
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005511#ifdef IXGBE_FCOE
5512 /* configure FCoE L2 filters, redirection table, and Rx control */
5513 ixgbe_configure_fcoe(adapter);
5514
5515#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005516 ixgbe_configure_tx(adapter);
5517 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005518 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005519}
5520
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005521/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005522 * ixgbe_sfp_link_config - set up SFP+ link
5523 * @adapter: pointer to private adapter struct
5524 **/
5525static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5526{
Alexander Duyck70864002011-04-27 09:13:56 +00005527 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005528 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005529 * is that an SFP was inserted/removed after the reset
5530 * but before SFP detection was enabled. As such the best
5531 * solution is to just start searching as soon as we start
5532 */
5533 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5534 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005535
Alexander Duyck70864002011-04-27 09:13:56 +00005536 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005537 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005538}
5539
5540/**
5541 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005542 * @hw: pointer to private hardware struct
5543 *
5544 * Returns 0 on success, negative on failure
5545 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005546static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005547{
Josh Hay3d292262012-12-15 03:28:19 +00005548 u32 speed;
5549 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005550 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005551
5552 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005553 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005554
5555 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005556 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005557
Josh Hay3d292262012-12-15 03:28:19 +00005558 speed = hw->phy.autoneg_advertised;
5559 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5560 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5561 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005562 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005563 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005564
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005565 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005566 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005567
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005568 return ret;
5569}
5570
Alexander Duycka34bcff2010-08-19 13:39:20 +00005571static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005572{
Auke Kok9a799d72007-09-15 14:07:45 -07005573 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005574 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005575
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005576 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005577 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5578 IXGBE_GPIE_OCD;
5579 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005580 /*
5581 * use EIAM to auto-mask when MSI-X interrupt is asserted
5582 * this saves a register write for every interrupt
5583 */
5584 switch (hw->mac.type) {
5585 case ixgbe_mac_82598EB:
5586 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5587 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005588 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005589 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005590 case ixgbe_mac_X550:
5591 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005592 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005593 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005594 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5595 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5596 break;
5597 }
5598 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005599 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5600 * specifically only auto mask tx and rx interrupts */
5601 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005602 }
5603
Alexander Duycka34bcff2010-08-19 13:39:20 +00005604 /* XXX: to interrupt immediately for EICS writes, enable this */
5605 /* gpie |= IXGBE_GPIE_EIMEN; */
5606
5607 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5608 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005609
5610 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5611 case IXGBE_82599_VMDQ_8Q_MASK:
5612 gpie |= IXGBE_GPIE_VTMODE_16;
5613 break;
5614 case IXGBE_82599_VMDQ_4Q_MASK:
5615 gpie |= IXGBE_GPIE_VTMODE_32;
5616 break;
5617 default:
5618 gpie |= IXGBE_GPIE_VTMODE_64;
5619 break;
5620 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005621 }
5622
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005623 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005624 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5625 switch (adapter->hw.mac.type) {
5626 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005627 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005628 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005629 default:
5630 break;
5631 }
5632 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005633
Alexander Duycka34bcff2010-08-19 13:39:20 +00005634 /* Enable fan failure interrupt */
5635 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005636 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005637
Don Skidmorea023bbd2015-06-24 16:38:53 -04005638 switch (hw->mac.type) {
5639 case ixgbe_mac_82599EB:
5640 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5641 break;
5642 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005643 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005644 gpie |= IXGBE_SDP0_GPIEN_X540;
5645 break;
5646 default:
5647 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005648 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005649
5650 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5651}
5652
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005653static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005654{
5655 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005656 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005657 u32 ctrl_ext;
5658
5659 ixgbe_get_hw_control(adapter);
5660 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005661
Auke Kok9a799d72007-09-15 14:07:45 -07005662 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5663 ixgbe_configure_msix(adapter);
5664 else
5665 ixgbe_configure_msi_and_legacy(adapter);
5666
Emil Tantilovec74a472012-09-20 03:33:56 +00005667 /* enable the optics for 82599 SFP+ fiber */
5668 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005669 hw->mac.ops.enable_tx_laser(hw);
5670
Don Skidmore961fac82015-06-09 16:09:47 -07005671 if (hw->phy.ops.set_phy_power)
5672 hw->phy.ops.set_phy_power(hw, true);
5673
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005674 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005675 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005676 ixgbe_napi_enable_all(adapter);
5677
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005678 if (ixgbe_is_sfp(hw)) {
5679 ixgbe_sfp_link_config(adapter);
5680 } else {
5681 err = ixgbe_non_sfp_link_config(hw);
5682 if (err)
5683 e_err(probe, "link_config FAILED %d\n", err);
5684 }
5685
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005686 /* clear any pending interrupts, may auto mask */
5687 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005688 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005689
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005690 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005691 * If this adapter has a fan, check to see if we had a failure
5692 * before we enabled the interrupt.
5693 */
5694 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5695 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5696 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005697 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005698 }
5699
Auke Kok9a799d72007-09-15 14:07:45 -07005700 /* bring the link up in the watchdog, this could race with our first
5701 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005702 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5703 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005704 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005705
5706 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5707 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5708 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5709 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005710}
5711
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005712void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5713{
5714 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005715 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005716 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005717
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005718 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005719 usleep_range(1000, 2000);
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005720 if (adapter->hw.phy.type == ixgbe_phy_fw)
5721 ixgbe_watchdog_link_is_down(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005722 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005723 /*
5724 * If SR-IOV enabled then wait a bit before bringing the adapter
5725 * back up to give the VFs time to respond to the reset. The
5726 * two second wait is based upon the watchdog timer cycle in
5727 * the VF driver.
5728 */
5729 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5730 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005731 ixgbe_up(adapter);
5732 clear_bit(__IXGBE_RESETTING, &adapter->state);
5733}
5734
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005735void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005736{
5737 /* hardware has been reset, we need to reload some things */
5738 ixgbe_configure(adapter);
5739
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005740 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005741}
5742
5743void ixgbe_reset(struct ixgbe_adapter *adapter)
5744{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005745 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005746 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005747 int err;
5748
Mark Rustadb0483c82014-01-14 18:53:17 -08005749 if (ixgbe_removed(hw->hw_addr))
5750 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005751 /* lock SFP init bit to prevent race conditions with the watchdog */
5752 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5753 usleep_range(1000, 2000);
5754
5755 /* clear all SFP and link config related flags while holding SFP_INIT */
5756 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5757 IXGBE_FLAG2_SFP_NEEDS_RESET);
5758 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5759
Don Skidmore8ca783a2009-05-26 20:40:47 -07005760 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005761 switch (err) {
5762 case 0:
5763 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005764 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005765 break;
5766 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005767 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005768 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005769 case IXGBE_ERR_EEPROM_VERSION:
5770 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005771 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005772 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005773 "your hardware. If you are experiencing problems "
5774 "please contact your Intel or hardware "
5775 "representative who provided you with this "
5776 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005777 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005778 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005779 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005780 }
Auke Kok9a799d72007-09-15 14:07:45 -07005781
Alexander Duyck70864002011-04-27 09:13:56 +00005782 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005783
5784 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005785 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005786 __dev_uc_unsync(netdev, NULL);
5787
5788 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005789 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005790
5791 /* update SAN MAC vmdq pool selection */
5792 if (hw->mac.san_mac_rar_index)
5793 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005794
Jacob Keller8fecf672013-06-21 08:14:32 +00005795 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005796 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005797
5798 if (hw->phy.ops.set_phy_power) {
5799 if (!netif_running(adapter->netdev) && !adapter->wol)
5800 hw->phy.ops.set_phy_power(hw, false);
5801 else
5802 hw->phy.ops.set_phy_power(hw, true);
5803 }
Auke Kok9a799d72007-09-15 14:07:45 -07005804}
5805
Auke Kok9a799d72007-09-15 14:07:45 -07005806/**
Auke Kok9a799d72007-09-15 14:07:45 -07005807 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005808 * @tx_ring: ring to be cleaned
5809 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005810static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005811{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005812 u16 i = tx_ring->next_to_clean;
5813 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07005814
Alexander Duyckffed21b2017-01-17 08:37:29 -08005815 while (i != tx_ring->next_to_use) {
5816 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -07005817
Alexander Duyckffed21b2017-01-17 08:37:29 -08005818 /* Free all the Tx ring sk_buffs */
John Fastabend33fdc822017-04-24 03:30:18 -07005819 if (ring_is_xdp(tx_ring))
5820 page_frag_free(tx_buffer->data);
5821 else
5822 dev_kfree_skb_any(tx_buffer->skb);
Alexander Duyckffed21b2017-01-17 08:37:29 -08005823
5824 /* unmap skb header data */
5825 dma_unmap_single(tx_ring->dev,
5826 dma_unmap_addr(tx_buffer, dma),
5827 dma_unmap_len(tx_buffer, len),
5828 DMA_TO_DEVICE);
5829
5830 /* check for eop_desc to determine the end of the packet */
5831 eop_desc = tx_buffer->next_to_watch;
5832 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5833
5834 /* unmap remaining buffers */
5835 while (tx_desc != eop_desc) {
5836 tx_buffer++;
5837 tx_desc++;
5838 i++;
5839 if (unlikely(i == tx_ring->count)) {
5840 i = 0;
5841 tx_buffer = tx_ring->tx_buffer_info;
5842 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5843 }
5844
5845 /* unmap any remaining paged data */
5846 if (dma_unmap_len(tx_buffer, len))
5847 dma_unmap_page(tx_ring->dev,
5848 dma_unmap_addr(tx_buffer, dma),
5849 dma_unmap_len(tx_buffer, len),
5850 DMA_TO_DEVICE);
5851 }
5852
5853 /* move us one more past the eop_desc for start of next pkt */
5854 tx_buffer++;
5855 i++;
5856 if (unlikely(i == tx_ring->count)) {
5857 i = 0;
5858 tx_buffer = tx_ring->tx_buffer_info;
5859 }
Auke Kok9a799d72007-09-15 14:07:45 -07005860 }
5861
Alexander Duyckffed21b2017-01-17 08:37:29 -08005862 /* reset BQL for queue */
John Fastabend33fdc822017-04-24 03:30:18 -07005863 if (!ring_is_xdp(tx_ring))
5864 netdev_tx_reset_queue(txring_txq(tx_ring));
John Fastabenddad8a3b2012-04-23 12:22:39 +00005865
Alexander Duyckffed21b2017-01-17 08:37:29 -08005866 /* reset next_to_use and next_to_clean */
Auke Kok9a799d72007-09-15 14:07:45 -07005867 tx_ring->next_to_use = 0;
5868 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005869}
5870
5871/**
Auke Kok9a799d72007-09-15 14:07:45 -07005872 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5873 * @adapter: board private structure
5874 **/
5875static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5876{
5877 int i;
5878
5879 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005880 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005881}
5882
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005883/**
5884 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5885 * @adapter: board private structure
5886 **/
5887static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5888{
5889 int i;
5890
5891 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005892 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07005893 for (i = 0; i < adapter->num_xdp_queues; i++)
5894 ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005895}
5896
Alexander Duycke4911d52011-05-11 07:18:52 +00005897static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5898{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005899 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005900 struct ixgbe_fdir_filter *filter;
5901
5902 spin_lock(&adapter->fdir_perfect_lock);
5903
Sasha Levinb67bfe02013-02-27 17:06:00 -08005904 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005905 &adapter->fdir_filter_list, fdir_node) {
5906 hlist_del(&filter->fdir_node);
5907 kfree(filter);
5908 }
5909 adapter->fdir_filter_count = 0;
5910
5911 spin_unlock(&adapter->fdir_perfect_lock);
5912}
5913
David Ahern1cd127f2016-10-17 19:15:48 -07005914static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
5915{
5916 if (netif_is_macvlan(upper)) {
5917 struct macvlan_dev *vlan = netdev_priv(upper);
5918
5919 if (vlan->fwd_priv) {
5920 netif_tx_stop_all_queues(upper);
5921 netif_carrier_off(upper);
5922 netif_tx_disable(upper);
5923 }
5924 }
5925
5926 return 0;
5927}
5928
Auke Kok9a799d72007-09-15 14:07:45 -07005929void ixgbe_down(struct ixgbe_adapter *adapter)
5930{
5931 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005932 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005933 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005934
5935 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005936 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5937 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005938
5939 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005940 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005941
Yi Zou2d39d572011-01-06 14:29:56 +00005942 /* disable all enabled rx queues */
5943 for (i = 0; i < adapter->num_rx_queues; i++)
5944 /* this call also flushes the previous write */
5945 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5946
Don Skidmore032b4322011-03-18 09:32:53 +00005947 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005948
John Fastabend11393cc2017-07-17 09:29:40 -07005949 /* synchronize_sched() needed for pending XDP buffers to drain */
5950 if (adapter->xdp_ring[0])
5951 synchronize_sched();
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005952 netif_tx_stop_all_queues(netdev);
5953
Alexander Duyck70864002011-04-27 09:13:56 +00005954 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005955 netif_carrier_off(netdev);
5956 netif_tx_disable(netdev);
5957
John Fastabend2a47fa42013-11-06 09:54:52 -08005958 /* disable any upper devices */
David Ahern1cd127f2016-10-17 19:15:48 -07005959 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5960 ixgbe_disable_macvlan, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005961
John Fastabendc0dfb902010-04-27 02:13:39 +00005962 ixgbe_irq_disable(adapter);
5963
5964 ixgbe_napi_disable_all(adapter);
5965
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005966 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5967 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005968 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5969
5970 del_timer_sync(&adapter->service_timer);
5971
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005972 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005973 /* Clear EITR Select mapping */
5974 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5975
5976 /* Mark all the VFs as inactive */
5977 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005978 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005979
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005980 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005981 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005982
Auke Kok9a799d72007-09-15 14:07:45 -07005983 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005984 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005985 }
5986
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005987 /* disable transmits in the hardware now that interrupts are off */
5988 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005989 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005990 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005991 }
John Fastabend33fdc822017-04-24 03:30:18 -07005992 for (i = 0; i < adapter->num_xdp_queues; i++) {
5993 u8 reg_idx = adapter->xdp_ring[i]->reg_idx;
5994
5995 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
5996 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005997
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005998 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005999 switch (hw->mac.type) {
6000 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006001 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006002 case ixgbe_mac_X550:
6003 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006004 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00006005 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00006006 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
6007 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08006008 break;
6009 default:
6010 break;
6011 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07006012
Paul Larson6f4a0e42008-06-24 17:00:56 -07006013 if (!pci_channel_offline(adapter->pdev))
6014 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00006015
Emil Tantilovec74a472012-09-20 03:33:56 +00006016 /* power down the optics for 82599 SFP+ fiber */
6017 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00006018 hw->mac.ops.disable_tx_laser(hw);
6019
Auke Kok9a799d72007-09-15 14:07:45 -07006020 ixgbe_clean_all_tx_rings(adapter);
6021 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006022}
6023
Auke Kok9a799d72007-09-15 14:07:45 -07006024/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006025 * ixgbe_eee_capable - helper function to determine EEE support on X550
6026 * @adapter: board private structure
6027 */
6028static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
6029{
6030 struct ixgbe_hw *hw = &adapter->hw;
6031
6032 switch (hw->device_id) {
6033 case IXGBE_DEV_ID_X550EM_A_1G_T:
6034 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6035 if (!hw->phy.eee_speeds_supported)
6036 break;
6037 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
6038 if (!hw->phy.eee_speeds_advertised)
6039 break;
6040 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
6041 break;
6042 default:
6043 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
6044 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
6045 break;
6046 }
6047}
6048
6049/**
Auke Kok9a799d72007-09-15 14:07:45 -07006050 * ixgbe_tx_timeout - Respond to a Tx Hang
6051 * @netdev: network interface device structure
6052 **/
6053static void ixgbe_tx_timeout(struct net_device *netdev)
6054{
6055 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6056
6057 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006058 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006059}
6060
Usha Ketineni88290092016-04-26 05:00:26 -07006061#ifdef CONFIG_IXGBE_DCB
6062static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
6063{
6064 struct ixgbe_hw *hw = &adapter->hw;
6065 struct tc_configuration *tc;
6066 int j;
6067
6068 switch (hw->mac.type) {
6069 case ixgbe_mac_82598EB:
6070 case ixgbe_mac_82599EB:
6071 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
6072 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
6073 break;
6074 case ixgbe_mac_X540:
6075 case ixgbe_mac_X550:
6076 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
6077 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
6078 break;
6079 case ixgbe_mac_X550EM_x:
6080 case ixgbe_mac_x550em_a:
6081 default:
6082 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
6083 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
6084 break;
6085 }
6086
6087 /* Configure DCB traffic classes */
6088 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
6089 tc = &adapter->dcb_cfg.tc_config[j];
6090 tc->path[DCB_TX_CONFIG].bwg_id = 0;
6091 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
6092 tc->path[DCB_RX_CONFIG].bwg_id = 0;
6093 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
6094 tc->dcb_pfc = pfc_disabled;
6095 }
6096
6097 /* Initialize default user to priority mapping, UPx->TC0 */
6098 tc = &adapter->dcb_cfg.tc_config[0];
6099 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
6100 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
6101
6102 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
6103 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
6104 adapter->dcb_cfg.pfc_mode_enable = false;
6105 adapter->dcb_set_bitmap = 0x00;
6106 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
6107 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
6108 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
6109 sizeof(adapter->temp_dcb_cfg));
6110}
6111#endif
6112
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006113/**
Auke Kok9a799d72007-09-15 14:07:45 -07006114 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
6115 * @adapter: board private structure to initialize
6116 *
6117 * ixgbe_sw_init initializes the Adapter private data structure.
6118 * Fields are initialized based on PCI device information and
6119 * OS network device settings (MTU size).
6120 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07006121static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
6122 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07006123{
6124 struct ixgbe_hw *hw = &adapter->hw;
6125 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00006126 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00006127 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04006128 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006129
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006130 /* PCI config space info */
6131
6132 hw->vendor_id = pdev->vendor;
6133 hw->device_id = pdev->device;
6134 hw->revision_id = pdev->revision;
6135 hw->subsystem_vendor_id = pdev->subsystem_vendor;
6136 hw->subsystem_device_id = pdev->subsystem_device;
6137
Emil Tantilov55570b62016-10-12 12:34:25 -07006138 /* get_invariants needs the device IDs */
6139 ii->get_invariants(hw);
6140
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006141 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00006142 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00006143 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006144 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006145 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
6146 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00006147 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
6148 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006149 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
6150#ifdef CONFIG_IXGBE_DCA
6151 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
6152#endif
Usha Ketineni88290092016-04-26 05:00:26 -07006153#ifdef CONFIG_IXGBE_DCB
6154 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
6155 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6156#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006157#ifdef IXGBE_FCOE
6158 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
6159 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6160#ifdef CONFIG_IXGBE_DCB
6161 /* Default traffic class to use for FCoE */
6162 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
6163#endif /* CONFIG_IXGBE_DCB */
6164#endif /* IXGBE_FCOE */
6165
John Fastabendb82b17d2016-02-16 21:18:53 -08006166 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04006167 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
6168 GFP_KERNEL);
6169 if (!adapter->jump_tables[0])
6170 return -ENOMEM;
6171 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
6172
6173 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
6174 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08006175
Jacob Keller5d7daa32014-03-29 06:51:25 +00006176 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
6177 hw->mac.num_rar_entries,
6178 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08006179 if (!adapter->mac_table)
6180 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00006181
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07006182 if (ixgbe_init_rss_key(adapter))
6183 return -ENOMEM;
6184
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006185 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08006186 switch (hw->mac.type) {
6187 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006188 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006189
Don Skidmorebf069c92009-05-07 10:39:54 +00006190 if (hw->device_id == IXGBE_DEV_ID_82598AT)
6191 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006192
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006193 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006194 adapter->ring_feature[RING_F_FDIR].limit = 0;
6195 adapter->atr_sample_rate = 0;
6196 adapter->fdir_pballoc = 0;
6197#ifdef IXGBE_FCOE
6198 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6199 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6200#ifdef CONFIG_IXGBE_DCB
6201 adapter->fcoe.up = 0;
6202#endif /* IXGBE_DCB */
6203#endif /* IXGBE_FCOE */
6204 break;
6205 case ixgbe_mac_82599EB:
6206 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
6207 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006208 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006209 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07006210 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00006211 if (fwsm & IXGBE_FWSM_TS_ENABLED)
6212 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006213 break;
Mark Rustad49425df2016-04-01 12:18:09 -07006214 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07006215 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006216 switch (hw->device_id) {
6217 case IXGBE_DEV_ID_X550EM_A_1G_T:
6218 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6219 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6220 break;
6221 default:
6222 break;
6223 }
Emil Tantilova21d0822016-08-10 11:19:23 -07006224 /* fall through */
6225 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07006226#ifdef CONFIG_IXGBE_DCB
6227 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
6228#endif
6229#ifdef IXGBE_FCOE
6230 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6231#ifdef CONFIG_IXGBE_DCB
6232 adapter->fcoe.up = 0;
6233#endif /* IXGBE_DCB */
6234#endif /* IXGBE_FCOE */
6235 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006236 case ixgbe_mac_X550:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006237 if (hw->mac.type == ixgbe_mac_X550)
6238 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006239#ifdef CONFIG_IXGBE_DCA
6240 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
6241#endif
Mark Rustad67359c32015-06-15 11:33:25 -07006242 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006243 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08006244 default:
6245 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00006246 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08006247
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006248#ifdef IXGBE_FCOE
6249 /* FCoE support exists, always init the FCoE lock */
6250 spin_lock_init(&adapter->fcoe.lock);
6251
6252#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00006253 /* n-tuple support exists, always init our spinlock */
6254 spin_lock_init(&adapter->fdir_perfect_lock);
6255
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08006256#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07006257 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006258#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006259
6260 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00006261 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00006262 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00006263 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07006264 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
6265 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00006266 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07006267
Alexander Duyck99d74482012-05-09 08:09:25 +00006268#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08006269 if (max_vfs > 0)
6270 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 +00006271
Jacob Keller170e8542013-11-09 04:52:32 -08006272 /* assign number of SR-IOV VFs */
6273 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08006274 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Emil Tantilov5c11f002017-01-20 14:11:56 -08006275 max_vfs = 0;
Jacob Keller170e8542013-11-09 04:52:32 -08006276 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
Jacob Keller170e8542013-11-09 04:52:32 -08006277 }
6278 }
6279#endif /* CONFIG_PCI_IOV */
6280
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006281 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006282 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006283 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006284
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006285 /* set default ring sizes */
6286 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
6287 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
6288
Alexander Duyckbd198052011-06-11 01:45:08 +00006289 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00006290 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00006291
Auke Kok9a799d72007-09-15 14:07:45 -07006292 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006293 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006294 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006295 return -EIO;
6296 }
6297
John Fastabend2a47fa42013-11-06 09:54:52 -08006298 /* PF holds first pool slot */
6299 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07006300 set_bit(__IXGBE_DOWN, &adapter->state);
6301
6302 return 0;
6303}
6304
6305/**
6306 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006307 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006308 *
6309 * Return 0 on success, negative on failure
6310 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006311int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006312{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006313 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006314 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006315 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07006316 int size;
6317
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006318 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006319
6320 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006321 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006322
Alexander Duyckffed21b2017-01-17 08:37:29 -08006323 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006324 if (!tx_ring->tx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006325 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006326 if (!tx_ring->tx_buffer_info)
6327 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006328
6329 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08006330 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006331 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006332
Mark Rustadca8dfe22014-07-24 06:19:24 +00006333 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006334 tx_ring->desc = dma_alloc_coherent(dev,
6335 tx_ring->size,
6336 &tx_ring->dma,
6337 GFP_KERNEL);
6338 set_dev_node(dev, orig_node);
6339 if (!tx_ring->desc)
6340 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6341 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006342 if (!tx_ring->desc)
6343 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006344
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006345 tx_ring->next_to_use = 0;
6346 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006347 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006348
6349err:
6350 vfree(tx_ring->tx_buffer_info);
6351 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006352 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006353 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006354}
6355
6356/**
Alexander Duyck69888672008-09-11 20:05:39 -07006357 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6358 * @adapter: board private structure
6359 *
6360 * If this function returns with an error, then it's possible one or
6361 * more of the rings is populated (while the rest are not). It is the
6362 * callers duty to clean those orphaned rings.
6363 *
6364 * Return 0 on success, negative on failure
6365 **/
6366static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6367{
John Fastabend33fdc822017-04-24 03:30:18 -07006368 int i, j = 0, err = 0;
Alexander Duyck69888672008-09-11 20:05:39 -07006369
6370 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006371 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006372 if (!err)
6373 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006374
Emil Tantilov396e7992010-07-01 20:05:12 +00006375 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006376 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07006377 }
John Fastabend33fdc822017-04-24 03:30:18 -07006378 for (j = 0; j < adapter->num_xdp_queues; j++) {
6379 err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
6380 if (!err)
6381 continue;
6382
6383 e_err(probe, "Allocation for Tx Queue %u failed\n", j);
6384 goto err_setup_tx;
6385 }
Alexander Duyck69888672008-09-11 20:05:39 -07006386
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006387 return 0;
6388err_setup_tx:
6389 /* rewind the index freeing the rings as we go */
John Fastabend33fdc822017-04-24 03:30:18 -07006390 while (j--)
6391 ixgbe_free_tx_resources(adapter->xdp_ring[j]);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006392 while (i--)
6393 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006394 return err;
6395}
6396
6397/**
Auke Kok9a799d72007-09-15 14:07:45 -07006398 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006399 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006400 *
6401 * Returns 0 on success, negative on failure
6402 **/
John Fastabend92470802017-04-24 03:30:17 -07006403int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
6404 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006405{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006406 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006407 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006408 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006409 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07006410
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006411 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006412
6413 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006414 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006415
Alexander Duyckffed21b2017-01-17 08:37:29 -08006416 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006417 if (!rx_ring->rx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006418 rx_ring->rx_buffer_info = vmalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006419 if (!rx_ring->rx_buffer_info)
6420 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006421
Auke Kok9a799d72007-09-15 14:07:45 -07006422 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006423 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6424 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006425
Mark Rustadca8dfe22014-07-24 06:19:24 +00006426 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006427 rx_ring->desc = dma_alloc_coherent(dev,
6428 rx_ring->size,
6429 &rx_ring->dma,
6430 GFP_KERNEL);
6431 set_dev_node(dev, orig_node);
6432 if (!rx_ring->desc)
6433 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6434 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006435 if (!rx_ring->desc)
6436 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006437
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006438 rx_ring->next_to_clean = 0;
6439 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006440
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01006441 /* XDP RX-queue info */
6442 if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev,
6443 rx_ring->queue_index) < 0)
6444 goto err;
6445
John Fastabend92470802017-04-24 03:30:17 -07006446 rx_ring->xdp_prog = adapter->xdp_prog;
6447
Auke Kok9a799d72007-09-15 14:07:45 -07006448 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006449err:
6450 vfree(rx_ring->rx_buffer_info);
6451 rx_ring->rx_buffer_info = NULL;
6452 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07006453 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006454}
6455
6456/**
Alexander Duyck69888672008-09-11 20:05:39 -07006457 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6458 * @adapter: board private structure
6459 *
6460 * If this function returns with an error, then it's possible one or
6461 * more of the rings is populated (while the rest are not). It is the
6462 * callers duty to clean those orphaned rings.
6463 *
6464 * Return 0 on success, negative on failure
6465 **/
Alexander Duyck69888672008-09-11 20:05:39 -07006466static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6467{
6468 int i, err = 0;
6469
6470 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend92470802017-04-24 03:30:17 -07006471 err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006472 if (!err)
6473 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006474
Emil Tantilov396e7992010-07-01 20:05:12 +00006475 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006476 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07006477 }
6478
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006479#ifdef IXGBE_FCOE
6480 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6481 if (!err)
6482#endif
6483 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006484err_setup_rx:
6485 /* rewind the index freeing the rings as we go */
6486 while (i--)
6487 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006488 return err;
6489}
6490
6491/**
Auke Kok9a799d72007-09-15 14:07:45 -07006492 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07006493 * @tx_ring: Tx descriptor ring for a specific queue
6494 *
6495 * Free all transmit software resources
6496 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006497void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006498{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006499 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006500
6501 vfree(tx_ring->tx_buffer_info);
6502 tx_ring->tx_buffer_info = NULL;
6503
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006504 /* if not set, then don't free */
6505 if (!tx_ring->desc)
6506 return;
6507
6508 dma_free_coherent(tx_ring->dev, tx_ring->size,
6509 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006510
6511 tx_ring->desc = NULL;
6512}
6513
6514/**
6515 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6516 * @adapter: board private structure
6517 *
6518 * Free all transmit software resources
6519 **/
6520static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6521{
6522 int i;
6523
6524 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006525 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006526 ixgbe_free_tx_resources(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07006527 for (i = 0; i < adapter->num_xdp_queues; i++)
6528 if (adapter->xdp_ring[i]->desc)
6529 ixgbe_free_tx_resources(adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006530}
6531
6532/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006533 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006534 * @rx_ring: ring to clean the resources from
6535 *
6536 * Free all receive software resources
6537 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006538void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006539{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006540 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006541
John Fastabend92470802017-04-24 03:30:17 -07006542 rx_ring->xdp_prog = NULL;
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01006543 xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
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;
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006786 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006787 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) {
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006811 u32 fctrl;
6812
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006813 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006814
Emil Tantilovec74a472012-09-20 03:33:56 +00006815 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6816 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006817 hw->mac.ops.enable_tx_laser(hw);
6818
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006819 /* enable the reception of multicast packets */
6820 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6821 fctrl |= IXGBE_FCTRL_MPE;
6822 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006823
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;
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007658 u32 cap_speed;
Josh Hay3d292262012-12-15 03:28:19 +00007659 u32 speed;
7660 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007661
7662 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7663 return;
7664
7665 /* someone else is in init, wait until next service event */
7666 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7667 return;
7668
7669 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7670
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007671 hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007672
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007673 /* advertise highest capable link speed */
7674 if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL))
7675 speed = IXGBE_LINK_SPEED_10GB_FULL;
7676 else
7677 speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL |
7678 IXGBE_LINK_SPEED_1GB_FULL);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007679
Alexander Duyck70864002011-04-27 09:13:56 +00007680 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007681 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007682
7683 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7684 adapter->link_check_timeout = jiffies;
7685 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7686}
7687
7688/**
7689 * ixgbe_service_timer - Timer Call-back
7690 * @data: pointer to adapter cast into an unsigned long
7691 **/
Kees Cook26566ea2017-10-16 17:29:35 -07007692static void ixgbe_service_timer(struct timer_list *t)
Alexander Duyck70864002011-04-27 09:13:56 +00007693{
Kees Cook26566ea2017-10-16 17:29:35 -07007694 struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer);
Alexander Duyck70864002011-04-27 09:13:56 +00007695 unsigned long next_event_offset;
7696
7697 /* poll faster when waiting for link */
7698 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7699 next_event_offset = HZ / 10;
7700 else
7701 next_event_offset = HZ * 2;
7702
7703 /* Reset the timer */
7704 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7705
Emil Tantilov9079e412014-11-19 03:18:19 +00007706 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007707}
7708
Don Skidmore597f22d2015-06-09 16:52:02 -07007709static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7710{
7711 struct ixgbe_hw *hw = &adapter->hw;
7712 u32 status;
7713
7714 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7715 return;
7716
7717 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7718
7719 if (!hw->phy.ops.handle_lasi)
7720 return;
7721
7722 status = hw->phy.ops.handle_lasi(&adapter->hw);
7723 if (status != IXGBE_ERR_OVERTEMP)
7724 return;
7725
7726 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7727}
7728
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007729static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7730{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007731 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007732 return;
7733
Mark Rustad09f40ae2014-01-14 18:53:11 -08007734 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007735 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007736 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007737 test_bit(__IXGBE_RESETTING, &adapter->state))
7738 return;
7739
7740 ixgbe_dump(adapter);
7741 netdev_err(adapter->netdev, "Reset adapter\n");
7742 adapter->tx_timeout_count++;
7743
John Fastabend8f4c5c92014-01-16 02:30:05 -08007744 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007745 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007746 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007747}
7748
Alexander Duyck70864002011-04-27 09:13:56 +00007749/**
7750 * ixgbe_service_task - manages and runs subtasks
7751 * @work: pointer to work_struct containing our data
7752 **/
7753static void ixgbe_service_task(struct work_struct *work)
7754{
7755 struct ixgbe_adapter *adapter = container_of(work,
7756 struct ixgbe_adapter,
7757 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007758 if (ixgbe_removed(adapter->hw.hw_addr)) {
7759 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7760 rtnl_lock();
7761 ixgbe_down(adapter);
7762 rtnl_unlock();
7763 }
7764 ixgbe_service_event_complete(adapter);
7765 return;
7766 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007767 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007768 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007769 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007770 udp_tunnel_get_rx_info(adapter->netdev);
7771 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007772 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007773 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007774 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007775 ixgbe_sfp_detection_subtask(adapter);
7776 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007777 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007778 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007779 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007780 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007781
Jacob Keller8fecf672013-06-21 08:14:32 +00007782 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007783 ixgbe_ptp_overflow_check(adapter);
7784 ixgbe_ptp_rx_hang(adapter);
Jacob Keller622a2ef2017-05-03 10:29:04 -07007785 ixgbe_ptp_tx_hang(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007786 }
Alexander Duyck70864002011-04-27 09:13:56 +00007787
7788 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007789}
7790
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007791static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7792 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007793 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007794{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007795 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007796 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007797 union {
7798 struct iphdr *v4;
7799 struct ipv6hdr *v6;
7800 unsigned char *hdr;
7801 } ip;
7802 union {
7803 struct tcphdr *tcp;
7804 unsigned char *hdr;
7805 } l4;
7806 u32 paylen, l4_offset;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007807 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007808
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007809 if (skb->ip_summed != CHECKSUM_PARTIAL)
7810 return 0;
7811
Alexander Duyck897ab152011-05-27 05:31:47 +00007812 if (!skb_is_gso(skb))
7813 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007814
Francois Romieu2049e1f2014-03-30 03:14:27 +00007815 err = skb_cow_head(skb, 0);
7816 if (err < 0)
7817 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007818
Scott Peterson2a205252016-11-18 11:25:42 -08007819 if (eth_p_mpls(first->protocol))
7820 ip.hdr = skb_inner_network_header(skb);
7821 else
7822 ip.hdr = skb_network_header(skb);
Alexander Duyckb83e3012016-04-14 17:19:31 -04007823 l4.hdr = skb_checksum_start(skb);
7824
Alexander Duyck897ab152011-05-27 05:31:47 +00007825 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7826 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7827
Alexander Duyckb83e3012016-04-14 17:19:31 -04007828 /* initialize outer IP header fields */
7829 if (ip.v4->version == 4) {
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007830 unsigned char *csum_start = skb_checksum_start(skb);
7831 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
7832
Alexander Duyckb83e3012016-04-14 17:19:31 -04007833 /* IP header will have to cancel out any data that
7834 * is not a part of the outer IP header
7835 */
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007836 ip.v4->check = csum_fold(csum_partial(trans_start,
7837 csum_start - trans_start,
7838 0));
Alexander Duyck897ab152011-05-27 05:31:47 +00007839 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007840
7841 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007842 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7843 IXGBE_TX_FLAGS_CSUM |
7844 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007845 } else {
7846 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007847 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7848 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007849 }
7850
Alexander Duyckb83e3012016-04-14 17:19:31 -04007851 /* determine offset of inner transport header */
7852 l4_offset = l4.hdr - skb->data;
7853
7854 /* compute length of segmentation header */
7855 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7856
7857 /* remove payload length from inner checksum */
7858 paylen = skb->len - l4_offset;
7859 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007860
Alexander Duyck091a6242012-02-08 07:51:01 +00007861 /* update gso size and bytecount with header size */
7862 first->gso_segs = skb_shinfo(skb)->gso_segs;
7863 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7864
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007865 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007866 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007867 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007868
7869 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007870 vlan_macip_lens = l4.hdr - ip.hdr;
7871 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007872 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007873
7874 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007875 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007876
7877 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007878}
7879
Alexander Duyck49763de2016-01-13 07:31:11 -08007880static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7881{
7882 unsigned int offset = 0;
7883
7884 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7885
7886 return offset == skb_checksum_start_offset(skb);
7887}
7888
Alexander Duyck244e27a2012-02-08 07:51:11 +00007889static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7890 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007891{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007892 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007893 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007894 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007895
Alexander Duyck897ab152011-05-27 05:31:47 +00007896 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007897csum_failed:
7898 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7899 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007900 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007901 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007902 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007903
Alexander Duyck49763de2016-01-13 07:31:11 -08007904 switch (skb->csum_offset) {
7905 case offsetof(struct tcphdr, check):
7906 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7907 /* fall through */
7908 case offsetof(struct udphdr, check):
7909 break;
7910 case offsetof(struct sctphdr, checksum):
7911 /* validate that this is actually an SCTP request */
7912 if (((first->protocol == htons(ETH_P_IP)) &&
7913 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7914 ((first->protocol == htons(ETH_P_IPV6)) &&
7915 ixgbe_ipv6_csum_is_sctp(skb))) {
7916 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7917 break;
7918 }
7919 /* fall through */
7920 default:
7921 skb_checksum_help(skb);
7922 goto csum_failed;
7923 }
7924
7925 /* update TX checksum flag */
7926 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7927 vlan_macip_lens = skb_checksum_start_offset(skb) -
7928 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007929no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007930 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007931 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007932 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007933
Alexander Duyck49763de2016-01-13 07:31:11 -08007934 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007935}
7936
Alexander Duyck472148c2012-11-07 02:34:28 +00007937#define IXGBE_SET_FLAG(_input, _flag, _result) \
7938 ((_flag <= _result) ? \
7939 ((u32)(_input & _flag) * (_result / _flag)) : \
7940 ((u32)(_input & _flag) / (_flag / _result)))
7941
7942static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007943{
7944 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007945 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7946 IXGBE_ADVTXD_DCMD_DEXT |
7947 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007948
7949 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007950 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7951 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007952
Alexander Duyckd3d00232011-07-15 02:31:25 +00007953 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007954 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7955 IXGBE_ADVTXD_DCMD_TSE);
7956
7957 /* set timestamp bit if present */
7958 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7959 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007960
Alexander Duyck62748b72012-07-20 08:09:01 +00007961 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007962 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007963
Alexander Duyckd3d00232011-07-15 02:31:25 +00007964 return cmd_type;
7965}
7966
Alexander Duyck729739b2012-02-08 07:51:06 +00007967static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7968 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007969{
Alexander Duyck472148c2012-11-07 02:34:28 +00007970 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007971
7972 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007973 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7974 IXGBE_TX_FLAGS_CSUM,
7975 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007976
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007977 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007978 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7979 IXGBE_TX_FLAGS_IPV4,
7980 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007981
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007982 /*
7983 * Check Context must be set if Tx switch is enabled, which it
7984 * always is for case where virtual functions are running
7985 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007986 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7987 IXGBE_TX_FLAGS_CC,
7988 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007989
Alexander Duyck472148c2012-11-07 02:34:28 +00007990 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007991}
7992
Daniel Borkmann2367a172014-08-26 19:34:18 +02007993static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7994{
7995 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7996
7997 /* Herbert's original patch had:
7998 * smp_mb__after_netif_stop_queue();
7999 * but since that doesn't exist yet, just open code it.
8000 */
8001 smp_mb();
8002
8003 /* We need to check again in a case another CPU has just
8004 * made room available.
8005 */
8006 if (likely(ixgbe_desc_unused(tx_ring) < size))
8007 return -EBUSY;
8008
8009 /* A reprieve! - use start_queue because it doesn't call schedule */
8010 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
8011 ++tx_ring->tx_stats.restart_queue;
8012 return 0;
8013}
8014
8015static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
8016{
8017 if (likely(ixgbe_desc_unused(tx_ring) >= size))
8018 return 0;
8019
8020 return __ixgbe_maybe_stop_tx(tx_ring, size);
8021}
8022
Alexander Duyckd3d00232011-07-15 02:31:25 +00008023#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
8024 IXGBE_TXD_CMD_RS)
8025
Jacob Keller5fef1242017-05-03 10:28:56 -07008026static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
8027 struct ixgbe_tx_buffer *first,
8028 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07008029{
Alexander Duyck729739b2012-02-08 07:51:06 +00008030 struct sk_buff *skb = first->skb;
8031 struct ixgbe_tx_buffer *tx_buffer;
8032 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00008033 struct skb_frag_struct *frag;
8034 dma_addr_t dma;
8035 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008036 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00008037 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008038 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07008039
Alexander Duyck729739b2012-02-08 07:51:06 +00008040 tx_desc = IXGBE_TX_DESC(tx_ring, i);
8041
Alexander Duyckec718252012-10-30 06:01:55 +00008042 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
8043
8044 size = skb_headlen(skb);
8045 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00008046
Alexander Duyckd3d00232011-07-15 02:31:25 +00008047#ifdef IXGBE_FCOE
8048 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00008049 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00008050 size -= sizeof(struct fcoe_crc_eof) - data_len;
8051 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00008052 } else {
8053 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00008054 }
Auke Kok9a799d72007-09-15 14:07:45 -07008055 }
8056
Alexander Duyckd3d00232011-07-15 02:31:25 +00008057#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00008058 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008059
Alexander Duyckec718252012-10-30 06:01:55 +00008060 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008061
Alexander Duyckec718252012-10-30 06:01:55 +00008062 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
8063 if (dma_mapping_error(tx_ring->dev, dma))
8064 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008065
Alexander Duyckec718252012-10-30 06:01:55 +00008066 /* record length, and DMA address */
8067 dma_unmap_len_set(tx_buffer, len, size);
8068 dma_unmap_addr_set(tx_buffer, dma, dma);
8069
8070 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8071
Alexander Duyck729739b2012-02-08 07:51:06 +00008072 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00008073 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00008074 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008075
Alexander Duyckd3d00232011-07-15 02:31:25 +00008076 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00008077 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008078 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00008079 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008080 i = 0;
8081 }
Alexander Duyckec718252012-10-30 06:01:55 +00008082 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00008083
8084 dma += IXGBE_MAX_DATA_PER_TXD;
8085 size -= IXGBE_MAX_DATA_PER_TXD;
8086
8087 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008088 }
8089
Alexander Duyck729739b2012-02-08 07:51:06 +00008090 if (likely(!data_len))
8091 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008092
Alexander Duyck472148c2012-11-07 02:34:28 +00008093 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008094
Alexander Duyck729739b2012-02-08 07:51:06 +00008095 i++;
8096 tx_desc++;
8097 if (i == tx_ring->count) {
8098 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
8099 i = 0;
8100 }
Alexander Duyckec718252012-10-30 06:01:55 +00008101 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008102
Alexander Duyckd3d00232011-07-15 02:31:25 +00008103#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00008104 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00008105#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00008106 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008107#endif
8108 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07008109
Alexander Duyck729739b2012-02-08 07:51:06 +00008110 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
8111 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07008112
Alexander Duyck729739b2012-02-08 07:51:06 +00008113 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07008114 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00008115
Alexander Duyck729739b2012-02-08 07:51:06 +00008116 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00008117 cmd_type |= size | IXGBE_TXD_CMD;
8118 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008119
Alexander Duyck091a6242012-02-08 07:51:01 +00008120 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00008121
Alexander Duyckd3d00232011-07-15 02:31:25 +00008122 /* set the timestamp */
8123 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07008124
8125 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00008126 * Force memory writes to complete before letting h/w know there
8127 * are new descriptors to fetch. (Only applicable for weak-ordered
8128 * memory model archs, such as IA-64).
8129 *
8130 * We also need this memory barrier to make certain all of the
8131 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07008132 */
8133 wmb();
8134
Alexander Duyckd3d00232011-07-15 02:31:25 +00008135 /* set next_to_watch value indicating a packet is present */
8136 first->next_to_watch = tx_desc;
8137
Alexander Duyck729739b2012-02-08 07:51:06 +00008138 i++;
8139 if (i == tx_ring->count)
8140 i = 0;
8141
8142 tx_ring->next_to_use = i;
8143
Daniel Borkmann2367a172014-08-26 19:34:18 +02008144 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
8145
8146 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00008147 writel(i, tx_ring->tail);
8148
8149 /* we need this if more than one processor can write to our tail
8150 * at a time, it synchronizes IO on IA64/Altix systems
8151 */
8152 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02008153 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02008154
Jacob Keller5fef1242017-05-03 10:28:56 -07008155 return 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008156dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00008157 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00008158
8159 /* clear dma mappings for failed tx_buffer_info map */
Alexander Duyck069db9c2017-10-19 17:07:13 -04008160 for (;;) {
8161 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckffed21b2017-01-17 08:37:29 -08008162 if (dma_unmap_len(tx_buffer, len))
8163 dma_unmap_page(tx_ring->dev,
8164 dma_unmap_addr(tx_buffer, dma),
8165 dma_unmap_len(tx_buffer, len),
8166 DMA_TO_DEVICE);
8167 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyck069db9c2017-10-19 17:07:13 -04008168 if (tx_buffer == first)
8169 break;
8170 if (i == 0)
Alexander Duyckffed21b2017-01-17 08:37:29 -08008171 i += tx_ring->count;
Alexander Duyck069db9c2017-10-19 17:07:13 -04008172 i--;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008173 }
8174
Alexander Duyckffed21b2017-01-17 08:37:29 -08008175 dev_kfree_skb_any(first->skb);
8176 first->skb = NULL;
8177
Alexander Duyckd3d00232011-07-15 02:31:25 +00008178 tx_ring->next_to_use = i;
Jacob Keller5fef1242017-05-03 10:28:56 -07008179
8180 return -1;
Auke Kok9a799d72007-09-15 14:07:45 -07008181}
8182
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008183static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00008184 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008185{
Alexander Duyck69830522011-01-06 14:29:58 +00008186 struct ixgbe_q_vector *q_vector = ring->q_vector;
8187 union ixgbe_atr_hash_dword input = { .dword = 0 };
8188 union ixgbe_atr_hash_dword common = { .dword = 0 };
8189 union {
8190 unsigned char *network;
8191 struct iphdr *ipv4;
8192 struct ipv6hdr *ipv6;
8193 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08008194 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08008195 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07008196 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00008197 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08008198 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008199
Alexander Duyck69830522011-01-06 14:29:58 +00008200 /* if ring doesn't have a interrupt vector, cannot perform ATR */
8201 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00008202 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008203
Alexander Duyck69830522011-01-06 14:29:58 +00008204 /* do nothing if sampling is disabled */
8205 if (!ring->atr_sample_rate)
8206 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008207
Alexander Duyck69830522011-01-06 14:29:58 +00008208 ring->atr_count++;
8209
Alexander Duycke2873d42016-01-25 19:39:40 -08008210 /* currently only IPv4/IPv6 with TCP is supported */
8211 if ((first->protocol != htons(ETH_P_IP)) &&
8212 (first->protocol != htons(ETH_P_IPV6)))
8213 return;
8214
Alexander Duyck69830522011-01-06 14:29:58 +00008215 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07008216 skb = first->skb;
8217 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008218 if (unlikely(hdr.network <= skb->data))
8219 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08008220 if (skb->encapsulation &&
8221 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07008222 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07008223 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00008224
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008225 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8226 VXLAN_HEADROOM))
8227 return;
8228
Alexander Duyck9f12df92016-01-25 19:36:29 -08008229 /* verify the port is recognized as VXLAN */
8230 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08008231 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08008232 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07008233
8234 if (adapter->geneve_port &&
8235 udp_hdr(skb)->dest == adapter->geneve_port)
8236 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08008237 }
8238
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008239 /* Make sure we have at least [minimum IPv4 header + TCP]
8240 * or [IPv6 header] bytes
8241 */
8242 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
8243 return;
8244
Mark Rustade19dcde2015-12-09 14:55:37 -08008245 /* Currently only IPv4/IPv6 with TCP is supported */
8246 switch (hdr.ipv4->version) {
8247 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08008248 /* access ihl as u8 to avoid unaligned access on ia64 */
8249 hlen = (hdr.network[0] & 0x0F) << 2;
8250 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08008251 break;
8252 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08008253 hlen = hdr.network - skb->data;
8254 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
8255 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08008256 break;
8257 default:
8258 return;
Mark Rustad67359c32015-06-15 11:33:25 -07008259 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008260
Alexander Duycke2873d42016-01-25 19:39:40 -08008261 if (l4_proto != IPPROTO_TCP)
8262 return;
8263
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008264 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8265 hlen + sizeof(struct tcphdr)))
8266 return;
8267
Alexander Duycke2873d42016-01-25 19:39:40 -08008268 th = (struct tcphdr *)(hdr.network + hlen);
8269
8270 /* skip this packet since the socket is closing */
8271 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00008272 return;
8273
8274 /* sample on all syn packets or once every atr sample count */
8275 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
8276 return;
8277
8278 /* reset sample count */
8279 ring->atr_count = 0;
8280
Alexander Duyck244e27a2012-02-08 07:51:11 +00008281 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00008282
8283 /*
8284 * src and dst are inverted, think how the receiver sees them
8285 *
8286 * The input is broken into two sections, a non-compressed section
8287 * containing vm_pool, vlan_id, and flow_type. The rest of the data
8288 * is XORed together and stored in the compressed dword.
8289 */
8290 input.formatted.vlan_id = vlan_id;
8291
8292 /*
8293 * since src port and flex bytes occupy the same word XOR them together
8294 * and write the value to source port portion of compressed dword
8295 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008296 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00008297 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00008298 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00008299 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00008300 common.port.dst ^= th->source;
8301
Mark Rustade19dcde2015-12-09 14:55:37 -08008302 switch (hdr.ipv4->version) {
8303 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00008304 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
8305 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08008306 break;
8307 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00008308 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
8309 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
8310 hdr.ipv6->saddr.s6_addr32[1] ^
8311 hdr.ipv6->saddr.s6_addr32[2] ^
8312 hdr.ipv6->saddr.s6_addr32[3] ^
8313 hdr.ipv6->daddr.s6_addr32[0] ^
8314 hdr.ipv6->daddr.s6_addr32[1] ^
8315 hdr.ipv6->daddr.s6_addr32[2] ^
8316 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08008317 break;
8318 default:
8319 break;
Alexander Duyck69830522011-01-06 14:29:58 +00008320 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008321
Alexander Duyck9f12df92016-01-25 19:36:29 -08008322 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07008323 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07008324
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008325 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00008326 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
8327 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008328}
8329
Jason Wangf663dd92014-01-10 16:18:26 +08008330static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01008331 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008332{
Jason Wangf663dd92014-01-10 16:18:26 +08008333 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
8334#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00008335 struct ixgbe_adapter *adapter;
8336 struct ixgbe_ring_feature *f;
8337 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08008338#endif
8339
8340 if (fwd_adapter)
8341 return skb->queue_mapping + fwd_adapter->tx_base_queue;
8342
8343#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00008344
Alexander Duyck97488bd2013-01-12 06:33:37 +00008345 /*
8346 * only execute the code below if protocol is FCoE
8347 * or FIP and we have FCoE enabled on the adapter
8348 */
8349 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00008350 case htons(ETH_P_FCOE):
8351 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00008352 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00008353
Alexander Duyck97488bd2013-01-12 06:33:37 +00008354 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8355 break;
Tony Nguyen93df9462017-05-31 04:43:47 -07008356 /* fall through */
Alexander Duyck97488bd2013-01-12 06:33:37 +00008357 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01008358 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00008359 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008360
Alexander Duyck97488bd2013-01-12 06:33:37 +00008361 f = &adapter->ring_feature[RING_F_FCOE];
8362
8363 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8364 smp_processor_id();
8365
8366 while (txq >= f->indices)
8367 txq -= f->indices;
8368
8369 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08008370#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01008371 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08008372#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008373}
8374
John Fastabend33fdc822017-04-24 03:30:18 -07008375static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
8376 struct xdp_buff *xdp)
8377{
8378 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
8379 struct ixgbe_tx_buffer *tx_buffer;
8380 union ixgbe_adv_tx_desc *tx_desc;
8381 u32 len, cmd_type;
8382 dma_addr_t dma;
8383 u16 i;
8384
8385 len = xdp->data_end - xdp->data;
8386
8387 if (unlikely(!ixgbe_desc_unused(ring)))
8388 return IXGBE_XDP_CONSUMED;
8389
8390 dma = dma_map_single(ring->dev, xdp->data, len, DMA_TO_DEVICE);
8391 if (dma_mapping_error(ring->dev, dma))
8392 return IXGBE_XDP_CONSUMED;
8393
8394 /* record the location of the first descriptor for this packet */
8395 tx_buffer = &ring->tx_buffer_info[ring->next_to_use];
8396 tx_buffer->bytecount = len;
8397 tx_buffer->gso_segs = 1;
8398 tx_buffer->protocol = 0;
8399
8400 i = ring->next_to_use;
8401 tx_desc = IXGBE_TX_DESC(ring, i);
8402
8403 dma_unmap_len_set(tx_buffer, len, len);
8404 dma_unmap_addr_set(tx_buffer, dma, dma);
8405 tx_buffer->data = xdp->data;
8406 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8407
8408 /* put descriptor type bits */
8409 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
8410 IXGBE_ADVTXD_DCMD_DEXT |
8411 IXGBE_ADVTXD_DCMD_IFCS;
8412 cmd_type |= len | IXGBE_TXD_CMD;
8413 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
8414 tx_desc->read.olinfo_status =
8415 cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT);
8416
John Fastabend7379f972017-03-28 09:47:03 -07008417 /* Avoid any potential race with xdp_xmit and cleanup */
8418 smp_wmb();
John Fastabend33fdc822017-04-24 03:30:18 -07008419
8420 /* set next_to_watch value indicating a packet is present */
8421 i++;
8422 if (i == ring->count)
8423 i = 0;
8424
8425 tx_buffer->next_to_watch = tx_desc;
8426 ring->next_to_use = i;
8427
John Fastabend33fdc822017-04-24 03:30:18 -07008428 return IXGBE_XDP_TX;
8429}
8430
Alexander Duyckfc77dc32010-11-16 19:26:51 -08008431netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00008432 struct ixgbe_adapter *adapter,
8433 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008434{
Alexander Duyckd3d00232011-07-15 02:31:25 +00008435 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00008436 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008437 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00008438 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00008439 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00008440 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00008441 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00008442
Alexander Duycka535c302011-05-27 05:31:52 +00008443 /*
8444 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00008445 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00008446 * + 2 desc gap to keep tail from touching head,
8447 * + 1 desc for context descriptor,
8448 * otherwise try next time
8449 */
Alexander Duycka535c302011-05-27 05:31:52 +00008450 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8451 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00008452
Alexander Duycka535c302011-05-27 05:31:52 +00008453 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8454 tx_ring->tx_stats.tx_busy++;
8455 return NETDEV_TX_BUSY;
8456 }
8457
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008458 /* record the location of the first descriptor for this packet */
8459 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8460 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00008461 first->bytecount = skb->len;
8462 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008463
Alexander Duyck66f32a82011-06-29 05:43:22 +00008464 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01008465 if (skb_vlan_tag_present(skb)) {
8466 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008467 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8468 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008469 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008470 struct vlan_hdr *vhdr, _vhdr;
8471 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8472 if (!vhdr)
8473 goto out_drop;
8474
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008475 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8476 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008477 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07008478 }
Toshiaki Makita02136682015-01-29 20:37:09 +09008479 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00008480
Mark Rustadd5234932014-08-09 07:02:09 +00008481 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
Jacob Keller4cc74c02017-05-03 10:29:00 -07008482 adapter->ptp_clock) {
8483 if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8484 &adapter->state)) {
8485 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8486 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00008487
Jacob Keller4cc74c02017-05-03 10:29:00 -07008488 /* schedule check for Tx timestamp */
8489 adapter->ptp_tx_skb = skb_get(skb);
8490 adapter->ptp_tx_start = jiffies;
8491 schedule_work(&adapter->ptp_tx_work);
8492 } else {
8493 adapter->tx_hwtstamp_skipped++;
8494 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008495 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008496
Jakub Kicinskiff29a862014-03-15 14:55:16 +00008497 skb_tx_timestamp(skb);
8498
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008499#ifdef CONFIG_PCI_IOV
8500 /*
8501 * Use the l2switch_enable flag - would be false if the DMA
8502 * Tx switch had been disabled.
8503 */
8504 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00008505 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008506
8507#endif
John Fastabend32701dc2011-09-27 03:51:56 +00008508 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00008509 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00008510 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8511 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008512 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00008513 tx_flags |= (skb->priority & 0x7) <<
8514 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008515 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8516 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00008517
8518 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00008519 goto out_drop;
8520 vhdr = (struct vlan_ethhdr *)skb->data;
8521 vhdr->h_vlan_TCI = htons(tx_flags >>
8522 IXGBE_TX_FLAGS_VLAN_SHIFT);
8523 } else {
8524 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8525 }
8526 }
Alexander Duycka535c302011-05-27 05:31:52 +00008527
Alexander Duyck244e27a2012-02-08 07:51:11 +00008528 /* record initial flags and protocol */
8529 first->tx_flags = tx_flags;
8530 first->protocol = protocol;
8531
Yi Zoueacd73f2009-05-13 13:11:06 +00008532#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00008533 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008534 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00008535 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00008536 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00008537 if (tso < 0)
8538 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07008539
Alexander Duyck66f32a82011-06-29 05:43:22 +00008540 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00008541 }
Auke Kok9a799d72007-09-15 14:07:45 -07008542
Auke Kok9a799d72007-09-15 14:07:45 -07008543#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008544 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008545 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07008546 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008547 else if (!tso)
8548 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008549
8550 /* add the ATR filter if ATR is on */
8551 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00008552 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008553
8554#ifdef IXGBE_FCOE
8555xmit_fcoe:
8556#endif /* IXGBE_FCOE */
Jacob Keller5fef1242017-05-03 10:28:56 -07008557 if (ixgbe_tx_map(tx_ring, first, hdr_len))
8558 goto cleanup_tx_timestamp;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008559
Auke Kok9a799d72007-09-15 14:07:45 -07008560 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00008561
8562out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008563 dev_kfree_skb_any(first->skb);
8564 first->skb = NULL;
Jacob Keller5fef1242017-05-03 10:28:56 -07008565cleanup_tx_timestamp:
8566 if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
8567 dev_kfree_skb_any(adapter->ptp_tx_skb);
8568 adapter->ptp_tx_skb = NULL;
8569 cancel_work_sync(&adapter->ptp_tx_work);
8570 clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state);
8571 }
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008572
Alexander Duyck897ab152011-05-27 05:31:47 +00008573 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07008574}
8575
John Fastabend2a47fa42013-11-06 09:54:52 -08008576static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8577 struct net_device *netdev,
8578 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008579{
8580 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008581 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07008582
Alexander Duycka50c29d2012-02-08 07:50:40 +00008583 /*
8584 * The minimum packet size for olinfo paylen is 17 so pad the skb
8585 * in order to meet this minimum size requirement.
8586 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08008587 if (skb_put_padto(skb, 17))
8588 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00008589
John Fastabend2a47fa42013-11-06 09:54:52 -08008590 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8591
Auke Kok9a799d72007-09-15 14:07:45 -07008592 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8593}
8594
John Fastabend2a47fa42013-11-06 09:54:52 -08008595static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8596 struct net_device *netdev)
8597{
8598 return __ixgbe_xmit_frame(skb, netdev, NULL);
8599}
8600
Auke Kok9a799d72007-09-15 14:07:45 -07008601/**
8602 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8603 * @netdev: network interface device structure
8604 * @p: pointer to an address structure
8605 *
8606 * Returns 0 on success, negative on failure
8607 **/
8608static int ixgbe_set_mac(struct net_device *netdev, void *p)
8609{
8610 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8611 struct ixgbe_hw *hw = &adapter->hw;
8612 struct sockaddr *addr = p;
8613
8614 if (!is_valid_ether_addr(addr->sa_data))
8615 return -EADDRNOTAVAIL;
8616
8617 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008618 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008619
Alexander Duyckc9f53e62015-10-22 16:26:30 -07008620 ixgbe_mac_set_default_filter(adapter);
8621
8622 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008623}
8624
Ben Hutchings6b73e102009-04-29 08:08:58 +00008625static int
8626ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8627{
8628 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8629 struct ixgbe_hw *hw = &adapter->hw;
8630 u16 value;
8631 int rc;
8632
8633 if (prtad != hw->phy.mdio.prtad)
8634 return -EINVAL;
8635 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8636 if (!rc)
8637 rc = value;
8638 return rc;
8639}
8640
8641static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8642 u16 addr, u16 value)
8643{
8644 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8645 struct ixgbe_hw *hw = &adapter->hw;
8646
8647 if (prtad != hw->phy.mdio.prtad)
8648 return -EINVAL;
8649 return hw->phy.ops.write_reg(hw, addr, devad, value);
8650}
8651
8652static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8653{
8654 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8655
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008656 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008657 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008658 return ixgbe_ptp_set_ts_config(adapter, req);
8659 case SIOCGHWTSTAMP:
8660 return ixgbe_ptp_get_ts_config(adapter, req);
Mark D Rustade0f06bb2016-08-31 10:34:28 -07008661 case SIOCGMIIPHY:
8662 if (!adapter->hw.phy.ops.read_reg)
8663 return -EOPNOTSUPP;
8664 /* fall through */
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008665 default:
8666 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8667 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008668}
8669
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008670/**
8671 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008672 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008673 * @netdev: network interface device structure
8674 *
8675 * Returns non-zero on failure
8676 **/
8677static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8678{
8679 int err = 0;
8680 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008681 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008682
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008683 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008684 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008685 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008686 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008687
8688 /* update SAN MAC vmdq pool selection */
8689 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008690 }
8691 return err;
8692}
8693
8694/**
8695 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008696 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008697 * @netdev: network interface device structure
8698 *
8699 * Returns non-zero on failure
8700 **/
8701static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8702{
8703 int err = 0;
8704 struct ixgbe_adapter *adapter = netdev_priv(dev);
8705 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8706
8707 if (is_valid_ether_addr(mac->san_addr)) {
8708 rtnl_lock();
8709 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8710 rtnl_unlock();
8711 }
8712 return err;
8713}
8714
Auke Kok9a799d72007-09-15 14:07:45 -07008715#ifdef CONFIG_NET_POLL_CONTROLLER
8716/*
8717 * Polling 'interrupt' - used by things like netconsole to send skbs
8718 * without having to re-enable interrupts. It's not called while
8719 * the interrupt routine is executing.
8720 */
8721static void ixgbe_netpoll(struct net_device *netdev)
8722{
8723 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008724 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008725
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008726 /* if interface is down do nothing */
8727 if (test_bit(__IXGBE_DOWN, &adapter->state))
8728 return;
8729
Alexander Duyck856f6062015-02-25 17:45:54 +00008730 /* loop through and schedule all active queues */
8731 for (i = 0; i < adapter->num_q_vectors; i++)
8732 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008733}
Auke Kok9a799d72007-09-15 14:07:45 -07008734
Alexander Duyck581330b2012-02-08 07:51:47 +00008735#endif
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008736
John Fastabend33fdc822017-04-24 03:30:18 -07008737static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
8738 struct ixgbe_ring *ring)
8739{
8740 u64 bytes, packets;
8741 unsigned int start;
8742
8743 if (ring) {
8744 do {
8745 start = u64_stats_fetch_begin_irq(&ring->syncp);
8746 packets = ring->stats.packets;
8747 bytes = ring->stats.bytes;
8748 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
8749 stats->tx_packets += packets;
8750 stats->tx_bytes += bytes;
8751 }
8752}
8753
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008754static void ixgbe_get_stats64(struct net_device *netdev,
8755 struct rtnl_link_stats64 *stats)
Eric Dumazetde1036b2010-10-20 23:00:04 +00008756{
8757 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8758 int i;
8759
Eric Dumazet1a515022010-11-16 19:26:42 -08008760 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008761 for (i = 0; i < adapter->num_rx_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008762 struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008763 u64 bytes, packets;
8764 unsigned int start;
8765
Eric Dumazet1a515022010-11-16 19:26:42 -08008766 if (ring) {
8767 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008768 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008769 packets = ring->stats.packets;
8770 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008771 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008772 stats->rx_packets += packets;
8773 stats->rx_bytes += bytes;
8774 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008775 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008776
8777 for (i = 0; i < adapter->num_tx_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008778 struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008779
John Fastabend33fdc822017-04-24 03:30:18 -07008780 ixgbe_get_ring_stats64(stats, ring);
8781 }
8782 for (i = 0; i < adapter->num_xdp_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008783 struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07008784
8785 ixgbe_get_ring_stats64(stats, ring);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008786 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008787 rcu_read_unlock();
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008788
Eric Dumazetde1036b2010-10-20 23:00:04 +00008789 /* following stats updated by ixgbe_watchdog_task() */
8790 stats->multicast = netdev->stats.multicast;
8791 stats->rx_errors = netdev->stats.rx_errors;
8792 stats->rx_length_errors = netdev->stats.rx_length_errors;
8793 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8794 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
Eric Dumazetde1036b2010-10-20 23:00:04 +00008795}
8796
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008797#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008798/**
8799 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8800 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008801 * @tc: number of traffic classes currently enabled
8802 *
8803 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8804 * 802.1Q priority maps to a packet buffer that exists.
8805 */
8806static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8807{
8808 struct ixgbe_hw *hw = &adapter->hw;
8809 u32 reg, rsave;
8810 int i;
8811
8812 /* 82598 have a static priority to TC mapping that can not
8813 * be changed so no validation is needed.
8814 */
8815 if (hw->mac.type == ixgbe_mac_82598EB)
8816 return;
8817
8818 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8819 rsave = reg;
8820
8821 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8822 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8823
8824 /* If up2tc is out of bounds default to zero */
8825 if (up2tc > tc)
8826 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8827 }
8828
8829 if (reg != rsave)
8830 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8831
8832 return;
8833}
8834
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008835/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008836 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8837 * @adapter: Pointer to adapter struct
8838 *
8839 * Populate the netdev user priority to tc map
8840 */
8841static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8842{
8843 struct net_device *dev = adapter->netdev;
8844 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8845 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8846 u8 prio;
8847
8848 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8849 u8 tc = 0;
8850
8851 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8852 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8853 else if (ets)
8854 tc = ets->prio_tc[prio];
8855
8856 netdev_set_prio_tc_map(dev, prio, tc);
8857 }
8858}
8859
Alexander Duyckcca73c52013-01-12 06:33:44 +00008860#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008861/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008862 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008863 *
8864 * @netdev: net device to configure
8865 * @tc: number of traffic classes to enable
8866 */
8867int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8868{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008869 struct ixgbe_adapter *adapter = netdev_priv(dev);
8870 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08008871 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008872
John Fastabend8b1c0b22011-05-03 02:26:48 +00008873 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008874 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8875 return -EINVAL;
8876
8877 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008878 return -EINVAL;
8879
John Fastabend2a47fa42013-11-06 09:54:52 -08008880 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
8881 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
8882 return -EBUSY;
8883
John Fastabend8b1c0b22011-05-03 02:26:48 +00008884 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008885 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008886 * hardware is not flexible enough to do this dynamically.
8887 */
8888 if (netif_running(dev))
8889 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008890 else
8891 ixgbe_reset(adapter);
8892
John Fastabend8b1c0b22011-05-03 02:26:48 +00008893 ixgbe_clear_interrupt_scheme(adapter);
8894
Alexander Duyckcca73c52013-01-12 06:33:44 +00008895#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008896 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008897 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008898 ixgbe_set_prio_tc_map(adapter);
8899
John Fastabende7589ea2011-07-18 22:38:36 +00008900 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008901
Alexander Duyck943561d2012-05-09 22:14:44 -07008902 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8903 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008904 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008905 }
John Fastabende7589ea2011-07-18 22:38:36 +00008906 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008907 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008908
Alexander Duyck943561d2012-05-09 22:14:44 -07008909 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8910 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008911
8912 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008913
8914 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8915 adapter->dcb_cfg.pfc_mode_enable = false;
8916 }
8917
John Fastabend8b1c0b22011-05-03 02:26:48 +00008918 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008919
8920#endif /* CONFIG_IXGBE_DCB */
8921 ixgbe_init_interrupt_scheme(adapter);
8922
John Fastabend8b1c0b22011-05-03 02:26:48 +00008923 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008924 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008925
8926 return 0;
8927}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008928
John Fastabendb82b17d2016-02-16 21:18:53 -08008929static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8930 struct tc_cls_u32_offload *cls)
8931{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008932 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008933 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008934 u32 loc = cls->knode.handle & 0xfffff;
8935 int err = 0, i, j;
8936 struct ixgbe_jump_table *jump = NULL;
8937
8938 if (loc > IXGBE_MAX_HW_ENTRIES)
8939 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008940
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008941 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8942 return -EINVAL;
8943
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008944 /* Clear this filter in the link data it is associated with */
8945 if (uhtid != 0x800) {
8946 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008947 if (!jump)
8948 return -EINVAL;
8949 if (!test_bit(loc - 1, jump->child_loc_map))
8950 return -EINVAL;
8951 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008952 }
8953
8954 /* Check if the filter being deleted is a link */
8955 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8956 jump = adapter->jump_tables[i];
8957 if (jump && jump->link_hdl == hdl) {
8958 /* Delete filters in the hardware in the child hash
8959 * table associated with this link
8960 */
8961 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8962 if (!test_bit(j, jump->child_loc_map))
8963 continue;
8964 spin_lock(&adapter->fdir_perfect_lock);
8965 err = ixgbe_update_ethtool_fdir_entry(adapter,
8966 NULL,
8967 j + 1);
8968 spin_unlock(&adapter->fdir_perfect_lock);
8969 clear_bit(j, jump->child_loc_map);
8970 }
8971 /* Remove resources for this link */
8972 kfree(jump->input);
8973 kfree(jump->mask);
8974 kfree(jump);
8975 adapter->jump_tables[i] = NULL;
8976 return err;
8977 }
8978 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008979
John Fastabendb82b17d2016-02-16 21:18:53 -08008980 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008981 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008982 spin_unlock(&adapter->fdir_perfect_lock);
8983 return err;
8984}
8985
John Fastabenddb956ae2016-02-16 21:19:19 -08008986static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
John Fastabenddb956ae2016-02-16 21:19:19 -08008987 struct tc_cls_u32_offload *cls)
8988{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008989 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8990
8991 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8992 return -EINVAL;
8993
John Fastabenddb956ae2016-02-16 21:19:19 -08008994 /* This ixgbe devices do not support hash tables at the moment
8995 * so abort when given hash tables.
8996 */
8997 if (cls->hnode.divisor > 0)
8998 return -EINVAL;
8999
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009000 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08009001 return 0;
9002}
9003
9004static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
9005 struct tc_cls_u32_offload *cls)
9006{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009007 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
9008
9009 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
9010 return -EINVAL;
9011
9012 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08009013 return 0;
9014}
9015
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009016#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07009017struct upper_walk_data {
9018 struct ixgbe_adapter *adapter;
9019 u64 action;
9020 int ifindex;
9021 u8 queue;
9022};
9023
9024static int get_macvlan_queue(struct net_device *upper, void *_data)
9025{
9026 if (netif_is_macvlan(upper)) {
9027 struct macvlan_dev *dfwd = netdev_priv(upper);
9028 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
9029 struct upper_walk_data *data = _data;
9030 struct ixgbe_adapter *adapter = data->adapter;
9031 int ifindex = data->ifindex;
9032
9033 if (vadapter && vadapter->netdev->ifindex == ifindex) {
9034 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
9035 data->action = data->queue;
9036 return 1;
9037 }
9038 }
9039
9040 return 0;
9041}
9042
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009043static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
9044 u8 *queue, u64 *action)
9045{
Alexander Duyck361b5342017-11-22 10:56:16 -08009046 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009047 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) {
Alexander Duyck361b5342017-11-22 10:56:16 -08009055 *queue = vf * __ALIGN_MASK(1, ~vmdq->mask);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009056 *action = vf + 1;
9057 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
9058 return 0;
9059 }
9060 }
9061
9062 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07009063 data.adapter = adapter;
9064 data.ifindex = ifindex;
9065 data.action = 0;
9066 data.queue = 0;
9067 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
9068 get_macvlan_queue, &data)) {
9069 *action = data.action;
9070 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009071
David Ahern1cd127f2016-10-17 19:15:48 -07009072 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009073 }
9074
9075 return -EINVAL;
9076}
9077
9078static int parse_tc_actions(struct ixgbe_adapter *adapter,
9079 struct tcf_exts *exts, u64 *action, u8 *queue)
9080{
9081 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07009082 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009083 int err;
9084
Jiri Pirko3bcc0ce2017-08-04 14:28:58 +02009085 if (!tcf_exts_has_actions(exts))
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009086 return -EINVAL;
9087
WANG Cong22dc13c2016-08-13 22:35:00 -07009088 tcf_exts_to_list(exts, &actions);
9089 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009090
9091 /* Drop action */
9092 if (is_tcf_gact_shot(a)) {
9093 *action = IXGBE_FDIR_DROP_QUEUE;
9094 *queue = IXGBE_FDIR_DROP_QUEUE;
9095 return 0;
9096 }
9097
9098 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03009099 if (is_tcf_mirred_egress_redirect(a)) {
Cong Wang9f8a7392017-12-05 16:17:26 -08009100 struct net_device *dev = tcf_mirred_dev(a);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009101
Cong Wang9f8a7392017-12-05 16:17:26 -08009102 if (!dev)
9103 return -EINVAL;
9104 err = handle_redirect_action(adapter, dev->ifindex, queue,
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009105 action);
9106 if (err == 0)
9107 return err;
9108 }
9109 }
9110
9111 return -EINVAL;
9112}
9113#else
9114static int parse_tc_actions(struct ixgbe_adapter *adapter,
9115 struct tcf_exts *exts, u64 *action, u8 *queue)
9116{
9117 return -EINVAL;
9118}
9119#endif /* CONFIG_NET_CLS_ACT */
9120
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009121static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
9122 union ixgbe_atr_input *mask,
9123 struct tc_cls_u32_offload *cls,
9124 struct ixgbe_mat_field *field_ptr,
9125 struct ixgbe_nexthdr *nexthdr)
9126{
9127 int i, j, off;
9128 __be32 val, m;
9129 bool found_entry = false, found_jump_field = false;
9130
9131 for (i = 0; i < cls->knode.sel->nkeys; i++) {
9132 off = cls->knode.sel->keys[i].off;
9133 val = cls->knode.sel->keys[i].val;
9134 m = cls->knode.sel->keys[i].mask;
9135
9136 for (j = 0; field_ptr[j].val; j++) {
9137 if (field_ptr[j].off == off) {
9138 field_ptr[j].val(input, mask, val, m);
9139 input->filter.formatted.flow_type |=
9140 field_ptr[j].type;
9141 found_entry = true;
9142 break;
9143 }
9144 }
9145 if (nexthdr) {
9146 if (nexthdr->off == cls->knode.sel->keys[i].off &&
9147 nexthdr->val == cls->knode.sel->keys[i].val &&
9148 nexthdr->mask == cls->knode.sel->keys[i].mask)
9149 found_jump_field = true;
9150 else
9151 continue;
9152 }
9153 }
9154
9155 if (nexthdr && !found_jump_field)
9156 return -EINVAL;
9157
9158 if (!found_entry)
9159 return 0;
9160
9161 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
9162 IXGBE_ATR_L4TYPE_MASK;
9163
9164 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
9165 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
9166
9167 return 0;
9168}
9169
John Fastabendb82b17d2016-02-16 21:18:53 -08009170static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
John Fastabendb82b17d2016-02-16 21:18:53 -08009171 struct tc_cls_u32_offload *cls)
9172{
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009173 __be16 protocol = cls->common.protocol;
John Fastabendb82b17d2016-02-16 21:18:53 -08009174 u32 loc = cls->knode.handle & 0xfffff;
9175 struct ixgbe_hw *hw = &adapter->hw;
9176 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009177 struct ixgbe_fdir_filter *input = NULL;
9178 union ixgbe_atr_input *mask = NULL;
9179 struct ixgbe_jump_table *jump = NULL;
9180 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08009181 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009182 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08009183
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009184 uhtid = TC_U32_USERHTID(cls->knode.handle);
9185 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08009186
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009187 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08009188 * L2 headers. The canonical method to match L2 frames is to use
9189 * negative values. However this is error prone at best but really
9190 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009191 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08009192 * headers when needed.
9193 */
9194 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009195 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009196
9197 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
9198 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009199 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009200 }
9201
9202 /* cls u32 is a graph starting at root node 0x800. The driver tracks
9203 * links and also the fields used to advance the parser across each
9204 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
9205 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
9206 * To add support for new nodes update ixgbe_model.h parse structures
9207 * this function _should_ be generic try not to hardcode values here.
9208 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009209 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009210 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009211 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009212 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009213 return err;
9214 if (!adapter->jump_tables[uhtid])
9215 return err;
9216 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009217 }
9218
9219 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009220 return err;
9221
9222 /* At this point we know the field_ptr is valid and need to either
9223 * build cls_u32 link or attach filter. Because adding a link to
9224 * a handle that does not exist is invalid and the same for adding
9225 * rules to handles that don't exist.
9226 */
9227
9228 if (link_uhtid) {
9229 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
9230
9231 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
9232 return err;
9233
9234 if (!test_bit(link_uhtid - 1, &adapter->tables))
9235 return err;
9236
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009237 /* Multiple filters as links to the same hash table are not
9238 * supported. To add a new filter with the same next header
9239 * but different match/jump conditions, create a new hash table
9240 * and link to it.
9241 */
9242 if (adapter->jump_tables[link_uhtid] &&
9243 (adapter->jump_tables[link_uhtid])->link_hdl) {
9244 e_err(drv, "Link filter exists for link: %x\n",
9245 link_uhtid);
9246 return err;
9247 }
9248
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009249 for (i = 0; nexthdr[i].jump; i++) {
9250 if (nexthdr[i].o != cls->knode.sel->offoff ||
9251 nexthdr[i].s != cls->knode.sel->offshift ||
9252 nexthdr[i].m != cls->knode.sel->offmask)
9253 return err;
9254
9255 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
9256 if (!jump)
9257 return -ENOMEM;
9258 input = kzalloc(sizeof(*input), GFP_KERNEL);
9259 if (!input) {
9260 err = -ENOMEM;
9261 goto free_jump;
9262 }
9263 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9264 if (!mask) {
9265 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009266 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009267 }
9268 jump->input = input;
9269 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009270 jump->link_hdl = cls->knode.handle;
9271
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009272 err = ixgbe_clsu32_build_input(input, mask, cls,
9273 field_ptr, &nexthdr[i]);
9274 if (!err) {
9275 jump->mat = nexthdr[i].jump;
9276 adapter->jump_tables[link_uhtid] = jump;
9277 break;
9278 }
9279 }
9280 return 0;
9281 }
John Fastabendb82b17d2016-02-16 21:18:53 -08009282
9283 input = kzalloc(sizeof(*input), GFP_KERNEL);
9284 if (!input)
9285 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009286 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9287 if (!mask) {
9288 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009289 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08009290 }
9291
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009292 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
9293 if ((adapter->jump_tables[uhtid])->input)
9294 memcpy(input, (adapter->jump_tables[uhtid])->input,
9295 sizeof(*input));
9296 if ((adapter->jump_tables[uhtid])->mask)
9297 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
9298 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009299
9300 /* Lookup in all child hash tables if this location is already
9301 * filled with a filter
9302 */
9303 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
9304 struct ixgbe_jump_table *link = adapter->jump_tables[i];
9305
9306 if (link && (test_bit(loc - 1, link->child_loc_map))) {
9307 e_err(drv, "Filter exists in location: %x\n",
9308 loc);
9309 err = -EINVAL;
9310 goto err_out;
9311 }
9312 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009313 }
9314 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
9315 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08009316 goto err_out;
9317
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009318 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
9319 &queue);
9320 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08009321 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08009322
John Fastabendb82b17d2016-02-16 21:18:53 -08009323 input->sw_idx = loc;
9324
9325 spin_lock(&adapter->fdir_perfect_lock);
9326
9327 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009328 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
9329 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009330 if (err)
9331 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009332 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08009333 err = -EINVAL;
9334 goto err_out_w_lock;
9335 }
9336
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009337 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009338 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
9339 input->sw_idx, queue);
9340 if (!err)
9341 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
9342 spin_unlock(&adapter->fdir_perfect_lock);
9343
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009344 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
9345 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009346
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009347 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009348 return err;
9349err_out_w_lock:
9350 spin_unlock(&adapter->fdir_perfect_lock);
9351err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009352 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009353free_input:
9354 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009355free_jump:
9356 kfree(jump);
9357 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009358}
9359
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009360static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009361 struct tc_cls_u32_offload *cls_u32)
9362{
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009363 if (cls_u32->common.chain_index)
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009364 return -EOPNOTSUPP;
9365
9366 switch (cls_u32->command) {
9367 case TC_CLSU32_NEW_KNODE:
9368 case TC_CLSU32_REPLACE_KNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009369 return ixgbe_configure_clsu32(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009370 case TC_CLSU32_DELETE_KNODE:
9371 return ixgbe_delete_clsu32(adapter, cls_u32);
9372 case TC_CLSU32_NEW_HNODE:
9373 case TC_CLSU32_REPLACE_HNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009374 return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009375 case TC_CLSU32_DELETE_HNODE:
9376 return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
9377 default:
9378 return -EOPNOTSUPP;
9379 }
9380}
9381
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009382static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
9383 void *cb_priv)
9384{
9385 struct ixgbe_adapter *adapter = cb_priv;
9386
Jiri Pirko44ae12a2017-11-01 11:47:39 +01009387 if (!tc_can_offload(adapter->netdev))
9388 return -EOPNOTSUPP;
9389
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009390 switch (type) {
9391 case TC_SETUP_CLSU32:
9392 return ixgbe_setup_tc_cls_u32(adapter, type_data);
9393 default:
9394 return -EOPNOTSUPP;
9395 }
9396}
9397
9398static int ixgbe_setup_tc_block(struct net_device *dev,
9399 struct tc_block_offload *f)
9400{
9401 struct ixgbe_adapter *adapter = netdev_priv(dev);
9402
9403 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
9404 return -EOPNOTSUPP;
9405
9406 switch (f->command) {
9407 case TC_BLOCK_BIND:
9408 return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
9409 adapter, adapter);
9410 case TC_BLOCK_UNBIND:
9411 tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
9412 adapter);
9413 return 0;
9414 default:
9415 return -EOPNOTSUPP;
9416 }
9417}
9418
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009419static int ixgbe_setup_tc_mqprio(struct net_device *dev,
9420 struct tc_mqprio_qopt *mqprio)
9421{
9422 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
9423 return ixgbe_setup_tc(dev, mqprio->num_tc);
9424}
9425
Jiri Pirko2572ac52017-08-07 10:15:17 +02009426static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02009427 void *type_data)
John Fastabende4c67342016-02-16 21:16:15 -08009428{
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009429 switch (type) {
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009430 case TC_SETUP_BLOCK:
9431 return ixgbe_setup_tc_block(dev, type_data);
Nogah Frankel575ed7d2017-11-06 07:23:42 +01009432 case TC_SETUP_QDISC_MQPRIO:
Jiri Pirkode4784c2017-08-07 10:15:32 +02009433 return ixgbe_setup_tc_mqprio(dev, type_data);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009434 default:
Jiri Pirkoa5fcf8a2017-06-06 17:00:16 +02009435 return -EOPNOTSUPP;
John Fastabendb82b17d2016-02-16 21:18:53 -08009436 }
John Fastabende4c67342016-02-16 21:16:15 -08009437}
9438
Greg Roseda36b642012-12-11 08:26:43 +00009439#ifdef CONFIG_PCI_IOV
9440void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
9441{
9442 struct net_device *netdev = adapter->netdev;
9443
9444 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00009445 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00009446 rtnl_unlock();
9447}
9448
9449#endif
Don Skidmore082757a2011-07-21 05:55:00 +00009450void ixgbe_do_reset(struct net_device *netdev)
9451{
9452 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9453
9454 if (netif_running(netdev))
9455 ixgbe_reinit_locked(adapter);
9456 else
9457 ixgbe_reset(adapter);
9458}
9459
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009460static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009461 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009462{
9463 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9464
Don Skidmore082757a2011-07-21 05:55:00 +00009465 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009466 if (!(features & NETIF_F_RXCSUM))
9467 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00009468
Alexander Duyck567d2de2012-02-11 07:18:57 +00009469 /* Turn off LRO if not RSC capable */
9470 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
9471 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009472
Alexander Duyck567d2de2012-02-11 07:18:57 +00009473 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00009474}
9475
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009476static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009477 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009478{
9479 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00009480 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00009481 bool need_reset = false;
9482
Don Skidmore082757a2011-07-21 05:55:00 +00009483 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009484 if (!(features & NETIF_F_LRO)) {
9485 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00009486 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00009487 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9488 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9489 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9490 if (adapter->rx_itr_setting == 1 ||
9491 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9492 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9493 need_reset = true;
9494 } else if ((changed ^ features) & NETIF_F_LRO) {
9495 e_info(probe, "rx-usecs set too low, "
9496 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00009497 }
9498 }
9499
9500 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08009501 * Check if Flow Director n-tuple support or hw_tc support was
9502 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00009503 */
John Fastabendb82b17d2016-02-16 21:18:53 -08009504 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00009505 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00009506 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9507 need_reset = true;
9508
Alexander Duyck567d2de2012-02-11 07:18:57 +00009509 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9510 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08009511 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00009512 /* turn off perfect filters, enable ATR and reset */
9513 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9514 need_reset = true;
9515
9516 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9517
9518 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08009519 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9520 /* We cannot enable ATR if we have 2 or more tcs */
9521 (netdev_get_num_tc(netdev) > 1) ||
9522 /* We cannot enable ATR if RSS is disabled */
9523 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9524 /* A sample rate of 0 indicates ATR disabled */
9525 (!adapter->atr_sample_rate))
9526 ; /* do nothing not supported */
9527 else /* otherwise supported and set the flag */
9528 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00009529 }
9530
Ben Greear3f2d1c02012-03-08 08:28:41 +00009531 if (changed & NETIF_F_RXALL)
9532 need_reset = true;
9533
Alexander Duyck567d2de2012-02-11 07:18:57 +00009534 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07009535
Mark Rustad67359c32015-06-15 11:33:25 -07009536 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07009537 if (features & NETIF_F_RXCSUM) {
9538 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9539 } else {
9540 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9541
9542 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9543 }
9544 }
9545
9546 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9547 if (features & NETIF_F_RXCSUM) {
9548 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9549 } else {
9550 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9551
9552 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9553 }
Mark Rustad67359c32015-06-15 11:33:25 -07009554 }
Mark Rustad67359c32015-06-15 11:33:25 -07009555
Don Skidmore082757a2011-07-21 05:55:00 +00009556 if (need_reset)
9557 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009558 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9559 NETIF_F_HW_VLAN_CTAG_FILTER))
9560 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00009561
9562 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00009563}
9564
Don Skidmore3f207802014-12-23 07:40:34 +00009565/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009566 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009567 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009568 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009569 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009570static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9571 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009572{
9573 struct ixgbe_adapter *adapter = netdev_priv(dev);
9574 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07009575 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07009576 u32 port_shift = 0;
9577 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07009578
Alexander Duyckb3a49552016-06-16 12:22:19 -07009579 if (ti->sa_family != AF_INET)
9580 return;
9581
Emil Tantilova21d0822016-08-10 11:19:23 -07009582 switch (ti->type) {
9583 case UDP_TUNNEL_TYPE_VXLAN:
9584 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9585 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009586
Emil Tantilova21d0822016-08-10 11:19:23 -07009587 if (adapter->vxlan_port == port)
9588 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009589
Emil Tantilova21d0822016-08-10 11:19:23 -07009590 if (adapter->vxlan_port) {
9591 netdev_info(dev,
9592 "VXLAN port %d set, not adding port %d\n",
9593 ntohs(adapter->vxlan_port),
9594 ntohs(port));
9595 return;
9596 }
9597
9598 adapter->vxlan_port = port;
9599 break;
9600 case UDP_TUNNEL_TYPE_GENEVE:
9601 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9602 return;
9603
9604 if (adapter->geneve_port == port)
9605 return;
9606
9607 if (adapter->geneve_port) {
9608 netdev_info(dev,
9609 "GENEVE port %d set, not adding port %d\n",
9610 ntohs(adapter->geneve_port),
9611 ntohs(port));
9612 return;
9613 }
9614
9615 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9616 adapter->geneve_port = port;
9617 break;
9618 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009619 return;
9620 }
9621
Emil Tantilova21d0822016-08-10 11:19:23 -07009622 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9623 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00009624}
9625
9626/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009627 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009628 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009629 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009630 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009631static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9632 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009633{
9634 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07009635 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00009636
Emil Tantilova21d0822016-08-10 11:19:23 -07009637 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9638 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07009639 return;
9640
9641 if (ti->sa_family != AF_INET)
9642 return;
9643
Emil Tantilova21d0822016-08-10 11:19:23 -07009644 switch (ti->type) {
9645 case UDP_TUNNEL_TYPE_VXLAN:
9646 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9647 return;
Mark Rustad67359c32015-06-15 11:33:25 -07009648
Emil Tantilova21d0822016-08-10 11:19:23 -07009649 if (adapter->vxlan_port != ti->port) {
9650 netdev_info(dev, "VXLAN port %d not found\n",
9651 ntohs(ti->port));
9652 return;
9653 }
9654
9655 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9656 break;
9657 case UDP_TUNNEL_TYPE_GENEVE:
9658 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9659 return;
9660
9661 if (adapter->geneve_port != ti->port) {
9662 netdev_info(dev, "GENEVE port %d not found\n",
9663 ntohs(ti->port));
9664 return;
9665 }
9666
9667 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9668 break;
9669 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009670 return;
9671 }
9672
Emil Tantilova21d0822016-08-10 11:19:23 -07009673 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9674 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00009675}
9676
stephen hemmingeredc7d572012-10-01 12:32:33 +00009677static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009678 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009679 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009680 u16 flags)
9681{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009682 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00009683 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009684 struct ixgbe_adapter *adapter = netdev_priv(dev);
9685 u16 pool = VMDQ_P(0);
9686
9687 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009688 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009689 }
9690
Jiri Pirkof6f64242014-11-28 14:34:15 +01009691 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009692}
9693
Don Skidmore219efe92015-04-09 22:03:22 -07009694/**
9695 * ixgbe_configure_bridge_mode - set various bridge modes
9696 * @adapter - the private structure
9697 * @mode - requested bridge mode
9698 *
9699 * Configure some settings require for various bridge modes.
9700 **/
9701static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9702 __u16 mode)
9703{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009704 struct ixgbe_hw *hw = &adapter->hw;
9705 unsigned int p, num_pools;
9706 u32 vmdctl;
9707
Don Skidmore219efe92015-04-09 22:03:22 -07009708 switch (mode) {
9709 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009710 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009711 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009712
9713 /* must enable Rx switching replication to allow multicast
9714 * packet reception on all VFs, and to enable source address
9715 * pruning.
9716 */
9717 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9718 vmdctl |= IXGBE_VT_CTL_REPLEN;
9719 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9720
9721 /* enable Rx source address pruning. Note, this requires
9722 * replication to be enabled or else it does nothing.
9723 */
9724 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9725 for (p = 0; p < num_pools; p++) {
9726 if (hw->mac.ops.set_source_address_pruning)
9727 hw->mac.ops.set_source_address_pruning(hw,
9728 true,
9729 p);
9730 }
Don Skidmore219efe92015-04-09 22:03:22 -07009731 break;
9732 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009733 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009734 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9735 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009736
9737 /* disable Rx switching replication unless we have SR-IOV
9738 * virtual functions
9739 */
9740 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9741 if (!adapter->num_vfs)
9742 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9743 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9744
9745 /* disable Rx source address pruning, since we don't expect to
9746 * be receiving external loopback of our transmitted frames.
9747 */
9748 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9749 for (p = 0; p < num_pools; p++) {
9750 if (hw->mac.ops.set_source_address_pruning)
9751 hw->mac.ops.set_source_address_pruning(hw,
9752 false,
9753 p);
9754 }
Don Skidmore219efe92015-04-09 22:03:22 -07009755 break;
9756 default:
9757 return -EINVAL;
9758 }
9759
9760 adapter->bridge_mode = mode;
9761
9762 e_info(drv, "enabling bridge mode: %s\n",
9763 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9764
9765 return 0;
9766}
9767
John Fastabend815cccb2012-10-24 08:13:09 +00009768static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009769 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009770{
9771 struct ixgbe_adapter *adapter = netdev_priv(dev);
9772 struct nlattr *attr, *br_spec;
9773 int rem;
9774
9775 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9776 return -EOPNOTSUPP;
9777
9778 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009779 if (!br_spec)
9780 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009781
9782 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009783 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009784 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009785
9786 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9787 continue;
9788
Thomas Grafb7c1a312014-11-26 13:42:17 +01009789 if (nla_len(attr) < sizeof(mode))
9790 return -EINVAL;
9791
John Fastabend815cccb2012-10-24 08:13:09 +00009792 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009793 status = ixgbe_configure_bridge_mode(adapter, mode);
9794 if (status)
9795 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009796
9797 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009798 }
9799
9800 return 0;
9801}
9802
9803static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009804 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009805 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009806{
9807 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009808
9809 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9810 return 0;
9811
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009812 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009813 adapter->bridge_mode, 0, 0, nlflags,
9814 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009815}
9816
John Fastabend2a47fa42013-11-06 09:54:52 -08009817static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9818{
9819 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
9820 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009821 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08009822 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009823 int pool, err;
9824
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009825 /* Hardware has a limited number of available pools. Each VF, and the
9826 * PF require a pool. Check to ensure we don't attempt to use more
9827 * then the available number of pools.
9828 */
9829 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9830 return ERR_PTR(-EINVAL);
9831
John Fastabend219354d2013-11-08 00:50:32 -08009832#ifdef CONFIG_RPS
9833 if (vdev->num_rx_queues != vdev->num_tx_queues) {
9834 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
9835 vdev->name);
9836 return ERR_PTR(-EINVAL);
9837 }
9838#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08009839 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08009840 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08009841 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
9842 netdev_info(pdev,
9843 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
9844 pdev->name);
9845 return ERR_PTR(-EINVAL);
9846 }
9847
9848 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
9849 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
9850 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
9851 return ERR_PTR(-EBUSY);
9852
Maninder Singhbc52f952015-06-19 09:37:55 +05309853 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08009854 if (!fwd_adapter)
9855 return ERR_PTR(-ENOMEM);
9856
9857 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
9858 adapter->num_rx_pools++;
9859 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08009860 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08009861
9862 /* Enable VMDq flag so device will be set in VM mode */
9863 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08009864 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08009865 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08009866
9867 /* Force reinit of ring allocation with VMDQ enabled */
9868 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9869 if (err)
9870 goto fwd_add_err;
9871 fwd_adapter->pool = pool;
9872 fwd_adapter->real_adapter = adapter;
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009873
9874 if (netif_running(pdev)) {
9875 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
9876 if (err)
9877 goto fwd_add_err;
9878 netif_tx_start_all_queues(vdev);
9879 }
9880
John Fastabend2a47fa42013-11-06 09:54:52 -08009881 return fwd_adapter;
9882fwd_add_err:
9883 /* unwind counter and free adapter struct */
9884 netdev_info(pdev,
9885 "%s: dfwd hardware acceleration failed\n", vdev->name);
9886 clear_bit(pool, &adapter->fwd_bitmask);
9887 adapter->num_rx_pools--;
9888 kfree(fwd_adapter);
9889 return ERR_PTR(err);
9890}
9891
9892static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9893{
9894 struct ixgbe_fwd_adapter *fwd_adapter = priv;
9895 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08009896 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009897
9898 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
9899 adapter->num_rx_pools--;
9900
John Fastabend51f37732013-11-08 00:51:10 -08009901 limit = find_last_bit(&adapter->fwd_bitmask, 32);
9902 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009903 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
Shannon Nelsonf5a71ca2017-08-15 08:59:54 -07009904
9905 /* go back to full RSS if we're done with our VMQs */
9906 if (adapter->ring_feature[RING_F_VMDQ].limit == 1) {
9907 int rss = min_t(int, ixgbe_max_rss_indices(adapter),
9908 num_online_cpus());
9909
9910 adapter->flags &= ~IXGBE_FLAG_VMDQ_ENABLED;
9911 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
9912 adapter->ring_feature[RING_F_RSS].limit = rss;
9913 }
9914
John Fastabend2a47fa42013-11-06 09:54:52 -08009915 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9916 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
9917 fwd_adapter->pool, adapter->num_rx_pools,
9918 fwd_adapter->rx_base_queue,
9919 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
9920 adapter->fwd_bitmask);
9921 kfree(fwd_adapter);
9922}
9923
Alexander Duyckb83e3012016-04-14 17:19:31 -04009924#define IXGBE_MAX_MAC_HDR_LEN 127
9925#define IXGBE_MAX_NETWORK_HDR_LEN 511
9926
Mark Rustadf467bc02015-06-15 11:33:20 -07009927static netdev_features_t
9928ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9929 netdev_features_t features)
9930{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009931 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009932
Alexander Duyckb83e3012016-04-14 17:19:31 -04009933 /* Make certain the headers can be described by a context descriptor */
9934 mac_hdr_len = skb_network_header(skb) - skb->data;
9935 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9936 return features & ~(NETIF_F_HW_CSUM |
9937 NETIF_F_SCTP_CRC |
9938 NETIF_F_HW_VLAN_CTAG_TX |
9939 NETIF_F_TSO |
9940 NETIF_F_TSO6);
9941
9942 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9943 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9944 return features & ~(NETIF_F_HW_CSUM |
9945 NETIF_F_SCTP_CRC |
9946 NETIF_F_TSO |
9947 NETIF_F_TSO6);
9948
9949 /* We can only support IPV4 TSO in tunnels if we can mangle the
9950 * inner IP ID field, so strip TSO if MANGLEID is not supported.
9951 */
9952 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
9953 features &= ~NETIF_F_TSO;
Mark Rustadf467bc02015-06-15 11:33:20 -07009954
9955 return features;
9956}
9957
John Fastabend92470802017-04-24 03:30:17 -07009958static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
9959{
9960 int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
9961 struct ixgbe_adapter *adapter = netdev_priv(dev);
9962 struct bpf_prog *old_prog;
9963
9964 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
9965 return -EINVAL;
9966
9967 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
9968 return -EINVAL;
9969
9970 /* verify ixgbe ring attributes are sufficient for XDP */
9971 for (i = 0; i < adapter->num_rx_queues; i++) {
9972 struct ixgbe_ring *ring = adapter->rx_ring[i];
9973
9974 if (ring_is_rsc_enabled(ring))
9975 return -EINVAL;
9976
9977 if (frame_size > ixgbe_rx_bufsz(ring))
9978 return -EINVAL;
9979 }
9980
John Fastabend33fdc822017-04-24 03:30:18 -07009981 if (nr_cpu_ids > MAX_XDP_QUEUES)
9982 return -ENOMEM;
9983
John Fastabend92470802017-04-24 03:30:17 -07009984 old_prog = xchg(&adapter->xdp_prog, prog);
John Fastabend33fdc822017-04-24 03:30:18 -07009985
9986 /* If transitioning XDP modes reconfigure rings */
9987 if (!!prog != !!old_prog) {
9988 int err = ixgbe_setup_tc(dev, netdev_get_num_tc(dev));
9989
9990 if (err) {
9991 rcu_assign_pointer(adapter->xdp_prog, old_prog);
9992 return -EINVAL;
9993 }
9994 } else {
9995 for (i = 0; i < adapter->num_rx_queues; i++)
9996 xchg(&adapter->rx_ring[i]->xdp_prog, adapter->xdp_prog);
9997 }
John Fastabend92470802017-04-24 03:30:17 -07009998
9999 if (old_prog)
10000 bpf_prog_put(old_prog);
10001
10002 return 0;
10003}
10004
Jakub Kicinskif4e63522017-11-03 13:56:16 -070010005static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
John Fastabend92470802017-04-24 03:30:17 -070010006{
10007 struct ixgbe_adapter *adapter = netdev_priv(dev);
10008
10009 switch (xdp->command) {
10010 case XDP_SETUP_PROG:
10011 return ixgbe_xdp_setup(dev, xdp->prog);
10012 case XDP_QUERY_PROG:
10013 xdp->prog_attached = !!(adapter->xdp_prog);
Martin KaFai Lau47920932017-06-15 17:29:15 -070010014 xdp->prog_id = adapter->xdp_prog ?
10015 adapter->xdp_prog->aux->id : 0;
John Fastabend92470802017-04-24 03:30:17 -070010016 return 0;
10017 default:
10018 return -EINVAL;
10019 }
10020}
10021
John Fastabend64530732017-07-17 09:28:12 -070010022static int ixgbe_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp)
10023{
10024 struct ixgbe_adapter *adapter = netdev_priv(dev);
10025 struct ixgbe_ring *ring;
10026 int err;
10027
10028 if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +020010029 return -ENETDOWN;
John Fastabend64530732017-07-17 09:28:12 -070010030
10031 /* During program transitions its possible adapter->xdp_prog is assigned
10032 * but ring has not been configured yet. In this case simply abort xmit.
10033 */
10034 ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
10035 if (unlikely(!ring))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +020010036 return -ENXIO;
John Fastabend64530732017-07-17 09:28:12 -070010037
10038 err = ixgbe_xmit_xdp_ring(adapter, xdp);
10039 if (err != IXGBE_XDP_TX)
Jesper Dangaard Brouerd2cee2e2017-08-17 18:22:32 +020010040 return -ENOSPC;
John Fastabend64530732017-07-17 09:28:12 -070010041
John Fastabend11393cc2017-07-17 09:29:40 -070010042 return 0;
10043}
10044
10045static void ixgbe_xdp_flush(struct net_device *dev)
10046{
10047 struct ixgbe_adapter *adapter = netdev_priv(dev);
10048 struct ixgbe_ring *ring;
10049
10050 /* Its possible the device went down between xdp xmit and flush so
10051 * we need to ensure device is still up.
10052 */
10053 if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
10054 return;
10055
10056 ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
10057 if (unlikely(!ring))
10058 return;
10059
John Fastabend64530732017-07-17 09:28:12 -070010060 /* Force memory writes to complete before letting h/w know there
10061 * are new descriptors to fetch.
10062 */
10063 wmb();
John Fastabend64530732017-07-17 09:28:12 -070010064 writel(ring->next_to_use, ring->tail);
10065
John Fastabend11393cc2017-07-17 09:29:40 -070010066 return;
John Fastabend64530732017-07-17 09:28:12 -070010067}
10068
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010069static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +000010070 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010071 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -080010072 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -070010073 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +000010074 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010075 .ndo_validate_addr = eth_validate_addr,
10076 .ndo_set_mac_address = ixgbe_set_mac,
10077 .ndo_change_mtu = ixgbe_change_mtu,
10078 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +000010079 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010080 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
10081 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +000010082 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +000010083 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
10084 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -040010085 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +000010086 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +030010087 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +000010088 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +000010089 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +000010090 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -080010091 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010092#ifdef CONFIG_NET_POLL_CONTROLLER
10093 .ndo_poll_controller = ixgbe_netpoll,
10094#endif
Yi Zou332d4a72009-05-13 13:11:53 +000010095#ifdef IXGBE_FCOE
10096 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +000010097 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +000010098 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +000010099 .ndo_fcoe_enable = ixgbe_fcoe_enable,
10100 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +000010101 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +000010102 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +000010103#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +000010104 .ndo_set_features = ixgbe_set_features,
10105 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +000010106 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +000010107 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
10108 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -080010109 .ndo_dfwd_add_station = ixgbe_fwd_add,
10110 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -070010111 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
10112 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -070010113 .ndo_features_check = ixgbe_features_check,
Jakub Kicinskif4e63522017-11-03 13:56:16 -070010114 .ndo_bpf = ixgbe_xdp,
John Fastabend64530732017-07-17 09:28:12 -070010115 .ndo_xdp_xmit = ixgbe_xdp_xmit,
John Fastabend11393cc2017-07-17 09:29:40 -070010116 .ndo_xdp_flush = ixgbe_xdp_flush,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010117};
10118
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010119/**
Jacob Kellere027d1a2013-07-31 06:53:31 +000010120 * ixgbe_enumerate_functions - Get the number of ports this device has
10121 * @adapter: adapter structure
10122 *
10123 * This function enumerates the phsyical functions co-located on a single slot,
10124 * in order to determine how many ports a device has. This is most useful in
10125 * determining the required GT/s of PCIe bandwidth necessary for optimal
10126 * performance.
10127 **/
10128static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
10129{
Jacob Kellercaafb952014-07-19 07:17:17 +000010130 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010131 int physfns = 0;
10132
Jacob Kellerf1f96572013-08-31 02:45:38 +000010133 /* Some cards can not use the generic count PCIe functions method,
10134 * because they are behind a parent switch, so we hardcode these with
10135 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +000010136 */
Jacob Keller88189702014-07-19 07:17:16 +000010137 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +000010138 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +000010139
10140 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
10141 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +000010142 if (entry->is_virtfn)
10143 continue;
10144
10145 /* When the devices on the bus don't all match our device ID,
10146 * we can't reliably determine the correct number of
10147 * functions. This can occur if a function has been direct
10148 * attached to a virtual machine using VT-d, for example. In
10149 * this case, simply return -1 to indicate this.
10150 */
10151 if ((entry->vendor != pdev->vendor) ||
10152 (entry->device != pdev->device))
10153 return -1;
10154
10155 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010156 }
10157
10158 return physfns;
10159}
10160
10161/**
Jacob Keller8e2813f2012-04-21 06:05:40 +000010162 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -070010163 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +000010164 * @device_id: the device ID
10165 * @subdev_id: the subsystem device ID
10166 *
10167 * This function is used by probe and ethtool to determine
10168 * which devices have WoL support
10169 *
10170 **/
Emil Tantilov740234f2016-04-21 11:37:12 -070010171bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
10172 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +000010173{
10174 struct ixgbe_hw *hw = &adapter->hw;
10175 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010176
Emil Tantilov740234f2016-04-21 11:37:12 -070010177 /* WOL not supported on 82598 */
10178 if (hw->mac.type == ixgbe_mac_82598EB)
10179 return false;
10180
10181 /* check eeprom to see if WOL is enabled for X540 and newer */
10182 if (hw->mac.type >= ixgbe_mac_X540) {
10183 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
10184 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
10185 (hw->bus.func == 0)))
10186 return true;
10187 }
10188
10189 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +000010190 switch (device_id) {
10191 case IXGBE_DEV_ID_82599_SFP:
10192 /* Only these subdevices could supports WOL */
10193 switch (subdevice_id) {
10194 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010195 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
10196 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
10197 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010198 /* only support first port */
10199 if (hw->bus.func != 0)
10200 break;
Tony Nguyen93df9462017-05-31 04:43:47 -070010201 /* fall through */
Emil Tantilov5700ff22013-04-18 08:18:55 +000010202 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010203 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +000010204 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +000010205 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010206 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
10207 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
10208 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -070010209 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010210 }
10211 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010212 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -070010213 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +000010214 switch (subdevice_id) {
10215 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -070010216 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010217 }
10218 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010219 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
10220 /* All except this subdevice support WOL */
10221 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -070010222 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010223 break;
10224 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -070010225 return true;
10226 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010227 break;
10228 }
10229
Emil Tantilov740234f2016-04-21 11:37:12 -070010230 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010231}
10232
10233/**
Paul Greenwalt73834ae2017-10-27 10:32:40 -040010234 * ixgbe_set_fw_version - Set FW version
10235 * @adapter: the adapter private structure
10236 *
10237 * This function is used by probe and ethtool to determine the FW version to
10238 * format to display. The FW version is taken from the EEPROM/NVM.
10239 */
10240static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter)
10241{
10242 struct ixgbe_hw *hw = &adapter->hw;
10243 struct ixgbe_nvm_version nvm_ver;
10244
10245 ixgbe_get_oem_prod_version(hw, &nvm_ver);
10246 if (nvm_ver.oem_valid) {
10247 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10248 "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor,
10249 nvm_ver.oem_release);
10250 return;
10251 }
10252
10253 ixgbe_get_etk_id(hw, &nvm_ver);
10254 ixgbe_get_orom_version(hw, &nvm_ver);
10255
10256 if (nvm_ver.or_valid) {
10257 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10258 "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major,
10259 nvm_ver.or_build, nvm_ver.or_patch);
10260 return;
10261 }
10262
10263 /* Set ETrack ID format */
10264 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10265 "0x%08x", nvm_ver.etk_id);
10266}
10267
10268/**
Auke Kok9a799d72007-09-15 14:07:45 -070010269 * ixgbe_probe - Device Initialization Routine
10270 * @pdev: PCI device information struct
10271 * @ent: entry in ixgbe_pci_tbl
10272 *
10273 * Returns 0 on success, negative on failure
10274 *
10275 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
10276 * The OS initialization, configuring of the adapter private structure,
10277 * and a hardware reset occur.
10278 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000010279static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -070010280{
10281 struct net_device *netdev;
10282 struct ixgbe_adapter *adapter = NULL;
10283 struct ixgbe_hw *hw;
10284 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +000010285 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010286 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +000010287 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010288 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +000010289#ifdef IXGBE_FCOE
10290 u16 device_caps;
10291#endif
Don Skidmore289700db2010-12-03 03:32:58 +000010292 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -070010293
Andy Gospodarekbded64a2010-07-21 06:40:31 +000010294 /* Catch broken hardware that put the wrong VF device ID in
10295 * the PCIe SR-IOV capability.
10296 */
10297 if (pdev->is_virtfn) {
10298 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
10299 pci_name(pdev), pdev->vendor, pdev->device);
10300 return -EINVAL;
10301 }
10302
gouji-new9ce77662009-05-06 10:44:45 +000010303 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010304 if (err)
10305 return err;
10306
Russell Kingf5f2eda2013-06-10 12:47:42 +010010307 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -070010308 pci_using_dac = 1;
10309 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010310 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -070010311 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010312 dev_err(&pdev->dev,
10313 "No usable DMA configuration, aborting\n");
10314 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -070010315 }
10316 pci_using_dac = 0;
10317 }
10318
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010319 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -070010320 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +000010321 dev_err(&pdev->dev,
10322 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -070010323 goto err_pci_reg;
10324 }
10325
Frans Pop19d5afd2009-10-02 10:04:12 -070010326 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010327
Auke Kok9a799d72007-09-15 14:07:45 -070010328 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -070010329 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010330
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010331 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +000010332#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010333 /* 8 TC w/ 4 queues per TC */
10334 indices = 4 * MAX_TRAFFIC_CLASS;
10335#else
10336 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +000010337#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010338 }
John Fastabende901acd2011-04-26 07:26:08 +000010339
John Fastabendc85a2612010-02-25 23:15:21 +000010340 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -070010341 if (!netdev) {
10342 err = -ENOMEM;
10343 goto err_alloc_etherdev;
10344 }
10345
Auke Kok9a799d72007-09-15 14:07:45 -070010346 SET_NETDEV_DEV(netdev, &pdev->dev);
10347
Auke Kok9a799d72007-09-15 14:07:45 -070010348 adapter = netdev_priv(netdev);
10349
10350 adapter->netdev = netdev;
10351 adapter->pdev = pdev;
10352 hw = &adapter->hw;
10353 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +000010354 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -070010355
Jeff Kirsher05857982008-09-11 19:57:00 -070010356 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +000010357 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -080010358 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -070010359 if (!hw->hw_addr) {
10360 err = -EIO;
10361 goto err_ioremap;
10362 }
10363
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010364 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010365 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010366 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +000010367 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -070010368
Auke Kok9a799d72007-09-15 14:07:45 -070010369 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -080010370 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010371 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010372 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -070010373 if (ii->link_ops)
10374 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010375
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010376 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -080010377 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010378 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +000010379 if (ixgbe_removed(hw->hw_addr)) {
10380 err = -EIO;
10381 goto err_ioremap;
10382 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010383 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -070010384 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010385 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
10386
10387 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -080010388 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010389 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +000010390 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
10391 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
10392 hw->phy.mdio.mmds = 0;
10393 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10394 hw->phy.mdio.dev = netdev;
10395 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
10396 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010397
Auke Kok9a799d72007-09-15 14:07:45 -070010398 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -070010399 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -070010400 if (err)
10401 goto err_sw_init;
10402
Don Skidmoredbd15b82016-03-09 16:45:00 -050010403 /* Make sure the SWFW semaphore is in a valid state */
10404 if (hw->mac.ops.init_swfw_sync)
10405 hw->mac.ops.init_swfw_sync(hw);
10406
Don Skidmoree86bff02010-02-11 04:14:08 +000010407 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -080010408 switch (adapter->hw.mac.type) {
10409 case ixgbe_mac_82599EB:
10410 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010411 case ixgbe_mac_X550:
10412 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -070010413 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +000010414 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -080010415 break;
10416 default:
10417 break;
10418 }
Don Skidmoree86bff02010-02-11 04:14:08 +000010419
Don Skidmorebf069c92009-05-07 10:39:54 +000010420 /*
10421 * If there is a fan on this device and it has failed log the
10422 * failure.
10423 */
10424 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
10425 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
10426 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +000010427 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +000010428 }
10429
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +000010430 if (allow_unsupported_sfp)
10431 hw->allow_unsupported_sfp = allow_unsupported_sfp;
10432
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010433 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010434 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010435 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010436 hw->phy.reset_if_overtemp = false;
Mark Rustadb3eb4e12016-12-14 11:02:16 -080010437 ixgbe_set_eee_capable(adapter);
Mark Rustad29a8dca2015-08-08 16:17:46 -070010438 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -070010439 err = 0;
10440 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +000010441 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
10442 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010443 goto err_sw_init;
10444 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010445 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010446 goto err_sw_init;
10447 }
10448
Alexander Duyck99d74482012-05-09 08:09:25 +000010449#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +000010450 /* SR-IOV not supported on the 82598 */
10451 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
10452 goto skip_sriov;
10453 /* Mailbox */
10454 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -080010455 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -080010456 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
Emil Tantilov5c11f002017-01-20 14:11:56 -080010457 ixgbe_enable_sriov(adapter, max_vfs);
Greg Rose60a1a682012-12-11 08:26:33 +000010458skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010459
Alexander Duyck99d74482012-05-09 08:09:25 +000010460#endif
Emil Tantilov396e7992010-07-01 20:05:12 +000010461 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +000010462 NETIF_F_TSO |
10463 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +000010464 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -080010465 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010466 NETIF_F_HW_CSUM;
10467
10468#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
10469 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -070010470 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -070010471 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -040010472 NETIF_F_GSO_UDP_TUNNEL | \
10473 NETIF_F_GSO_UDP_TUNNEL_CSUM)
10474
10475 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
10476 netdev->features |= NETIF_F_GSO_PARTIAL |
10477 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -070010478
Alexander Duyck49763de2016-01-13 07:31:11 -080010479 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -080010480 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +000010481
Alexander Duyck49763de2016-01-13 07:31:11 -080010482 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -040010483 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -070010484 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010485 NETIF_F_HW_VLAN_CTAG_RX |
10486 NETIF_F_HW_VLAN_CTAG_TX |
10487 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -080010488 NETIF_F_HW_L2FW_DOFFLOAD;
10489
10490 if (hw->mac.type >= ixgbe_mac_82599EB)
10491 netdev->hw_features |= NETIF_F_NTUPLE |
10492 NETIF_F_HW_TC;
10493
Alexander Duyckb83e3012016-04-14 17:19:31 -040010494 if (pci_using_dac)
10495 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -070010496
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010497 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
10498 netdev->hw_enc_features |= netdev->vlan_features;
Scott Peterson2a205252016-11-18 11:25:42 -080010499 netdev->mpls_features |= NETIF_F_SG |
10500 NETIF_F_TSO |
10501 NETIF_F_TSO6 |
10502 NETIF_F_HW_CSUM;
10503 netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010504
Alexander Duyckb83e3012016-04-14 17:19:31 -040010505 /* set this bit last since it cannot be part of vlan_features */
10506 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
10507 NETIF_F_HW_VLAN_CTAG_RX |
10508 NETIF_F_HW_VLAN_CTAG_TX;
10509
Jiri Pirko01789342011-08-16 06:29:00 +000010510 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +000010511 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +000010512
Jarod Wilson91c527a2016-10-17 15:54:05 -040010513 /* MTU range: 68 - 9710 */
10514 netdev->min_mtu = ETH_MIN_MTU;
10515 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
10516
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -080010517#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -070010518 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
Stephen Hemminger3f40c742016-11-21 09:52:40 -080010519 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -080010520#endif
10521
Yi Zoueacd73f2009-05-13 13:11:06 +000010522#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +000010523 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010524 unsigned int fcoe_l;
10525
Yi Zoueacd73f2009-05-13 13:11:06 +000010526 if (hw->mac.ops.get_device_caps) {
10527 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +000010528 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
10529 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +000010530 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010531
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010532
10533 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
10534 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010535
Alexander Duycka58915c2012-05-25 06:38:18 +000010536 netdev->features |= NETIF_F_FSO |
10537 NETIF_F_FCOE_CRC;
10538
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010539 netdev->vlan_features |= NETIF_F_FSO |
10540 NETIF_F_FCOE_CRC |
10541 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +000010542 }
Yi Zoueacd73f2009-05-13 13:11:06 +000010543#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -070010544
Don Skidmore082757a2011-07-21 05:55:00 +000010545 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
10546 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +000010547 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +000010548 netdev->features |= NETIF_F_LRO;
10549
Auke Kok9a799d72007-09-15 14:07:45 -070010550 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010551 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010552 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010553 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010554 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010555 }
10556
Sowmini Varadhanc7374b52016-01-12 19:32:30 -080010557 eth_platform_get_mac_address(&adapter->pdev->dev,
10558 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +000010559
Auke Kok9a799d72007-09-15 14:07:45 -070010560 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -070010561
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +000010562 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010563 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010564 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010565 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010566 }
10567
Tushar Dave56768042016-01-07 14:17:03 -080010568 /* Set hw->mac.addr to permanent MAC address */
10569 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -070010570 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010571
Kees Cook26566ea2017-10-16 17:29:35 -070010572 timer_setup(&adapter->service_timer, ixgbe_service_timer, 0);
Auke Kok9a799d72007-09-15 14:07:45 -070010573
Mark Rustad58cf6632014-03-12 00:38:40 +000010574 if (ixgbe_removed(hw->hw_addr)) {
10575 err = -EIO;
10576 goto err_sw_init;
10577 }
Alexander Duyck70864002011-04-27 09:13:56 +000010578 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +000010579 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010580 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010581
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010582 err = ixgbe_init_interrupt_scheme(adapter);
10583 if (err)
10584 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010585
Liwei Songb09457e2016-12-04 22:40:44 -050010586 for (i = 0; i < adapter->num_rx_queues; i++)
10587 u64_stats_init(&adapter->rx_ring[i]->syncp);
10588 for (i = 0; i < adapter->num_tx_queues; i++)
10589 u64_stats_init(&adapter->tx_ring[i]->syncp);
John Fastabend33fdc822017-04-24 03:30:18 -070010590 for (i = 0; i < adapter->num_xdp_queues; i++)
10591 u64_stats_init(&adapter->xdp_ring[i]->syncp);
10592
Jacob Keller8e2813f2012-04-21 06:05:40 +000010593 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010594 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010595 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010596 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +000010597 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010598 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +000010599 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010600
PJ Waskiewicze8e26352009-02-27 15:45:05 +000010601 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
10602
Emil Tantilov15e52092011-09-29 05:01:29 +000010603 /* save off EEPROM version number */
Paul Greenwalt73834ae2017-10-27 10:32:40 -040010604 ixgbe_set_fw_version(adapter);
Emil Tantilov15e52092011-09-29 05:01:29 +000010605
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010606 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +000010607 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +000010608 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -040010609 else
10610 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010611
Jacob Kellere027d1a2013-07-31 06:53:31 +000010612 /* calculate the expected PCIe bandwidth required for optimal
10613 * performance. Note that some older parts will never have enough
10614 * bandwidth due to being older generation PCIe parts. We clamp these
10615 * parts to ensure no warning is displayed if it can't be fixed.
10616 */
10617 switch (hw->mac.type) {
10618 case ixgbe_mac_82598EB:
10619 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
10620 break;
10621 default:
10622 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
10623 break;
Auke Kok0c254d82008-02-11 09:25:56 -080010624 }
Jacob Kellercaafb952014-07-19 07:17:17 +000010625
10626 /* don't check link if we failed to enumerate functions */
10627 if (expected_gts > 0)
10628 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -080010629
Mark Rustad339de302014-06-06 01:57:06 +000010630 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010631 if (err)
Mark Rustad339de302014-06-06 01:57:06 +000010632 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010633 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
10634 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
10635 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +000010636 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +000010637 else
10638 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
10639 hw->mac.type, hw->phy.type, part_str);
10640
10641 e_dev_info("%pM\n", netdev->dev_addr);
10642
Auke Kok9a799d72007-09-15 14:07:45 -070010643 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010644 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010645 if (err == IXGBE_ERR_EEPROM_VERSION) {
10646 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +000010647 e_dev_warn("This device is a pre-production adapter/LOM. "
10648 "Please be aware there may be issues associated "
10649 "with your hardware. If you are experiencing "
10650 "problems please contact your Intel or hardware "
10651 "representative who provided you with this "
10652 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010653 }
Auke Kok9a799d72007-09-15 14:07:45 -070010654 strcpy(netdev->name, "eth%d");
Jeff Mahoneya09c0fc2017-06-03 18:01:17 -040010655 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010656 err = register_netdev(netdev);
10657 if (err)
10658 goto err_register;
10659
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010660
Emil Tantilovec74a472012-09-20 03:33:56 +000010661 /* power down the optics for 82599 SFP+ fiber */
10662 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +000010663 hw->mac.ops.disable_tx_laser(hw);
10664
Jesse Brandeburg54386462009-04-17 20:44:27 +000010665 /* carrier off reporting is important to ethtool even BEFORE open */
10666 netif_carrier_off(netdev);
10667
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010668#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +030010669 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010670 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010671 ixgbe_setup_dca(adapter);
10672 }
10673#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010674 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010675 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010676 for (i = 0; i < adapter->num_vfs; i++)
10677 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10678 }
10679
Jacob Keller2466dd92011-09-08 03:50:54 +000010680 /* firmware requires driver version to be 0xFFFFFFFF
10681 * since os does not support feature
10682 */
Emil Tantilov9612de92011-05-07 07:40:20 +000010683 if (hw->mac.ops.set_fw_drv_ver)
Tony Nguyencb8e0512016-10-26 16:25:18 -070010684 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10685 sizeof(ixgbe_driver_version) - 1,
10686 ixgbe_driver_version);
Emil Tantilov9612de92011-05-07 07:40:20 +000010687
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010688 /* add san mac addr to netdev */
10689 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010690
Neerav Parikhea818752012-01-04 20:23:40 +000010691 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010692
Don Skidmore12109822012-05-04 06:07:08 +000010693#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010694 if (ixgbe_sysfs_init(adapter))
10695 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +000010696#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010697
Catherine Sullivan00949162012-08-10 01:59:10 +000010698 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010699
Emil Tantilovd1a35ee2014-05-13 08:24:00 +000010700 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10701 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +000010702 hw->mac.ops.setup_link(hw,
10703 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10704 true);
10705
Auke Kok9a799d72007-09-15 14:07:45 -070010706 return 0;
10707
10708err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010709 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010710 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010711err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +000010712 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +000010713 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -080010714 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010715 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010716 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010717 kfree(adapter->rss_key);
Auke Kok9a799d72007-09-15 14:07:45 -070010718err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010719 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010720 free_netdev(netdev);
10721err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010722 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010723err_pci_reg:
10724err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010725 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010726 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010727 return err;
10728}
10729
10730/**
10731 * ixgbe_remove - Device Removal Routine
10732 * @pdev: PCI device information struct
10733 *
10734 * ixgbe_remove is called by the PCI subsystem to alert the driver
10735 * that it should release a PCI device. The could be caused by a
10736 * Hot-Plug event, or because the driver is going to be removed from
10737 * memory.
10738 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010739static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -070010740{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010741 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010742 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010743 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010744 int i;
Auke Kok9a799d72007-09-15 14:07:45 -070010745
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010746 /* if !adapter then we already cleaned up in probe */
10747 if (!adapter)
10748 return;
10749
10750 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +000010751 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010752
Mark Rustad09f40ae2014-01-14 18:53:11 -080010753 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010754 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -070010755
Jacob Keller3a6a4ed2012-05-01 05:24:58 +000010756
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010757#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010758 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10759 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10760 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -070010761 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10762 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010763 }
10764
10765#endif
Don Skidmore12109822012-05-04 06:07:08 +000010766#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010767 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +000010768#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010769
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010770 /* remove the added san mac */
10771 ixgbe_del_sanmac_netdev(netdev);
10772
Greg Roseda36b642012-12-11 08:26:43 +000010773#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -060010774 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +000010775#endif
Alex Williamson6b010e92015-07-29 14:38:21 -060010776 if (netdev->reg_state == NETREG_REGISTERED)
10777 unregister_netdev(netdev);
10778
Alexander Duyck7a921c92009-05-06 10:43:28 +000010779 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010780
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010781 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010782
Alexander Duyck2b1588c2012-03-17 02:39:16 +000010783#ifdef CONFIG_DCB
10784 kfree(adapter->ixgbe_ieee_pfc);
10785 kfree(adapter->ixgbe_ieee_ets);
10786
10787#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -080010788 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010789 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010790
Emil Tantilov849c4542010-06-03 16:53:41 +000010791 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010792
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010793 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
10794 if (adapter->jump_tables[i]) {
10795 kfree(adapter->jump_tables[i]->input);
10796 kfree(adapter->jump_tables[i]->mask);
10797 }
10798 kfree(adapter->jump_tables[i]);
10799 }
10800
Jacob Keller5d7daa32014-03-29 06:51:25 +000010801 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010802 kfree(adapter->rss_key);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010803 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010804 free_netdev(netdev);
10805
Frans Pop19d5afd2009-10-02 10:04:12 -070010806 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010807
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010808 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010809 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010810}
10811
10812/**
10813 * ixgbe_io_error_detected - called when PCI error is detected
10814 * @pdev: Pointer to PCI device
10815 * @state: The current pci connection state
10816 *
10817 * This function is called after a PCI bus error affecting
10818 * this device has been detected.
10819 */
10820static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +000010821 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -070010822{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010823 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10824 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010825
Greg Rose83c61fa2011-09-07 05:59:35 +000010826#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -080010827 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +000010828 struct pci_dev *bdev, *vfdev;
10829 u32 dw0, dw1, dw2, dw3;
10830 int vf, pos;
10831 u16 req_id, pf_func;
10832
10833 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
10834 adapter->num_vfs == 0)
10835 goto skip_bad_vf_detection;
10836
10837 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +080010838 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +000010839 bdev = bdev->bus->self;
10840
10841 if (!bdev)
10842 goto skip_bad_vf_detection;
10843
10844 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
10845 if (!pos)
10846 goto skip_bad_vf_detection;
10847
Mark Rustad14438462014-02-28 15:48:57 -080010848 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
10849 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
10850 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
10851 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
10852 if (ixgbe_removed(hw->hw_addr))
10853 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +000010854
10855 req_id = dw1 >> 16;
10856 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10857 if (!(req_id & 0x0080))
10858 goto skip_bad_vf_detection;
10859
10860 pf_func = req_id & 0x01;
10861 if ((pf_func & 1) == (pdev->devfn & 1)) {
10862 unsigned int device_id;
10863
10864 vf = (req_id & 0x7F) >> 1;
10865 e_dev_err("VF %d has caused a PCIe error\n", vf);
10866 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10867 "%8.8x\tdw3: %8.8x\n",
10868 dw0, dw1, dw2, dw3);
10869 switch (adapter->hw.mac.type) {
10870 case ixgbe_mac_82599EB:
10871 device_id = IXGBE_82599_VF_DEVICE_ID;
10872 break;
10873 case ixgbe_mac_X540:
10874 device_id = IXGBE_X540_VF_DEVICE_ID;
10875 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010876 case ixgbe_mac_X550:
10877 device_id = IXGBE_DEV_ID_X550_VF;
10878 break;
10879 case ixgbe_mac_X550EM_x:
10880 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10881 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010882 case ixgbe_mac_x550em_a:
10883 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10884 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010885 default:
10886 device_id = 0;
10887 break;
10888 }
10889
10890 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010891 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010892 while (vfdev) {
10893 if (vfdev->devfn == (req_id & 0xFF))
10894 break;
Jon Mason36e90312012-07-19 21:02:09 +000010895 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010896 device_id, vfdev);
10897 }
10898 /*
10899 * There's a slim chance the VF could have been hot plugged,
10900 * so if it is no longer present we don't need to issue the
10901 * VFLR. Just clean up the AER in that case.
10902 */
10903 if (vfdev) {
Christoph Hellwig63af8f72017-04-14 21:11:28 +020010904 pcie_flr(vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010905 /* Free device reference count */
10906 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010907 }
10908
10909 pci_cleanup_aer_uncorrect_error_status(pdev);
10910 }
10911
10912 /*
10913 * Even though the error may have occurred on the other port
10914 * we still need to increment the vf error reference count for
10915 * both ports because the I/O resume function will be called
10916 * for both of them.
10917 */
10918 adapter->vferr_refcount++;
10919
10920 return PCI_ERS_RESULT_RECOVERED;
10921
10922skip_bad_vf_detection:
10923#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010924 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10925 return PCI_ERS_RESULT_DISCONNECT;
10926
Emil Tantilovb64666a2017-09-29 10:55:42 -070010927 if (!netif_device_present(netdev))
10928 return PCI_ERS_RESULT_DISCONNECT;
10929
Mark Rustad41c62842014-03-12 00:38:35 +000010930 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010931 netif_device_detach(netdev);
10932
Mark Rustad41c62842014-03-12 00:38:35 +000010933 if (state == pci_channel_io_perm_failure) {
10934 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010935 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010936 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010937
Auke Kok9a799d72007-09-15 14:07:45 -070010938 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010939 ixgbe_close_suspend(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +000010940
10941 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10942 pci_disable_device(pdev);
10943 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010944
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010945 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010946 return PCI_ERS_RESULT_NEED_RESET;
10947}
10948
10949/**
10950 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10951 * @pdev: Pointer to PCI device
10952 *
10953 * Restart the card from scratch, as if from a cold-boot.
10954 */
10955static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10956{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010957 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010958 pci_ers_result_t result;
10959 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010960
gouji-new9ce77662009-05-06 10:44:45 +000010961 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010962 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010963 result = PCI_ERS_RESULT_DISCONNECT;
10964 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010965 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010966 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010967 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010968 pci_set_master(pdev);
10969 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010970 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010971
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010972 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010973
10974 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010975 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010976 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010977 }
Auke Kok9a799d72007-09-15 14:07:45 -070010978
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010979 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10980 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010981 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10982 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010983 /* non-fatal, continue */
10984 }
Auke Kok9a799d72007-09-15 14:07:45 -070010985
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010986 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010987}
10988
10989/**
10990 * ixgbe_io_resume - called when traffic can start flowing again.
10991 * @pdev: Pointer to PCI device
10992 *
10993 * This callback is called when the error recovery driver tells us that
10994 * its OK to resume normal operation.
10995 */
10996static void ixgbe_io_resume(struct pci_dev *pdev)
10997{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010998 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10999 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070011000
Greg Rose83c61fa2011-09-07 05:59:35 +000011001#ifdef CONFIG_PCI_IOV
11002 if (adapter->vferr_refcount) {
11003 e_info(drv, "Resuming after VF err\n");
11004 adapter->vferr_refcount--;
11005 return;
11006 }
11007
11008#endif
Emil Tantilov126db132016-11-16 09:48:02 -080011009 rtnl_lock();
Alexander Duyckc7ccde02011-07-21 00:40:40 +000011010 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080011011 ixgbe_open(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070011012
11013 netif_device_attach(netdev);
Emil Tantilov126db132016-11-16 09:48:02 -080011014 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070011015}
11016
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070011017static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070011018 .error_detected = ixgbe_io_error_detected,
11019 .slot_reset = ixgbe_io_slot_reset,
11020 .resume = ixgbe_io_resume,
11021};
11022
11023static struct pci_driver ixgbe_driver = {
11024 .name = ixgbe_driver_name,
11025 .id_table = ixgbe_pci_tbl,
11026 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050011027 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070011028#ifdef CONFIG_PM
11029 .suspend = ixgbe_suspend,
11030 .resume = ixgbe_resume,
11031#endif
11032 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000011033 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070011034 .err_handler = &ixgbe_err_handler
11035};
11036
11037/**
11038 * ixgbe_init_module - Driver Registration Routine
11039 *
11040 * ixgbe_init_module is the first routine called when the driver is
11041 * loaded. All it does is register with the PCI subsystem.
11042 **/
11043static int __init ixgbe_init_module(void)
11044{
11045 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000011046 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000011047 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070011048
Mark Rustad780484d2015-10-21 17:21:10 -070011049 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
11050 if (!ixgbe_wq) {
11051 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
11052 return -ENOMEM;
11053 }
11054
Catherine Sullivan00949162012-08-10 01:59:10 +000011055 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000011056
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011057 ret = pci_register_driver(&ixgbe_driver);
11058 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000011059 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011060 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011061 return ret;
11062 }
11063
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011064#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011065 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011066#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011067
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011068 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070011069}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070011070
Auke Kok9a799d72007-09-15 14:07:45 -070011071module_init(ixgbe_init_module);
11072
11073/**
11074 * ixgbe_exit_module - Driver Exit Cleanup Routine
11075 *
11076 * ixgbe_exit_module is called just before the driver is removed
11077 * from memory.
11078 **/
11079static void __exit ixgbe_exit_module(void)
11080{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011081#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011082 dca_unregister_notify(&dca_notifier);
11083#endif
Auke Kok9a799d72007-09-15 14:07:45 -070011084 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000011085
Catherine Sullivan00949162012-08-10 01:59:10 +000011086 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070011087 if (ixgbe_wq) {
11088 destroy_workqueue(ixgbe_wq);
11089 ixgbe_wq = NULL;
11090 }
Auke Kok9a799d72007-09-15 14:07:45 -070011091}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011092
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011093#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011094static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011095 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011096{
11097 int ret_val;
11098
11099 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011100 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011101
11102 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
11103}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011104
Alexander Duyckb4533682009-03-31 21:32:42 +000011105#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000011106
Auke Kok9a799d72007-09-15 14:07:45 -070011107module_exit(ixgbe_exit_module);
11108
11109/* ixgbe_main.c */