blob: 1a7bfcfc030e79dde38375ec4ee4d644e7b4bb44 [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>
Yi Zoueacd73f2009-05-13 13:11:06 +000052#include <scsi/fc/fc_fcoe.h>
Don Skidmore3f207802014-12-23 07:40:34 +000053#include <net/vxlan.h>
John Fastabendb82b17d2016-02-16 21:18:53 -080054#include <net/pkt_cls.h>
55#include <net/tc_act/tc_gact.h>
Auke Kok9a799d72007-09-15 14:07:45 -070056
57#include "ixgbe.h"
58#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000059#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000060#include "ixgbe_sriov.h"
John Fastabendb82b17d2016-02-16 21:18:53 -080061#include "ixgbe_model.h"
Auke Kok9a799d72007-09-15 14:07:45 -070062
63char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070064static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000065 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000066#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000067char ixgbe_default_device_descr[] =
68 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000069#else
70static char ixgbe_default_device_descr[] =
71 "Intel(R) 10 Gigabit Network Connection";
72#endif
Mark Rustad21dd5602015-08-11 13:11:58 -070073#define DRV_VERSION "4.2.1-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070074const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000075static const char ixgbe_copyright[] =
Mark Rustad49425df2016-04-01 12:18:09 -070076 "Copyright (c) 1999-2016 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070077
Don Skidmoref44e7512015-06-09 16:36:23 -070078static 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";
79
Auke Kok9a799d72007-09-15 14:07:45 -070080static const struct ixgbe_info *ixgbe_info_tbl[] = {
Don Skidmore6a14ee02014-12-05 03:59:50 +000081 [board_82598] = &ixgbe_82598_info,
82 [board_82599] = &ixgbe_82599_info,
83 [board_X540] = &ixgbe_X540_info,
84 [board_X550] = &ixgbe_X550_info,
85 [board_X550EM_x] = &ixgbe_X550EM_x_info,
Mark Rustad49425df2016-04-01 12:18:09 -070086 [board_x550em_a] = &ixgbe_x550em_a_info,
Auke Kok9a799d72007-09-15 14:07:45 -070087};
88
89/* ixgbe_pci_tbl - PCI Device ID Table
90 *
91 * Wildcard entries (PCI_ANY_ID) should come last
92 * Last entry must be all 0s
93 *
94 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
95 * Class, Class Mask, private data (not used) }
96 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020097static const struct pci_device_id ixgbe_pci_tbl[] = {
Alexander Duyck54239c62011-07-15 03:06:06 +000098 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Don Skidmore8f583322013-07-27 06:25:38 +0000124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Don Skidmore6a14ee02014-12-05 03:59:50 +0000128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
Mark Rustada711ad82016-03-21 11:21:31 -0700129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
Don Skidmore6a14ee02014-12-05 03:59:50 +0000130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
Don Skidmorededa5622015-06-09 17:39:46 -0700132 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
Mark Rustad018d7142015-08-08 16:19:19 -0700133 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
Mark Rustadf572b2c2016-04-01 12:18:46 -0700134 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
135 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
Mark Rustad49425df2016-04-01 12:18:09 -0700136 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
Mark Rustad200157c2016-04-01 12:18:40 -0700137 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
138 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
Mark Rustad2d40cd12016-04-01 12:18:35 -0700139 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
Auke Kok9a799d72007-09-15 14:07:45 -0700140 /* required last entry */
141 {0, }
142};
143MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
144
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400145#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800146static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000147 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800148static struct notifier_block dca_notifier = {
149 .notifier_call = ixgbe_notify_dca,
150 .next = NULL,
151 .priority = 0
152};
153#endif
154
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000155#ifdef CONFIG_PCI_IOV
156static unsigned int max_vfs;
157module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000158MODULE_PARM_DESC(max_vfs,
Jacob Keller170e8542013-11-09 04:52:32 -0800159 "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 +0000160#endif /* CONFIG_PCI_IOV */
161
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000162static unsigned int allow_unsupported_sfp;
163module_param(allow_unsupported_sfp, uint, 0);
164MODULE_PARM_DESC(allow_unsupported_sfp,
165 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
166
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000167#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
168static int debug = -1;
169module_param(debug, int, 0);
170MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
171
Auke Kok9a799d72007-09-15 14:07:45 -0700172MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
173MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
174MODULE_LICENSE("GPL");
175MODULE_VERSION(DRV_VERSION);
176
Mark Rustad780484d2015-10-21 17:21:10 -0700177static struct workqueue_struct *ixgbe_wq;
178
Mark Rustad14438462014-02-28 15:48:57 -0800179static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
180
Jacob Kellerb8e82002013-04-09 07:20:09 +0000181static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
182 u32 reg, u16 *value)
183{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000184 struct pci_dev *parent_dev;
185 struct pci_bus *parent_bus;
186
187 parent_bus = adapter->pdev->bus->parent;
188 if (!parent_bus)
189 return -1;
190
191 parent_dev = parent_bus->self;
192 if (!parent_dev)
193 return -1;
194
Yijing Wangc0798ed2013-09-04 17:30:08 +0000195 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000196 return -1;
197
Yijing Wangc0798ed2013-09-04 17:30:08 +0000198 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800199 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
200 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
201 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000202 return 0;
203}
204
205static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
206{
207 struct ixgbe_hw *hw = &adapter->hw;
208 u16 link_status = 0;
209 int err;
210
211 hw->bus.type = ixgbe_bus_type_pci_express;
212
213 /* Get the negotiated link width and speed from PCI config space of the
214 * parent, as this device is behind a switch
215 */
216 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
217
218 /* assume caller will handle error case */
219 if (err)
220 return err;
221
222 hw->bus.width = ixgbe_convert_bus_width(link_status);
223 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
224
225 return 0;
226}
227
Jacob Kellere027d1a2013-07-31 06:53:31 +0000228/**
229 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
230 * @hw: hw specific details
231 *
232 * This function is used by probe to determine whether a device's PCI-Express
233 * bandwidth details should be gathered from the parent bus instead of from the
234 * device. Used to ensure that various locations all have the correct device ID
235 * checks.
236 */
237static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
238{
239 switch (hw->device_id) {
240 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000241 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000242 return true;
243 default:
244 return false;
245 }
246}
247
248static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
249 int expected_gts)
250{
Don Skidmoref9328bc2015-06-18 13:24:06 -0400251 struct ixgbe_hw *hw = &adapter->hw;
Jacob Kellere027d1a2013-07-31 06:53:31 +0000252 int max_gts = 0;
253 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
254 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
255 struct pci_dev *pdev;
256
Don Skidmoref9328bc2015-06-18 13:24:06 -0400257 /* Some devices are not connected over PCIe and thus do not negotiate
258 * speed. These devices do not have valid bus info, and thus any report
259 * we generate may not be correct.
260 */
261 if (hw->bus.type == ixgbe_bus_type_internal)
262 return;
263
Jacob Keller56d13922015-06-10 11:44:45 -0700264 /* determine whether to use the parent device */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000265 if (ixgbe_pcie_from_parent(&adapter->hw))
266 pdev = adapter->pdev->bus->parent->self;
267 else
268 pdev = adapter->pdev;
269
270 if (pcie_get_minimum_link(pdev, &speed, &width) ||
271 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
272 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
273 return;
274 }
275
276 switch (speed) {
277 case PCIE_SPEED_2_5GT:
278 /* 8b/10b encoding reduces max throughput by 20% */
279 max_gts = 2 * width;
280 break;
281 case PCIE_SPEED_5_0GT:
282 /* 8b/10b encoding reduces max throughput by 20% */
283 max_gts = 4 * width;
284 break;
285 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000286 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000287 max_gts = 8 * width;
288 break;
289 default:
290 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
291 return;
292 }
293
294 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
295 max_gts);
296 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
297 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
298 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
299 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
300 "Unknown"),
301 width,
302 (speed == PCIE_SPEED_2_5GT ? "20%" :
303 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000304 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000305 "Unknown"));
306
307 if (max_gts < expected_gts) {
308 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
309 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
310 expected_gts);
311 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
312 }
313}
314
Alexander Duyck70864002011-04-27 09:13:56 +0000315static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
316{
317 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800318 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000319 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
Mark Rustad780484d2015-10-21 17:21:10 -0700320 queue_work(ixgbe_wq, &adapter->service_task);
Alexander Duyck70864002011-04-27 09:13:56 +0000321}
322
Mark Rustad2a1a0912014-01-14 18:53:15 -0800323static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
324{
325 struct ixgbe_adapter *adapter = hw->back;
326
327 if (!hw->hw_addr)
328 return;
329 hw->hw_addr = NULL;
330 e_dev_err("Adapter removed\n");
Mark Rustad58cf6632014-03-12 00:38:40 +0000331 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
332 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800333}
334
Mark Rustadf8e24722014-03-18 07:03:40 +0000335static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800336{
337 u32 value;
338
339 /* The following check not only optimizes a bit by not
340 * performing a read on the status register when the
341 * register just read was a status register read that
342 * returned IXGBE_FAILED_READ_REG. It also blocks any
343 * potential recursion.
344 */
345 if (reg == IXGBE_STATUS) {
346 ixgbe_remove_adapter(hw);
347 return;
348 }
349 value = ixgbe_read_reg(hw, IXGBE_STATUS);
350 if (value == IXGBE_FAILED_READ_REG)
351 ixgbe_remove_adapter(hw);
352}
353
Mark Rustadf8e24722014-03-18 07:03:40 +0000354/**
355 * ixgbe_read_reg - Read from device register
356 * @hw: hw specific details
357 * @reg: offset of register to read
358 *
359 * Returns : value read or IXGBE_FAILED_READ_REG if removed
360 *
361 * This function is used to read device registers. It checks for device
362 * removal by confirming any read that returns all ones by checking the
363 * status register value for all ones. This function avoids reading from
364 * the hardware if a removal was previously detected in which case it
365 * returns IXGBE_FAILED_READ_REG (all ones).
366 */
367u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
368{
369 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
370 u32 value;
371
372 if (ixgbe_removed(reg_addr))
373 return IXGBE_FAILED_READ_REG;
374 value = readl(reg_addr + reg);
375 if (unlikely(value == IXGBE_FAILED_READ_REG))
376 ixgbe_check_remove(hw, reg);
377 return value;
378}
379
Mark Rustad14438462014-02-28 15:48:57 -0800380static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
381{
382 u16 value;
383
384 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
385 if (value == IXGBE_FAILED_READ_CFG_WORD) {
386 ixgbe_remove_adapter(hw);
387 return true;
388 }
389 return false;
390}
391
392u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
393{
394 struct ixgbe_adapter *adapter = hw->back;
395 u16 value;
396
397 if (ixgbe_removed(hw->hw_addr))
398 return IXGBE_FAILED_READ_CFG_WORD;
399 pci_read_config_word(adapter->pdev, reg, &value);
400 if (value == IXGBE_FAILED_READ_CFG_WORD &&
401 ixgbe_check_cfg_remove(hw, adapter->pdev))
402 return IXGBE_FAILED_READ_CFG_WORD;
403 return value;
404}
405
406#ifdef CONFIG_PCI_IOV
407static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
408{
409 struct ixgbe_adapter *adapter = hw->back;
410 u32 value;
411
412 if (ixgbe_removed(hw->hw_addr))
413 return IXGBE_FAILED_READ_CFG_DWORD;
414 pci_read_config_dword(adapter->pdev, reg, &value);
415 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
416 ixgbe_check_cfg_remove(hw, adapter->pdev))
417 return IXGBE_FAILED_READ_CFG_DWORD;
418 return value;
419}
420#endif /* CONFIG_PCI_IOV */
421
Jacob Kellered192312014-02-22 01:23:53 +0000422void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
423{
424 struct ixgbe_adapter *adapter = hw->back;
425
426 if (ixgbe_removed(hw->hw_addr))
427 return;
428 pci_write_config_word(adapter->pdev, reg, value);
429}
430
Alexander Duyck70864002011-04-27 09:13:56 +0000431static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
432{
433 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
434
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000435 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100436 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000437 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
438}
439
Taku Izumidcd79ae2010-04-27 14:39:53 +0000440struct ixgbe_reg_info {
441 u32 ofs;
442 char *name;
443};
444
445static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
446
447 /* General Registers */
448 {IXGBE_CTRL, "CTRL"},
449 {IXGBE_STATUS, "STATUS"},
450 {IXGBE_CTRL_EXT, "CTRL_EXT"},
451
452 /* Interrupt Registers */
453 {IXGBE_EICR, "EICR"},
454
455 /* RX Registers */
456 {IXGBE_SRRCTL(0), "SRRCTL"},
457 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
458 {IXGBE_RDLEN(0), "RDLEN"},
459 {IXGBE_RDH(0), "RDH"},
460 {IXGBE_RDT(0), "RDT"},
461 {IXGBE_RXDCTL(0), "RXDCTL"},
462 {IXGBE_RDBAL(0), "RDBAL"},
463 {IXGBE_RDBAH(0), "RDBAH"},
464
465 /* TX Registers */
466 {IXGBE_TDBAL(0), "TDBAL"},
467 {IXGBE_TDBAH(0), "TDBAH"},
468 {IXGBE_TDLEN(0), "TDLEN"},
469 {IXGBE_TDH(0), "TDH"},
470 {IXGBE_TDT(0), "TDT"},
471 {IXGBE_TXDCTL(0), "TXDCTL"},
472
473 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000474 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000475};
476
477
478/*
479 * ixgbe_regdump - register printout routine
480 */
481static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
482{
483 int i = 0, j = 0;
484 char rname[16];
485 u32 regs[64];
486
487 switch (reginfo->ofs) {
488 case IXGBE_SRRCTL(0):
489 for (i = 0; i < 64; i++)
490 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
491 break;
492 case IXGBE_DCA_RXCTRL(0):
493 for (i = 0; i < 64; i++)
494 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
495 break;
496 case IXGBE_RDLEN(0):
497 for (i = 0; i < 64; i++)
498 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
499 break;
500 case IXGBE_RDH(0):
501 for (i = 0; i < 64; i++)
502 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
503 break;
504 case IXGBE_RDT(0):
505 for (i = 0; i < 64; i++)
506 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
507 break;
508 case IXGBE_RXDCTL(0):
509 for (i = 0; i < 64; i++)
510 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
511 break;
512 case IXGBE_RDBAL(0):
513 for (i = 0; i < 64; i++)
514 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
515 break;
516 case IXGBE_RDBAH(0):
517 for (i = 0; i < 64; i++)
518 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
519 break;
520 case IXGBE_TDBAL(0):
521 for (i = 0; i < 64; i++)
522 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
523 break;
524 case IXGBE_TDBAH(0):
525 for (i = 0; i < 64; i++)
526 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
527 break;
528 case IXGBE_TDLEN(0):
529 for (i = 0; i < 64; i++)
530 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
531 break;
532 case IXGBE_TDH(0):
533 for (i = 0; i < 64; i++)
534 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
535 break;
536 case IXGBE_TDT(0):
537 for (i = 0; i < 64; i++)
538 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
539 break;
540 case IXGBE_TXDCTL(0):
541 for (i = 0; i < 64; i++)
542 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
543 break;
544 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000545 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000546 IXGBE_READ_REG(hw, reginfo->ofs));
547 return;
548 }
549
550 for (i = 0; i < 8; i++) {
551 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000552 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000553 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000554 pr_cont(" %08x", regs[i*8+j]);
555 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000556 }
557
558}
559
560/*
561 * ixgbe_dump - Print registers, tx-rings and rx-rings
562 */
563static void ixgbe_dump(struct ixgbe_adapter *adapter)
564{
565 struct net_device *netdev = adapter->netdev;
566 struct ixgbe_hw *hw = &adapter->hw;
567 struct ixgbe_reg_info *reginfo;
568 int n = 0;
569 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000570 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000571 union ixgbe_adv_tx_desc *tx_desc;
572 struct my_u0 { u64 a; u64 b; } *u0;
573 struct ixgbe_ring *rx_ring;
574 union ixgbe_adv_rx_desc *rx_desc;
575 struct ixgbe_rx_buffer *rx_buffer_info;
576 u32 staterr;
577 int i = 0;
578
579 if (!netif_msg_hw(adapter))
580 return;
581
582 /* Print netdevice Info */
583 if (netdev) {
584 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000585 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000586 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000587 pr_info("%-15s %016lX %016lX %016lX\n",
588 netdev->name,
589 netdev->state,
590 netdev->trans_start,
591 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000592 }
593
594 /* Print Registers */
595 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000596 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000597 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
598 reginfo->name; reginfo++) {
599 ixgbe_regdump(hw, reginfo);
600 }
601
602 /* Print TX Ring Summary */
603 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000604 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000605
606 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000607 pr_info(" %s %s %s %s\n",
608 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
609 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000610 for (n = 0; n < adapter->num_tx_queues; n++) {
611 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000612 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000613 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000614 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000615 (u64)dma_unmap_addr(tx_buffer, dma),
616 dma_unmap_len(tx_buffer, len),
617 tx_buffer->next_to_watch,
618 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000619 }
620
621 /* Print TX Rings */
622 if (!netif_msg_tx_done(adapter))
623 goto rx_ring_summary;
624
625 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
626
627 /* Transmit Descriptor Formats
628 *
Josh Hay39ac8682012-09-26 05:59:36 +0000629 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000630 * +--------------------------------------------------------------+
631 * 0 | Buffer Address [63:0] |
632 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000633 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000634 * +--------------------------------------------------------------+
635 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000636 *
637 * 82598 Advanced Transmit Descriptor (Write-Back Format)
638 * +--------------------------------------------------------------+
639 * 0 | RSV [63:0] |
640 * +--------------------------------------------------------------+
641 * 8 | RSV | STA | NXTSEQ |
642 * +--------------------------------------------------------------+
643 * 63 36 35 32 31 0
644 *
645 * 82599+ Advanced Transmit Descriptor
646 * +--------------------------------------------------------------+
647 * 0 | Buffer Address [63:0] |
648 * +--------------------------------------------------------------+
649 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
650 * +--------------------------------------------------------------+
651 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
652 *
653 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
654 * +--------------------------------------------------------------+
655 * 0 | RSV [63:0] |
656 * +--------------------------------------------------------------+
657 * 8 | RSV | STA | RSV |
658 * +--------------------------------------------------------------+
659 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000660 */
661
662 for (n = 0; n < adapter->num_tx_queues; n++) {
663 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000664 pr_info("------------------------------------\n");
665 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
666 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000667 pr_info("%s%s %s %s %s %s\n",
668 "T [desc] [address 63:0 ] ",
669 "[PlPOIdStDDt Ln] [bi->dma ] ",
670 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000671
672 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000673 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000674 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000675 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000676 if (dma_unmap_len(tx_buffer, len) > 0) {
677 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
678 i,
679 le64_to_cpu(u0->a),
680 le64_to_cpu(u0->b),
681 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000682 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000683 tx_buffer->next_to_watch,
684 (u64)tx_buffer->time_stamp,
685 tx_buffer->skb);
686 if (i == tx_ring->next_to_use &&
687 i == tx_ring->next_to_clean)
688 pr_cont(" NTC/U\n");
689 else if (i == tx_ring->next_to_use)
690 pr_cont(" NTU\n");
691 else if (i == tx_ring->next_to_clean)
692 pr_cont(" NTC\n");
693 else
694 pr_cont("\n");
695
696 if (netif_msg_pktdata(adapter) &&
697 tx_buffer->skb)
698 print_hex_dump(KERN_INFO, "",
699 DUMP_PREFIX_ADDRESS, 16, 1,
700 tx_buffer->skb->data,
701 dma_unmap_len(tx_buffer, len),
702 true);
703 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000704 }
705 }
706
707 /* Print RX Rings Summary */
708rx_ring_summary:
709 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000710 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000711 for (n = 0; n < adapter->num_rx_queues; n++) {
712 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000713 pr_info("%5d %5X %5X\n",
714 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000715 }
716
717 /* Print RX Rings */
718 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000719 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000720
721 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
722
Josh Hay39ac8682012-09-26 05:59:36 +0000723 /* Receive Descriptor Formats
724 *
725 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000726 * 63 1 0
727 * +-----------------------------------------------------+
728 * 0 | Packet Buffer Address [63:1] |A0/NSE|
729 * +----------------------------------------------+------+
730 * 8 | Header Buffer Address [63:1] | DD |
731 * +-----------------------------------------------------+
732 *
733 *
Josh Hay39ac8682012-09-26 05:59:36 +0000734 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000735 *
736 * 63 48 47 32 31 30 21 20 16 15 4 3 0
737 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000738 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
739 * | Packet | IP | | | | Type | Type |
740 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000741 * +------------------------------------------------------+
742 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
743 * +------------------------------------------------------+
744 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000745 *
746 * 82599+ Advanced Receive Descriptor (Read) Format
747 * 63 1 0
748 * +-----------------------------------------------------+
749 * 0 | Packet Buffer Address [63:1] |A0/NSE|
750 * +----------------------------------------------+------+
751 * 8 | Header Buffer Address [63:1] | DD |
752 * +-----------------------------------------------------+
753 *
754 *
755 * 82599+ Advanced Receive Descriptor (Write-Back) Format
756 *
757 * 63 48 47 32 31 30 21 20 17 16 4 3 0
758 * +------------------------------------------------------+
759 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
760 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
761 * |/ Flow Dir Flt ID | | | | | |
762 * +------------------------------------------------------+
763 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
764 * +------------------------------------------------------+
765 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000766 */
Josh Hay39ac8682012-09-26 05:59:36 +0000767
Taku Izumidcd79ae2010-04-27 14:39:53 +0000768 for (n = 0; n < adapter->num_rx_queues; n++) {
769 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000770 pr_info("------------------------------------\n");
771 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
772 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000773 pr_info("%s%s%s",
774 "R [desc] [ PktBuf A0] ",
775 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000776 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000777 pr_info("%s%s%s",
778 "RWB[desc] [PcsmIpSHl PtRs] ",
779 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000780 "<-- Adv Rx Write-Back format\n");
781
782 for (i = 0; i < rx_ring->count; i++) {
783 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000784 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000785 u0 = (struct my_u0 *)rx_desc;
786 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
787 if (staterr & IXGBE_RXD_STAT_DD) {
788 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000789 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000790 "%016llX ---------------- %p", i,
791 le64_to_cpu(u0->a),
792 le64_to_cpu(u0->b),
793 rx_buffer_info->skb);
794 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000795 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000796 "%016llX %016llX %p", i,
797 le64_to_cpu(u0->a),
798 le64_to_cpu(u0->b),
799 (u64)rx_buffer_info->dma,
800 rx_buffer_info->skb);
801
Emil Tantilov9c50c032012-07-26 01:21:24 +0000802 if (netif_msg_pktdata(adapter) &&
803 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000804 print_hex_dump(KERN_INFO, "",
805 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000806 page_address(rx_buffer_info->page) +
807 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000808 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000809 }
810 }
811
812 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000813 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000814 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000815 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000816 else
Joe Perchesc7689572010-09-07 21:35:17 +0000817 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000818
819 }
820 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000821}
822
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800823static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
824{
825 u32 ctrl_ext;
826
827 /* Let firmware take over control of h/w */
828 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
829 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000830 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800831}
832
833static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
834{
835 u32 ctrl_ext;
836
837 /* Let firmware know the driver has taken over */
838 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
839 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000840 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800841}
Auke Kok9a799d72007-09-15 14:07:45 -0700842
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000843/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000844 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
845 * @adapter: pointer to adapter struct
846 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
847 * @queue: queue to map the corresponding interrupt to
848 * @msix_vector: the vector to map to the corresponding queue
849 *
850 */
851static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000852 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700853{
854 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000855 struct ixgbe_hw *hw = &adapter->hw;
856 switch (hw->mac.type) {
857 case ixgbe_mac_82598EB:
858 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
859 if (direction == -1)
860 direction = 0;
861 index = (((direction * 64) + queue) >> 2) & 0x1F;
862 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
863 ivar &= ~(0xFF << (8 * (queue & 0x3)));
864 ivar |= (msix_vector << (8 * (queue & 0x3)));
865 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
866 break;
867 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800868 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000869 case ixgbe_mac_X550:
870 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700871 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000872 if (direction == -1) {
873 /* other causes */
874 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
875 index = ((queue & 1) * 8);
876 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
877 ivar &= ~(0xFF << index);
878 ivar |= (msix_vector << index);
879 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
880 break;
881 } else {
882 /* tx or rx causes */
883 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
884 index = ((16 * (queue & 1)) + (8 * direction));
885 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
886 ivar &= ~(0xFF << index);
887 ivar |= (msix_vector << index);
888 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
889 break;
890 }
891 default:
892 break;
893 }
Auke Kok9a799d72007-09-15 14:07:45 -0700894}
895
Alexander Duyckfe49f042009-06-04 16:00:09 +0000896static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000897 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000898{
899 u32 mask;
900
Alexander Duyckbd508172010-11-16 19:27:03 -0800901 switch (adapter->hw.mac.type) {
902 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000903 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
904 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800905 break;
906 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800907 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000908 case ixgbe_mac_X550:
909 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700910 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000911 mask = (qmask & 0xFFFFFFFF);
912 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
913 mask = (qmask >> 32);
914 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800915 break;
916 default:
917 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000918 }
919}
920
Alexander Duyck729739b2012-02-08 07:51:06 +0000921void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
922 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000923{
Alexander Duyck729739b2012-02-08 07:51:06 +0000924 if (tx_buffer->skb) {
925 dev_kfree_skb_any(tx_buffer->skb);
926 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000927 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000928 dma_unmap_addr(tx_buffer, dma),
929 dma_unmap_len(tx_buffer, len),
930 DMA_TO_DEVICE);
931 } else if (dma_unmap_len(tx_buffer, len)) {
932 dma_unmap_page(ring->dev,
933 dma_unmap_addr(tx_buffer, dma),
934 dma_unmap_len(tx_buffer, len),
935 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000936 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000937 tx_buffer->next_to_watch = NULL;
938 tx_buffer->skb = NULL;
939 dma_unmap_len_set(tx_buffer, len, 0);
940 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700941}
942
Alexander Duyck943561d2012-05-09 22:14:44 -0700943static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
944{
945 struct ixgbe_hw *hw = &adapter->hw;
946 struct ixgbe_hw_stats *hwstats = &adapter->stats;
947 int i;
948 u32 data;
949
950 if ((hw->fc.current_mode != ixgbe_fc_full) &&
951 (hw->fc.current_mode != ixgbe_fc_rx_pause))
952 return;
953
954 switch (hw->mac.type) {
955 case ixgbe_mac_82598EB:
956 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
957 break;
958 default:
959 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
960 }
961 hwstats->lxoffrxc += data;
962
963 /* refill credits (no tx hang) if we received xoff */
964 if (!data)
965 return;
966
967 for (i = 0; i < adapter->num_tx_queues; i++)
968 clear_bit(__IXGBE_HANG_CHECK_ARMED,
969 &adapter->tx_ring[i]->state);
970}
971
John Fastabendc84d3242010-11-16 19:27:12 -0800972static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700973{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700974 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800975 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800976 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000977 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800978 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700979 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700980
Alexander Duyck943561d2012-05-09 22:14:44 -0700981 if (adapter->ixgbe_ieee_pfc)
982 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800983
Alexander Duyck943561d2012-05-09 22:14:44 -0700984 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
985 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800986 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700987 }
John Fastabendc84d3242010-11-16 19:27:12 -0800988
989 /* update stats for each tc, only valid with PFC enabled */
990 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000991 u32 pxoffrxc;
992
John Fastabendc84d3242010-11-16 19:27:12 -0800993 switch (hw->mac.type) {
994 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000995 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800996 break;
997 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000998 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800999 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001000 hwstats->pxoffrxc[i] += pxoffrxc;
1001 /* Get the TC for given UP */
1002 tc = netdev_get_prio_tc_map(adapter->netdev, i);
1003 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -07001004 }
1005
John Fastabendc84d3242010-11-16 19:27:12 -08001006 /* disarm tx queues that have received xoff frames */
1007 for (i = 0; i < adapter->num_tx_queues; i++) {
1008 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -08001009
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001010 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001011 if (xoff[tc])
1012 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1013 }
1014}
1015
1016static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1017{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001018 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001019}
1020
1021static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1022{
John Fastabend2a47fa42013-11-06 09:54:52 -08001023 struct ixgbe_adapter *adapter;
1024 struct ixgbe_hw *hw;
1025 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001026
John Fastabend2a47fa42013-11-06 09:54:52 -08001027 if (ring->l2_accel_priv)
1028 adapter = ring->l2_accel_priv->real_adapter;
1029 else
1030 adapter = netdev_priv(ring->netdev);
1031
1032 hw = &adapter->hw;
1033 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1034 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001035
1036 if (head != tail)
1037 return (head < tail) ?
1038 tail - head : (tail + ring->count - head);
1039
1040 return 0;
1041}
1042
1043static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1044{
1045 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1046 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1047 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001048
1049 clear_check_for_tx_hang(tx_ring);
1050
1051 /*
1052 * Check for a hung queue, but be thorough. This verifies
1053 * that a transmit has been completed since the previous
1054 * check AND there is at least one packet pending. The
1055 * ARMED bit is set to indicate a potential hang. The
1056 * bit is cleared if a pause frame is received to remove
1057 * false hang detection due to PFC or 802.3x frames. By
1058 * requiring this to fail twice we avoid races with
1059 * pfc clearing the ARMED bit and conditions where we
1060 * run the check_tx_hang logic with a transmit completion
1061 * pending but without time to complete it yet.
1062 */
Mark Rustade90dd262014-07-22 06:51:08 +00001063 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001064 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001065 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1066 &tx_ring->state);
1067 /* update completed stats and continue */
1068 tx_ring->tx_stats.tx_done_old = tx_done;
1069 /* reset the countdown */
1070 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001071
Mark Rustade90dd262014-07-22 06:51:08 +00001072 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001073}
1074
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001075/**
1076 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1077 * @adapter: driver private struct
1078 **/
1079static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1080{
1081
1082 /* Do the reset outside of interrupt context */
1083 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1084 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Jacob Keller12ff3f32012-12-01 07:57:17 +00001085 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001086 ixgbe_service_event_schedule(adapter);
1087 }
1088}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001089
Auke Kok9a799d72007-09-15 14:07:45 -07001090/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001091 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1092 **/
1093static int ixgbe_tx_maxrate(struct net_device *netdev,
1094 int queue_index, u32 maxrate)
1095{
1096 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1097 struct ixgbe_hw *hw = &adapter->hw;
1098 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1099
1100 if (!maxrate)
1101 return 0;
1102
1103 /* Calculate the rate factor values to set */
1104 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1105 bcnrc_val /= maxrate;
1106
1107 /* clear everything but the rate factor */
1108 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1109 IXGBE_RTTBCNRC_RF_DEC_MASK;
1110
1111 /* enable the rate scheduler */
1112 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1113
1114 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1115 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1116
1117 return 0;
1118}
1119
1120/**
Auke Kok9a799d72007-09-15 14:07:45 -07001121 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001122 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001123 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001124 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001125 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001126static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001127 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001128{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001129 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001130 struct ixgbe_tx_buffer *tx_buffer;
1131 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001132 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001133 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001134 unsigned int i = tx_ring->next_to_clean;
1135
1136 if (test_bit(__IXGBE_DOWN, &adapter->state))
1137 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001138
Alexander Duyckd3d00232011-07-15 02:31:25 +00001139 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001140 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001141 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001142
Alexander Duyck729739b2012-02-08 07:51:06 +00001143 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001144 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001145
Alexander Duyckd3d00232011-07-15 02:31:25 +00001146 /* if next_to_watch is not set then there is no work pending */
1147 if (!eop_desc)
1148 break;
1149
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001150 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001151 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001152
Alexander Duyckd3d00232011-07-15 02:31:25 +00001153 /* if DD is not set pending work has not been completed */
1154 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1155 break;
1156
Alexander Duyckd3d00232011-07-15 02:31:25 +00001157 /* clear next_to_watch to prevent false hangs */
1158 tx_buffer->next_to_watch = NULL;
1159
Alexander Duyck091a6242012-02-08 07:51:01 +00001160 /* update the statistics for this packet */
1161 total_bytes += tx_buffer->bytecount;
1162 total_packets += tx_buffer->gso_segs;
1163
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001164 /* free the skb */
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001165 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001166
Alexander Duyck729739b2012-02-08 07:51:06 +00001167 /* unmap skb header data */
1168 dma_unmap_single(tx_ring->dev,
1169 dma_unmap_addr(tx_buffer, dma),
1170 dma_unmap_len(tx_buffer, len),
1171 DMA_TO_DEVICE);
1172
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001173 /* clear tx_buffer data */
1174 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +00001175 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001176
Alexander Duyck729739b2012-02-08 07:51:06 +00001177 /* unmap remaining buffers */
1178 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001179 tx_buffer++;
1180 tx_desc++;
1181 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001182 if (unlikely(!i)) {
1183 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001184 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001185 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001186 }
1187
Alexander Duyck729739b2012-02-08 07:51:06 +00001188 /* unmap any remaining paged data */
1189 if (dma_unmap_len(tx_buffer, len)) {
1190 dma_unmap_page(tx_ring->dev,
1191 dma_unmap_addr(tx_buffer, dma),
1192 dma_unmap_len(tx_buffer, len),
1193 DMA_TO_DEVICE);
1194 dma_unmap_len_set(tx_buffer, len, 0);
1195 }
1196 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001197
Alexander Duyck729739b2012-02-08 07:51:06 +00001198 /* move us one more past the eop_desc for start of next pkt */
1199 tx_buffer++;
1200 tx_desc++;
1201 i++;
1202 if (unlikely(!i)) {
1203 i -= tx_ring->count;
1204 tx_buffer = tx_ring->tx_buffer_info;
1205 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1206 }
1207
1208 /* issue prefetch for next Tx descriptor */
1209 prefetch(tx_desc);
1210
1211 /* update budget accounting */
1212 budget--;
1213 } while (likely(budget));
1214
1215 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001216 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001217 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001218 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001219 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001220 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001221 q_vector->tx.total_bytes += total_bytes;
1222 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001223
John Fastabendc84d3242010-11-16 19:27:12 -08001224 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001225 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001226 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001227 e_err(drv, "Detected Tx Unit Hang\n"
1228 " Tx Queue <%d>\n"
1229 " TDH, TDT <%x>, <%x>\n"
1230 " next_to_use <%x>\n"
1231 " next_to_clean <%x>\n"
1232 "tx_buffer_info[next_to_clean]\n"
1233 " time_stamp <%lx>\n"
1234 " jiffies <%lx>\n",
1235 tx_ring->queue_index,
1236 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1237 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001238 tx_ring->next_to_use, i,
1239 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001240
1241 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1242
1243 e_info(probe,
1244 "tx hang %d detected on queue %d, resetting adapter\n",
1245 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1246
1247 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001248 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001249
1250 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001251 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001252 }
Auke Kok9a799d72007-09-15 14:07:45 -07001253
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001254 netdev_tx_completed_queue(txring_txq(tx_ring),
1255 total_packets, total_bytes);
1256
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001257#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001258 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001259 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001260 /* Make sure that anybody stopping the queue after this
1261 * sees the new next_to_clean.
1262 */
1263 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001264 if (__netif_subqueue_stopped(tx_ring->netdev,
1265 tx_ring->queue_index)
1266 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1267 netif_wake_subqueue(tx_ring->netdev,
1268 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001269 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001270 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001271 }
Auke Kok9a799d72007-09-15 14:07:45 -07001272
Alexander Duyck59224552011-08-31 00:01:06 +00001273 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001274}
1275
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001276#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001277static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001278 struct ixgbe_ring *tx_ring,
1279 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001280{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001281 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001282 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001283 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001284
Mark Rustad9de76052015-08-08 16:27:41 -07001285 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1286 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1287
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001288 switch (hw->mac.type) {
1289 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001290 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001291 break;
1292 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001293 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001294 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1295 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1296 break;
1297 default:
1298 /* for unknown hardware do not write register */
1299 return;
1300 }
1301
1302 /*
1303 * We can enable relaxed ordering for reads, but not writes when
1304 * DCA is enabled. This is due to a known issue in some chipsets
1305 * which will cause the DCA tag to be cleared.
1306 */
1307 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1308 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1309 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1310
1311 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1312}
1313
1314static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1315 struct ixgbe_ring *rx_ring,
1316 int cpu)
1317{
1318 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001319 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001320 u8 reg_idx = rx_ring->reg_idx;
1321
Mark Rustad9de76052015-08-08 16:27:41 -07001322 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1323 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001324
1325 switch (hw->mac.type) {
1326 case ixgbe_mac_82599EB:
1327 case ixgbe_mac_X540:
1328 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001329 break;
1330 default:
1331 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001332 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001333
1334 /*
1335 * We can enable relaxed ordering for reads, but not writes when
1336 * DCA is enabled. This is due to a known issue in some chipsets
1337 * which will cause the DCA tag to be cleared.
1338 */
1339 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Mark Rustad9de76052015-08-08 16:27:41 -07001340 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001341 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1342
1343 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001344}
1345
1346static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1347{
1348 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001349 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001350 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001351
1352 if (q_vector->cpu == cpu)
1353 goto out_no_update;
1354
Alexander Duycka5579282012-02-08 07:50:04 +00001355 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001356 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001357
Alexander Duycka5579282012-02-08 07:50:04 +00001358 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001359 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001360
1361 q_vector->cpu = cpu;
1362out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001363 put_cpu();
1364}
1365
1366static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1367{
1368 int i;
1369
Alexander Duycke35ec122009-05-21 13:07:12 +00001370 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001371 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1372 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1373 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1374 else
1375 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1376 IXGBE_DCA_CTRL_DCA_DISABLE);
Alexander Duycke35ec122009-05-21 13:07:12 +00001377
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001378 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001379 adapter->q_vector[i]->cpu = -1;
1380 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001381 }
1382}
1383
1384static int __ixgbe_notify_dca(struct device *dev, void *data)
1385{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001386 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001387 unsigned long event = *(unsigned long *)data;
1388
Don Skidmore2a72c312011-07-20 02:27:05 +00001389 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001390 return 0;
1391
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001392 switch (event) {
1393 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001394 /* if we're already enabled, don't do it again */
1395 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1396 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001397 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001398 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001399 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1400 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001401 break;
1402 }
1403 /* Fall Through since DCA is disabled. */
1404 case DCA_PROVIDER_REMOVE:
1405 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1406 dca_remove_requester(dev);
1407 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001408 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1409 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001410 }
1411 break;
1412 }
1413
Denis V. Lunev652f0932008-03-27 14:39:17 +03001414 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001415}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001416
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001417#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b82015-04-29 10:57:39 +08001418
1419#define IXGBE_RSS_L4_TYPES_MASK \
1420 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1421 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1422 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1423 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1424
Alexander Duyck8a0da212012-01-31 02:59:49 +00001425static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1426 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001427 struct sk_buff *skb)
1428{
Fan Du7edda4b82015-04-29 10:57:39 +08001429 u16 rss_type;
1430
1431 if (!(ring->netdev->features & NETIF_F_RXHASH))
1432 return;
1433
1434 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1435 IXGBE_RXDADV_RSSTYPE_MASK;
1436
1437 if (!rss_type)
1438 return;
1439
1440 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1441 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1442 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001443}
1444
Alexander Duyckf8003262012-03-03 02:35:52 +00001445#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001446/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001447 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001448 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001449 * @rx_desc: advanced rx descriptor
1450 *
1451 * Returns : true if it is FCoE pkt
1452 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001453static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001454 union ixgbe_adv_rx_desc *rx_desc)
1455{
1456 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1457
Alexander Duyck57efd442012-06-25 21:54:46 +00001458 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001459 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1460 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1461 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1462}
1463
Alexander Duyckf8003262012-03-03 02:35:52 +00001464#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001465/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001466 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001467 * @ring: structure containing ring specific data
1468 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001469 * @skb: skb currently being received and modified
1470 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001471static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001472 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001473 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001474{
Don Skidmore3f207802014-12-23 07:40:34 +00001475 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1476 __le16 hdr_info = rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
1477 bool encap_pkt = false;
1478
Alexander Duyck8a0da212012-01-31 02:59:49 +00001479 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001480
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001481 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001482 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001483 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001484
Don Skidmore3f207802014-12-23 07:40:34 +00001485 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) &&
1486 (hdr_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL >> 16))) {
1487 encap_pkt = true;
1488 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001489 }
1490
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001491 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001492 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1493 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001494 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001495 return;
1496 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001497
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001498 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001499 return;
1500
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001501 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001502 /*
1503 * 82599 errata, UDP frames with a 0 checksum can be marked as
1504 * checksum errors.
1505 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001506 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1507 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001508 return;
1509
Alexander Duyck8a0da212012-01-31 02:59:49 +00001510 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001511 return;
1512 }
1513
Auke Kok9a799d72007-09-15 14:07:45 -07001514 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001515 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001516 if (encap_pkt) {
1517 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1518 return;
1519
1520 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
Mark Rustadd4692512015-12-04 11:26:43 -08001521 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001522 return;
1523 }
1524 /* If we checked the outer header let the stack know */
1525 skb->csum_level = 1;
1526 }
Auke Kok9a799d72007-09-15 14:07:45 -07001527}
1528
Alexander Duyckf990b792012-01-31 02:59:34 +00001529static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1530 struct ixgbe_rx_buffer *bi)
1531{
1532 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001533 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001534
Alexander Duyckf8003262012-03-03 02:35:52 +00001535 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001536 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001537 return true;
1538
Alexander Duyckf8003262012-03-03 02:35:52 +00001539 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001540 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1541 if (unlikely(!page)) {
1542 rx_ring->rx_stats.alloc_rx_page_failed++;
1543 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001544 }
1545
Alexander Duyckf8003262012-03-03 02:35:52 +00001546 /* map page for use */
1547 dma = dma_map_page(rx_ring->dev, page, 0,
1548 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001549
Alexander Duyckf8003262012-03-03 02:35:52 +00001550 /*
1551 * if mapping failed free memory back to system since
1552 * there isn't much point in holding memory we can't use
1553 */
1554 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001555 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001556
Alexander Duyckf990b792012-01-31 02:59:34 +00001557 rx_ring->rx_stats.alloc_rx_page_failed++;
1558 return false;
1559 }
1560
Alexander Duyckf8003262012-03-03 02:35:52 +00001561 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001562 bi->page = page;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001563 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001564
Alexander Duyckf990b792012-01-31 02:59:34 +00001565 return true;
1566}
1567
Auke Kok9a799d72007-09-15 14:07:45 -07001568/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001569 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001570 * @rx_ring: ring to place buffers on
1571 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001572 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001573void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001574{
Auke Kok9a799d72007-09-15 14:07:45 -07001575 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001576 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001577 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001578
Alexander Duyckf8003262012-03-03 02:35:52 +00001579 /* nothing to do */
1580 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001581 return;
1582
Alexander Duycke4f74022012-01-31 02:59:44 +00001583 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001584 bi = &rx_ring->rx_buffer_info[i];
1585 i -= rx_ring->count;
1586
Alexander Duyckf8003262012-03-03 02:35:52 +00001587 do {
1588 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001589 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001590
Alexander Duyckf8003262012-03-03 02:35:52 +00001591 /*
1592 * Refresh the desc even if buffer_addrs didn't change
1593 * because each write-back erases this info.
1594 */
1595 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001596
Alexander Duyckf990b792012-01-31 02:59:34 +00001597 rx_desc++;
1598 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001599 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001600 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001601 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001602 bi = rx_ring->rx_buffer_info;
1603 i -= rx_ring->count;
1604 }
1605
Alexander Duyck18cb6522014-11-14 00:56:29 +00001606 /* clear the status bits for the next_to_use descriptor */
1607 rx_desc->wb.upper.status_error = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001608
1609 cleaned_count--;
1610 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001611
Alexander Duyckf990b792012-01-31 02:59:34 +00001612 i += rx_ring->count;
1613
Alexander Duyckad435ec2014-11-14 00:56:35 +00001614 if (rx_ring->next_to_use != i) {
1615 rx_ring->next_to_use = i;
1616
1617 /* update next to alloc since we have filled the ring */
1618 rx_ring->next_to_alloc = i;
1619
1620 /* Force memory writes to complete before letting h/w
1621 * know there are new descriptors to fetch. (Only
1622 * applicable for weak-ordered memory model archs,
1623 * such as IA-64).
1624 */
1625 wmb();
1626 writel(i, rx_ring->tail);
1627 }
Auke Kok9a799d72007-09-15 14:07:45 -07001628}
1629
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001630static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1631 struct sk_buff *skb)
1632{
Alexander Duyckf8003262012-03-03 02:35:52 +00001633 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001634
1635 /* set gso_size to avoid messing up TCP MSS */
1636 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1637 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001638 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001639}
1640
1641static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1642 struct sk_buff *skb)
1643{
1644 /* if append_cnt is 0 then frame is not RSC */
1645 if (!IXGBE_CB(skb)->append_cnt)
1646 return;
1647
1648 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1649 rx_ring->rx_stats.rsc_flush++;
1650
1651 ixgbe_set_rsc_gso_size(rx_ring, skb);
1652
1653 /* gso_size is computed using append_cnt so always clear it last */
1654 IXGBE_CB(skb)->append_cnt = 0;
1655}
1656
Alexander Duyck8a0da212012-01-31 02:59:49 +00001657/**
1658 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1659 * @rx_ring: rx descriptor ring packet is being transacted on
1660 * @rx_desc: pointer to the EOP Rx descriptor
1661 * @skb: pointer to current skb being populated
1662 *
1663 * This function checks the ring, descriptor, and packet information in
1664 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1665 * other fields within the skb.
1666 **/
1667static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1668 union ixgbe_adv_rx_desc *rx_desc,
1669 struct sk_buff *skb)
1670{
John Fastabend43e95f12012-05-15 06:12:17 +00001671 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001672 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001673
Alexander Duyck8a0da212012-01-31 02:59:49 +00001674 ixgbe_update_rsc_stats(rx_ring, skb);
1675
1676 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1677
1678 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1679
Mark Rustada9763f32015-10-27 09:58:07 -07001680 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1681 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001682
Patrick McHardyf6469682013-04-19 02:04:27 +00001683 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001684 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001685 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001686 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001687 }
1688
1689 skb_record_rx_queue(skb, rx_ring->queue_index);
1690
John Fastabend43e95f12012-05-15 06:12:17 +00001691 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001692}
1693
1694static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1695 struct sk_buff *skb)
1696{
Eric Dumazet93f93a42015-11-18 06:30:59 -08001697 skb_mark_napi_id(skb, &q_vector->napi);
Jacob Kellerb4640032013-10-01 04:33:54 -07001698 if (ixgbe_qv_busy_polling(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001699 netif_receive_skb(skb);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001700 else
Alexander Duyck856f6062015-02-25 17:45:54 +00001701 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001702}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001703
Alexander Duyckf8003262012-03-03 02:35:52 +00001704/**
1705 * ixgbe_is_non_eop - process handling of non-EOP buffers
1706 * @rx_ring: Rx ring being processed
1707 * @rx_desc: Rx descriptor for current buffer
1708 * @skb: Current socket buffer containing buffer in progress
1709 *
1710 * This function updates next to clean. If the buffer is an EOP buffer
1711 * this function exits returning false, otherwise it will place the
1712 * sk_buff in the next buffer to be chained and return true indicating
1713 * that this is in fact a non-EOP buffer.
1714 **/
1715static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1716 union ixgbe_adv_rx_desc *rx_desc,
1717 struct sk_buff *skb)
1718{
1719 u32 ntc = rx_ring->next_to_clean + 1;
1720
1721 /* fetch, update, and store next to clean */
1722 ntc = (ntc < rx_ring->count) ? ntc : 0;
1723 rx_ring->next_to_clean = ntc;
1724
1725 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1726
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001727 /* update RSC append count if present */
1728 if (ring_is_rsc_enabled(rx_ring)) {
1729 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1730 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1731
1732 if (unlikely(rsc_enabled)) {
1733 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1734
1735 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1736 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1737
1738 /* update ntc based on RSC value */
1739 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1740 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1741 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1742 }
1743 }
1744
1745 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001746 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1747 return false;
1748
Alexander Duyckf8003262012-03-03 02:35:52 +00001749 /* place skb in next buffer to be received */
1750 rx_ring->rx_buffer_info[ntc].skb = skb;
1751 rx_ring->rx_stats.non_eop_descs++;
1752
1753 return true;
1754}
1755
1756/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001757 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1758 * @rx_ring: rx descriptor ring packet is being transacted on
1759 * @skb: pointer to current skb being adjusted
1760 *
1761 * This function is an ixgbe specific version of __pskb_pull_tail. The
1762 * main difference between this version and the original function is that
1763 * this function can make several assumptions about the state of things
1764 * that allow for significant optimizations versus the standard function.
1765 * As a result we can do things like drop a frag and maintain an accurate
1766 * truesize for the skb.
1767 */
1768static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1769 struct sk_buff *skb)
1770{
1771 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1772 unsigned char *va;
1773 unsigned int pull_len;
1774
1775 /*
1776 * it is valid to use page_address instead of kmap since we are
1777 * working with pages allocated out of the lomem pool per
1778 * alloc_page(GFP_ATOMIC)
1779 */
1780 va = skb_frag_address(frag);
1781
1782 /*
1783 * we need the header to contain the greater of either ETH_HLEN or
1784 * 60 bytes if the skb->len is less than 60 for skb_pad.
1785 */
Alexander Duyck8496e3382014-09-05 19:22:18 -04001786 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001787
1788 /* align pull length to size of long to optimize memcpy performance */
1789 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1790
1791 /* update all of the pointers */
1792 skb_frag_size_sub(frag, pull_len);
1793 frag->page_offset += pull_len;
1794 skb->data_len -= pull_len;
1795 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001796}
1797
1798/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001799 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1800 * @rx_ring: rx descriptor ring packet is being transacted on
1801 * @skb: pointer to current skb being updated
1802 *
1803 * This function provides a basic DMA sync up for the first fragment of an
1804 * skb. The reason for doing this is that the first fragment cannot be
1805 * unmapped until we have reached the end of packet descriptor for a buffer
1806 * chain.
1807 */
1808static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1809 struct sk_buff *skb)
1810{
1811 /* if the page was released unmap it, else just sync our portion */
1812 if (unlikely(IXGBE_CB(skb)->page_released)) {
1813 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1814 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1815 IXGBE_CB(skb)->page_released = false;
1816 } else {
1817 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1818
1819 dma_sync_single_range_for_cpu(rx_ring->dev,
1820 IXGBE_CB(skb)->dma,
1821 frag->page_offset,
1822 ixgbe_rx_bufsz(rx_ring),
1823 DMA_FROM_DEVICE);
1824 }
1825 IXGBE_CB(skb)->dma = 0;
1826}
1827
1828/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001829 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1830 * @rx_ring: rx descriptor ring packet is being transacted on
1831 * @rx_desc: pointer to the EOP Rx descriptor
1832 * @skb: pointer to current skb being fixed
1833 *
1834 * Check for corrupted packet headers caused by senders on the local L2
1835 * embedded NIC switch not setting up their Tx Descriptors right. These
1836 * should be very rare.
1837 *
1838 * Also address the case where we are pulling data in on pages only
1839 * and as such no data is present in the skb header.
1840 *
1841 * In addition if skb is not at least 60 bytes we need to pad it so that
1842 * it is large enough to qualify as a valid Ethernet frame.
1843 *
1844 * Returns true if an error was encountered and skb was freed.
1845 **/
1846static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1847 union ixgbe_adv_rx_desc *rx_desc,
1848 struct sk_buff *skb)
1849{
Alexander Duyckf8003262012-03-03 02:35:52 +00001850 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001851
1852 /* verify that the packet does not have any known errors */
1853 if (unlikely(ixgbe_test_staterr(rx_desc,
1854 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1855 !(netdev->features & NETIF_F_RXALL))) {
1856 dev_kfree_skb_any(skb);
1857 return true;
1858 }
1859
Alexander Duyck19861ce2012-07-20 08:08:33 +00001860 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001861 if (skb_is_nonlinear(skb))
1862 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001863
Alexander Duyck57efd442012-06-25 21:54:46 +00001864#ifdef IXGBE_FCOE
1865 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1866 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1867 return false;
1868
1869#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001870 /* if eth_skb_pad returns an error the skb was freed */
1871 if (eth_skb_pad(skb))
1872 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001873
1874 return false;
1875}
1876
1877/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001878 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1879 * @rx_ring: rx descriptor ring to store buffers on
1880 * @old_buff: donor buffer to have page reused
1881 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001882 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001883 **/
1884static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1885 struct ixgbe_rx_buffer *old_buff)
1886{
1887 struct ixgbe_rx_buffer *new_buff;
1888 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001889
1890 new_buff = &rx_ring->rx_buffer_info[nta];
1891
1892 /* update, and store next to alloc */
1893 nta++;
1894 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1895
1896 /* transfer page from old buffer to new buffer */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001897 *new_buff = *old_buff;
Alexander Duyckf8003262012-03-03 02:35:52 +00001898
1899 /* sync the buffer for use by the device */
1900 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001901 new_buff->page_offset,
1902 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001903 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001904}
1905
Alexander Duyck18cb6522014-11-14 00:56:29 +00001906static inline bool ixgbe_page_is_reserved(struct page *page)
1907{
Michal Hocko2f064f32015-08-21 14:11:51 -07001908 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001909}
1910
Alexander Duyckf8003262012-03-03 02:35:52 +00001911/**
1912 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1913 * @rx_ring: rx descriptor ring to transact packets on
1914 * @rx_buffer: buffer containing page to add
1915 * @rx_desc: descriptor containing length of buffer written by hardware
1916 * @skb: sk_buff to place the data into
1917 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001918 * This function will add the data contained in rx_buffer->page to the skb.
1919 * This is done either through a direct copy if the data in the buffer is
1920 * less than the skb header size, otherwise it will just attach the page as
1921 * a frag to the skb.
1922 *
1923 * The function will then update the page offset if necessary and return
1924 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001925 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001926static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001927 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001928 union ixgbe_adv_rx_desc *rx_desc,
1929 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001930{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001931 struct page *page = rx_buffer->page;
1932 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001933#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001934 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001935#else
1936 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1937 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1938 ixgbe_rx_bufsz(rx_ring);
1939#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001940
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001941 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1942 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1943
1944 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1945
Alexander Duyck18cb6522014-11-14 00:56:29 +00001946 /* page is not reserved, we can reuse buffer as-is */
1947 if (likely(!ixgbe_page_is_reserved(page)))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001948 return true;
1949
1950 /* this page cannot be reused so discard it */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001951 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001952 return false;
1953 }
1954
Alexander Duyck0549ae22012-07-20 08:08:18 +00001955 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1956 rx_buffer->page_offset, size, truesize);
1957
Alexander Duyck09816fb2012-07-20 08:08:23 +00001958 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001959 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001960 return false;
1961
1962#if (PAGE_SIZE < 8192)
1963 /* if we are only owner of page we can reuse it */
1964 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001965 return false;
1966
1967 /* flip page offset to other buffer */
1968 rx_buffer->page_offset ^= truesize;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001969#else
1970 /* move offset up to the next cache line */
1971 rx_buffer->page_offset += truesize;
1972
1973 if (rx_buffer->page_offset > last_offset)
1974 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001975#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001976
Alexander Duyck18cb6522014-11-14 00:56:29 +00001977 /* Even if we own the page, we are not allowed to use atomic_set()
1978 * This would break get_page_unless_zero() users.
1979 */
Joonsoo Kimfe896d12016-03-17 14:19:26 -07001980 page_ref_inc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001981
Alexander Duyck0549ae22012-07-20 08:08:18 +00001982 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001983}
1984
Alexander Duyck18806c92012-07-20 08:08:44 +00001985static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1986 union ixgbe_adv_rx_desc *rx_desc)
1987{
1988 struct ixgbe_rx_buffer *rx_buffer;
1989 struct sk_buff *skb;
1990 struct page *page;
1991
1992 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1993 page = rx_buffer->page;
1994 prefetchw(page);
1995
1996 skb = rx_buffer->skb;
1997
1998 if (likely(!skb)) {
1999 void *page_addr = page_address(page) +
2000 rx_buffer->page_offset;
2001
2002 /* prefetch first cache line of first page */
2003 prefetch(page_addr);
2004#if L1_CACHE_BYTES < 128
2005 prefetch(page_addr + L1_CACHE_BYTES);
2006#endif
2007
2008 /* allocate a skb to store the frags */
Alexander Duyck67fd8932014-12-09 19:40:56 -08002009 skb = napi_alloc_skb(&rx_ring->q_vector->napi,
2010 IXGBE_RX_HDR_SIZE);
Alexander Duyck18806c92012-07-20 08:08:44 +00002011 if (unlikely(!skb)) {
2012 rx_ring->rx_stats.alloc_rx_buff_failed++;
2013 return NULL;
2014 }
2015
2016 /*
2017 * we will be copying header into skb->data in
2018 * pskb_may_pull so it is in our interest to prefetch
2019 * it now to avoid a possible cache miss
2020 */
2021 prefetchw(skb->data);
2022
2023 /*
2024 * Delay unmapping of the first packet. It carries the
2025 * header information, HW may still access the header
2026 * after the writeback. Only unmap it when EOP is
2027 * reached
2028 */
2029 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
2030 goto dma_sync;
2031
2032 IXGBE_CB(skb)->dma = rx_buffer->dma;
2033 } else {
2034 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2035 ixgbe_dma_sync_frag(rx_ring, skb);
2036
2037dma_sync:
2038 /* we are reusing so sync this buffer for CPU use */
2039 dma_sync_single_range_for_cpu(rx_ring->dev,
2040 rx_buffer->dma,
2041 rx_buffer->page_offset,
2042 ixgbe_rx_bufsz(rx_ring),
2043 DMA_FROM_DEVICE);
Alexander Duyck18cb6522014-11-14 00:56:29 +00002044
2045 rx_buffer->skb = NULL;
Alexander Duyck18806c92012-07-20 08:08:44 +00002046 }
2047
2048 /* pull page into skb */
2049 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
2050 /* hand second half of page back to the ring */
2051 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
2052 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
2053 /* the page has been released from the ring */
2054 IXGBE_CB(skb)->page_released = true;
2055 } else {
2056 /* we are not reusing the buffer so unmap it */
2057 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
2058 ixgbe_rx_pg_size(rx_ring),
2059 DMA_FROM_DEVICE);
2060 }
2061
2062 /* clear contents of buffer_info */
Alexander Duyck18806c92012-07-20 08:08:44 +00002063 rx_buffer->page = NULL;
2064
2065 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002066}
2067
2068/**
2069 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2070 * @q_vector: structure containing interrupt and ring information
2071 * @rx_ring: rx descriptor ring to transact packets on
2072 * @budget: Total limit on number of packets to process
2073 *
2074 * This function provides a "bounce buffer" approach to Rx interrupt
2075 * processing. The advantage to this is that on systems that have
2076 * expensive overhead for IOMMU access this provides a means of avoiding
2077 * it by maintaining the mapping of the page to the syste.
2078 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002079 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002080 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002081static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002082 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002083 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002084{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002085 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00002086#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00002087 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00002088 int ddp_bytes;
2089 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002090#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002091 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002092
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002093 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002094 union ixgbe_adv_rx_desc *rx_desc;
2095 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002096
Alexander Duyckf8003262012-03-03 02:35:52 +00002097 /* return some buffers to hardware, one at a time is too slow */
2098 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2099 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2100 cleaned_count = 0;
2101 }
Auke Kok9a799d72007-09-15 14:07:45 -07002102
Alexander Duyck18806c92012-07-20 08:08:44 +00002103 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07002104
Alexander Duyck124b74c2014-12-11 15:02:28 -08002105 if (!rx_desc->wb.upper.status_error)
Alexander Duyckf8003262012-03-03 02:35:52 +00002106 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002107
Alexander Duyck124b74c2014-12-11 15:02:28 -08002108 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002109 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002110 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002111 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002112 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002113
Alexander Duyck18806c92012-07-20 08:08:44 +00002114 /* retrieve a buffer from the ring */
2115 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00002116
Alexander Duyck18806c92012-07-20 08:08:44 +00002117 /* exit if we failed to retrieve a buffer */
2118 if (!skb)
2119 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002120
Auke Kok9a799d72007-09-15 14:07:45 -07002121 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002122
Alexander Duyckf8003262012-03-03 02:35:52 +00002123 /* place incomplete frames back on ring for completion */
2124 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2125 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002126
Alexander Duyckf8003262012-03-03 02:35:52 +00002127 /* verify the packet layout is correct */
2128 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2129 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002130
2131 /* probably a little skewed due to removing CRC */
2132 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002133
Alexander Duyck8a0da212012-01-31 02:59:49 +00002134 /* populate checksum, timestamp, VLAN, and protocol */
2135 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2136
Yi Zou332d4a72009-05-13 13:11:53 +00002137#ifdef IXGBE_FCOE
2138 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002139 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002140 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002141 /* include DDPed FCoE data */
2142 if (ddp_bytes > 0) {
2143 if (!mss) {
2144 mss = rx_ring->netdev->mtu -
2145 sizeof(struct fcoe_hdr) -
2146 sizeof(struct fc_frame_header) -
2147 sizeof(struct fcoe_crc_eof);
2148 if (mss > 512)
2149 mss &= ~511;
2150 }
2151 total_rx_bytes += ddp_bytes;
2152 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2153 mss);
2154 }
David S. Miller823dcd22011-08-20 10:39:12 -07002155 if (!ddp_bytes) {
2156 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002157 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002158 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002159 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002160
Yi Zou332d4a72009-05-13 13:11:53 +00002161#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002162 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002163
Alexander Duyckf8003262012-03-03 02:35:52 +00002164 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002165 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002166 }
Auke Kok9a799d72007-09-15 14:07:45 -07002167
Alexander Duyckc267fc12010-11-16 19:27:00 -08002168 u64_stats_update_begin(&rx_ring->syncp);
2169 rx_ring->stats.packets += total_rx_packets;
2170 rx_ring->stats.bytes += total_rx_bytes;
2171 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002172 q_vector->rx.total_packets += total_rx_packets;
2173 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002174
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002175 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002176}
2177
Cong Wange0d10952013-08-01 11:10:25 +08002178#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002179/* must be called with local_bh_disable()d */
2180static int ixgbe_low_latency_recv(struct napi_struct *napi)
2181{
2182 struct ixgbe_q_vector *q_vector =
2183 container_of(napi, struct ixgbe_q_vector, napi);
2184 struct ixgbe_adapter *adapter = q_vector->adapter;
2185 struct ixgbe_ring *ring;
2186 int found = 0;
2187
2188 if (test_bit(__IXGBE_DOWN, &adapter->state))
2189 return LL_FLUSH_FAILED;
2190
2191 if (!ixgbe_qv_lock_poll(q_vector))
2192 return LL_FLUSH_BUSY;
2193
2194 ixgbe_for_each_ring(ring, q_vector->rx) {
2195 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
Jacob Kellerb4640032013-10-01 04:33:54 -07002196#ifdef BP_EXTENDED_STATS
Eliezer Tamir7e15b902013-06-10 11:40:31 +03002197 if (found)
2198 ring->stats.cleaned += found;
2199 else
2200 ring->stats.misses++;
2201#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002202 if (found)
2203 break;
2204 }
2205
2206 ixgbe_qv_unlock_poll(q_vector);
2207
2208 return found;
2209}
Cong Wange0d10952013-08-01 11:10:25 +08002210#endif /* CONFIG_NET_RX_BUSY_POLL */
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002211
Auke Kok9a799d72007-09-15 14:07:45 -07002212/**
2213 * ixgbe_configure_msix - Configure MSI-X hardware
2214 * @adapter: board private structure
2215 *
2216 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2217 * interrupts.
2218 **/
2219static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2220{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002221 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002222 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002223 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002224
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002225 /* Populate MSIX to EITR Select */
2226 if (adapter->num_vfs > 32) {
2227 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2228 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2229 }
2230
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002231 /*
2232 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002233 * corresponding register.
2234 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002235 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002236 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002237 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002238
Alexander Duycka5579282012-02-08 07:50:04 +00002239 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002240 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002241
Alexander Duycka5579282012-02-08 07:50:04 +00002242 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002243 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244
Alexander Duyckfe49f042009-06-04 16:00:09 +00002245 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002246 }
2247
Alexander Duyckbd508172010-11-16 19:27:03 -08002248 switch (adapter->hw.mac.type) {
2249 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002250 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002251 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002252 break;
2253 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002254 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002255 case ixgbe_mac_X550:
2256 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002257 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002258 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002259 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002260 default:
2261 break;
2262 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002263 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002264
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002265 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002266 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002267 mask &= ~(IXGBE_EIMS_OTHER |
2268 IXGBE_EIMS_MAILBOX |
2269 IXGBE_EIMS_LSC);
2270
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002271 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002272}
2273
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002274enum latency_range {
2275 lowest_latency = 0,
2276 low_latency = 1,
2277 bulk_latency = 2,
2278 latency_invalid = 255
2279};
2280
2281/**
2282 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002283 * @q_vector: structure containing interrupt and ring information
2284 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002285 *
2286 * Stores a new ITR value based on packets and byte
2287 * counts during the last interrupt. The advantage of per interrupt
2288 * computation is faster updates and more accurate ITR for the current
2289 * traffic pattern. Constants in this function were computed
2290 * based on theoretical maximum wire speed and thresholds were set based
2291 * on testing data as well as attempting to minimize response time
2292 * while increasing bulk throughput.
2293 * this functionality is controlled by the InterruptThrottleRate module
2294 * parameter (see ixgbe_param.c)
2295 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002296static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2297 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002298{
Alexander Duyckbd198052011-06-11 01:45:08 +00002299 int bytes = ring_container->total_bytes;
2300 int packets = ring_container->total_packets;
2301 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002302 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002303 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002304
2305 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002306 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002307
2308 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002309 * 0-10MB/s lowest (100000 ints/s)
2310 * 10-20MB/s low (20000 ints/s)
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002311 * 20-1249MB/s bulk (12000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002312 */
2313 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002314 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002315 if (timepassed_us == 0)
2316 return;
2317
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002318 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2319
2320 switch (itr_setting) {
2321 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002322 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002323 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002324 break;
2325 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002326 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002327 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002328 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002329 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002330 break;
2331 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002332 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002333 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002334 break;
2335 }
2336
Alexander Duyckbd198052011-06-11 01:45:08 +00002337 /* clear work counters since we have the values we need */
2338 ring_container->total_bytes = 0;
2339 ring_container->total_packets = 0;
2340
2341 /* write updated itr to ring container */
2342 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002343}
2344
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002345/**
2346 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002347 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002348 *
2349 * This function is made to be called by ethtool and by the driver
2350 * when it needs to update EITR registers at runtime. Hardware
2351 * specific quirks/differences are taken care of here.
2352 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002353void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002354{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002355 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002356 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002357 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002358 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002359
Alexander Duyckbd508172010-11-16 19:27:03 -08002360 switch (adapter->hw.mac.type) {
2361 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002362 /* must write high and low 16 bits to reset counter */
2363 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002364 break;
2365 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002366 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002367 case ixgbe_mac_X550:
2368 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002369 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002370 /*
2371 * set the WDIS bit to not clear the timer bits and cause an
2372 * immediate assertion of the interrupt
2373 */
2374 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002375 break;
2376 default:
2377 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002378 }
2379 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2380}
2381
Alexander Duyckbd198052011-06-11 01:45:08 +00002382static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002383{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002384 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002385 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002386
Alexander Duyckbd198052011-06-11 01:45:08 +00002387 ixgbe_update_itr(q_vector, &q_vector->tx);
2388 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002389
Alexander Duyck08c88332011-06-11 01:45:03 +00002390 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002391
2392 switch (current_itr) {
2393 /* counts and packets in update_itr are dependent on these numbers */
2394 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002395 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002396 break;
2397 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002398 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002399 break;
2400 case bulk_latency:
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002401 new_itr = IXGBE_12K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002402 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002403 default:
2404 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002405 }
2406
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002407 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002408 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002409 new_itr = (10 * new_itr * q_vector->itr) /
2410 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002411
Alexander Duyckbd198052011-06-11 01:45:08 +00002412 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002413 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002414
2415 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002416 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002417}
2418
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002419/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002420 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002421 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002422 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002423static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002424{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002425 struct ixgbe_hw *hw = &adapter->hw;
2426 u32 eicr = adapter->interrupt_event;
2427
Alexander Duyckf0f97782011-04-22 04:08:09 +00002428 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002429 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002430
Alexander Duyckf0f97782011-04-22 04:08:09 +00002431 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2432 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2433 return;
2434
2435 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2436
Joe Perches7ca647b2010-09-07 21:35:40 +00002437 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002438 case IXGBE_DEV_ID_82599_T3_LOM:
2439 /*
2440 * Since the warning interrupt is for both ports
2441 * we don't have to check if:
2442 * - This interrupt wasn't for our port.
2443 * - We may have missed the interrupt so always have to
2444 * check if we got a LSC
2445 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002446 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002447 !(eicr & IXGBE_EICR_LSC))
2448 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002449
Alexander Duyckf0f97782011-04-22 04:08:09 +00002450 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002451 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002452 bool link_up = false;
2453
Josh Hay3d292262012-12-15 03:28:19 +00002454 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002455
Alexander Duyckf0f97782011-04-22 04:08:09 +00002456 if (link_up)
2457 return;
2458 }
2459
2460 /* Check if this is not due to overtemp */
2461 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2462 return;
2463
2464 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002465 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002466 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2467 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002468 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002469 return;
2470 break;
2471 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002472 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002473
2474 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002475}
2476
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002477static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2478{
2479 struct ixgbe_hw *hw = &adapter->hw;
2480
2481 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002482 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002483 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002484 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002485 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002486 }
2487}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002488
Jacob Keller4f51bf72011-08-20 04:49:45 +00002489static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2490{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002491 struct ixgbe_hw *hw = &adapter->hw;
2492
Jacob Keller4f51bf72011-08-20 04:49:45 +00002493 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2494 return;
2495
2496 switch (adapter->hw.mac.type) {
2497 case ixgbe_mac_82599EB:
2498 /*
2499 * Need to check link state so complete overtemp check
2500 * on service task
2501 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002502 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2503 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002504 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2505 adapter->interrupt_event = eicr;
2506 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2507 ixgbe_service_event_schedule(adapter);
2508 return;
2509 }
2510 return;
2511 case ixgbe_mac_X540:
2512 if (!(eicr & IXGBE_EICR_TS))
2513 return;
2514 break;
2515 default:
2516 return;
2517 }
2518
Don Skidmoref44e7512015-06-09 16:36:23 -07002519 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002520}
2521
Don Skidmore45788d22015-06-09 16:59:04 -07002522static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2523{
2524 switch (hw->mac.type) {
2525 case ixgbe_mac_82598EB:
2526 if (hw->phy.type == ixgbe_phy_nl)
2527 return true;
2528 return false;
2529 case ixgbe_mac_82599EB:
2530 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002531 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002532 switch (hw->mac.ops.get_media_type(hw)) {
2533 case ixgbe_media_type_fiber:
2534 case ixgbe_media_type_fiber_qsfp:
2535 return true;
2536 default:
2537 return false;
2538 }
2539 default:
2540 return false;
2541 }
2542}
2543
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002544static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2545{
2546 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002547 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002548
Don Skidmore4ccc6502015-09-02 13:47:54 -07002549 if (!ixgbe_is_sfp(hw))
2550 return;
2551
2552 /* Later MAC's use different SDP */
2553 if (hw->mac.type >= ixgbe_mac_X540)
2554 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2555
2556 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002557 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002558 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002559 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2560 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002561 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002562 ixgbe_service_event_schedule(adapter);
2563 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002564 }
2565
Don Skidmore4ccc6502015-09-02 13:47:54 -07002566 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2567 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002568 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002569 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002570 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2571 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2572 ixgbe_service_event_schedule(adapter);
2573 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002574 }
2575}
2576
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002577static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2578{
2579 struct ixgbe_hw *hw = &adapter->hw;
2580
2581 adapter->lsc_int++;
2582 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2583 adapter->link_check_timeout = jiffies;
2584 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2585 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002586 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002587 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002588 }
2589}
2590
Alexander Duyckfe49f042009-06-04 16:00:09 +00002591static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2592 u64 qmask)
2593{
2594 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002595 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002596
Alexander Duyckbd508172010-11-16 19:27:03 -08002597 switch (hw->mac.type) {
2598 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002599 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002600 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2601 break;
2602 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002603 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002604 case ixgbe_mac_X550:
2605 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002606 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002607 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002608 if (mask)
2609 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002610 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002611 if (mask)
2612 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2613 break;
2614 default:
2615 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002616 }
2617 /* skip the flush */
2618}
2619
2620static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002621 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002622{
2623 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002624 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002625
Alexander Duyckbd508172010-11-16 19:27:03 -08002626 switch (hw->mac.type) {
2627 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002628 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002629 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2630 break;
2631 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002632 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002633 case ixgbe_mac_X550:
2634 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002635 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002636 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002637 if (mask)
2638 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002639 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002640 if (mask)
2641 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2642 break;
2643 default:
2644 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002645 }
2646 /* skip the flush */
2647}
2648
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002649/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002650 * ixgbe_irq_enable - Enable default interrupt generation settings
2651 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002652 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002653static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2654 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002655{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002656 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002657 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002658
Alexander Duyck2c4af692011-07-15 07:29:55 +00002659 /* don't reenable LSC while waiting for link */
2660 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2661 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002662
Alexander Duyck2c4af692011-07-15 07:29:55 +00002663 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002664 switch (adapter->hw.mac.type) {
2665 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002666 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002667 break;
2668 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002669 case ixgbe_mac_X550:
2670 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002671 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002672 mask |= IXGBE_EIMS_TS;
2673 break;
2674 default:
2675 break;
2676 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002677 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002678 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002679 switch (adapter->hw.mac.type) {
2680 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002681 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2682 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002683 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00002684 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002685 case ixgbe_mac_X550:
2686 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002687 case ixgbe_mac_x550em_a:
2688 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07002689 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07002690 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07002691 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07002692 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
2693 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00002694 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002695 mask |= IXGBE_EIMS_MAILBOX;
2696 break;
2697 default:
2698 break;
2699 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002700
Alexander Duyck2c4af692011-07-15 07:29:55 +00002701 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2702 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2703 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002704
Alexander Duyck2c4af692011-07-15 07:29:55 +00002705 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2706 if (queues)
2707 ixgbe_irq_enable_queues(adapter, ~0);
2708 if (flush)
2709 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002710}
2711
Alexander Duyck2c4af692011-07-15 07:29:55 +00002712static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002713{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002714 struct ixgbe_adapter *adapter = data;
2715 struct ixgbe_hw *hw = &adapter->hw;
2716 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002717
Alexander Duyck2c4af692011-07-15 07:29:55 +00002718 /*
2719 * Workaround for Silicon errata. Use clear-by-write instead
2720 * of clear-by-read. Reading with EICS will return the
2721 * interrupt causes without clearing, which later be done
2722 * with the write to EICR.
2723 */
2724 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002725
2726 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08002727 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00002728 * the bits are high when ixgbe_msix_other is called. There is a race
2729 * condition otherwise which results in possible performance loss
2730 * especially if the ixgbe_msix_other interrupt is triggering
2731 * consistently (as it would when PPS is turned on for the X540 device)
2732 */
2733 eicr &= 0xFFFF0000;
2734
Alexander Duyck2c4af692011-07-15 07:29:55 +00002735 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002736
Alexander Duyck2c4af692011-07-15 07:29:55 +00002737 if (eicr & IXGBE_EICR_LSC)
2738 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002739
Alexander Duyck2c4af692011-07-15 07:29:55 +00002740 if (eicr & IXGBE_EICR_MAILBOX)
2741 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002742
Alexander Duyck2c4af692011-07-15 07:29:55 +00002743 switch (hw->mac.type) {
2744 case ixgbe_mac_82599EB:
2745 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002746 case ixgbe_mac_X550:
2747 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002748 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07002749 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
2750 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
2751 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
2752 ixgbe_service_event_schedule(adapter);
2753 IXGBE_WRITE_REG(hw, IXGBE_EICR,
2754 IXGBE_EICR_GPI_SDP0_X540);
2755 }
Don Skidmored773ce22014-02-25 17:58:53 -08002756 if (eicr & IXGBE_EICR_ECC) {
2757 e_info(link, "Received ECC Err, initiating reset\n");
2758 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2759 ixgbe_service_event_schedule(adapter);
2760 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2761 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002762 /* Handle Flow Director Full threshold interrupt */
2763 if (eicr & IXGBE_EICR_FLOW_DIR) {
2764 int reinit_count = 0;
2765 int i;
2766 for (i = 0; i < adapter->num_tx_queues; i++) {
2767 struct ixgbe_ring *ring = adapter->tx_ring[i];
2768 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2769 &ring->state))
2770 reinit_count++;
2771 }
2772 if (reinit_count) {
2773 /* no more flow director interrupts until after init */
2774 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2775 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2776 ixgbe_service_event_schedule(adapter);
2777 }
2778 }
2779 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002780 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002781 break;
2782 default:
2783 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002784 }
2785
Alexander Duyck2c4af692011-07-15 07:29:55 +00002786 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002787
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002788 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07002789 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002790
Alexander Duyck2c4af692011-07-15 07:29:55 +00002791 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002792 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002793 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002794
Alexander Duyck2c4af692011-07-15 07:29:55 +00002795 return IRQ_HANDLED;
2796}
2797
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002798static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002799{
2800 struct ixgbe_q_vector *q_vector = data;
2801
Auke Kok9a799d72007-09-15 14:07:45 -07002802 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002803
2804 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07002805 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002806
2807 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002808}
2809
Auke Kok9a799d72007-09-15 14:07:45 -07002810/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002811 * ixgbe_poll - NAPI Rx polling callback
2812 * @napi: structure for representing this polling device
2813 * @budget: how many packets driver is allowed to clean
2814 *
2815 * This function is used for legacy and MSI, NAPI mode
2816 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002817int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002818{
2819 struct ixgbe_q_vector *q_vector =
2820 container_of(napi, struct ixgbe_q_vector, napi);
2821 struct ixgbe_adapter *adapter = q_vector->adapter;
2822 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002823 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00002824 bool clean_complete = true;
2825
2826#ifdef CONFIG_IXGBE_DCA
2827 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2828 ixgbe_update_dca(q_vector);
2829#endif
2830
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002831 ixgbe_for_each_ring(ring, q_vector->tx) {
2832 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
2833 clean_complete = false;
2834 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002835
Alexander Duyck5d6002b2015-09-22 14:35:41 -07002836 /* Exit if we are called by netpoll or busy polling is active */
2837 if ((budget <= 0) || !ixgbe_qv_lock_napi(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002838 return budget;
2839
Alexander Duyckeb01b972012-02-08 07:51:27 +00002840 /* attempt to distribute budget to each queue fairly, but don't allow
2841 * the budget to go below 1 because we'll exit polling */
2842 if (q_vector->rx.count > 1)
2843 per_ring_budget = max(budget/q_vector->rx.count, 1);
2844 else
2845 per_ring_budget = budget;
2846
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002847 ixgbe_for_each_ring(ring, q_vector->rx) {
2848 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
2849 per_ring_budget);
2850
2851 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002852 if (cleaned >= per_ring_budget)
2853 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002854 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002855
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002856 ixgbe_qv_unlock_napi(q_vector);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002857 /* If all work not completed, return budget and keep polling */
2858 if (!clean_complete)
2859 return budget;
2860
2861 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002862 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002863 if (adapter->rx_itr_setting & 1)
2864 ixgbe_set_itr(q_vector);
2865 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2866 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2867
2868 return 0;
2869}
2870
2871/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002872 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2873 * @adapter: board private structure
2874 *
2875 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2876 * interrupts from the kernel.
2877 **/
2878static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2879{
2880 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002881 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002882 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002883
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002884 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002885 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002886 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002887
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002888 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002889 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002890 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002891 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002892 } else if (q_vector->rx.ring) {
2893 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2894 "%s-%s-%d", netdev->name, "rx", ri++);
2895 } else if (q_vector->tx.ring) {
2896 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2897 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002898 } else {
2899 /* skip this unused q_vector */
2900 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002901 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002902 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2903 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002904 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002905 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002906 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002907 goto free_queue_irqs;
2908 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002909 /* If Flow Director is enabled, set interrupt affinity */
2910 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2911 /* assign the mask for this irq */
2912 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002913 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002914 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002915 }
2916
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002917 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002918 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002919 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002920 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002921 goto free_queue_irqs;
2922 }
2923
2924 return 0;
2925
2926free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002927 while (vector) {
2928 vector--;
2929 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2930 NULL);
2931 free_irq(adapter->msix_entries[vector].vector,
2932 adapter->q_vector[vector]);
2933 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002934 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2935 pci_disable_msix(adapter->pdev);
2936 kfree(adapter->msix_entries);
2937 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002938 return err;
2939}
2940
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002941/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002942 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002943 * @irq: interrupt number
2944 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002945 **/
2946static irqreturn_t ixgbe_intr(int irq, void *data)
2947{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002948 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002949 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002950 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002951 u32 eicr;
2952
Don Skidmore54037502009-02-21 15:42:56 -08002953 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002954 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002955 * before the read of EICR.
2956 */
2957 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2958
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002959 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002960 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002961 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002962 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002963 /*
2964 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002965 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002966 * have disabled interrupts due to EIAM
2967 * finish the workaround of silicon errata on 82598. Unmask
2968 * the interrupt that we masked before the EICR read.
2969 */
2970 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2971 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002972 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002973 }
Auke Kok9a799d72007-09-15 14:07:45 -07002974
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002975 if (eicr & IXGBE_EICR_LSC)
2976 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002977
Alexander Duyckbd508172010-11-16 19:27:03 -08002978 switch (hw->mac.type) {
2979 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002980 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002981 /* Fall through */
2982 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002983 case ixgbe_mac_X550:
2984 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002985 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08002986 if (eicr & IXGBE_EICR_ECC) {
2987 e_info(link, "Received ECC Err, initiating reset\n");
2988 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2989 ixgbe_service_event_schedule(adapter);
2990 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2991 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00002992 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002993 break;
2994 default:
2995 break;
2996 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002997
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002998 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002999 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003000 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003001
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003002 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003003 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003004
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003005 /*
3006 * re-enable link(maybe) and non-queue interrupts, no flush.
3007 * ixgbe_poll will re-enable the queue interrupts
3008 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003009 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3010 ixgbe_irq_enable(adapter, false, false);
3011
Auke Kok9a799d72007-09-15 14:07:45 -07003012 return IRQ_HANDLED;
3013}
3014
3015/**
3016 * ixgbe_request_irq - initialize interrupts
3017 * @adapter: board private structure
3018 *
3019 * Attempts to configure interrupts using the best available
3020 * capabilities of the hardware and kernel.
3021 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003022static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003023{
3024 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003025 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003026
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003027 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003028 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003029 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003030 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003031 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003032 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003033 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003034 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003035
Alexander Duyckde88eee2012-02-08 07:49:59 +00003036 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003037 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003038
Auke Kok9a799d72007-09-15 14:07:45 -07003039 return err;
3040}
3041
3042static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3043{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003044 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003045
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003046 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003047 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003048 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003049 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003050
3051 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3052 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3053 struct msix_entry *entry = &adapter->msix_entries[vector];
3054
3055 /* free only the irqs that were actually requested */
3056 if (!q_vector->rx.ring && !q_vector->tx.ring)
3057 continue;
3058
3059 /* clear the affinity_mask in the IRQ descriptor */
3060 irq_set_affinity_hint(entry->vector, NULL);
3061
3062 free_irq(entry->vector, q_vector);
3063 }
3064
3065 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003066}
3067
3068/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003069 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3070 * @adapter: board private structure
3071 **/
3072static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3073{
Alexander Duyckbd508172010-11-16 19:27:03 -08003074 switch (adapter->hw.mac.type) {
3075 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003076 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003077 break;
3078 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003079 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003080 case ixgbe_mac_X550:
3081 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003082 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003083 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3084 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003085 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003086 break;
3087 default:
3088 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003089 }
3090 IXGBE_WRITE_FLUSH(&adapter->hw);
3091 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003092 int vector;
3093
3094 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3095 synchronize_irq(adapter->msix_entries[vector].vector);
3096
3097 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003098 } else {
3099 synchronize_irq(adapter->pdev->irq);
3100 }
3101}
3102
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003103/**
Auke Kok9a799d72007-09-15 14:07:45 -07003104 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3105 *
3106 **/
3107static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3108{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003109 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003110
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003111 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003112
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003113 ixgbe_set_ivar(adapter, 0, 0, 0);
3114 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003115
Emil Tantilov396e7992010-07-01 20:05:12 +00003116 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003117}
3118
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003119/**
3120 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3121 * @adapter: board private structure
3122 * @ring: structure containing ring specific data
3123 *
3124 * Configure the Tx descriptor ring after a reset.
3125 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003126void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3127 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003128{
3129 struct ixgbe_hw *hw = &adapter->hw;
3130 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003131 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003132 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003133 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003134
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003135 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003136 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003137 IXGBE_WRITE_FLUSH(hw);
3138
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003139 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003140 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003141 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3142 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3143 ring->count * sizeof(union ixgbe_adv_tx_desc));
3144 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3145 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003146 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003147
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003148 /*
3149 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003150 * higher than 1 when:
3151 * - ITR is 0 as it could cause false TX hangs
3152 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003153 *
3154 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3155 * to or less than the number of on chip descriptors, which is
3156 * currently 40.
3157 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003158 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003159 txdctl |= (1 << 16); /* WTHRESH = 1 */
3160 else
3161 txdctl |= (8 << 16); /* WTHRESH = 8 */
3162
Alexander Duycke954b372012-02-08 07:49:38 +00003163 /*
3164 * Setting PTHRESH to 32 both improves performance
3165 * and avoids a TX hang with DFP enabled
3166 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003167 txdctl |= (1 << 8) | /* HTHRESH = 1 */
3168 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003169
3170 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003171 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003172 ring->atr_sample_rate = adapter->atr_sample_rate;
3173 ring->atr_count = 0;
3174 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3175 } else {
3176 ring->atr_sample_rate = 0;
3177 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003178
Alexander Duyckfd786b72013-01-12 06:33:31 +00003179 /* initialize XPS */
3180 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3181 struct ixgbe_q_vector *q_vector = ring->q_vector;
3182
3183 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003184 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003185 &q_vector->affinity_mask,
3186 ring->queue_index);
3187 }
3188
John Fastabendc84d3242010-11-16 19:27:12 -08003189 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3190
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003191 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003192 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3193
3194 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3195 if (hw->mac.type == ixgbe_mac_82598EB &&
3196 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3197 return;
3198
3199 /* poll to verify queue is enabled */
3200 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003201 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003202 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3203 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3204 if (!wait_loop)
3205 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003206}
3207
Alexander Duyck120ff942010-08-19 13:34:50 +00003208static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3209{
3210 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003211 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003212 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003213
3214 if (hw->mac.type == ixgbe_mac_82598EB)
3215 return;
3216
3217 /* disable the arbiter while setting MTQC */
3218 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3219 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3220 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3221
3222 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003223 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3224 mtqc = IXGBE_MTQC_VT_ENA;
3225 if (tcs > 4)
3226 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3227 else if (tcs > 1)
3228 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3229 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3230 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003231 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003232 mtqc |= IXGBE_MTQC_64VF;
3233 } else {
3234 if (tcs > 4)
3235 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3236 else if (tcs > 1)
3237 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3238 else
3239 mtqc = IXGBE_MTQC_64Q_1PB;
3240 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003241
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003242 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003243
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003244 /* Enable Security TX Buffer IFG for multiple pb */
3245 if (tcs) {
3246 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3247 sectx |= IXGBE_SECTX_DCB;
3248 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003249 }
3250
3251 /* re-enable the arbiter */
3252 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3253 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3254}
3255
Auke Kok9a799d72007-09-15 14:07:45 -07003256/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003257 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003258 * @adapter: board private structure
3259 *
3260 * Configure the Tx unit of the MAC after a reset.
3261 **/
3262static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3263{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003264 struct ixgbe_hw *hw = &adapter->hw;
3265 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003266 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003267
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003268 ixgbe_setup_mtqc(adapter);
3269
3270 if (hw->mac.type != ixgbe_mac_82598EB) {
3271 /* DMATXCTL.EN must be before Tx queues are enabled */
3272 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3273 dmatxctl |= IXGBE_DMATXCTL_TE;
3274 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3275 }
3276
Auke Kok9a799d72007-09-15 14:07:45 -07003277 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003278 for (i = 0; i < adapter->num_tx_queues; i++)
3279 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003280}
3281
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003282static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3283 struct ixgbe_ring *ring)
3284{
3285 struct ixgbe_hw *hw = &adapter->hw;
3286 u8 reg_idx = ring->reg_idx;
3287 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3288
3289 srrctl |= IXGBE_SRRCTL_DROP_EN;
3290
3291 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3292}
3293
3294static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3295 struct ixgbe_ring *ring)
3296{
3297 struct ixgbe_hw *hw = &adapter->hw;
3298 u8 reg_idx = ring->reg_idx;
3299 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3300
3301 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3302
3303 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3304}
3305
3306#ifdef CONFIG_IXGBE_DCB
3307void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3308#else
3309static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3310#endif
3311{
3312 int i;
3313 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3314
3315 if (adapter->ixgbe_ieee_pfc)
3316 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3317
3318 /*
3319 * We should set the drop enable bit if:
3320 * SR-IOV is enabled
3321 * or
3322 * Number of Rx queues > 1 and flow control is disabled
3323 *
3324 * This allows us to avoid head of line blocking for security
3325 * and performance reasons.
3326 */
3327 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3328 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3329 for (i = 0; i < adapter->num_rx_queues; i++)
3330 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3331 } else {
3332 for (i = 0; i < adapter->num_rx_queues; i++)
3333 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3334 }
3335}
3336
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003337#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003338
Yi Zoua6616b42009-08-06 13:05:23 +00003339static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003340 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003341{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003342 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003343 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003344 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003345
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003346 if (hw->mac.type == ixgbe_mac_82598EB) {
3347 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3348
3349 /*
3350 * if VMDq is not active we must program one srrctl register
3351 * per RSS queue since we have enabled RDRXCTL.MVMEN
3352 */
3353 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003354 }
3355
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003356 /* configure header buffer length, needed for RSC */
3357 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003358
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003359 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00003360 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003361
3362 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003363 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003364
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003365 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003366}
3367
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003368/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003369 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003370 * @adapter: device handle
3371 *
3372 * - 82598/82599/X540: 128
3373 * - X550(non-SRIOV mode): 512
3374 * - X550(SRIOV mode): 64
3375 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003376u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003377{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003378 if (adapter->hw.mac.type < ixgbe_mac_X550)
3379 return 128;
3380 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3381 return 64;
3382 else
3383 return 512;
3384}
3385
3386/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003387 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003388 * @adapter: device handle
3389 *
3390 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3391 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003392void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003393{
3394 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003395 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003396 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003397 u32 indices_multi;
3398 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003399
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003400 /* Fill out the redirection table as follows:
3401 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3402 * indices.
3403 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3404 * - X550: 8 bit wide entries containing 6 bit RSS index
3405 */
3406 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3407 indices_multi = 0x11;
3408 else
3409 indices_multi = 0x1;
3410
3411 /* Write redirection table to HW */
3412 for (i = 0; i < reta_entries; i++) {
3413 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3414 if ((i & 3) == 3) {
3415 if (i < 128)
3416 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3417 else
3418 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3419 reta);
3420 reta = 0;
3421 }
3422 }
3423}
3424
3425/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003426 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003427 * @adapter: device handle
3428 *
3429 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3430 */
3431static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3432{
3433 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3434 struct ixgbe_hw *hw = &adapter->hw;
3435 u32 vfreta = 0;
3436 unsigned int pf_pool = adapter->num_vfs;
3437
3438 /* Write redirection table to HW */
3439 for (i = 0; i < reta_entries; i++) {
3440 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3441 if ((i & 3) == 3) {
3442 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3443 vfreta);
3444 vfreta = 0;
3445 }
3446 }
3447}
3448
3449static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3450{
3451 struct ixgbe_hw *hw = &adapter->hw;
3452 u32 i, j;
3453 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3454 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3455
3456 /* Program table for at least 2 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003457 * make full use of any rings they may have. We will use the
3458 * PSRTYPE register to control how many rings we use within the PF.
3459 */
3460 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3461 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003462
Alexander Duyck05abb122010-08-19 13:35:41 +00003463 /* Fill out hash function seeds */
3464 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003465 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003466
Alexander Duyck05abb122010-08-19 13:35:41 +00003467 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003468 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3469
Don Skidmore0f9b2322014-11-18 09:35:08 +00003470 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003471 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003472 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003473
3474 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003475 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003476
3477 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003478}
3479
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003480static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003481{
3482 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003483 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3484 unsigned int pf_pool = adapter->num_vfs;
3485 int i, j;
3486
3487 /* Fill out hash function seeds */
3488 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003489 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
3490 adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003491
3492 /* Fill out the redirection table */
3493 for (i = 0, j = 0; i < 64; i++, j++) {
3494 if (j == rss_i)
3495 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003496
3497 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003498 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003499
3500 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003501}
3502
3503static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3504{
3505 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003506 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003507 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003508
3509 /* Disable indicating checksum in descriptor, enables RSS hash */
3510 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3511 rxcsum |= IXGBE_RXCSUM_PCSD;
3512 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3513
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003514 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003515 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003516 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003517 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003518 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003519
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003520 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3521 if (tcs > 4)
3522 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3523 else if (tcs > 1)
3524 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3525 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3526 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3527 else
3528 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3529 } else {
3530 if (tcs > 4)
3531 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3532 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003533 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3534 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003535 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003536 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003537 }
3538
Alexander Duyck05abb122010-08-19 13:35:41 +00003539 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003540 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3541 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3542 IXGBE_MRQC_RSS_FIELD_IPV6 |
3543 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003544
Alexander Duyckef6afc02012-02-08 07:51:53 +00003545 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003546 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003547 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003548 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003549
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003550 netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003551 if ((hw->mac.type >= ixgbe_mac_X550) &&
3552 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3553 unsigned int pf_pool = adapter->num_vfs;
3554
3555 /* Enable VF RSS mode */
3556 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3557 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3558
3559 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003560 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003561 vfmrqc = IXGBE_MRQC_RSSEN;
3562 vfmrqc |= rss_field;
3563 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3564 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003565 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003566 mrqc |= rss_field;
3567 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3568 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003569}
3570
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003571/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003572 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3573 * @adapter: address of board private structure
3574 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003575 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003576static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003577 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003578{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003579 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003580 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003581 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003582
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003583 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003584 return;
3585
Alexander Duyck73670962010-08-19 13:38:34 +00003586 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003587 rscctrl |= IXGBE_RSCCTL_RSCEN;
3588 /*
3589 * we must limit the number of descriptors so that the
3590 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003591 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003592 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003593 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003594 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003595}
3596
Alexander Duyck9e10e042010-08-19 13:40:06 +00003597#define IXGBE_MAX_RX_DESC_POLL 10
3598static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3599 struct ixgbe_ring *ring)
3600{
3601 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003602 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3603 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003604 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003605
Mark Rustadb0483c82014-01-14 18:53:17 -08003606 if (ixgbe_removed(hw->hw_addr))
3607 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003608 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3609 if (hw->mac.type == ixgbe_mac_82598EB &&
3610 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3611 return;
3612
3613 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003614 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003615 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3616 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3617
3618 if (!wait_loop) {
3619 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3620 "the polling period\n", reg_idx);
3621 }
3622}
3623
Yi Zou2d39d572011-01-06 14:29:56 +00003624void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3625 struct ixgbe_ring *ring)
3626{
3627 struct ixgbe_hw *hw = &adapter->hw;
3628 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3629 u32 rxdctl;
3630 u8 reg_idx = ring->reg_idx;
3631
Mark Rustadb0483c82014-01-14 18:53:17 -08003632 if (ixgbe_removed(hw->hw_addr))
3633 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003634 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3635 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3636
3637 /* write value back with RXDCTL.ENABLE bit cleared */
3638 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3639
3640 if (hw->mac.type == ixgbe_mac_82598EB &&
3641 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3642 return;
3643
3644 /* the hardware may take up to 100us to really disable the rx queue */
3645 do {
3646 udelay(10);
3647 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3648 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3649
3650 if (!wait_loop) {
3651 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3652 "the polling period\n", reg_idx);
3653 }
3654}
3655
Alexander Duyck84418e32010-08-19 13:40:54 +00003656void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3657 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003658{
3659 struct ixgbe_hw *hw = &adapter->hw;
3660 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003661 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003662 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003663
Alexander Duyck9e10e042010-08-19 13:40:06 +00003664 /* disable queue to avoid issues while updating state */
3665 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003666 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003667
Alexander Duyckacd37172010-08-19 13:36:05 +00003668 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3669 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3670 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3671 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08003672 /* Force flushing of IXGBE_RDLEN to prevent MDD */
3673 IXGBE_WRITE_FLUSH(hw);
3674
Alexander Duyckacd37172010-08-19 13:36:05 +00003675 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3676 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003677 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003678
3679 ixgbe_configure_srrctl(adapter, ring);
3680 ixgbe_configure_rscctl(adapter, ring);
3681
3682 if (hw->mac.type == ixgbe_mac_82598EB) {
3683 /*
3684 * enable cache line friendly hardware writes:
3685 * PTHRESH=32 descriptors (half the internal cache),
3686 * this also removes ugly rx_no_buffer_count increment
3687 * HTHRESH=4 descriptors (to minimize latency on fetch)
3688 * WTHRESH=8 burst writeback up to two cache lines
3689 */
3690 rxdctl &= ~0x3FFFFF;
3691 rxdctl |= 0x080420;
3692 }
3693
3694 /* enable receive descriptor ring */
3695 rxdctl |= IXGBE_RXDCTL_ENABLE;
3696 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3697
3698 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003699 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003700}
3701
Alexander Duyck48654522010-08-19 13:36:27 +00003702static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3703{
3704 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003705 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003706 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003707
3708 /* PSRTYPE must be initialized in non 82598 adapters */
3709 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003710 IXGBE_PSRTYPE_UDPHDR |
3711 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003712 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003713 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003714
3715 if (hw->mac.type == ixgbe_mac_82598EB)
3716 return;
3717
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003718 if (rss_i > 3)
3719 psrtype |= 2 << 29;
3720 else if (rss_i > 1)
3721 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003722
John Fastabend2a47fa42013-11-06 09:54:52 -08003723 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3724 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003725}
3726
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003727static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3728{
3729 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003730 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003731 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003732 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003733
3734 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3735 return;
3736
3737 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003738 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3739 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003740 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003741 vmdctl |= IXGBE_VT_CTL_REPLEN;
3742 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003743
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003744 vf_shift = VMDQ_P(0) % 32;
3745 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003746
3747 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003748 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3749 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3750 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3751 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07003752 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00003753 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003754
3755 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003756 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003757
Alexander Duyck16369562015-11-02 17:10:13 -08003758 /* clear VLAN promisc flag so VFTA will be updated if necessary */
3759 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
3760
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003761 /*
3762 * Set up VF register offsets for selected VT Mode,
3763 * i.e. 32 or 64 VFs for SR-IOV
3764 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003765 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3766 case IXGBE_82599_VMDQ_8Q_MASK:
3767 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3768 break;
3769 case IXGBE_82599_VMDQ_4Q_MASK:
3770 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3771 break;
3772 default:
3773 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3774 break;
3775 }
3776
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003777 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3778
Alexander Duyck435b19f2012-05-18 06:34:08 +00003779
Greg Rosea985b6c32010-11-18 03:02:52 +00003780 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003781 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003782 adapter->num_vfs);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003783
Emil Tantilovf079fa02015-08-20 15:31:20 -07003784 /* Ensure LLDP and FC is set for Ethertype Antispoofing if we will be
Don Skidmore5b7f0002015-01-28 07:03:38 +00003785 * calling set_ethertype_anti_spoofing for each VF in loop below
3786 */
Emil Tantilovf079fa02015-08-20 15:31:20 -07003787 if (hw->mac.ops.set_ethertype_anti_spoofing) {
Don Skidmore5b7f0002015-01-28 07:03:38 +00003788 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP),
Emil Tantilovf079fa02015-08-20 15:31:20 -07003789 (IXGBE_ETQF_FILTER_EN |
3790 IXGBE_ETQF_TX_ANTISPOOF |
3791 IXGBE_ETH_P_LLDP));
3792
3793 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FC),
3794 (IXGBE_ETQF_FILTER_EN |
3795 IXGBE_ETQF_TX_ANTISPOOF |
3796 ETH_P_PAUSE));
3797 }
Don Skidmore5b7f0002015-01-28 07:03:38 +00003798
Greg Rosede4c7f62011-09-29 05:57:33 +00003799 /* For VFs that have spoof checking turned off */
3800 for (i = 0; i < adapter->num_vfs; i++) {
3801 if (!adapter->vfinfo[i].spoofchk_enabled)
3802 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003803
3804 /* enable ethertype anti spoofing if hw supports it */
3805 if (hw->mac.ops.set_ethertype_anti_spoofing)
3806 hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03003807
3808 /* Enable/Disable RSS query feature */
3809 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
3810 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00003811 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003812}
3813
Alexander Duyck477de6e2010-08-19 13:38:11 +00003814static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003815{
Auke Kok9a799d72007-09-15 14:07:45 -07003816 struct ixgbe_hw *hw = &adapter->hw;
3817 struct net_device *netdev = adapter->netdev;
3818 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003819 struct ixgbe_ring *rx_ring;
3820 int i;
3821 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003822
Alexander Duyck477de6e2010-08-19 13:38:11 +00003823#ifdef IXGBE_FCOE
3824 /* adjust max frame to be able to do baby jumbo for FCoE */
3825 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3826 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3827 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3828
3829#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003830
3831 /* adjust max frame to be at least the size of a standard frame */
3832 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3833 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3834
Alexander Duyck477de6e2010-08-19 13:38:11 +00003835 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3836 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3837 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3838 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3839
3840 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003841 }
3842
Auke Kok9a799d72007-09-15 14:07:45 -07003843 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003844 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3845 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003846 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3847
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003848 /*
3849 * Setup the HW Rx Head and Tail Descriptor Pointers and
3850 * the Base and Length of the Rx Descriptor Ring
3851 */
Auke Kok9a799d72007-09-15 14:07:45 -07003852 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003853 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003854 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3855 set_ring_rsc_enabled(rx_ring);
3856 else
3857 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003858 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003859}
3860
Alexander Duyck73670962010-08-19 13:38:34 +00003861static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3862{
3863 struct ixgbe_hw *hw = &adapter->hw;
3864 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3865
3866 switch (hw->mac.type) {
3867 case ixgbe_mac_82598EB:
3868 /*
3869 * For VMDq support of different descriptor types or
3870 * buffer sizes through the use of multiple SRRCTL
3871 * registers, RDRXCTL.MVMEN must be set to 1
3872 *
3873 * also, the manual doesn't mention it clearly but DCA hints
3874 * will only use queue 0's tags unless this bit is set. Side
3875 * effects of setting this bit are only that SRRCTL must be
3876 * fully programmed [0..15]
3877 */
3878 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3879 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07003880 case ixgbe_mac_X550:
3881 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003882 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07003883 if (adapter->num_vfs)
3884 rdrxctl |= IXGBE_RDRXCTL_PSP;
3885 /* fall through for older HW */
Alexander Duyck73670962010-08-19 13:38:34 +00003886 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003887 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003888 /* Disable RSC for ACK packets */
3889 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3890 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3891 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3892 /* hardware requires some bits to be set by default */
3893 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3894 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3895 break;
3896 default:
3897 /* We should do nothing since we don't know this hardware */
3898 return;
3899 }
3900
3901 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3902}
3903
Alexander Duyck477de6e2010-08-19 13:38:11 +00003904/**
3905 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3906 * @adapter: board private structure
3907 *
3908 * Configure the Rx unit of the MAC after a reset.
3909 **/
3910static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3911{
3912 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003913 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003914 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003915
3916 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07003917 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003918
3919 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003920 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003921
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003922 /* RSC Setup */
3923 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
3924 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
3925 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
3926 rfctl |= IXGBE_RFCTL_RSC_DIS;
3927 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
3928
Alexander Duyck9e10e042010-08-19 13:40:06 +00003929 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003930 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003931
Alexander Duyck477de6e2010-08-19 13:38:11 +00003932 /* set_rx_buffer_len must be called before ring initialization */
3933 ixgbe_set_rx_buffer_len(adapter);
3934
3935 /*
3936 * Setup the HW Rx Head and Tail Descriptor Pointers and
3937 * the Base and Length of the Rx Descriptor Ring
3938 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003939 for (i = 0; i < adapter->num_rx_queues; i++)
3940 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003941
Don Skidmore1f9ac572015-03-13 13:54:30 -07003942 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003943 /* disable drop enable for 82598 parts */
3944 if (hw->mac.type == ixgbe_mac_82598EB)
3945 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3946
3947 /* enable all receives */
3948 rxctrl |= IXGBE_RXCTRL_RXEN;
3949 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003950}
3951
Patrick McHardy80d5c362013-04-19 02:04:28 +00003952static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3953 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003954{
3955 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003956 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003957
3958 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08003959 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
3960 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
3961
Jesse Grossf62bbb52010-10-20 13:56:10 +00003962 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003963
3964 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003965}
3966
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08003967static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
3968{
3969 u32 vlvf;
3970 int idx;
3971
3972 /* short cut the special case */
3973 if (vlan == 0)
3974 return 0;
3975
3976 /* Search for the vlan id in the VLVF entries */
3977 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
3978 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
3979 if ((vlvf & VLAN_VID_MASK) == vlan)
3980 break;
3981 }
3982
3983 return idx;
3984}
3985
3986void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
3987{
3988 struct ixgbe_hw *hw = &adapter->hw;
3989 u32 bits, word;
3990 int idx;
3991
3992 idx = ixgbe_find_vlvf_entry(hw, vid);
3993 if (!idx)
3994 return;
3995
3996 /* See if any other pools are set for this VLAN filter
3997 * entry other than the PF.
3998 */
3999 word = idx * 2 + (VMDQ_P(0) / 32);
4000 bits = ~(1 << (VMDQ_P(0)) % 32);
4001 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4002
4003 /* Disable the filter so this falls into the default pool. */
4004 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4005 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4006 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4007 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4008 }
4009}
4010
Patrick McHardy80d5c362013-04-19 02:04:28 +00004011static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4012 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004013{
4014 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004015 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004016
Auke Kok9a799d72007-09-15 14:07:45 -07004017 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004018 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004019 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4020
Jesse Grossf62bbb52010-10-20 13:56:10 +00004021 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004022
4023 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004024}
4025
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004026/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004027 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4028 * @adapter: driver data
4029 */
4030static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4031{
4032 struct ixgbe_hw *hw = &adapter->hw;
4033 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004034 int i, j;
4035
4036 switch (hw->mac.type) {
4037 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004038 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4039 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004040 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4041 break;
4042 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004043 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004044 case ixgbe_mac_X550:
4045 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004046 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004047 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004048 struct ixgbe_ring *ring = adapter->rx_ring[i];
4049
4050 if (ring->l2_accel_priv)
4051 continue;
4052 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004053 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4054 vlnctrl &= ~IXGBE_RXDCTL_VME;
4055 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4056 }
4057 break;
4058 default:
4059 break;
4060 }
4061}
4062
4063/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004064 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004065 * @adapter: driver data
4066 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004067static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004068{
4069 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004070 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004071 int i, j;
4072
4073 switch (hw->mac.type) {
4074 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004075 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4076 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004077 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4078 break;
4079 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004080 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004081 case ixgbe_mac_X550:
4082 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004083 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004084 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004085 struct ixgbe_ring *ring = adapter->rx_ring[i];
4086
4087 if (ring->l2_accel_priv)
4088 continue;
4089 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004090 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4091 vlnctrl |= IXGBE_RXDCTL_VME;
4092 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4093 }
4094 break;
4095 default:
4096 break;
4097 }
4098}
4099
Alexander Duyck16369562015-11-02 17:10:13 -08004100static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4101{
4102 struct ixgbe_hw *hw = &adapter->hw;
4103 u32 vlnctrl, i;
4104
4105 switch (hw->mac.type) {
4106 case ixgbe_mac_82599EB:
4107 case ixgbe_mac_X540:
4108 case ixgbe_mac_X550:
4109 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004110 case ixgbe_mac_x550em_a:
Alexander Duyck16369562015-11-02 17:10:13 -08004111 default:
4112 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED)
4113 break;
4114 /* fall through */
4115 case ixgbe_mac_82598EB:
4116 /* legacy case, we can just disable VLAN filtering */
4117 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4118 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
4119 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4120 return;
4121 }
4122
4123 /* We are already in VLAN promisc, nothing to do */
4124 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4125 return;
4126
4127 /* Set flag so we don't redo unnecessary work */
4128 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4129
4130 /* Add PF to all active pools */
4131 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4132 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4133 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4134
4135 vlvfb |= 1 << (VMDQ_P(0) % 32);
4136 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4137 }
4138
4139 /* Set all bits in the VLAN filter table array */
4140 for (i = hw->mac.vft_size; i--;)
4141 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4142}
4143
4144#define VFTA_BLOCK_SIZE 8
4145static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4146{
4147 struct ixgbe_hw *hw = &adapter->hw;
4148 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4149 u32 vid_start = vfta_offset * 32;
4150 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4151 u32 i, vid, word, bits;
4152
4153 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4154 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4155
4156 /* pull VLAN ID from VLVF */
4157 vid = vlvf & VLAN_VID_MASK;
4158
4159 /* only concern outselves with a certain range */
4160 if (vid < vid_start || vid >= vid_end)
4161 continue;
4162
4163 if (vlvf) {
4164 /* record VLAN ID in VFTA */
4165 vfta[(vid - vid_start) / 32] |= 1 << (vid % 32);
4166
4167 /* if PF is part of this then continue */
4168 if (test_bit(vid, adapter->active_vlans))
4169 continue;
4170 }
4171
4172 /* remove PF from the pool */
4173 word = i * 2 + VMDQ_P(0) / 32;
4174 bits = ~(1 << (VMDQ_P(0) % 32));
4175 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4176 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4177 }
4178
4179 /* extract values from active_vlans and write back to VFTA */
4180 for (i = VFTA_BLOCK_SIZE; i--;) {
4181 vid = (vfta_offset + i) * 32;
4182 word = vid / BITS_PER_LONG;
4183 bits = vid % BITS_PER_LONG;
4184
4185 vfta[i] |= adapter->active_vlans[word] >> bits;
4186
4187 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4188 }
4189}
4190
4191static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4192{
4193 struct ixgbe_hw *hw = &adapter->hw;
4194 u32 vlnctrl, i;
4195
4196 switch (hw->mac.type) {
4197 case ixgbe_mac_82599EB:
4198 case ixgbe_mac_X540:
4199 case ixgbe_mac_X550:
4200 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004201 case ixgbe_mac_x550em_a:
Alexander Duyck16369562015-11-02 17:10:13 -08004202 default:
4203 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED)
4204 break;
4205 /* fall through */
4206 case ixgbe_mac_82598EB:
4207 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4208 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
4209 vlnctrl |= IXGBE_VLNCTRL_VFE;
4210 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4211 return;
4212 }
4213
4214 /* We are not in VLAN promisc, nothing to do */
4215 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4216 return;
4217
4218 /* Set flag so we don't redo unnecessary work */
4219 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4220
4221 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4222 ixgbe_scrub_vfta(adapter, i);
4223}
4224
Auke Kok9a799d72007-09-15 14:07:45 -07004225static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4226{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004227 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004228
Patrick McHardy80d5c362013-04-19 02:04:28 +00004229 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004230
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004231 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004232 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004233}
4234
4235/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004236 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4237 * @netdev: network interface device structure
4238 *
4239 * Writes multicast address list to the MTA hash table.
4240 * Returns: -ENOMEM on failure
4241 * 0 on no addresses written
4242 * X on writing X addresses to MTA
4243 **/
4244static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4245{
4246 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4247 struct ixgbe_hw *hw = &adapter->hw;
4248
4249 if (!netif_running(netdev))
4250 return 0;
4251
4252 if (hw->mac.ops.update_mc_addr_list)
4253 hw->mac.ops.update_mc_addr_list(hw, netdev);
4254 else
4255 return -ENOMEM;
4256
4257#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004258 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004259#endif
4260
4261 return netdev_mc_count(netdev);
4262}
4263
Jacob Keller5d7daa32014-03-29 06:51:25 +00004264#ifdef CONFIG_PCI_IOV
4265void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4266{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004267 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004268 struct ixgbe_hw *hw = &adapter->hw;
4269 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004270
4271 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4272 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4273
4274 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4275 hw->mac.ops.set_rar(hw, i,
4276 mac_table->addr,
4277 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004278 IXGBE_RAH_AV);
4279 else
4280 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004281 }
4282}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004283
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004284#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004285static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4286{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004287 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004288 struct ixgbe_hw *hw = &adapter->hw;
4289 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004290
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004291 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4292 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4293 continue;
4294
4295 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4296
4297 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4298 hw->mac.ops.set_rar(hw, i,
4299 mac_table->addr,
4300 mac_table->pool,
4301 IXGBE_RAH_AV);
4302 else
4303 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004304 }
4305}
4306
4307static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4308{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004309 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004310 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004311 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004312
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004313 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4314 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4315 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004316 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004317
Jacob Keller5d7daa32014-03-29 06:51:25 +00004318 ixgbe_sync_mac_table(adapter);
4319}
4320
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004321static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004322{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004323 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004324 struct ixgbe_hw *hw = &adapter->hw;
4325 int i, count = 0;
4326
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004327 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4328 /* do not count default RAR as available */
4329 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4330 continue;
4331
4332 /* only count unused and addresses that belong to us */
4333 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4334 if (mac_table->pool != pool)
4335 continue;
4336 }
4337
4338 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004339 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004340
Jacob Keller5d7daa32014-03-29 06:51:25 +00004341 return count;
4342}
4343
4344/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004345static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004346{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004347 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004348 struct ixgbe_hw *hw = &adapter->hw;
4349
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004350 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4351 mac_table->pool = VMDQ_P(0);
4352
4353 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4354
4355 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004356 IXGBE_RAH_AV);
4357}
4358
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004359int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4360 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004361{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004362 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004363 struct ixgbe_hw *hw = &adapter->hw;
4364 int i;
4365
4366 if (is_zero_ether_addr(addr))
4367 return -EINVAL;
4368
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004369 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4370 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004371 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004372
4373 ether_addr_copy(mac_table->addr, addr);
4374 mac_table->pool = pool;
4375
4376 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4377 IXGBE_MAC_STATE_IN_USE;
4378
Jacob Keller5d7daa32014-03-29 06:51:25 +00004379 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004380
Jacob Keller5d7daa32014-03-29 06:51:25 +00004381 return i;
4382 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004383
Jacob Keller5d7daa32014-03-29 06:51:25 +00004384 return -ENOMEM;
4385}
4386
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004387int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4388 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004389{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004390 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004391 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004392 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004393
4394 if (is_zero_ether_addr(addr))
4395 return -EINVAL;
4396
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004397 /* search table for addr, if found clear IN_USE flag and sync */
4398 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4399 /* we can only delete an entry if it is in use */
4400 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4401 continue;
4402 /* we only care about entries that belong to the given pool */
4403 if (mac_table->pool != pool)
4404 continue;
4405 /* we only care about a specific MAC address */
4406 if (!ether_addr_equal(addr, mac_table->addr))
4407 continue;
4408
4409 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4410 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4411
4412 ixgbe_sync_mac_table(adapter);
4413
4414 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004415 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004416
Jacob Keller5d7daa32014-03-29 06:51:25 +00004417 return -ENOMEM;
4418}
Jacob Kellerb335e752014-03-25 07:45:27 +00004419/**
Alexander Duyck28500622010-06-15 09:25:48 +00004420 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4421 * @netdev: network interface device structure
4422 *
4423 * Writes unicast address list to the RAR table.
4424 * Returns: -ENOMEM on failure/insufficient address space
4425 * 0 on no addresses written
4426 * X on writing X addresses to the RAR table
4427 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004428static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004429{
4430 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004431 int count = 0;
4432
4433 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004434 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004435 return -ENOMEM;
4436
John Fastabend95447462012-05-31 12:42:26 +00004437 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004438 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004439 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004440 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4441 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004442 count++;
4443 }
4444 }
Alexander Duyck28500622010-06-15 09:25:48 +00004445 return count;
4446}
4447
Alexander Duyck0f079d22015-10-22 16:26:36 -07004448static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4449{
4450 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4451 int ret;
4452
4453 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4454
4455 return min_t(int, ret, 0);
4456}
4457
4458static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4459{
4460 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4461
4462 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4463
4464 return 0;
4465}
4466
Alexander Duyck28500622010-06-15 09:25:48 +00004467/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004468 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004469 * @netdev: network interface device structure
4470 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004471 * The set_rx_method entry point is called whenever the unicast/multicast
4472 * address list or the network interface flags are updated. This routine is
4473 * responsible for configuring the hardware for proper unicast, multicast and
4474 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004475 **/
Greg Rose7f870472010-01-09 02:25:29 +00004476void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004477{
4478 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4479 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004480 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004481 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004482 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004483
4484 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004485 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4486
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004487 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004488 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004489 fctrl |= IXGBE_FCTRL_BAM;
4490 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4491 fctrl |= IXGBE_FCTRL_PMCF;
4492
Alexander Duyck28500622010-06-15 09:25:48 +00004493 /* clear the bits we are changing the status of */
4494 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004495 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004496 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004497 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004498 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004499 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004500 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004501 if (netdev->flags & IFF_ALLMULTI) {
4502 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004503 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004504 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004505 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004506 }
4507
4508 /*
4509 * Write addresses to available RAR registers, if there is not
4510 * sufficient space to store all the addresses then enable
4511 * unicast promiscuous mode
4512 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004513 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004514 fctrl |= IXGBE_FCTRL_UPE;
4515 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004516 }
4517
Emil Tantilovcf789592013-10-26 08:13:20 +00004518 /* Write addresses to the MTA, if the attempt fails
4519 * then we should just turn on promiscuous mode so
4520 * that we can at least receive multicast traffic
4521 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004522 count = ixgbe_write_mc_addr_list(netdev);
4523 if (count < 0) {
4524 fctrl |= IXGBE_FCTRL_MPE;
4525 vmolr |= IXGBE_VMOLR_MPE;
4526 } else if (count) {
4527 vmolr |= IXGBE_VMOLR_ROMPE;
4528 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004529
4530 if (hw->mac.type != ixgbe_mac_82598EB) {
4531 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004532 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4533 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004534 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004535 }
4536
Ben Greear3f2d1c02012-03-08 08:28:41 +00004537 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004538 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004539 /* UPE and MPE will be handled by normal PROMISC logic
4540 * in e1000e_set_rx_mode */
4541 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4542 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4543 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4544
4545 fctrl &= ~(IXGBE_FCTRL_DPF);
4546 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4547 }
4548
Auke Kok9a799d72007-09-15 14:07:45 -07004549 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004550
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004551 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004552 ixgbe_vlan_strip_enable(adapter);
4553 else
4554 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004555
4556 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4557 ixgbe_vlan_promisc_disable(adapter);
4558 else
4559 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004560}
4561
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004562static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4563{
4564 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004565
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004566 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
4567 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004568 napi_enable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004569 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004570}
4571
4572static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4573{
4574 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004575
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004576 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004577 napi_disable(&adapter->q_vector[q_idx]->napi);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004578 while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) {
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004579 pr_info("QV %d locked\n", q_idx);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004580 usleep_range(1000, 20000);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004581 }
4582 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004583}
4584
Mark Rustad67359c32015-06-15 11:33:25 -07004585static void ixgbe_clear_vxlan_port(struct ixgbe_adapter *adapter)
4586{
4587 switch (adapter->hw.mac.type) {
4588 case ixgbe_mac_X550:
4589 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004590 case ixgbe_mac_x550em_a:
Mark Rustad67359c32015-06-15 11:33:25 -07004591 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VXLANCTRL, 0);
Mark Rustad67359c32015-06-15 11:33:25 -07004592 adapter->vxlan_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07004593 break;
4594 default:
4595 break;
4596 }
4597}
4598
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004599#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004600/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004601 * ixgbe_configure_dcb - Configure DCB hardware
4602 * @adapter: ixgbe adapter struct
4603 *
4604 * This is called by the driver on open to configure the DCB hardware.
4605 * This is also called by the gennetlink interface when reconfiguring
4606 * the DCB state.
4607 */
4608static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4609{
4610 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00004611 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004612
Alexander Duyck67ebd792010-08-19 13:34:04 +00004613 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4614 if (hw->mac.type == ixgbe_mac_82598EB)
4615 netif_set_gso_max_size(adapter->netdev, 65536);
4616 return;
4617 }
4618
4619 if (hw->mac.type == ixgbe_mac_82598EB)
4620 netif_set_gso_max_size(adapter->netdev, 32768);
4621
John Fastabendb1208182011-10-15 05:00:10 +00004622#ifdef IXGBE_FCOE
4623 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4624 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4625#endif
4626
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004627 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004628 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004629 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4630 DCB_TX_CONFIG);
4631 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4632 DCB_RX_CONFIG);
4633 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004634 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4635 ixgbe_dcb_hw_ets(&adapter->hw,
4636 adapter->ixgbe_ieee_ets,
4637 max_frame);
4638 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4639 adapter->ixgbe_ieee_pfc->pfc_en,
4640 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004641 }
John Fastabend8187cd42011-02-23 05:58:08 +00004642
4643 /* Enable RSS Hash per TC */
4644 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004645 u32 msb = 0;
4646 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004647
Alexander Duyckd411a932012-06-30 00:14:01 +00004648 while (rss_i) {
4649 msb++;
4650 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004651 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004652
Alexander Duyck4ae63732012-06-22 06:46:33 +00004653 /* write msb to all 8 TCs in one write */
4654 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004655 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004656}
John Fastabend9da712d2011-08-23 03:14:22 +00004657#endif
4658
4659/* Additional bittime to account for IXGBE framing */
4660#define IXGBE_ETH_FRAMING 20
4661
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004662/**
John Fastabend9da712d2011-08-23 03:14:22 +00004663 * ixgbe_hpbthresh - calculate high water mark for flow control
4664 *
4665 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004666 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004667 */
4668static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4669{
4670 struct ixgbe_hw *hw = &adapter->hw;
4671 struct net_device *dev = adapter->netdev;
4672 int link, tc, kb, marker;
4673 u32 dv_id, rx_pba;
4674
4675 /* Calculate max LAN frame size */
4676 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4677
4678#ifdef IXGBE_FCOE
4679 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004680 if ((dev->features & NETIF_F_FCOE_MTU) &&
4681 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4682 (pb == ixgbe_fcoe_get_tc(adapter)))
4683 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004684#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004685
John Fastabend9da712d2011-08-23 03:14:22 +00004686 /* Calculate delay value for device */
4687 switch (hw->mac.type) {
4688 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004689 case ixgbe_mac_X550:
4690 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004691 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004692 dv_id = IXGBE_DV_X540(link, tc);
4693 break;
4694 default:
4695 dv_id = IXGBE_DV(link, tc);
4696 break;
4697 }
4698
4699 /* Loopback switch introduces additional latency */
4700 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4701 dv_id += IXGBE_B2BT(tc);
4702
4703 /* Delay value is calculated in bit times convert to KB */
4704 kb = IXGBE_BT2KB(dv_id);
4705 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4706
4707 marker = rx_pba - kb;
4708
4709 /* It is possible that the packet buffer is not large enough
4710 * to provide required headroom. In this case throw an error
4711 * to user and a do the best we can.
4712 */
4713 if (marker < 0) {
4714 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4715 "headroom to support flow control."
4716 "Decrease MTU or number of traffic classes\n", pb);
4717 marker = tc + 1;
4718 }
4719
4720 return marker;
4721}
4722
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004723/**
John Fastabend9da712d2011-08-23 03:14:22 +00004724 * ixgbe_lpbthresh - calculate low water mark for for flow control
4725 *
4726 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004727 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004728 */
Jacob Kellere5776622014-04-05 02:35:52 +00004729static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00004730{
4731 struct ixgbe_hw *hw = &adapter->hw;
4732 struct net_device *dev = adapter->netdev;
4733 int tc;
4734 u32 dv_id;
4735
4736 /* Calculate max LAN frame size */
4737 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4738
Jacob Kellere5776622014-04-05 02:35:52 +00004739#ifdef IXGBE_FCOE
4740 /* FCoE traffic class uses FCOE jumbo frames */
4741 if ((dev->features & NETIF_F_FCOE_MTU) &&
4742 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4743 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4744 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4745#endif
4746
John Fastabend9da712d2011-08-23 03:14:22 +00004747 /* Calculate delay value for device */
4748 switch (hw->mac.type) {
4749 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004750 case ixgbe_mac_X550:
4751 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004752 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004753 dv_id = IXGBE_LOW_DV_X540(tc);
4754 break;
4755 default:
4756 dv_id = IXGBE_LOW_DV(tc);
4757 break;
4758 }
4759
4760 /* Delay value is calculated in bit times convert to KB */
4761 return IXGBE_BT2KB(dv_id);
4762}
4763
4764/*
4765 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4766 */
4767static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4768{
4769 struct ixgbe_hw *hw = &adapter->hw;
4770 int num_tc = netdev_get_num_tc(adapter->netdev);
4771 int i;
4772
4773 if (!num_tc)
4774 num_tc = 1;
4775
John Fastabend9da712d2011-08-23 03:14:22 +00004776 for (i = 0; i < num_tc; i++) {
4777 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00004778 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00004779
4780 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00004781 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4782 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004783 }
Jacob Kellere5776622014-04-05 02:35:52 +00004784
4785 for (; i < MAX_TRAFFIC_CLASS; i++)
4786 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004787}
John Fastabend80605c652011-05-02 12:34:10 +00004788
4789static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4790{
John Fastabend80605c652011-05-02 12:34:10 +00004791 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004792 int hdrm;
4793 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004794
4795 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4796 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004797 hdrm = 32 << adapter->fdir_pballoc;
4798 else
4799 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004800
Alexander Duyckf7e10272011-07-21 00:40:35 +00004801 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004802 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004803}
4804
Alexander Duycke4911d52011-05-11 07:18:52 +00004805static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4806{
4807 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004808 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004809 struct ixgbe_fdir_filter *filter;
4810
4811 spin_lock(&adapter->fdir_perfect_lock);
4812
4813 if (!hlist_empty(&adapter->fdir_filter_list))
4814 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4815
Sasha Levinb67bfe02013-02-27 17:06:00 -08004816 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004817 &adapter->fdir_filter_list, fdir_node) {
4818 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004819 &filter->filter,
4820 filter->sw_idx,
4821 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4822 IXGBE_FDIR_DROP_QUEUE :
4823 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004824 }
4825
4826 spin_unlock(&adapter->fdir_perfect_lock);
4827}
4828
John Fastabend2a47fa42013-11-06 09:54:52 -08004829static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4830 struct ixgbe_adapter *adapter)
4831{
4832 struct ixgbe_hw *hw = &adapter->hw;
4833 u32 vmolr;
4834
4835 /* No unicast promiscuous support for VMDQ devices. */
4836 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4837 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4838
4839 /* clear the affected bit */
4840 vmolr &= ~IXGBE_VMOLR_MPE;
4841
4842 if (dev->flags & IFF_ALLMULTI) {
4843 vmolr |= IXGBE_VMOLR_MPE;
4844 } else {
4845 vmolr |= IXGBE_VMOLR_ROMPE;
4846 hw->mac.ops.update_mc_addr_list(hw, dev);
4847 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00004848 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08004849 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4850}
4851
John Fastabend2a47fa42013-11-06 09:54:52 -08004852static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4853{
4854 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004855 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004856 struct ixgbe_hw *hw = &adapter->hw;
4857 u16 pool = vadapter->pool;
4858 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4859 IXGBE_PSRTYPE_UDPHDR |
4860 IXGBE_PSRTYPE_IPV4HDR |
4861 IXGBE_PSRTYPE_L2HDR |
4862 IXGBE_PSRTYPE_IPV6HDR;
4863
4864 if (hw->mac.type == ixgbe_mac_82598EB)
4865 return;
4866
4867 if (rss_i > 3)
4868 psrtype |= 2 << 29;
4869 else if (rss_i > 1)
4870 psrtype |= 1 << 29;
4871
4872 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4873}
4874
4875/**
4876 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4877 * @rx_ring: ring to free buffers from
4878 **/
4879static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4880{
4881 struct device *dev = rx_ring->dev;
4882 unsigned long size;
4883 u16 i;
4884
4885 /* ring already cleared, nothing to do */
4886 if (!rx_ring->rx_buffer_info)
4887 return;
4888
4889 /* Free all the Rx ring sk_buffs */
4890 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyck18cb6522014-11-14 00:56:29 +00004891 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08004892
John Fastabend2a47fa42013-11-06 09:54:52 -08004893 if (rx_buffer->skb) {
4894 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00004895 if (IXGBE_CB(skb)->page_released)
John Fastabend2a47fa42013-11-06 09:54:52 -08004896 dma_unmap_page(dev,
4897 IXGBE_CB(skb)->dma,
4898 ixgbe_rx_bufsz(rx_ring),
4899 DMA_FROM_DEVICE);
John Fastabend2a47fa42013-11-06 09:54:52 -08004900 dev_kfree_skb(skb);
Junwei Zhang4d2fcfb2014-10-22 15:29:03 +00004901 rx_buffer->skb = NULL;
John Fastabend2a47fa42013-11-06 09:54:52 -08004902 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00004903
4904 if (!rx_buffer->page)
4905 continue;
4906
4907 dma_unmap_page(dev, rx_buffer->dma,
4908 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
4909 __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring));
4910
John Fastabend2a47fa42013-11-06 09:54:52 -08004911 rx_buffer->page = NULL;
4912 }
4913
4914 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4915 memset(rx_ring->rx_buffer_info, 0, size);
4916
4917 /* Zero out the descriptor ring */
4918 memset(rx_ring->desc, 0, rx_ring->size);
4919
4920 rx_ring->next_to_alloc = 0;
4921 rx_ring->next_to_clean = 0;
4922 rx_ring->next_to_use = 0;
4923}
4924
4925static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
4926 struct ixgbe_ring *rx_ring)
4927{
4928 struct ixgbe_adapter *adapter = vadapter->real_adapter;
4929 int index = rx_ring->queue_index + vadapter->rx_base_queue;
4930
4931 /* shutdown specific queue receive and wait for dma to settle */
4932 ixgbe_disable_rx_queue(adapter, rx_ring);
4933 usleep_range(10000, 20000);
4934 ixgbe_irq_disable_queues(adapter, ((u64)1 << index));
4935 ixgbe_clean_rx_ring(rx_ring);
4936 rx_ring->l2_accel_priv = NULL;
4937}
4938
John Fastabendae72c8d2013-11-09 07:11:26 +00004939static int ixgbe_fwd_ring_down(struct net_device *vdev,
4940 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08004941{
4942 struct ixgbe_adapter *adapter = accel->real_adapter;
4943 unsigned int rxbase = accel->rx_base_queue;
4944 unsigned int txbase = accel->tx_base_queue;
4945 int i;
4946
4947 netif_tx_stop_all_queues(vdev);
4948
4949 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4950 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4951 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
4952 }
4953
4954 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4955 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
4956 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
4957 }
4958
4959
4960 return 0;
4961}
4962
4963static int ixgbe_fwd_ring_up(struct net_device *vdev,
4964 struct ixgbe_fwd_adapter *accel)
4965{
4966 struct ixgbe_adapter *adapter = accel->real_adapter;
4967 unsigned int rxbase, txbase, queues;
4968 int i, baseq, err = 0;
4969
4970 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
4971 return 0;
4972
4973 baseq = accel->pool * adapter->num_rx_queues_per_pool;
4974 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4975 accel->pool, adapter->num_rx_pools,
4976 baseq, baseq + adapter->num_rx_queues_per_pool,
4977 adapter->fwd_bitmask);
4978
4979 accel->netdev = vdev;
4980 accel->rx_base_queue = rxbase = baseq;
4981 accel->tx_base_queue = txbase = baseq;
4982
4983 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
4984 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4985
4986 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4987 adapter->rx_ring[rxbase + i]->netdev = vdev;
4988 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
4989 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
4990 }
4991
4992 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4993 adapter->tx_ring[txbase + i]->netdev = vdev;
4994 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
4995 }
4996
4997 queues = min_t(unsigned int,
4998 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
4999 err = netif_set_real_num_tx_queues(vdev, queues);
5000 if (err)
5001 goto fwd_queue_err;
5002
John Fastabend2a47fa42013-11-06 09:54:52 -08005003 err = netif_set_real_num_rx_queues(vdev, queues);
5004 if (err)
5005 goto fwd_queue_err;
5006
5007 if (is_valid_ether_addr(vdev->dev_addr))
5008 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
5009
5010 ixgbe_fwd_psrtype(accel);
5011 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
5012 return err;
5013fwd_queue_err:
5014 ixgbe_fwd_ring_down(vdev, accel);
5015 return err;
5016}
5017
5018static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5019{
5020 struct net_device *upper;
5021 struct list_head *iter;
5022 int err;
5023
5024 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
5025 if (netif_is_macvlan(upper)) {
5026 struct macvlan_dev *dfwd = netdev_priv(upper);
5027 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5028
5029 if (dfwd->fwd_priv) {
5030 err = ixgbe_fwd_ring_up(upper, vadapter);
5031 if (err)
5032 continue;
5033 }
5034 }
5035 }
5036}
5037
Auke Kok9a799d72007-09-15 14:07:45 -07005038static void ixgbe_configure(struct ixgbe_adapter *adapter)
5039{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005040 struct ixgbe_hw *hw = &adapter->hw;
5041
John Fastabend80605c652011-05-02 12:34:10 +00005042 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005043#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005044 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005045#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005046 /*
5047 * We must restore virtualization before VLANs or else
5048 * the VLVF registers will not be populated
5049 */
5050 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005051
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005052 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005053 ixgbe_restore_vlan(adapter);
5054
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005055 switch (hw->mac.type) {
5056 case ixgbe_mac_82599EB:
5057 case ixgbe_mac_X540:
5058 hw->mac.ops.disable_rx_buff(hw);
5059 break;
5060 default:
5061 break;
5062 }
5063
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005064 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005065 ixgbe_init_fdir_signature_82599(&adapter->hw,
5066 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005067 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5068 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5069 adapter->fdir_pballoc);
5070 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005071 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005072
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005073 switch (hw->mac.type) {
5074 case ixgbe_mac_82599EB:
5075 case ixgbe_mac_X540:
5076 hw->mac.ops.enable_rx_buff(hw);
5077 break;
5078 default:
5079 break;
5080 }
5081
Mark Rustad9de76052015-08-08 16:27:41 -07005082#ifdef CONFIG_IXGBE_DCA
5083 /* configure DCA */
5084 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5085 ixgbe_setup_dca(adapter);
5086#endif /* CONFIG_IXGBE_DCA */
5087
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005088#ifdef IXGBE_FCOE
5089 /* configure FCoE L2 filters, redirection table, and Rx control */
5090 ixgbe_configure_fcoe(adapter);
5091
5092#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005093 ixgbe_configure_tx(adapter);
5094 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005095 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005096}
5097
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005098/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005099 * ixgbe_sfp_link_config - set up SFP+ link
5100 * @adapter: pointer to private adapter struct
5101 **/
5102static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5103{
Alexander Duyck70864002011-04-27 09:13:56 +00005104 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005105 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005106 * is that an SFP was inserted/removed after the reset
5107 * but before SFP detection was enabled. As such the best
5108 * solution is to just start searching as soon as we start
5109 */
5110 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5111 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005112
Alexander Duyck70864002011-04-27 09:13:56 +00005113 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005114 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005115}
5116
5117/**
5118 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005119 * @hw: pointer to private hardware struct
5120 *
5121 * Returns 0 on success, negative on failure
5122 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005123static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005124{
Josh Hay3d292262012-12-15 03:28:19 +00005125 u32 speed;
5126 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005127 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005128
5129 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005130 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005131
5132 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005133 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005134
Josh Hay3d292262012-12-15 03:28:19 +00005135 speed = hw->phy.autoneg_advertised;
5136 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5137 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5138 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005139 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005140 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005141
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005142 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005143 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005144
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005145 return ret;
5146}
5147
Alexander Duycka34bcff2010-08-19 13:39:20 +00005148static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005149{
Auke Kok9a799d72007-09-15 14:07:45 -07005150 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005151 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005152
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005153 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005154 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5155 IXGBE_GPIE_OCD;
5156 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005157 /*
5158 * use EIAM to auto-mask when MSI-X interrupt is asserted
5159 * this saves a register write for every interrupt
5160 */
5161 switch (hw->mac.type) {
5162 case ixgbe_mac_82598EB:
5163 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5164 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005165 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005166 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005167 case ixgbe_mac_X550:
5168 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005169 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005170 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005171 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5172 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5173 break;
5174 }
5175 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005176 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5177 * specifically only auto mask tx and rx interrupts */
5178 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005179 }
5180
Alexander Duycka34bcff2010-08-19 13:39:20 +00005181 /* XXX: to interrupt immediately for EICS writes, enable this */
5182 /* gpie |= IXGBE_GPIE_EIMEN; */
5183
5184 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5185 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005186
5187 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5188 case IXGBE_82599_VMDQ_8Q_MASK:
5189 gpie |= IXGBE_GPIE_VTMODE_16;
5190 break;
5191 case IXGBE_82599_VMDQ_4Q_MASK:
5192 gpie |= IXGBE_GPIE_VTMODE_32;
5193 break;
5194 default:
5195 gpie |= IXGBE_GPIE_VTMODE_64;
5196 break;
5197 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005198 }
5199
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005200 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005201 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5202 switch (adapter->hw.mac.type) {
5203 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005204 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005205 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005206 default:
5207 break;
5208 }
5209 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005210
Alexander Duycka34bcff2010-08-19 13:39:20 +00005211 /* Enable fan failure interrupt */
5212 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005213 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005214
Don Skidmorea023bbd2015-06-24 16:38:53 -04005215 switch (hw->mac.type) {
5216 case ixgbe_mac_82599EB:
5217 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5218 break;
5219 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005220 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005221 gpie |= IXGBE_SDP0_GPIEN_X540;
5222 break;
5223 default:
5224 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005225 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005226
5227 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5228}
5229
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005230static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005231{
5232 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005233 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005234 u32 ctrl_ext;
5235
5236 ixgbe_get_hw_control(adapter);
5237 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005238
Auke Kok9a799d72007-09-15 14:07:45 -07005239 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5240 ixgbe_configure_msix(adapter);
5241 else
5242 ixgbe_configure_msi_and_legacy(adapter);
5243
Emil Tantilovec74a472012-09-20 03:33:56 +00005244 /* enable the optics for 82599 SFP+ fiber */
5245 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005246 hw->mac.ops.enable_tx_laser(hw);
5247
Don Skidmore961fac82015-06-09 16:09:47 -07005248 if (hw->phy.ops.set_phy_power)
5249 hw->phy.ops.set_phy_power(hw, true);
5250
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005251 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005252 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005253 ixgbe_napi_enable_all(adapter);
5254
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005255 if (ixgbe_is_sfp(hw)) {
5256 ixgbe_sfp_link_config(adapter);
5257 } else {
5258 err = ixgbe_non_sfp_link_config(hw);
5259 if (err)
5260 e_err(probe, "link_config FAILED %d\n", err);
5261 }
5262
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005263 /* clear any pending interrupts, may auto mask */
5264 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005265 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005266
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005267 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005268 * If this adapter has a fan, check to see if we had a failure
5269 * before we enabled the interrupt.
5270 */
5271 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5272 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5273 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005274 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005275 }
5276
Auke Kok9a799d72007-09-15 14:07:45 -07005277 /* bring the link up in the watchdog, this could race with our first
5278 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005279 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5280 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005281 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005282
5283 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5284 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5285 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5286 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005287}
5288
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005289void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5290{
5291 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005292 /* put off any impending NetWatchDogTimeout */
5293 adapter->netdev->trans_start = jiffies;
5294
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005295 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005296 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005297 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005298 /*
5299 * If SR-IOV enabled then wait a bit before bringing the adapter
5300 * back up to give the VFs time to respond to the reset. The
5301 * two second wait is based upon the watchdog timer cycle in
5302 * the VF driver.
5303 */
5304 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5305 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005306 ixgbe_up(adapter);
5307 clear_bit(__IXGBE_RESETTING, &adapter->state);
5308}
5309
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005310void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005311{
5312 /* hardware has been reset, we need to reload some things */
5313 ixgbe_configure(adapter);
5314
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005315 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005316}
5317
5318void ixgbe_reset(struct ixgbe_adapter *adapter)
5319{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005320 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005321 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005322 int err;
5323
Mark Rustadb0483c82014-01-14 18:53:17 -08005324 if (ixgbe_removed(hw->hw_addr))
5325 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005326 /* lock SFP init bit to prevent race conditions with the watchdog */
5327 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5328 usleep_range(1000, 2000);
5329
5330 /* clear all SFP and link config related flags while holding SFP_INIT */
5331 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5332 IXGBE_FLAG2_SFP_NEEDS_RESET);
5333 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5334
Don Skidmore8ca783a2009-05-26 20:40:47 -07005335 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005336 switch (err) {
5337 case 0:
5338 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005339 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005340 break;
5341 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005342 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005343 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005344 case IXGBE_ERR_EEPROM_VERSION:
5345 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005346 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005347 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005348 "your hardware. If you are experiencing problems "
5349 "please contact your Intel or hardware "
5350 "representative who provided you with this "
5351 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005352 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005353 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005354 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005355 }
Auke Kok9a799d72007-09-15 14:07:45 -07005356
Alexander Duyck70864002011-04-27 09:13:56 +00005357 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005358
5359 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005360 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005361 __dev_uc_unsync(netdev, NULL);
5362
5363 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005364 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005365
5366 /* update SAN MAC vmdq pool selection */
5367 if (hw->mac.san_mac_rar_index)
5368 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005369
Jacob Keller8fecf672013-06-21 08:14:32 +00005370 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005371 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005372
5373 if (hw->phy.ops.set_phy_power) {
5374 if (!netif_running(adapter->netdev) && !adapter->wol)
5375 hw->phy.ops.set_phy_power(hw, false);
5376 else
5377 hw->phy.ops.set_phy_power(hw, true);
5378 }
Auke Kok9a799d72007-09-15 14:07:45 -07005379}
5380
Auke Kok9a799d72007-09-15 14:07:45 -07005381/**
Auke Kok9a799d72007-09-15 14:07:45 -07005382 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005383 * @tx_ring: ring to be cleaned
5384 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005385static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005386{
5387 struct ixgbe_tx_buffer *tx_buffer_info;
5388 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005389 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07005390
Alexander Duyck84418e32010-08-19 13:40:54 +00005391 /* ring already cleared, nothing to do */
5392 if (!tx_ring->tx_buffer_info)
5393 return;
Auke Kok9a799d72007-09-15 14:07:45 -07005394
Alexander Duyck84418e32010-08-19 13:40:54 +00005395 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07005396 for (i = 0; i < tx_ring->count; i++) {
5397 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005398 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07005399 }
5400
John Fastabenddad8a3b2012-04-23 12:22:39 +00005401 netdev_tx_reset_queue(txring_txq(tx_ring));
5402
Auke Kok9a799d72007-09-15 14:07:45 -07005403 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5404 memset(tx_ring->tx_buffer_info, 0, size);
5405
5406 /* Zero out the descriptor ring */
5407 memset(tx_ring->desc, 0, tx_ring->size);
5408
5409 tx_ring->next_to_use = 0;
5410 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005411}
5412
5413/**
Auke Kok9a799d72007-09-15 14:07:45 -07005414 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5415 * @adapter: board private structure
5416 **/
5417static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5418{
5419 int i;
5420
5421 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005422 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005423}
5424
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005425/**
5426 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5427 * @adapter: board private structure
5428 **/
5429static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5430{
5431 int i;
5432
5433 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005434 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005435}
5436
Alexander Duycke4911d52011-05-11 07:18:52 +00005437static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5438{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005439 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005440 struct ixgbe_fdir_filter *filter;
5441
5442 spin_lock(&adapter->fdir_perfect_lock);
5443
Sasha Levinb67bfe02013-02-27 17:06:00 -08005444 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005445 &adapter->fdir_filter_list, fdir_node) {
5446 hlist_del(&filter->fdir_node);
5447 kfree(filter);
5448 }
5449 adapter->fdir_filter_count = 0;
5450
5451 spin_unlock(&adapter->fdir_perfect_lock);
5452}
5453
Auke Kok9a799d72007-09-15 14:07:45 -07005454void ixgbe_down(struct ixgbe_adapter *adapter)
5455{
5456 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005457 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08005458 struct net_device *upper;
5459 struct list_head *iter;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005460 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005461
5462 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005463 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5464 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005465
5466 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005467 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005468
Yi Zou2d39d572011-01-06 14:29:56 +00005469 /* disable all enabled rx queues */
5470 for (i = 0; i < adapter->num_rx_queues; i++)
5471 /* this call also flushes the previous write */
5472 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5473
Don Skidmore032b4322011-03-18 09:32:53 +00005474 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005475
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005476 netif_tx_stop_all_queues(netdev);
5477
Alexander Duyck70864002011-04-27 09:13:56 +00005478 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005479 netif_carrier_off(netdev);
5480 netif_tx_disable(netdev);
5481
John Fastabend2a47fa42013-11-06 09:54:52 -08005482 /* disable any upper devices */
5483 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
5484 if (netif_is_macvlan(upper)) {
5485 struct macvlan_dev *vlan = netdev_priv(upper);
5486
5487 if (vlan->fwd_priv) {
5488 netif_tx_stop_all_queues(upper);
5489 netif_carrier_off(upper);
5490 netif_tx_disable(upper);
5491 }
5492 }
5493 }
5494
John Fastabendc0dfb902010-04-27 02:13:39 +00005495 ixgbe_irq_disable(adapter);
5496
5497 ixgbe_napi_disable_all(adapter);
5498
Alexander Duyckd034acf2011-04-27 09:25:34 +00005499 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
5500 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00005501 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5502
5503 del_timer_sync(&adapter->service_timer);
5504
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005505 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005506 /* Clear EITR Select mapping */
5507 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5508
5509 /* Mark all the VFs as inactive */
5510 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005511 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005512
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005513 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005514 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005515
Auke Kok9a799d72007-09-15 14:07:45 -07005516 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005517 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005518 }
5519
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005520 /* disable transmits in the hardware now that interrupts are off */
5521 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005522 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005523 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005524 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005525
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005526 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005527 switch (hw->mac.type) {
5528 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005529 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005530 case ixgbe_mac_X550:
5531 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005532 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005533 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005534 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5535 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005536 break;
5537 default:
5538 break;
5539 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005540
Paul Larson6f4a0e42008-06-24 17:00:56 -07005541 if (!pci_channel_offline(adapter->pdev))
5542 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005543
Emil Tantilovec74a472012-09-20 03:33:56 +00005544 /* power down the optics for 82599 SFP+ fiber */
5545 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005546 hw->mac.ops.disable_tx_laser(hw);
5547
Auke Kok9a799d72007-09-15 14:07:45 -07005548 ixgbe_clean_all_tx_rings(adapter);
5549 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005550}
5551
Auke Kok9a799d72007-09-15 14:07:45 -07005552/**
Auke Kok9a799d72007-09-15 14:07:45 -07005553 * ixgbe_tx_timeout - Respond to a Tx Hang
5554 * @netdev: network interface device structure
5555 **/
5556static void ixgbe_tx_timeout(struct net_device *netdev)
5557{
5558 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5559
5560 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005561 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005562}
5563
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005564/**
Auke Kok9a799d72007-09-15 14:07:45 -07005565 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5566 * @adapter: board private structure to initialize
5567 *
5568 * ixgbe_sw_init initializes the Adapter private data structure.
5569 * Fields are initialized based on PCI device information and
5570 * OS network device settings (MTU size).
5571 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05005572static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005573{
5574 struct ixgbe_hw *hw = &adapter->hw;
5575 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005576 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005577 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005578#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005579 int j;
5580 struct tc_configuration *tc;
5581#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005582
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005583 /* PCI config space info */
5584
5585 hw->vendor_id = pdev->vendor;
5586 hw->device_id = pdev->device;
5587 hw->revision_id = pdev->revision;
5588 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5589 hw->subsystem_device_id = pdev->subsystem_device;
5590
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005591 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00005592 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005593 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005594 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005595 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5596 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005597 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5598 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005599 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5600#ifdef CONFIG_IXGBE_DCA
5601 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5602#endif
5603#ifdef IXGBE_FCOE
5604 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5605 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5606#ifdef CONFIG_IXGBE_DCB
5607 /* Default traffic class to use for FCoE */
5608 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5609#endif /* CONFIG_IXGBE_DCB */
5610#endif /* IXGBE_FCOE */
5611
John Fastabendb82b17d2016-02-16 21:18:53 -08005612 /* initialize static ixgbe jump table entries */
5613 adapter->jump_tables[0] = ixgbe_ipv4_fields;
5614
Jacob Keller5d7daa32014-03-29 06:51:25 +00005615 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5616 hw->mac.num_rar_entries,
5617 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08005618 if (!adapter->mac_table)
5619 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005620
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005621 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005622 switch (hw->mac.type) {
5623 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005624 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005625
Don Skidmorebf069c92009-05-07 10:39:54 +00005626 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5627 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005628
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005629 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005630 adapter->ring_feature[RING_F_FDIR].limit = 0;
5631 adapter->atr_sample_rate = 0;
5632 adapter->fdir_pballoc = 0;
5633#ifdef IXGBE_FCOE
5634 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5635 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5636#ifdef CONFIG_IXGBE_DCB
5637 adapter->fcoe.up = 0;
5638#endif /* IXGBE_DCB */
5639#endif /* IXGBE_FCOE */
5640 break;
5641 case ixgbe_mac_82599EB:
5642 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5643 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005644 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005645 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005646 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005647 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5648 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005649 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005650 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005651 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005652 case ixgbe_mac_X550:
5653#ifdef CONFIG_IXGBE_DCA
5654 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
5655#endif
Mark Rustad67359c32015-06-15 11:33:25 -07005656#ifdef CONFIG_IXGBE_VXLAN
5657 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
5658#endif
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005659 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08005660 default:
5661 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005662 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005663
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005664#ifdef IXGBE_FCOE
5665 /* FCoE support exists, always init the FCoE lock */
5666 spin_lock_init(&adapter->fcoe.lock);
5667
5668#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005669 /* n-tuple support exists, always init our spinlock */
5670 spin_lock_init(&adapter->fdir_perfect_lock);
5671
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005672#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005673 switch (hw->mac.type) {
5674 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005675 case ixgbe_mac_X550:
5676 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005677 case ixgbe_mac_x550em_a:
John Fastabend4de2a022011-09-27 03:52:01 +00005678 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5679 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5680 break;
5681 default:
5682 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5683 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5684 break;
5685 }
5686
Alexander Duyck2f90b862008-11-20 20:52:10 -08005687 /* Configure DCB traffic classes */
5688 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5689 tc = &adapter->dcb_cfg.tc_config[j];
5690 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5691 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5692 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5693 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5694 tc->dcb_pfc = pfc_disabled;
5695 }
John Fastabend4de2a022011-09-27 03:52:01 +00005696
5697 /* Initialize default user to priority mapping, UPx->TC0 */
5698 tc = &adapter->dcb_cfg.tc_config[0];
5699 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5700 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5701
Alexander Duyck2f90b862008-11-20 20:52:10 -08005702 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5703 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005704 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005705 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005706 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00005707 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5708 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08005709
5710#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005711
5712 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005713 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005714 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005715 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005716 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5717 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005718 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005719
Alexander Duyck99d74482012-05-09 08:09:25 +00005720#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005721 if (max_vfs > 0)
5722 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 +00005723
Jacob Keller170e8542013-11-09 04:52:32 -08005724 /* assign number of SR-IOV VFs */
5725 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005726 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Jacob Keller170e8542013-11-09 04:52:32 -08005727 adapter->num_vfs = 0;
5728 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5729 } else {
5730 adapter->num_vfs = max_vfs;
5731 }
5732 }
5733#endif /* CONFIG_PCI_IOV */
5734
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005735 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005736 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005737 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005738
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005739 /* set default ring sizes */
5740 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5741 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5742
Alexander Duyckbd198052011-06-11 01:45:08 +00005743 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005744 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005745
Auke Kok9a799d72007-09-15 14:07:45 -07005746 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005747 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005748 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005749 return -EIO;
5750 }
5751
John Fastabend2a47fa42013-11-06 09:54:52 -08005752 /* PF holds first pool slot */
5753 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005754 set_bit(__IXGBE_DOWN, &adapter->state);
5755
5756 return 0;
5757}
5758
5759/**
5760 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005761 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005762 *
5763 * Return 0 on success, negative on failure
5764 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005765int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005766{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005767 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005768 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005769 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005770 int size;
5771
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005772 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005773
5774 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005775 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005776
Mark Rustadca8dfe22014-07-24 06:19:24 +00005777 tx_ring->tx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005778 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005779 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005780 if (!tx_ring->tx_buffer_info)
5781 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005782
John Stultz827da442013-10-07 15:51:58 -07005783 u64_stats_init(&tx_ring->syncp);
5784
Auke Kok9a799d72007-09-15 14:07:45 -07005785 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005786 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005787 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005788
Mark Rustadca8dfe22014-07-24 06:19:24 +00005789 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005790 tx_ring->desc = dma_alloc_coherent(dev,
5791 tx_ring->size,
5792 &tx_ring->dma,
5793 GFP_KERNEL);
5794 set_dev_node(dev, orig_node);
5795 if (!tx_ring->desc)
5796 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5797 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005798 if (!tx_ring->desc)
5799 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005800
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005801 tx_ring->next_to_use = 0;
5802 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005803 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005804
5805err:
5806 vfree(tx_ring->tx_buffer_info);
5807 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005808 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005809 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005810}
5811
5812/**
Alexander Duyck69888672008-09-11 20:05:39 -07005813 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5814 * @adapter: board private structure
5815 *
5816 * If this function returns with an error, then it's possible one or
5817 * more of the rings is populated (while the rest are not). It is the
5818 * callers duty to clean those orphaned rings.
5819 *
5820 * Return 0 on success, negative on failure
5821 **/
5822static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5823{
5824 int i, err = 0;
5825
5826 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005827 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005828 if (!err)
5829 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005830
Emil Tantilov396e7992010-07-01 20:05:12 +00005831 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005832 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07005833 }
5834
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005835 return 0;
5836err_setup_tx:
5837 /* rewind the index freeing the rings as we go */
5838 while (i--)
5839 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005840 return err;
5841}
5842
5843/**
Auke Kok9a799d72007-09-15 14:07:45 -07005844 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005845 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005846 *
5847 * Returns 0 on success, negative on failure
5848 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005849int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005850{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005851 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005852 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005853 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005854 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005855
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005856 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005857
5858 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005859 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005860
Mark Rustadca8dfe22014-07-24 06:19:24 +00005861 rx_ring->rx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005862 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005863 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005864 if (!rx_ring->rx_buffer_info)
5865 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005866
John Stultz827da442013-10-07 15:51:58 -07005867 u64_stats_init(&rx_ring->syncp);
5868
Auke Kok9a799d72007-09-15 14:07:45 -07005869 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005870 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5871 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005872
Mark Rustadca8dfe22014-07-24 06:19:24 +00005873 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005874 rx_ring->desc = dma_alloc_coherent(dev,
5875 rx_ring->size,
5876 &rx_ring->dma,
5877 GFP_KERNEL);
5878 set_dev_node(dev, orig_node);
5879 if (!rx_ring->desc)
5880 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5881 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005882 if (!rx_ring->desc)
5883 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005884
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005885 rx_ring->next_to_clean = 0;
5886 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005887
5888 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005889err:
5890 vfree(rx_ring->rx_buffer_info);
5891 rx_ring->rx_buffer_info = NULL;
5892 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005893 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005894}
5895
5896/**
Alexander Duyck69888672008-09-11 20:05:39 -07005897 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5898 * @adapter: board private structure
5899 *
5900 * If this function returns with an error, then it's possible one or
5901 * more of the rings is populated (while the rest are not). It is the
5902 * callers duty to clean those orphaned rings.
5903 *
5904 * Return 0 on success, negative on failure
5905 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005906static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5907{
5908 int i, err = 0;
5909
5910 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005911 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005912 if (!err)
5913 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005914
Emil Tantilov396e7992010-07-01 20:05:12 +00005915 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005916 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07005917 }
5918
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005919#ifdef IXGBE_FCOE
5920 err = ixgbe_setup_fcoe_ddp_resources(adapter);
5921 if (!err)
5922#endif
5923 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005924err_setup_rx:
5925 /* rewind the index freeing the rings as we go */
5926 while (i--)
5927 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005928 return err;
5929}
5930
5931/**
Auke Kok9a799d72007-09-15 14:07:45 -07005932 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005933 * @tx_ring: Tx descriptor ring for a specific queue
5934 *
5935 * Free all transmit software resources
5936 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005937void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005938{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005939 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005940
5941 vfree(tx_ring->tx_buffer_info);
5942 tx_ring->tx_buffer_info = NULL;
5943
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005944 /* if not set, then don't free */
5945 if (!tx_ring->desc)
5946 return;
5947
5948 dma_free_coherent(tx_ring->dev, tx_ring->size,
5949 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005950
5951 tx_ring->desc = NULL;
5952}
5953
5954/**
5955 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5956 * @adapter: board private structure
5957 *
5958 * Free all transmit software resources
5959 **/
5960static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5961{
5962 int i;
5963
5964 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005965 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005966 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005967}
5968
5969/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005970 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005971 * @rx_ring: ring to clean the resources from
5972 *
5973 * Free all receive software resources
5974 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005975void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005976{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005977 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005978
5979 vfree(rx_ring->rx_buffer_info);
5980 rx_ring->rx_buffer_info = NULL;
5981
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005982 /* if not set, then don't free */
5983 if (!rx_ring->desc)
5984 return;
5985
5986 dma_free_coherent(rx_ring->dev, rx_ring->size,
5987 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005988
5989 rx_ring->desc = NULL;
5990}
5991
5992/**
5993 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5994 * @adapter: board private structure
5995 *
5996 * Free all receive software resources
5997 **/
5998static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5999{
6000 int i;
6001
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006002#ifdef IXGBE_FCOE
6003 ixgbe_free_fcoe_ddp_resources(adapter);
6004
6005#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006006 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006007 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006008 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006009}
6010
6011/**
Auke Kok9a799d72007-09-15 14:07:45 -07006012 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6013 * @netdev: network interface device structure
6014 * @new_mtu: new value for maximum frame size
6015 *
6016 * Returns 0 on success, negative on failure
6017 **/
6018static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6019{
6020 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6021 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
6022
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07006023 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00006024 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
6025 return -EINVAL;
6026
6027 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006028 * For 82599EB we cannot allow legacy VFs to enable their receive
6029 * paths when MTU greater than 1500 is configured. So display a
6030 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006031 */
6032 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6033 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Alexander Duyckc5604512013-01-09 08:50:42 +00006034 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck872844d2012-08-15 02:10:43 +00006035 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006036
Emil Tantilov396e7992010-07-01 20:05:12 +00006037 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006038
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006039 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006040 netdev->mtu = new_mtu;
6041
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006042 if (netif_running(netdev))
6043 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006044
6045 return 0;
6046}
6047
6048/**
6049 * ixgbe_open - Called when a network interface is made active
6050 * @netdev: network interface device structure
6051 *
6052 * Returns 0 on success, negative value on failure
6053 *
6054 * The open entry point is called when a network interface is made
6055 * active by the system (IFF_UP). At this point all resources needed
6056 * for transmit and receive operations are allocated, the interrupt
6057 * handler is registered with the OS, the watchdog timer is started,
6058 * and the stack is notified that the interface is ready.
6059 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006060int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006061{
6062 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006063 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006064 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006065
Auke Kok4bebfaa2008-02-11 09:26:01 -08006066 /* disallow open during test */
6067 if (test_bit(__IXGBE_TESTING, &adapter->state))
6068 return -EBUSY;
6069
Jesse Brandeburg54386462009-04-17 20:44:27 +00006070 netif_carrier_off(netdev);
6071
Auke Kok9a799d72007-09-15 14:07:45 -07006072 /* allocate transmit descriptors */
6073 err = ixgbe_setup_all_tx_resources(adapter);
6074 if (err)
6075 goto err_setup_tx;
6076
Auke Kok9a799d72007-09-15 14:07:45 -07006077 /* allocate receive descriptors */
6078 err = ixgbe_setup_all_rx_resources(adapter);
6079 if (err)
6080 goto err_setup_rx;
6081
6082 ixgbe_configure(adapter);
6083
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006084 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006085 if (err)
6086 goto err_req_irq;
6087
Alexander Duyckac802f52012-07-12 05:52:53 +00006088 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08006089 if (adapter->num_rx_pools > 1)
6090 queues = adapter->num_rx_queues_per_pool;
6091 else
6092 queues = adapter->num_tx_queues;
6093
6094 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006095 if (err)
6096 goto err_set_queues;
6097
John Fastabend2a47fa42013-11-06 09:54:52 -08006098 if (adapter->num_rx_pools > 1 &&
6099 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
6100 queues = IXGBE_MAX_L2A_QUEUES;
6101 else
6102 queues = adapter->num_rx_queues;
6103 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006104 if (err)
6105 goto err_set_queues;
6106
Jacob Keller1a71ab22012-08-25 03:54:19 +00006107 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006108
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006109 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006110
Mark Rustad67359c32015-06-15 11:33:25 -07006111 ixgbe_clear_vxlan_port(adapter);
6112#ifdef CONFIG_IXGBE_VXLAN
Don Skidmore3f207802014-12-23 07:40:34 +00006113 vxlan_get_rx_port(netdev);
Don Skidmore3f207802014-12-23 07:40:34 +00006114#endif
Mark Rustad67359c32015-06-15 11:33:25 -07006115
Auke Kok9a799d72007-09-15 14:07:45 -07006116 return 0;
6117
Alexander Duyckac802f52012-07-12 05:52:53 +00006118err_set_queues:
6119 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006120err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006121 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006122 if (hw->phy.ops.set_phy_power && !adapter->wol)
6123 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006124err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006125 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006126err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006127 ixgbe_reset(adapter);
6128
6129 return err;
6130}
6131
Jacob Kellera0cccce2014-05-16 05:12:29 +00006132static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6133{
6134 ixgbe_ptp_suspend(adapter);
6135
Don Skidmore6ac74392015-06-17 17:34:31 -04006136 if (adapter->hw.phy.ops.enter_lplu) {
6137 adapter->hw.phy.reset_disable = true;
6138 ixgbe_down(adapter);
6139 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6140 adapter->hw.phy.reset_disable = false;
6141 } else {
6142 ixgbe_down(adapter);
6143 }
6144
Jacob Kellera0cccce2014-05-16 05:12:29 +00006145 ixgbe_free_irq(adapter);
6146
6147 ixgbe_free_all_tx_resources(adapter);
6148 ixgbe_free_all_rx_resources(adapter);
6149}
6150
Auke Kok9a799d72007-09-15 14:07:45 -07006151/**
6152 * ixgbe_close - Disables a network interface
6153 * @netdev: network interface device structure
6154 *
6155 * Returns 0, this is not allowed to fail
6156 *
6157 * The close entry point is called when an interface is de-activated
6158 * by the OS. The hardware is still under the drivers control, but
6159 * needs to be disabled. A global MAC reset is issued to stop the
6160 * hardware, and all transmit and receive resources are freed.
6161 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006162int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006163{
6164 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006165
Jacob Keller1a71ab22012-08-25 03:54:19 +00006166 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006167
Jacob Kellera0cccce2014-05-16 05:12:29 +00006168 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006169
Alexander Duycke4911d52011-05-11 07:18:52 +00006170 ixgbe_fdir_filter_exit(adapter);
6171
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006172 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006173
6174 return 0;
6175}
6176
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006177#ifdef CONFIG_PM
6178static int ixgbe_resume(struct pci_dev *pdev)
6179{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006180 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6181 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006182 u32 err;
6183
Mark Rustad0391bbe2014-02-28 15:48:55 -08006184 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006185 pci_set_power_state(pdev, PCI_D0);
6186 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006187 /*
6188 * pci_restore_state clears dev->state_saved so call
6189 * pci_save_state to restore it.
6190 */
6191 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006192
6193 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006194 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006195 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006196 return err;
6197 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006198 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006199 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006200 pci_set_master(pdev);
6201
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006202 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006203
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006204 ixgbe_reset(adapter);
6205
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006206 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6207
Alexander Duyckac802f52012-07-12 05:52:53 +00006208 rtnl_lock();
6209 err = ixgbe_init_interrupt_scheme(adapter);
6210 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006211 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006212
6213 rtnl_unlock();
6214
6215 if (err)
6216 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006217
6218 netif_device_attach(netdev);
6219
6220 return 0;
6221}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006222#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006223
6224static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006225{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006226 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6227 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006228 struct ixgbe_hw *hw = &adapter->hw;
6229 u32 ctrl, fctrl;
6230 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006231#ifdef CONFIG_PM
6232 int retval = 0;
6233#endif
6234
6235 netif_device_detach(netdev);
6236
akepner499ab5c2013-03-13 14:54:58 +00006237 rtnl_lock();
Jacob Kellera0cccce2014-05-16 05:12:29 +00006238 if (netif_running(netdev))
6239 ixgbe_close_suspend(adapter);
akepner499ab5c2013-03-13 14:54:58 +00006240 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006241
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006242 ixgbe_clear_interrupt_scheme(adapter);
6243
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006244#ifdef CONFIG_PM
6245 retval = pci_save_state(pdev);
6246 if (retval)
6247 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006248
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006249#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006250 if (hw->mac.ops.stop_link_on_d3)
6251 hw->mac.ops.stop_link_on_d3(hw);
6252
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006253 if (wufc) {
6254 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006255
Emil Tantilovec74a472012-09-20 03:33:56 +00006256 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6257 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006258 hw->mac.ops.enable_tx_laser(hw);
6259
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006260 /* turn on all-multi mode if wake on multicast is enabled */
6261 if (wufc & IXGBE_WUFC_MC) {
6262 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6263 fctrl |= IXGBE_FCTRL_MPE;
6264 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
6265 }
6266
6267 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6268 ctrl |= IXGBE_CTRL_GIO_DIS;
6269 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6270
6271 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6272 } else {
6273 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6274 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6275 }
6276
Alexander Duyckbd508172010-11-16 19:27:03 -08006277 switch (hw->mac.type) {
6278 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006279 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006280 break;
6281 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006282 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006283 case ixgbe_mac_X550:
6284 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006285 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006286 pci_wake_from_d3(pdev, !!wufc);
6287 break;
6288 default:
6289 break;
6290 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006291
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006292 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006293 if (hw->phy.ops.set_phy_power && !*enable_wake)
6294 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006295
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006296 ixgbe_release_hw_control(adapter);
6297
Mark Rustad41c62842014-03-12 00:38:35 +00006298 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6299 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006300
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006301 return 0;
6302}
6303
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006304#ifdef CONFIG_PM
6305static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6306{
6307 int retval;
6308 bool wake;
6309
6310 retval = __ixgbe_shutdown(pdev, &wake);
6311 if (retval)
6312 return retval;
6313
6314 if (wake) {
6315 pci_prepare_to_sleep(pdev);
6316 } else {
6317 pci_wake_from_d3(pdev, false);
6318 pci_set_power_state(pdev, PCI_D3hot);
6319 }
6320
6321 return 0;
6322}
6323#endif /* CONFIG_PM */
6324
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006325static void ixgbe_shutdown(struct pci_dev *pdev)
6326{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006327 bool wake;
6328
6329 __ixgbe_shutdown(pdev, &wake);
6330
6331 if (system_state == SYSTEM_POWER_OFF) {
6332 pci_wake_from_d3(pdev, wake);
6333 pci_set_power_state(pdev, PCI_D3hot);
6334 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006335}
6336
6337/**
Auke Kok9a799d72007-09-15 14:07:45 -07006338 * ixgbe_update_stats - Update the board statistics counters.
6339 * @adapter: board private structure
6340 **/
6341void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6342{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006343 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006344 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006345 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006346 u64 total_mpc = 0;
6347 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006348 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6349 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006350 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006351
Don Skidmored08935c2010-06-11 13:20:29 +00006352 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6353 test_bit(__IXGBE_RESETTING, &adapter->state))
6354 return;
6355
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006356 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006357 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006358 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006359 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006360 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6361 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006362 }
6363 adapter->rsc_total_count = rsc_count;
6364 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006365 }
6366
Alexander Duyck5b7da512010-11-16 19:26:50 -08006367 for (i = 0; i < adapter->num_rx_queues; i++) {
6368 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6369 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
6370 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6371 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006372 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006373 bytes += rx_ring->stats.bytes;
6374 packets += rx_ring->stats.packets;
6375 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006376 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006377 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6378 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006379 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006380 netdev->stats.rx_bytes = bytes;
6381 netdev->stats.rx_packets = packets;
6382
6383 bytes = 0;
6384 packets = 0;
6385 /* gather some stats to the adapter struct that are per queue */
6386 for (i = 0; i < adapter->num_tx_queues; i++) {
6387 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6388 restart_queue += tx_ring->tx_stats.restart_queue;
6389 tx_busy += tx_ring->tx_stats.tx_busy;
6390 bytes += tx_ring->stats.bytes;
6391 packets += tx_ring->stats.packets;
6392 }
6393 adapter->restart_queue = restart_queue;
6394 adapter->tx_busy = tx_busy;
6395 netdev->stats.tx_bytes = bytes;
6396 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006397
Joe Perches7ca647b2010-09-07 21:35:40 +00006398 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006399
6400 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006401 for (i = 0; i < 8; i++) {
6402 /* for packet buffers not used, the register should read 0 */
6403 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6404 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006405 hwstats->mpc[i] += mpc;
6406 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006407 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6408 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006409 switch (hw->mac.type) {
6410 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006411 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6412 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6413 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006414 hwstats->pxonrxc[i] +=
6415 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006416 break;
6417 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006418 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006419 case ixgbe_mac_X550:
6420 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006421 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006422 hwstats->pxonrxc[i] +=
6423 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006424 break;
6425 default:
6426 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006427 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006428 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006429
6430 /*16 register reads */
6431 for (i = 0; i < 16; i++) {
6432 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6433 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6434 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006435 (hw->mac.type == ixgbe_mac_X540) ||
6436 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006437 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6438 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006439 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6440 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6441 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6442 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6443 }
6444 }
6445
Joe Perches7ca647b2010-09-07 21:35:40 +00006446 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006447 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006448 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006449
John Fastabendc84d3242010-11-16 19:27:12 -08006450 ixgbe_update_xoff_received(adapter);
6451
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006452 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006453 switch (hw->mac.type) {
6454 case ixgbe_mac_82598EB:
6455 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006456 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6457 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6458 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6459 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006460 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006461 case ixgbe_mac_X550:
6462 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006463 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006464 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006465 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6466 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6467 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6468 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6469 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006470 for (i = 0; i < 16; i++)
6471 adapter->hw_rx_no_dma_resources +=
6472 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006473 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006474 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006475 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006476 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006477 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006478 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006479 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006480 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6481 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006482#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006483 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6484 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6485 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6486 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6487 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6488 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006489 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006490 if (adapter->fcoe.ddp_pool) {
6491 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6492 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6493 unsigned int cpu;
6494 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006495 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006496 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6497 noddp += ddp_pool->noddp;
6498 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006499 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006500 hwstats->fcoe_noddp = noddp;
6501 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006502 }
Yi Zou6d455222009-05-13 13:12:16 +00006503#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006504 break;
6505 default:
6506 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006507 }
Auke Kok9a799d72007-09-15 14:07:45 -07006508 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006509 hwstats->bprc += bprc;
6510 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006511 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006512 hwstats->mprc -= bprc;
6513 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6514 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6515 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6516 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6517 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6518 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6519 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6520 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006521 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006522 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006523 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006524 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006525 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6526 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006527 /*
6528 * 82598 errata - tx of flow control packets is included in tx counters
6529 */
6530 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006531 hwstats->gptc -= xon_off_tot;
6532 hwstats->mptc -= xon_off_tot;
6533 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6534 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6535 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6536 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6537 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6538 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6539 hwstats->ptc64 -= xon_off_tot;
6540 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6541 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6542 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6543 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6544 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6545 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006546
6547 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006548 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006549
6550 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006551 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006552 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006553 netdev->stats.rx_length_errors = hwstats->rlec;
6554 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006555 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006556}
6557
6558/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006559 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006560 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006561 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006562static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006563{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006564 struct ixgbe_hw *hw = &adapter->hw;
6565 int i;
6566
Alexander Duyckd034acf2011-04-27 09:25:34 +00006567 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6568 return;
6569
6570 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6571
6572 /* if interface is down do nothing */
6573 if (test_bit(__IXGBE_DOWN, &adapter->state))
6574 return;
6575
6576 /* do nothing if we are not using signature filters */
6577 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6578 return;
6579
6580 adapter->fdir_overflow++;
6581
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006582 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6583 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006584 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00006585 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006586 /* re-enable flow director interrupts */
6587 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006588 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006589 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006590 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006591 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006592}
6593
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006594/**
6595 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006596 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006597 *
6598 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006599 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006600 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006601 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006602 */
6603static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6604{
Auke Kok9a799d72007-09-15 14:07:45 -07006605 struct ixgbe_hw *hw = &adapter->hw;
6606 u64 eics = 0;
6607 int i;
6608
Mark Rustad09f40ae2014-01-14 18:53:11 -08006609 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006610 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006611 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006612 test_bit(__IXGBE_RESETTING, &adapter->state))
6613 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006614
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006615 /* Force detection of hung controller */
6616 if (netif_carrier_ok(adapter->netdev)) {
6617 for (i = 0; i < adapter->num_tx_queues; i++)
6618 set_check_for_tx_hang(adapter->tx_ring[i]);
6619 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006620
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006621 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006622 /*
6623 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006624 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006625 * would set *both* EIMS and EICS for any bit in EIAM
6626 */
6627 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6628 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006629 } else {
6630 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006631 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006632 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006633 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006634 eics |= ((u64)1 << i);
6635 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006636 }
6637
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006638 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006639 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00006640}
6641
6642/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006643 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006644 * @adapter: pointer to the device adapter structure
6645 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006646 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006647static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006648{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006649 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006650 u32 link_speed = adapter->link_speed;
6651 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006652 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006653
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006654 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6655 return;
6656
6657 if (hw->mac.ops.check_link) {
6658 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006659 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006660 /* always assume link is up, if no check link function */
6661 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6662 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006663 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006664
6665 if (adapter->ixgbe_ieee_pfc)
6666 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6667
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006668 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006669 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006670 ixgbe_set_rx_drop_en(adapter);
6671 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006672
6673 if (link_up ||
6674 time_after(jiffies, (adapter->link_check_timeout +
6675 IXGBE_TRY_LINK_TIMEOUT))) {
6676 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6677 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6678 IXGBE_WRITE_FLUSH(hw);
6679 }
6680
6681 adapter->link_up = link_up;
6682 adapter->link_speed = link_speed;
6683}
6684
Alexander Duyck107d3012012-10-02 00:17:03 +00006685static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6686{
6687#ifdef CONFIG_IXGBE_DCB
6688 struct net_device *netdev = adapter->netdev;
6689 struct dcb_app app = {
6690 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6691 .protocol = 0,
6692 };
6693 u8 up = 0;
6694
6695 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6696 up = dcb_ieee_getapp_mask(netdev, &app);
6697
6698 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6699#endif
6700}
6701
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006702/**
6703 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6704 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006705 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006706 **/
6707static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6708{
6709 struct net_device *netdev = adapter->netdev;
6710 struct ixgbe_hw *hw = &adapter->hw;
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006711 struct net_device *upper;
6712 struct list_head *iter;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006713 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07006714 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006715 bool flow_rx, flow_tx;
6716
6717 /* only continue if link was previously down */
6718 if (netif_carrier_ok(netdev))
6719 return;
6720
6721 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6722
6723 switch (hw->mac.type) {
6724 case ixgbe_mac_82598EB: {
6725 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6726 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6727 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6728 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6729 }
6730 break;
6731 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006732 case ixgbe_mac_X550:
6733 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006734 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006735 case ixgbe_mac_82599EB: {
6736 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6737 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6738 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6739 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6740 }
6741 break;
6742 default:
6743 flow_tx = false;
6744 flow_rx = false;
6745 break;
6746 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006747
Jacob Keller6cb562d2012-12-05 07:24:41 +00006748 adapter->last_rx_ptp_check = jiffies;
6749
Jacob Keller8fecf672013-06-21 08:14:32 +00006750 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006751 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006752
Mark Rustad454adb02015-07-10 14:19:22 -07006753 switch (link_speed) {
6754 case IXGBE_LINK_SPEED_10GB_FULL:
6755 speed_str = "10 Gbps";
6756 break;
6757 case IXGBE_LINK_SPEED_2_5GB_FULL:
6758 speed_str = "2.5 Gbps";
6759 break;
6760 case IXGBE_LINK_SPEED_1GB_FULL:
6761 speed_str = "1 Gbps";
6762 break;
6763 case IXGBE_LINK_SPEED_100_FULL:
6764 speed_str = "100 Mbps";
6765 break;
6766 default:
6767 speed_str = "unknown speed";
6768 break;
6769 }
6770 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006771 ((flow_rx && flow_tx) ? "RX/TX" :
6772 (flow_rx ? "RX" :
6773 (flow_tx ? "TX" : "None"))));
6774
6775 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006776 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006777
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006778 /* enable transmits */
6779 netif_tx_wake_all_queues(adapter->netdev);
6780
6781 /* enable any upper devices */
6782 rtnl_lock();
6783 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
6784 if (netif_is_macvlan(upper)) {
6785 struct macvlan_dev *vlan = netdev_priv(upper);
6786
6787 if (vlan->fwd_priv)
6788 netif_tx_wake_all_queues(upper);
6789 }
6790 }
6791 rtnl_unlock();
6792
Alexander Duyck107d3012012-10-02 00:17:03 +00006793 /* update the default user priority for VFs */
6794 ixgbe_update_default_up(adapter);
6795
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006796 /* ping all the active vfs to let them know link has changed */
6797 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006798}
6799
6800/**
6801 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6802 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006803 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006804 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00006805static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006806{
6807 struct net_device *netdev = adapter->netdev;
6808 struct ixgbe_hw *hw = &adapter->hw;
6809
6810 adapter->link_up = false;
6811 adapter->link_speed = 0;
6812
6813 /* only continue if link was up previously */
6814 if (!netif_carrier_ok(netdev))
6815 return;
6816
6817 /* poll for SFP+ cable when link is down */
6818 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6819 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6820
Jacob Keller8fecf672013-06-21 08:14:32 +00006821 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006822 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006823
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006824 e_info(drv, "NIC Link is Down\n");
6825 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006826
6827 /* ping all the active vfs to let them know link has changed */
6828 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006829}
6830
Emil Tantilov07923c12014-08-12 07:12:08 +00006831static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
6832{
6833 int i;
6834
6835 for (i = 0; i < adapter->num_tx_queues; i++) {
6836 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6837
6838 if (tx_ring->next_to_use != tx_ring->next_to_clean)
6839 return true;
6840 }
6841
6842 return false;
6843}
6844
6845static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
6846{
6847 struct ixgbe_hw *hw = &adapter->hw;
6848 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
6849 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
6850
6851 int i, j;
6852
6853 if (!adapter->num_vfs)
6854 return false;
6855
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006856 /* resetting the PF is only needed for MAC before X550 */
6857 if (hw->mac.type >= ixgbe_mac_X550)
6858 return false;
6859
Emil Tantilov07923c12014-08-12 07:12:08 +00006860 for (i = 0; i < adapter->num_vfs; i++) {
6861 for (j = 0; j < q_per_pool; j++) {
6862 u32 h, t;
6863
6864 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
6865 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
6866
6867 if (h != t)
6868 return true;
6869 }
6870 }
6871
6872 return false;
6873}
6874
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006875/**
6876 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006877 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006878 **/
6879static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6880{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006881 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00006882 if (ixgbe_ring_tx_pending(adapter) ||
6883 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006884 /* We've lost link, so the controller stops DMA,
6885 * but we've got queued Tx work that's never going
6886 * to get done, so reset controller to flush Tx.
6887 * (Do the reset outside of interrupt context).
6888 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00006889 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006890 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006891 }
6892 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006893}
6894
Emil Tantilov9079e412014-11-19 03:18:19 +00006895#ifdef CONFIG_PCI_IOV
6896static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
6897 struct pci_dev *vfdev)
6898{
6899 if (!pci_wait_for_pending_transaction(vfdev))
6900 e_dev_warn("Issuing VFLR with pending transactions\n");
6901
6902 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
6903 pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
6904
6905 msleep(100);
6906}
6907
6908static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6909{
6910 struct ixgbe_hw *hw = &adapter->hw;
6911 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07006912 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00006913 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00006914
6915 if (!(netif_carrier_ok(adapter->netdev)))
6916 return;
6917
6918 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6919 if (gpc) /* If incrementing then no need for the check below */
6920 return;
6921 /* Check to see if a bad DMA write target from an errant or
6922 * malicious VF has caused a PCIe error. If so then we can
6923 * issue a VFLR to the offending VF(s) and then resume without
6924 * requesting a full slot reset.
6925 */
6926
6927 if (!pdev)
6928 return;
6929
Emil Tantilov9079e412014-11-19 03:18:19 +00006930 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07006931 for (vf = 0; vf < adapter->num_vfs; ++vf) {
6932 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
6933 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00006934
Mark Rustad988d1302015-10-30 15:29:34 -07006935 if (!vfdev)
6936 continue;
6937 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
6938 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
6939 status_reg & PCI_STATUS_REC_MASTER_ABORT)
6940 ixgbe_issue_vf_flr(adapter, vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00006941 }
6942}
6943
Greg Rosea985b6c32010-11-18 03:02:52 +00006944static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6945{
6946 u32 ssvpc;
6947
Greg Rose0584d992012-08-08 00:00:58 +00006948 /* Do not perform spoof check for 82598 or if not in IOV mode */
6949 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
6950 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00006951 return;
6952
6953 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6954
6955 /*
6956 * ssvpc register is cleared on read, if zero then no
6957 * spoofed packets in the last interval.
6958 */
6959 if (!ssvpc)
6960 return;
6961
Emil Tantilovd6ea0752012-08-08 06:28:37 +00006962 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00006963}
Emil Tantilov9079e412014-11-19 03:18:19 +00006964#else
6965static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
6966{
6967}
6968
6969static void
6970ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
6971{
6972}
6973#endif /* CONFIG_PCI_IOV */
6974
Greg Rosea985b6c32010-11-18 03:02:52 +00006975
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006976/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006977 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006978 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006979 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006980static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006981{
Mark Rustad09f40ae2014-01-14 18:53:11 -08006982 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006983 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006984 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00006985 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006986 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006987
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006988 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006989
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006990 if (adapter->link_up)
6991 ixgbe_watchdog_link_is_up(adapter);
6992 else
6993 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006994
Emil Tantilov9079e412014-11-19 03:18:19 +00006995 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00006996 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006997 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006998
6999 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007000}
7001
Alexander Duyck70864002011-04-27 09:13:56 +00007002/**
7003 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007004 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007005 **/
7006static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7007{
7008 struct ixgbe_hw *hw = &adapter->hw;
7009 s32 err;
7010
7011 /* not searching for SFP so there is nothing to do here */
7012 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7013 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7014 return;
7015
Mark Rustad58e7cd22015-08-08 16:18:48 -07007016 if (adapter->sfp_poll_time &&
7017 time_after(adapter->sfp_poll_time, jiffies))
7018 return; /* If not yet time to poll for SFP */
7019
Alexander Duyck70864002011-04-27 09:13:56 +00007020 /* someone else is in init, wait until next service event */
7021 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7022 return;
7023
Mark Rustad58e7cd22015-08-08 16:18:48 -07007024 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7025
Alexander Duyck70864002011-04-27 09:13:56 +00007026 err = hw->phy.ops.identify_sfp(hw);
7027 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7028 goto sfp_out;
7029
7030 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7031 /* If no cable is present, then we need to reset
7032 * the next time we find a good cable. */
7033 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7034 }
7035
7036 /* exit on error */
7037 if (err)
7038 goto sfp_out;
7039
7040 /* exit if reset not needed */
7041 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7042 goto sfp_out;
7043
7044 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7045
7046 /*
7047 * A module may be identified correctly, but the EEPROM may not have
7048 * support for that module. setup_sfp() will fail in that case, so
7049 * we should not allow that module to load.
7050 */
7051 if (hw->mac.type == ixgbe_mac_82598EB)
7052 err = hw->phy.ops.reset(hw);
7053 else
7054 err = hw->mac.ops.setup_sfp(hw);
7055
7056 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7057 goto sfp_out;
7058
7059 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7060 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7061
7062sfp_out:
7063 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7064
7065 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7066 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7067 e_dev_err("failed to initialize because an unsupported "
7068 "SFP+ module type was detected.\n");
7069 e_dev_err("Reload the driver after installing a "
7070 "supported module.\n");
7071 unregister_netdev(adapter->netdev);
7072 }
7073}
7074
7075/**
7076 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007077 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007078 **/
7079static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7080{
7081 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00007082 u32 speed;
7083 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007084
7085 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7086 return;
7087
7088 /* someone else is in init, wait until next service event */
7089 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7090 return;
7091
7092 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7093
Josh Hay3d292262012-12-15 03:28:19 +00007094 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00007095 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00007096 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007097
7098 /* setup the highest link when no autoneg */
7099 if (!autoneg) {
7100 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
7101 speed = IXGBE_LINK_SPEED_10GB_FULL;
7102 }
7103 }
7104
Alexander Duyck70864002011-04-27 09:13:56 +00007105 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007106 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007107
7108 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7109 adapter->link_check_timeout = jiffies;
7110 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7111}
7112
7113/**
7114 * ixgbe_service_timer - Timer Call-back
7115 * @data: pointer to adapter cast into an unsigned long
7116 **/
7117static void ixgbe_service_timer(unsigned long data)
7118{
7119 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
7120 unsigned long next_event_offset;
7121
7122 /* poll faster when waiting for link */
7123 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7124 next_event_offset = HZ / 10;
7125 else
7126 next_event_offset = HZ * 2;
7127
7128 /* Reset the timer */
7129 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7130
Emil Tantilov9079e412014-11-19 03:18:19 +00007131 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007132}
7133
Don Skidmore597f22d2015-06-09 16:52:02 -07007134static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7135{
7136 struct ixgbe_hw *hw = &adapter->hw;
7137 u32 status;
7138
7139 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7140 return;
7141
7142 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7143
7144 if (!hw->phy.ops.handle_lasi)
7145 return;
7146
7147 status = hw->phy.ops.handle_lasi(&adapter->hw);
7148 if (status != IXGBE_ERR_OVERTEMP)
7149 return;
7150
7151 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7152}
7153
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007154static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7155{
7156 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
7157 return;
7158
7159 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
7160
Mark Rustad09f40ae2014-01-14 18:53:11 -08007161 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007162 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007163 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007164 test_bit(__IXGBE_RESETTING, &adapter->state))
7165 return;
7166
7167 ixgbe_dump(adapter);
7168 netdev_err(adapter->netdev, "Reset adapter\n");
7169 adapter->tx_timeout_count++;
7170
John Fastabend8f4c5c92014-01-16 02:30:05 -08007171 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007172 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007173 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007174}
7175
Alexander Duyck70864002011-04-27 09:13:56 +00007176/**
7177 * ixgbe_service_task - manages and runs subtasks
7178 * @work: pointer to work_struct containing our data
7179 **/
7180static void ixgbe_service_task(struct work_struct *work)
7181{
7182 struct ixgbe_adapter *adapter = container_of(work,
7183 struct ixgbe_adapter,
7184 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007185 if (ixgbe_removed(adapter->hw.hw_addr)) {
7186 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7187 rtnl_lock();
7188 ixgbe_down(adapter);
7189 rtnl_unlock();
7190 }
7191 ixgbe_service_event_complete(adapter);
7192 return;
7193 }
Mark Rustad67359c32015-06-15 11:33:25 -07007194#ifdef CONFIG_IXGBE_VXLAN
7195 if (adapter->flags2 & IXGBE_FLAG2_VXLAN_REREG_NEEDED) {
7196 adapter->flags2 &= ~IXGBE_FLAG2_VXLAN_REREG_NEEDED;
7197 vxlan_get_rx_port(adapter->netdev);
7198 }
7199#endif /* CONFIG_IXGBE_VXLAN */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007200 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007201 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007202 ixgbe_sfp_detection_subtask(adapter);
7203 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007204 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007205 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007206 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007207 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007208
Jacob Keller8fecf672013-06-21 08:14:32 +00007209 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007210 ixgbe_ptp_overflow_check(adapter);
7211 ixgbe_ptp_rx_hang(adapter);
7212 }
Alexander Duyck70864002011-04-27 09:13:56 +00007213
7214 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007215}
7216
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007217static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7218 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007219 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007220{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007221 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007222 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007223 u32 mss_l4len_idx, l4len;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007224 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007225
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007226 if (skb->ip_summed != CHECKSUM_PARTIAL)
7227 return 0;
7228
Alexander Duyck897ab152011-05-27 05:31:47 +00007229 if (!skb_is_gso(skb))
7230 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007231
Francois Romieu2049e1f2014-03-30 03:14:27 +00007232 err = skb_cow_head(skb, 0);
7233 if (err < 0)
7234 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007235
Alexander Duyck897ab152011-05-27 05:31:47 +00007236 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7237 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7238
Joe Perchesa1108ff2014-03-13 05:19:25 +00007239 if (first->protocol == htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007240 struct iphdr *iph = ip_hdr(skb);
7241 iph->tot_len = 0;
7242 iph->check = 0;
7243 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
7244 iph->daddr, 0,
7245 IPPROTO_TCP,
7246 0);
7247 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007248 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7249 IXGBE_TX_FLAGS_CSUM |
7250 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00007251 } else if (skb_is_gso_v6(skb)) {
7252 ipv6_hdr(skb)->payload_len = 0;
7253 tcp_hdr(skb)->check =
7254 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
7255 &ipv6_hdr(skb)->daddr,
7256 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00007257 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7258 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007259 }
7260
Alexander Duyck091a6242012-02-08 07:51:01 +00007261 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00007262 l4len = tcp_hdrlen(skb);
7263 *hdr_len = skb_transport_offset(skb) + l4len;
7264
Alexander Duyck091a6242012-02-08 07:51:01 +00007265 /* update gso size and bytecount with header size */
7266 first->gso_segs = skb_shinfo(skb)->gso_segs;
7267 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7268
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007269 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00007270 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
7271 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007272
7273 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
7274 vlan_macip_lens = skb_network_header_len(skb);
7275 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007276 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007277
7278 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007279 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007280
7281 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007282}
7283
Alexander Duyck49763de2016-01-13 07:31:11 -08007284static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7285{
7286 unsigned int offset = 0;
7287
7288 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7289
7290 return offset == skb_checksum_start_offset(skb);
7291}
7292
Alexander Duyck244e27a2012-02-08 07:51:11 +00007293static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7294 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007295{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007296 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007297 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007298 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007299
Alexander Duyck897ab152011-05-27 05:31:47 +00007300 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007301csum_failed:
7302 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7303 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007304 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007305 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007306 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007307
Alexander Duyck49763de2016-01-13 07:31:11 -08007308 switch (skb->csum_offset) {
7309 case offsetof(struct tcphdr, check):
7310 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7311 /* fall through */
7312 case offsetof(struct udphdr, check):
7313 break;
7314 case offsetof(struct sctphdr, checksum):
7315 /* validate that this is actually an SCTP request */
7316 if (((first->protocol == htons(ETH_P_IP)) &&
7317 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7318 ((first->protocol == htons(ETH_P_IPV6)) &&
7319 ixgbe_ipv6_csum_is_sctp(skb))) {
7320 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7321 break;
7322 }
7323 /* fall through */
7324 default:
7325 skb_checksum_help(skb);
7326 goto csum_failed;
7327 }
7328
7329 /* update TX checksum flag */
7330 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7331 vlan_macip_lens = skb_checksum_start_offset(skb) -
7332 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007333no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007334 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007335 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007336 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007337
Alexander Duyck49763de2016-01-13 07:31:11 -08007338 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007339}
7340
Alexander Duyck472148c2012-11-07 02:34:28 +00007341#define IXGBE_SET_FLAG(_input, _flag, _result) \
7342 ((_flag <= _result) ? \
7343 ((u32)(_input & _flag) * (_result / _flag)) : \
7344 ((u32)(_input & _flag) / (_flag / _result)))
7345
7346static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007347{
7348 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007349 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7350 IXGBE_ADVTXD_DCMD_DEXT |
7351 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007352
7353 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007354 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7355 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007356
Alexander Duyckd3d00232011-07-15 02:31:25 +00007357 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007358 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7359 IXGBE_ADVTXD_DCMD_TSE);
7360
7361 /* set timestamp bit if present */
7362 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7363 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007364
Alexander Duyck62748b72012-07-20 08:09:01 +00007365 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007366 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007367
Alexander Duyckd3d00232011-07-15 02:31:25 +00007368 return cmd_type;
7369}
7370
Alexander Duyck729739b2012-02-08 07:51:06 +00007371static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7372 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007373{
Alexander Duyck472148c2012-11-07 02:34:28 +00007374 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007375
7376 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007377 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7378 IXGBE_TX_FLAGS_CSUM,
7379 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007380
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007381 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007382 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7383 IXGBE_TX_FLAGS_IPV4,
7384 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007385
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007386 /*
7387 * Check Context must be set if Tx switch is enabled, which it
7388 * always is for case where virtual functions are running
7389 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007390 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7391 IXGBE_TX_FLAGS_CC,
7392 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007393
Alexander Duyck472148c2012-11-07 02:34:28 +00007394 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007395}
7396
Daniel Borkmann2367a172014-08-26 19:34:18 +02007397static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7398{
7399 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7400
7401 /* Herbert's original patch had:
7402 * smp_mb__after_netif_stop_queue();
7403 * but since that doesn't exist yet, just open code it.
7404 */
7405 smp_mb();
7406
7407 /* We need to check again in a case another CPU has just
7408 * made room available.
7409 */
7410 if (likely(ixgbe_desc_unused(tx_ring) < size))
7411 return -EBUSY;
7412
7413 /* A reprieve! - use start_queue because it doesn't call schedule */
7414 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7415 ++tx_ring->tx_stats.restart_queue;
7416 return 0;
7417}
7418
7419static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7420{
7421 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7422 return 0;
7423
7424 return __ixgbe_maybe_stop_tx(tx_ring, size);
7425}
7426
Alexander Duyckd3d00232011-07-15 02:31:25 +00007427#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7428 IXGBE_TXD_CMD_RS)
7429
7430static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007431 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007432 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007433{
Alexander Duyck729739b2012-02-08 07:51:06 +00007434 struct sk_buff *skb = first->skb;
7435 struct ixgbe_tx_buffer *tx_buffer;
7436 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007437 struct skb_frag_struct *frag;
7438 dma_addr_t dma;
7439 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007440 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007441 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007442 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007443
Alexander Duyck729739b2012-02-08 07:51:06 +00007444 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7445
Alexander Duyckec718252012-10-30 06:01:55 +00007446 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7447
7448 size = skb_headlen(skb);
7449 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007450
Alexander Duyckd3d00232011-07-15 02:31:25 +00007451#ifdef IXGBE_FCOE
7452 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007453 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007454 size -= sizeof(struct fcoe_crc_eof) - data_len;
7455 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007456 } else {
7457 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007458 }
Auke Kok9a799d72007-09-15 14:07:45 -07007459 }
7460
Alexander Duyckd3d00232011-07-15 02:31:25 +00007461#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007462 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007463
Alexander Duyckec718252012-10-30 06:01:55 +00007464 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007465
Alexander Duyckec718252012-10-30 06:01:55 +00007466 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7467 if (dma_mapping_error(tx_ring->dev, dma))
7468 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007469
Alexander Duyckec718252012-10-30 06:01:55 +00007470 /* record length, and DMA address */
7471 dma_unmap_len_set(tx_buffer, len, size);
7472 dma_unmap_addr_set(tx_buffer, dma, dma);
7473
7474 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7475
Alexander Duyck729739b2012-02-08 07:51:06 +00007476 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007477 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007478 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007479
Alexander Duyckd3d00232011-07-15 02:31:25 +00007480 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007481 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007482 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007483 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007484 i = 0;
7485 }
Alexander Duyckec718252012-10-30 06:01:55 +00007486 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007487
7488 dma += IXGBE_MAX_DATA_PER_TXD;
7489 size -= IXGBE_MAX_DATA_PER_TXD;
7490
7491 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007492 }
7493
Alexander Duyck729739b2012-02-08 07:51:06 +00007494 if (likely(!data_len))
7495 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007496
Alexander Duyck472148c2012-11-07 02:34:28 +00007497 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007498
Alexander Duyck729739b2012-02-08 07:51:06 +00007499 i++;
7500 tx_desc++;
7501 if (i == tx_ring->count) {
7502 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7503 i = 0;
7504 }
Alexander Duyckec718252012-10-30 06:01:55 +00007505 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007506
Alexander Duyckd3d00232011-07-15 02:31:25 +00007507#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007508 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007509#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007510 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007511#endif
7512 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007513
Alexander Duyck729739b2012-02-08 07:51:06 +00007514 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7515 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007516
Alexander Duyck729739b2012-02-08 07:51:06 +00007517 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007518 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007519
Alexander Duyck729739b2012-02-08 07:51:06 +00007520 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007521 cmd_type |= size | IXGBE_TXD_CMD;
7522 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007523
Alexander Duyck091a6242012-02-08 07:51:01 +00007524 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007525
Alexander Duyckd3d00232011-07-15 02:31:25 +00007526 /* set the timestamp */
7527 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007528
7529 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007530 * Force memory writes to complete before letting h/w know there
7531 * are new descriptors to fetch. (Only applicable for weak-ordered
7532 * memory model archs, such as IA-64).
7533 *
7534 * We also need this memory barrier to make certain all of the
7535 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007536 */
7537 wmb();
7538
Alexander Duyckd3d00232011-07-15 02:31:25 +00007539 /* set next_to_watch value indicating a packet is present */
7540 first->next_to_watch = tx_desc;
7541
Alexander Duyck729739b2012-02-08 07:51:06 +00007542 i++;
7543 if (i == tx_ring->count)
7544 i = 0;
7545
7546 tx_ring->next_to_use = i;
7547
Daniel Borkmann2367a172014-08-26 19:34:18 +02007548 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7549
7550 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00007551 writel(i, tx_ring->tail);
7552
7553 /* we need this if more than one processor can write to our tail
7554 * at a time, it synchronizes IO on IA64/Altix systems
7555 */
7556 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02007557 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02007558
Alexander Duyckd3d00232011-07-15 02:31:25 +00007559 return;
7560dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00007561 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00007562
7563 /* clear dma mappings for failed tx_buffer_info map */
7564 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007565 tx_buffer = &tx_ring->tx_buffer_info[i];
7566 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
7567 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007568 break;
7569 if (i == 0)
7570 i = tx_ring->count;
7571 i--;
7572 }
7573
Alexander Duyckd3d00232011-07-15 02:31:25 +00007574 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07007575}
7576
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007577static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007578 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007579{
Alexander Duyck69830522011-01-06 14:29:58 +00007580 struct ixgbe_q_vector *q_vector = ring->q_vector;
7581 union ixgbe_atr_hash_dword input = { .dword = 0 };
7582 union ixgbe_atr_hash_dword common = { .dword = 0 };
7583 union {
7584 unsigned char *network;
7585 struct iphdr *ipv4;
7586 struct ipv6hdr *ipv6;
7587 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007588 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08007589 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07007590 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00007591 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08007592 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007593
Alexander Duyck69830522011-01-06 14:29:58 +00007594 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7595 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00007596 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007597
Alexander Duyck69830522011-01-06 14:29:58 +00007598 /* do nothing if sampling is disabled */
7599 if (!ring->atr_sample_rate)
7600 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007601
Alexander Duyck69830522011-01-06 14:29:58 +00007602 ring->atr_count++;
7603
Alexander Duycke2873d42016-01-25 19:39:40 -08007604 /* currently only IPv4/IPv6 with TCP is supported */
7605 if ((first->protocol != htons(ETH_P_IP)) &&
7606 (first->protocol != htons(ETH_P_IPV6)))
7607 return;
7608
Alexander Duyck69830522011-01-06 14:29:58 +00007609 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07007610 skb = first->skb;
7611 hdr.network = skb_network_header(skb);
Mark Rustad67359c32015-06-15 11:33:25 -07007612#ifdef CONFIG_IXGBE_VXLAN
Alexander Duyck9f12df92016-01-25 19:36:29 -08007613 if (skb->encapsulation &&
7614 first->protocol == htons(ETH_P_IP) &&
7615 hdr.ipv4->protocol != IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07007616 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00007617
Alexander Duyck9f12df92016-01-25 19:36:29 -08007618 /* verify the port is recognized as VXLAN */
7619 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08007620 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08007621 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08007622 }
Alexander Duyck9f12df92016-01-25 19:36:29 -08007623#endif /* CONFIG_IXGBE_VXLAN */
Mark Rustade19dcde2015-12-09 14:55:37 -08007624
7625 /* Currently only IPv4/IPv6 with TCP is supported */
7626 switch (hdr.ipv4->version) {
7627 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08007628 /* access ihl as u8 to avoid unaligned access on ia64 */
7629 hlen = (hdr.network[0] & 0x0F) << 2;
7630 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08007631 break;
7632 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08007633 hlen = hdr.network - skb->data;
7634 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
7635 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08007636 break;
7637 default:
7638 return;
Mark Rustad67359c32015-06-15 11:33:25 -07007639 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007640
Alexander Duycke2873d42016-01-25 19:39:40 -08007641 if (l4_proto != IPPROTO_TCP)
7642 return;
7643
7644 th = (struct tcphdr *)(hdr.network + hlen);
7645
7646 /* skip this packet since the socket is closing */
7647 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00007648 return;
7649
7650 /* sample on all syn packets or once every atr sample count */
7651 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
7652 return;
7653
7654 /* reset sample count */
7655 ring->atr_count = 0;
7656
Alexander Duyck244e27a2012-02-08 07:51:11 +00007657 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00007658
7659 /*
7660 * src and dst are inverted, think how the receiver sees them
7661 *
7662 * The input is broken into two sections, a non-compressed section
7663 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7664 * is XORed together and stored in the compressed dword.
7665 */
7666 input.formatted.vlan_id = vlan_id;
7667
7668 /*
7669 * since src port and flex bytes occupy the same word XOR them together
7670 * and write the value to source port portion of compressed dword
7671 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007672 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00007673 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00007674 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00007675 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00007676 common.port.dst ^= th->source;
7677
Mark Rustade19dcde2015-12-09 14:55:37 -08007678 switch (hdr.ipv4->version) {
7679 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00007680 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7681 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08007682 break;
7683 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00007684 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7685 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7686 hdr.ipv6->saddr.s6_addr32[1] ^
7687 hdr.ipv6->saddr.s6_addr32[2] ^
7688 hdr.ipv6->saddr.s6_addr32[3] ^
7689 hdr.ipv6->daddr.s6_addr32[0] ^
7690 hdr.ipv6->daddr.s6_addr32[1] ^
7691 hdr.ipv6->daddr.s6_addr32[2] ^
7692 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08007693 break;
7694 default:
7695 break;
Alexander Duyck69830522011-01-06 14:29:58 +00007696 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007697
Alexander Duyck9f12df92016-01-25 19:36:29 -08007698 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07007699 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07007700
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007701 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007702 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7703 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007704}
7705
Jason Wangf663dd92014-01-10 16:18:26 +08007706static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01007707 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007708{
Jason Wangf663dd92014-01-10 16:18:26 +08007709 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7710#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00007711 struct ixgbe_adapter *adapter;
7712 struct ixgbe_ring_feature *f;
7713 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08007714#endif
7715
7716 if (fwd_adapter)
7717 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7718
7719#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00007720
Alexander Duyck97488bd2013-01-12 06:33:37 +00007721 /*
7722 * only execute the code below if protocol is FCoE
7723 * or FIP and we have FCoE enabled on the adapter
7724 */
7725 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00007726 case htons(ETH_P_FCOE):
7727 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00007728 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00007729
Alexander Duyck97488bd2013-01-12 06:33:37 +00007730 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7731 break;
7732 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01007733 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007734 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007735
Alexander Duyck97488bd2013-01-12 06:33:37 +00007736 f = &adapter->ring_feature[RING_F_FCOE];
7737
7738 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7739 smp_processor_id();
7740
7741 while (txq >= f->indices)
7742 txq -= f->indices;
7743
7744 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08007745#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01007746 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08007747#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007748}
7749
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007750netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007751 struct ixgbe_adapter *adapter,
7752 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007753{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007754 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007755 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007756 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007757 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00007758 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007759 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007760 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007761
Alexander Duycka535c302011-05-27 05:31:52 +00007762 /*
7763 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007764 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007765 * + 2 desc gap to keep tail from touching head,
7766 * + 1 desc for context descriptor,
7767 * otherwise try next time
7768 */
Alexander Duycka535c302011-05-27 05:31:52 +00007769 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7770 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00007771
Alexander Duycka535c302011-05-27 05:31:52 +00007772 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7773 tx_ring->tx_stats.tx_busy++;
7774 return NETDEV_TX_BUSY;
7775 }
7776
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007777 /* record the location of the first descriptor for this packet */
7778 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7779 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00007780 first->bytecount = skb->len;
7781 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007782
Alexander Duyck66f32a82011-06-29 05:43:22 +00007783 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01007784 if (skb_vlan_tag_present(skb)) {
7785 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007786 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7787 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007788 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007789 struct vlan_hdr *vhdr, _vhdr;
7790 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7791 if (!vhdr)
7792 goto out_drop;
7793
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007794 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7795 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007796 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007797 }
Toshiaki Makita02136682015-01-29 20:37:09 +09007798 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00007799
Mark Rustadd5234932014-08-09 07:02:09 +00007800 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
7801 adapter->ptp_clock &&
7802 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
7803 &adapter->state)) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007804 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
7805 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00007806
7807 /* schedule check for Tx timestamp */
7808 adapter->ptp_tx_skb = skb_get(skb);
7809 adapter->ptp_tx_start = jiffies;
7810 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007811 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007812
Jakub Kicinskiff29a862014-03-15 14:55:16 +00007813 skb_tx_timestamp(skb);
7814
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007815#ifdef CONFIG_PCI_IOV
7816 /*
7817 * Use the l2switch_enable flag - would be false if the DMA
7818 * Tx switch had been disabled.
7819 */
7820 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00007821 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007822
7823#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007824 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007825 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007826 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7827 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007828 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007829 tx_flags |= (skb->priority & 0x7) <<
7830 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007831 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7832 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007833
7834 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00007835 goto out_drop;
7836 vhdr = (struct vlan_ethhdr *)skb->data;
7837 vhdr->h_vlan_TCI = htons(tx_flags >>
7838 IXGBE_TX_FLAGS_VLAN_SHIFT);
7839 } else {
7840 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7841 }
7842 }
Alexander Duycka535c302011-05-27 05:31:52 +00007843
Alexander Duyck244e27a2012-02-08 07:51:11 +00007844 /* record initial flags and protocol */
7845 first->tx_flags = tx_flags;
7846 first->protocol = protocol;
7847
Yi Zoueacd73f2009-05-13 13:11:06 +00007848#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007849 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007850 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00007851 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00007852 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00007853 if (tso < 0)
7854 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07007855
Alexander Duyck66f32a82011-06-29 05:43:22 +00007856 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007857 }
Auke Kok9a799d72007-09-15 14:07:45 -07007858
Auke Kok9a799d72007-09-15 14:07:45 -07007859#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007860 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007861 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007862 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007863 else if (!tso)
7864 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007865
7866 /* add the ATR filter if ATR is on */
7867 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00007868 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007869
7870#ifdef IXGBE_FCOE
7871xmit_fcoe:
7872#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007873 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007874
Auke Kok9a799d72007-09-15 14:07:45 -07007875 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007876
7877out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007878 dev_kfree_skb_any(first->skb);
7879 first->skb = NULL;
7880
Alexander Duyck897ab152011-05-27 05:31:47 +00007881 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007882}
7883
John Fastabend2a47fa42013-11-06 09:54:52 -08007884static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
7885 struct net_device *netdev,
7886 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007887{
7888 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007889 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07007890
Alexander Duycka50c29d2012-02-08 07:50:40 +00007891 /*
7892 * The minimum packet size for olinfo paylen is 17 so pad the skb
7893 * in order to meet this minimum size requirement.
7894 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08007895 if (skb_put_padto(skb, 17))
7896 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00007897
John Fastabend2a47fa42013-11-06 09:54:52 -08007898 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
7899
Auke Kok9a799d72007-09-15 14:07:45 -07007900 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7901}
7902
John Fastabend2a47fa42013-11-06 09:54:52 -08007903static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7904 struct net_device *netdev)
7905{
7906 return __ixgbe_xmit_frame(skb, netdev, NULL);
7907}
7908
Auke Kok9a799d72007-09-15 14:07:45 -07007909/**
7910 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7911 * @netdev: network interface device structure
7912 * @p: pointer to an address structure
7913 *
7914 * Returns 0 on success, negative on failure
7915 **/
7916static int ixgbe_set_mac(struct net_device *netdev, void *p)
7917{
7918 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7919 struct ixgbe_hw *hw = &adapter->hw;
7920 struct sockaddr *addr = p;
7921
7922 if (!is_valid_ether_addr(addr->sa_data))
7923 return -EADDRNOTAVAIL;
7924
7925 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007926 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007927
Alexander Duyckc9f53e62015-10-22 16:26:30 -07007928 ixgbe_mac_set_default_filter(adapter);
7929
7930 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007931}
7932
Ben Hutchings6b73e102009-04-29 08:08:58 +00007933static int
7934ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7935{
7936 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7937 struct ixgbe_hw *hw = &adapter->hw;
7938 u16 value;
7939 int rc;
7940
7941 if (prtad != hw->phy.mdio.prtad)
7942 return -EINVAL;
7943 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7944 if (!rc)
7945 rc = value;
7946 return rc;
7947}
7948
7949static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7950 u16 addr, u16 value)
7951{
7952 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7953 struct ixgbe_hw *hw = &adapter->hw;
7954
7955 if (prtad != hw->phy.mdio.prtad)
7956 return -EINVAL;
7957 return hw->phy.ops.write_reg(hw, addr, devad, value);
7958}
7959
7960static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7961{
7962 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7963
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007964 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007965 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08007966 return ixgbe_ptp_set_ts_config(adapter, req);
7967 case SIOCGHWTSTAMP:
7968 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007969 default:
7970 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7971 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00007972}
7973
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007974/**
7975 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007976 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007977 * @netdev: network interface device structure
7978 *
7979 * Returns non-zero on failure
7980 **/
7981static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7982{
7983 int err = 0;
7984 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007985 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007986
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007987 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007988 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007989 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007990 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007991
7992 /* update SAN MAC vmdq pool selection */
7993 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007994 }
7995 return err;
7996}
7997
7998/**
7999 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008000 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008001 * @netdev: network interface device structure
8002 *
8003 * Returns non-zero on failure
8004 **/
8005static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8006{
8007 int err = 0;
8008 struct ixgbe_adapter *adapter = netdev_priv(dev);
8009 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8010
8011 if (is_valid_ether_addr(mac->san_addr)) {
8012 rtnl_lock();
8013 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8014 rtnl_unlock();
8015 }
8016 return err;
8017}
8018
Auke Kok9a799d72007-09-15 14:07:45 -07008019#ifdef CONFIG_NET_POLL_CONTROLLER
8020/*
8021 * Polling 'interrupt' - used by things like netconsole to send skbs
8022 * without having to re-enable interrupts. It's not called while
8023 * the interrupt routine is executing.
8024 */
8025static void ixgbe_netpoll(struct net_device *netdev)
8026{
8027 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008028 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008029
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008030 /* if interface is down do nothing */
8031 if (test_bit(__IXGBE_DOWN, &adapter->state))
8032 return;
8033
Alexander Duyck856f6062015-02-25 17:45:54 +00008034 /* loop through and schedule all active queues */
8035 for (i = 0; i < adapter->num_q_vectors; i++)
8036 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008037}
Auke Kok9a799d72007-09-15 14:07:45 -07008038
Alexander Duyck581330b2012-02-08 07:51:47 +00008039#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00008040static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
8041 struct rtnl_link_stats64 *stats)
8042{
8043 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8044 int i;
8045
Eric Dumazet1a515022010-11-16 19:26:42 -08008046 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008047 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08008048 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008049 u64 bytes, packets;
8050 unsigned int start;
8051
Eric Dumazet1a515022010-11-16 19:26:42 -08008052 if (ring) {
8053 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008054 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008055 packets = ring->stats.packets;
8056 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008057 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008058 stats->rx_packets += packets;
8059 stats->rx_bytes += bytes;
8060 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008061 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008062
8063 for (i = 0; i < adapter->num_tx_queues; i++) {
8064 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
8065 u64 bytes, packets;
8066 unsigned int start;
8067
8068 if (ring) {
8069 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008070 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008071 packets = ring->stats.packets;
8072 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008073 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008074 stats->tx_packets += packets;
8075 stats->tx_bytes += bytes;
8076 }
8077 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008078 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008079 /* following stats updated by ixgbe_watchdog_task() */
8080 stats->multicast = netdev->stats.multicast;
8081 stats->rx_errors = netdev->stats.rx_errors;
8082 stats->rx_length_errors = netdev->stats.rx_length_errors;
8083 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8084 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
8085 return stats;
8086}
8087
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008088#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008089/**
8090 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8091 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008092 * @tc: number of traffic classes currently enabled
8093 *
8094 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8095 * 802.1Q priority maps to a packet buffer that exists.
8096 */
8097static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8098{
8099 struct ixgbe_hw *hw = &adapter->hw;
8100 u32 reg, rsave;
8101 int i;
8102
8103 /* 82598 have a static priority to TC mapping that can not
8104 * be changed so no validation is needed.
8105 */
8106 if (hw->mac.type == ixgbe_mac_82598EB)
8107 return;
8108
8109 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8110 rsave = reg;
8111
8112 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8113 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8114
8115 /* If up2tc is out of bounds default to zero */
8116 if (up2tc > tc)
8117 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8118 }
8119
8120 if (reg != rsave)
8121 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8122
8123 return;
8124}
8125
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008126/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008127 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8128 * @adapter: Pointer to adapter struct
8129 *
8130 * Populate the netdev user priority to tc map
8131 */
8132static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8133{
8134 struct net_device *dev = adapter->netdev;
8135 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8136 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8137 u8 prio;
8138
8139 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8140 u8 tc = 0;
8141
8142 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8143 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8144 else if (ets)
8145 tc = ets->prio_tc[prio];
8146
8147 netdev_set_prio_tc_map(dev, prio, tc);
8148 }
8149}
8150
Alexander Duyckcca73c52013-01-12 06:33:44 +00008151#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008152/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008153 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008154 *
8155 * @netdev: net device to configure
8156 * @tc: number of traffic classes to enable
8157 */
8158int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8159{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008160 struct ixgbe_adapter *adapter = netdev_priv(dev);
8161 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08008162 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008163
John Fastabend8b1c0b22011-05-03 02:26:48 +00008164 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008165 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8166 return -EINVAL;
8167
8168 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008169 return -EINVAL;
8170
John Fastabend2a47fa42013-11-06 09:54:52 -08008171 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
8172 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
8173 return -EBUSY;
8174
John Fastabend8b1c0b22011-05-03 02:26:48 +00008175 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008176 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008177 * hardware is not flexible enough to do this dynamically.
8178 */
8179 if (netif_running(dev))
8180 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008181 else
8182 ixgbe_reset(adapter);
8183
John Fastabend8b1c0b22011-05-03 02:26:48 +00008184 ixgbe_clear_interrupt_scheme(adapter);
8185
Alexander Duyckcca73c52013-01-12 06:33:44 +00008186#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008187 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008188 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008189 ixgbe_set_prio_tc_map(adapter);
8190
John Fastabende7589ea2011-07-18 22:38:36 +00008191 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008192
Alexander Duyck943561d2012-05-09 22:14:44 -07008193 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8194 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008195 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008196 }
John Fastabende7589ea2011-07-18 22:38:36 +00008197 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008198 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008199
Alexander Duyck943561d2012-05-09 22:14:44 -07008200 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8201 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008202
8203 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008204
8205 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8206 adapter->dcb_cfg.pfc_mode_enable = false;
8207 }
8208
John Fastabend8b1c0b22011-05-03 02:26:48 +00008209 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008210
8211#endif /* CONFIG_IXGBE_DCB */
8212 ixgbe_init_interrupt_scheme(adapter);
8213
John Fastabend8b1c0b22011-05-03 02:26:48 +00008214 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008215 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008216
8217 return 0;
8218}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008219
John Fastabendb82b17d2016-02-16 21:18:53 -08008220static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8221 struct tc_cls_u32_offload *cls)
8222{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008223 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
8224 u32 loc;
John Fastabendb82b17d2016-02-16 21:18:53 -08008225 int err;
8226
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008227 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8228 return -EINVAL;
8229
8230 loc = cls->knode.handle & 0xfffff;
8231
John Fastabendb82b17d2016-02-16 21:18:53 -08008232 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008233 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008234 spin_unlock(&adapter->fdir_perfect_lock);
8235 return err;
8236}
8237
John Fastabenddb956ae2016-02-16 21:19:19 -08008238static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
8239 __be16 protocol,
8240 struct tc_cls_u32_offload *cls)
8241{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008242 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8243
8244 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8245 return -EINVAL;
8246
John Fastabenddb956ae2016-02-16 21:19:19 -08008247 /* This ixgbe devices do not support hash tables at the moment
8248 * so abort when given hash tables.
8249 */
8250 if (cls->hnode.divisor > 0)
8251 return -EINVAL;
8252
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008253 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008254 return 0;
8255}
8256
8257static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8258 struct tc_cls_u32_offload *cls)
8259{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008260 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8261
8262 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8263 return -EINVAL;
8264
8265 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008266 return 0;
8267}
8268
John Fastabendb82b17d2016-02-16 21:18:53 -08008269static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
8270 __be16 protocol,
8271 struct tc_cls_u32_offload *cls)
8272{
8273 u32 loc = cls->knode.handle & 0xfffff;
8274 struct ixgbe_hw *hw = &adapter->hw;
8275 struct ixgbe_mat_field *field_ptr;
8276 struct ixgbe_fdir_filter *input;
8277 union ixgbe_atr_input mask;
8278#ifdef CONFIG_NET_CLS_ACT
8279 const struct tc_action *a;
8280#endif
8281 int i, err = 0;
8282 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008283 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08008284
8285 memset(&mask, 0, sizeof(union ixgbe_atr_input));
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008286 uhtid = TC_U32_USERHTID(cls->knode.handle);
8287 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08008288
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008289 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08008290 * L2 headers. The canonical method to match L2 frames is to use
8291 * negative values. However this is error prone at best but really
8292 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008293 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08008294 * headers when needed.
8295 */
8296 if (protocol != htons(ETH_P_IP))
8297 return -EINVAL;
8298
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008299 if (link_uhtid) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008300 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
John Fastabendb82b17d2016-02-16 21:18:53 -08008301
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008302 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
8303 return -EINVAL;
8304
8305 if (!test_bit(link_uhtid - 1, &adapter->tables))
John Fastabenddb956ae2016-02-16 21:19:19 -08008306 return -EINVAL;
8307
John Fastabendb82b17d2016-02-16 21:18:53 -08008308 for (i = 0; nexthdr[i].jump; i++) {
Amritha Nambiar4ae78342016-03-09 18:32:16 -05008309 if (nexthdr[i].o != cls->knode.sel->offoff ||
8310 nexthdr[i].s != cls->knode.sel->offshift ||
8311 nexthdr[i].m != cls->knode.sel->offmask ||
John Fastabendb82b17d2016-02-16 21:18:53 -08008312 /* do not support multiple key jumps its just mad */
8313 cls->knode.sel->nkeys > 1)
8314 return -EINVAL;
8315
Amritha Nambiar4ae78342016-03-09 18:32:16 -05008316 if (nexthdr[i].off == cls->knode.sel->keys[0].off &&
8317 nexthdr[i].val == cls->knode.sel->keys[0].val &&
8318 nexthdr[i].mask == cls->knode.sel->keys[0].mask) {
8319 adapter->jump_tables[link_uhtid] =
8320 nexthdr[i].jump;
8321 break;
8322 }
John Fastabendb82b17d2016-02-16 21:18:53 -08008323 }
8324 return 0;
8325 }
8326
8327 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
8328 e_err(drv, "Location out of range\n");
8329 return -EINVAL;
8330 }
8331
8332 /* cls u32 is a graph starting at root node 0x800. The driver tracks
8333 * links and also the fields used to advance the parser across each
8334 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
8335 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
8336 * To add support for new nodes update ixgbe_model.h parse structures
8337 * this function _should_ be generic try not to hardcode values here.
8338 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008339 if (uhtid == 0x800) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008340 field_ptr = adapter->jump_tables[0];
8341 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008342 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
John Fastabendb82b17d2016-02-16 21:18:53 -08008343 return -EINVAL;
8344
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008345 field_ptr = adapter->jump_tables[uhtid];
John Fastabendb82b17d2016-02-16 21:18:53 -08008346 }
8347
8348 if (!field_ptr)
8349 return -EINVAL;
8350
8351 input = kzalloc(sizeof(*input), GFP_KERNEL);
8352 if (!input)
8353 return -ENOMEM;
8354
8355 for (i = 0; i < cls->knode.sel->nkeys; i++) {
8356 int off = cls->knode.sel->keys[i].off;
8357 __be32 val = cls->knode.sel->keys[i].val;
8358 __be32 m = cls->knode.sel->keys[i].mask;
8359 bool found_entry = false;
8360 int j;
8361
8362 for (j = 0; field_ptr[j].val; j++) {
Sridhar Samudralaebd83ad2016-03-07 09:41:48 -08008363 if (field_ptr[j].off == off) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008364 field_ptr[j].val(input, &mask, val, m);
8365 input->filter.formatted.flow_type |=
8366 field_ptr[j].type;
8367 found_entry = true;
8368 break;
8369 }
8370 }
8371
8372 if (!found_entry)
8373 goto err_out;
8374 }
8375
8376 mask.formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
8377 IXGBE_ATR_L4TYPE_MASK;
8378
8379 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
8380 mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
8381
8382#ifdef CONFIG_NET_CLS_ACT
8383 if (list_empty(&cls->knode.exts->actions))
8384 goto err_out;
8385
8386 list_for_each_entry(a, &cls->knode.exts->actions, list) {
8387 if (!is_tcf_gact_shot(a))
8388 goto err_out;
8389 }
8390#endif
8391
8392 input->action = IXGBE_FDIR_DROP_QUEUE;
8393 queue = IXGBE_FDIR_DROP_QUEUE;
8394 input->sw_idx = loc;
8395
8396 spin_lock(&adapter->fdir_perfect_lock);
8397
8398 if (hlist_empty(&adapter->fdir_filter_list)) {
8399 memcpy(&adapter->fdir_mask, &mask, sizeof(mask));
8400 err = ixgbe_fdir_set_input_mask_82599(hw, &mask);
8401 if (err)
8402 goto err_out_w_lock;
8403 } else if (memcmp(&adapter->fdir_mask, &mask, sizeof(mask))) {
8404 err = -EINVAL;
8405 goto err_out_w_lock;
8406 }
8407
8408 ixgbe_atr_compute_perfect_hash_82599(&input->filter, &mask);
8409 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
8410 input->sw_idx, queue);
8411 if (!err)
8412 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
8413 spin_unlock(&adapter->fdir_perfect_lock);
8414
8415 return err;
8416err_out_w_lock:
8417 spin_unlock(&adapter->fdir_perfect_lock);
8418err_out:
8419 kfree(input);
8420 return -EINVAL;
8421}
8422
Emil Tantilov6e2a60b2016-02-17 15:55:06 -08008423static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
8424 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08008425{
John Fastabendb82b17d2016-02-16 21:18:53 -08008426 struct ixgbe_adapter *adapter = netdev_priv(dev);
8427
8428 if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
8429 tc->type == TC_SETUP_CLSU32) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008430 switch (tc->cls_u32->command) {
8431 case TC_CLSU32_NEW_KNODE:
8432 case TC_CLSU32_REPLACE_KNODE:
8433 return ixgbe_configure_clsu32(adapter,
8434 proto, tc->cls_u32);
8435 case TC_CLSU32_DELETE_KNODE:
8436 return ixgbe_delete_clsu32(adapter, tc->cls_u32);
John Fastabenddb956ae2016-02-16 21:19:19 -08008437 case TC_CLSU32_NEW_HNODE:
8438 case TC_CLSU32_REPLACE_HNODE:
8439 return ixgbe_configure_clsu32_add_hnode(adapter, proto,
8440 tc->cls_u32);
8441 case TC_CLSU32_DELETE_HNODE:
8442 return ixgbe_configure_clsu32_del_hnode(adapter,
8443 tc->cls_u32);
John Fastabendb82b17d2016-02-16 21:18:53 -08008444 default:
8445 return -EINVAL;
8446 }
8447 }
8448
John Fastabend5eb4dce2016-02-29 11:26:13 -08008449 if (tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08008450 return -EINVAL;
8451
John Fastabend16e5cc62016-02-16 21:16:43 -08008452 return ixgbe_setup_tc(dev, tc->tc);
John Fastabende4c67342016-02-16 21:16:15 -08008453}
8454
Greg Roseda36b642012-12-11 08:26:43 +00008455#ifdef CONFIG_PCI_IOV
8456void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
8457{
8458 struct net_device *netdev = adapter->netdev;
8459
8460 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00008461 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00008462 rtnl_unlock();
8463}
8464
8465#endif
Don Skidmore082757a2011-07-21 05:55:00 +00008466void ixgbe_do_reset(struct net_device *netdev)
8467{
8468 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8469
8470 if (netif_running(netdev))
8471 ixgbe_reinit_locked(adapter);
8472 else
8473 ixgbe_reset(adapter);
8474}
8475
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008476static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008477 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008478{
8479 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8480
Don Skidmore082757a2011-07-21 05:55:00 +00008481 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00008482 if (!(features & NETIF_F_RXCSUM))
8483 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00008484
Alexander Duyck567d2de2012-02-11 07:18:57 +00008485 /* Turn off LRO if not RSC capable */
8486 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
8487 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008488
Alexander Duyck567d2de2012-02-11 07:18:57 +00008489 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00008490}
8491
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008492static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008493 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008494{
8495 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00008496 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00008497 bool need_reset = false;
8498
Don Skidmore082757a2011-07-21 05:55:00 +00008499 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00008500 if (!(features & NETIF_F_LRO)) {
8501 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00008502 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00008503 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
8504 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
8505 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
8506 if (adapter->rx_itr_setting == 1 ||
8507 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
8508 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
8509 need_reset = true;
8510 } else if ((changed ^ features) & NETIF_F_LRO) {
8511 e_info(probe, "rx-usecs set too low, "
8512 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00008513 }
8514 }
8515
8516 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08008517 * Check if Flow Director n-tuple support or hw_tc support was
8518 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00008519 */
John Fastabendb82b17d2016-02-16 21:18:53 -08008520 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00008521 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00008522 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
8523 need_reset = true;
8524
Alexander Duyck567d2de2012-02-11 07:18:57 +00008525 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
8526 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08008527 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00008528 /* turn off perfect filters, enable ATR and reset */
8529 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
8530 need_reset = true;
8531
8532 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
8533
8534 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08008535 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
8536 /* We cannot enable ATR if we have 2 or more tcs */
8537 (netdev_get_num_tc(netdev) > 1) ||
8538 /* We cannot enable ATR if RSS is disabled */
8539 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
8540 /* A sample rate of 0 indicates ATR disabled */
8541 (!adapter->atr_sample_rate))
8542 ; /* do nothing not supported */
8543 else /* otherwise supported and set the flag */
8544 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00008545 }
8546
Ben Greear3f2d1c02012-03-08 08:28:41 +00008547 if (changed & NETIF_F_RXALL)
8548 need_reset = true;
8549
Alexander Duyck567d2de2012-02-11 07:18:57 +00008550 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07008551
8552#ifdef CONFIG_IXGBE_VXLAN
8553 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
8554 if (features & NETIF_F_RXCSUM)
8555 adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED;
8556 else
8557 ixgbe_clear_vxlan_port(adapter);
8558 }
8559#endif /* CONFIG_IXGBE_VXLAN */
8560
Don Skidmore082757a2011-07-21 05:55:00 +00008561 if (need_reset)
8562 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08008563 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
8564 NETIF_F_HW_VLAN_CTAG_FILTER))
8565 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00008566
8567 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00008568}
8569
Mark Rustad67359c32015-06-15 11:33:25 -07008570#ifdef CONFIG_IXGBE_VXLAN
Don Skidmore3f207802014-12-23 07:40:34 +00008571/**
8572 * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up
8573 * @dev: The port's netdev
8574 * @sa_family: Socket Family that VXLAN is notifiying us about
8575 * @port: New UDP port number that VXLAN started listening to
8576 **/
8577static void ixgbe_add_vxlan_port(struct net_device *dev, sa_family_t sa_family,
8578 __be16 port)
8579{
8580 struct ixgbe_adapter *adapter = netdev_priv(dev);
8581 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore3f207802014-12-23 07:40:34 +00008582
Mark Rustad67359c32015-06-15 11:33:25 -07008583 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
8584 return;
8585
Don Skidmore3f207802014-12-23 07:40:34 +00008586 if (sa_family == AF_INET6)
8587 return;
8588
Alexander Duyck9f12df92016-01-25 19:36:29 -08008589 if (adapter->vxlan_port == port)
Don Skidmore3f207802014-12-23 07:40:34 +00008590 return;
Don Skidmore3f207802014-12-23 07:40:34 +00008591
8592 if (adapter->vxlan_port) {
8593 netdev_info(dev,
Mark Rustad67359c32015-06-15 11:33:25 -07008594 "Hit Max num of VXLAN ports, not adding port %d\n",
Alexander Duyck9f12df92016-01-25 19:36:29 -08008595 ntohs(port));
Don Skidmore3f207802014-12-23 07:40:34 +00008596 return;
8597 }
8598
Alexander Duyck9f12df92016-01-25 19:36:29 -08008599 adapter->vxlan_port = port;
8600 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, ntohs(port));
Don Skidmore3f207802014-12-23 07:40:34 +00008601}
8602
8603/**
8604 * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away
8605 * @dev: The port's netdev
8606 * @sa_family: Socket Family that VXLAN is notifying us about
8607 * @port: UDP port number that VXLAN stopped listening to
8608 **/
8609static void ixgbe_del_vxlan_port(struct net_device *dev, sa_family_t sa_family,
8610 __be16 port)
8611{
8612 struct ixgbe_adapter *adapter = netdev_priv(dev);
Don Skidmore3f207802014-12-23 07:40:34 +00008613
Mark Rustad67359c32015-06-15 11:33:25 -07008614 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
8615 return;
8616
Don Skidmore3f207802014-12-23 07:40:34 +00008617 if (sa_family == AF_INET6)
8618 return;
8619
Alexander Duyck9f12df92016-01-25 19:36:29 -08008620 if (adapter->vxlan_port != port) {
Don Skidmore3f207802014-12-23 07:40:34 +00008621 netdev_info(dev, "Port %d was not found, not deleting\n",
Alexander Duyck9f12df92016-01-25 19:36:29 -08008622 ntohs(port));
Don Skidmore3f207802014-12-23 07:40:34 +00008623 return;
8624 }
8625
Mark Rustad67359c32015-06-15 11:33:25 -07008626 ixgbe_clear_vxlan_port(adapter);
8627 adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00008628}
Mark Rustad67359c32015-06-15 11:33:25 -07008629#endif /* CONFIG_IXGBE_VXLAN */
Don Skidmore3f207802014-12-23 07:40:34 +00008630
stephen hemmingeredc7d572012-10-01 12:32:33 +00008631static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008632 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01008633 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008634 u16 flags)
8635{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00008636 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00008637 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07008638 struct ixgbe_adapter *adapter = netdev_priv(dev);
8639 u16 pool = VMDQ_P(0);
8640
8641 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00008642 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008643 }
8644
Jiri Pirkof6f64242014-11-28 14:34:15 +01008645 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008646}
8647
Don Skidmore219efe92015-04-09 22:03:22 -07008648/**
8649 * ixgbe_configure_bridge_mode - set various bridge modes
8650 * @adapter - the private structure
8651 * @mode - requested bridge mode
8652 *
8653 * Configure some settings require for various bridge modes.
8654 **/
8655static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
8656 __u16 mode)
8657{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008658 struct ixgbe_hw *hw = &adapter->hw;
8659 unsigned int p, num_pools;
8660 u32 vmdctl;
8661
Don Skidmore219efe92015-04-09 22:03:22 -07008662 switch (mode) {
8663 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008664 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07008665 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008666
8667 /* must enable Rx switching replication to allow multicast
8668 * packet reception on all VFs, and to enable source address
8669 * pruning.
8670 */
8671 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
8672 vmdctl |= IXGBE_VT_CTL_REPLEN;
8673 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
8674
8675 /* enable Rx source address pruning. Note, this requires
8676 * replication to be enabled or else it does nothing.
8677 */
8678 num_pools = adapter->num_vfs + adapter->num_rx_pools;
8679 for (p = 0; p < num_pools; p++) {
8680 if (hw->mac.ops.set_source_address_pruning)
8681 hw->mac.ops.set_source_address_pruning(hw,
8682 true,
8683 p);
8684 }
Don Skidmore219efe92015-04-09 22:03:22 -07008685 break;
8686 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008687 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07008688 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
8689 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008690
8691 /* disable Rx switching replication unless we have SR-IOV
8692 * virtual functions
8693 */
8694 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
8695 if (!adapter->num_vfs)
8696 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
8697 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
8698
8699 /* disable Rx source address pruning, since we don't expect to
8700 * be receiving external loopback of our transmitted frames.
8701 */
8702 num_pools = adapter->num_vfs + adapter->num_rx_pools;
8703 for (p = 0; p < num_pools; p++) {
8704 if (hw->mac.ops.set_source_address_pruning)
8705 hw->mac.ops.set_source_address_pruning(hw,
8706 false,
8707 p);
8708 }
Don Skidmore219efe92015-04-09 22:03:22 -07008709 break;
8710 default:
8711 return -EINVAL;
8712 }
8713
8714 adapter->bridge_mode = mode;
8715
8716 e_info(drv, "enabling bridge mode: %s\n",
8717 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
8718
8719 return 0;
8720}
8721
John Fastabend815cccb2012-10-24 08:13:09 +00008722static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08008723 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00008724{
8725 struct ixgbe_adapter *adapter = netdev_priv(dev);
8726 struct nlattr *attr, *br_spec;
8727 int rem;
8728
8729 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8730 return -EOPNOTSUPP;
8731
8732 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01008733 if (!br_spec)
8734 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00008735
8736 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07008737 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00008738 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00008739
8740 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8741 continue;
8742
Thomas Grafb7c1a312014-11-26 13:42:17 +01008743 if (nla_len(attr) < sizeof(mode))
8744 return -EINVAL;
8745
John Fastabend815cccb2012-10-24 08:13:09 +00008746 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07008747 status = ixgbe_configure_bridge_mode(adapter, mode);
8748 if (status)
8749 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07008750
8751 break;
John Fastabend815cccb2012-10-24 08:13:09 +00008752 }
8753
8754 return 0;
8755}
8756
8757static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00008758 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02008759 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00008760{
8761 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00008762
8763 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8764 return 0;
8765
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07008766 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07008767 adapter->bridge_mode, 0, 0, nlflags,
8768 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00008769}
8770
John Fastabend2a47fa42013-11-06 09:54:52 -08008771static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
8772{
8773 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
8774 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00008775 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08008776 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08008777 int pool, err;
8778
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00008779 /* Hardware has a limited number of available pools. Each VF, and the
8780 * PF require a pool. Check to ensure we don't attempt to use more
8781 * then the available number of pools.
8782 */
8783 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
8784 return ERR_PTR(-EINVAL);
8785
John Fastabend219354d2013-11-08 00:50:32 -08008786#ifdef CONFIG_RPS
8787 if (vdev->num_rx_queues != vdev->num_tx_queues) {
8788 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
8789 vdev->name);
8790 return ERR_PTR(-EINVAL);
8791 }
8792#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08008793 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08008794 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08008795 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
8796 netdev_info(pdev,
8797 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
8798 pdev->name);
8799 return ERR_PTR(-EINVAL);
8800 }
8801
8802 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
8803 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
8804 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
8805 return ERR_PTR(-EBUSY);
8806
Maninder Singhbc52f952015-06-19 09:37:55 +05308807 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08008808 if (!fwd_adapter)
8809 return ERR_PTR(-ENOMEM);
8810
8811 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
8812 adapter->num_rx_pools++;
8813 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08008814 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08008815
8816 /* Enable VMDq flag so device will be set in VM mode */
8817 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08008818 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08008819 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08008820
8821 /* Force reinit of ring allocation with VMDQ enabled */
8822 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8823 if (err)
8824 goto fwd_add_err;
8825 fwd_adapter->pool = pool;
8826 fwd_adapter->real_adapter = adapter;
8827 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
8828 if (err)
8829 goto fwd_add_err;
8830 netif_tx_start_all_queues(vdev);
8831 return fwd_adapter;
8832fwd_add_err:
8833 /* unwind counter and free adapter struct */
8834 netdev_info(pdev,
8835 "%s: dfwd hardware acceleration failed\n", vdev->name);
8836 clear_bit(pool, &adapter->fwd_bitmask);
8837 adapter->num_rx_pools--;
8838 kfree(fwd_adapter);
8839 return ERR_PTR(err);
8840}
8841
8842static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
8843{
8844 struct ixgbe_fwd_adapter *fwd_adapter = priv;
8845 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08008846 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08008847
8848 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
8849 adapter->num_rx_pools--;
8850
John Fastabend51f37732013-11-08 00:51:10 -08008851 limit = find_last_bit(&adapter->fwd_bitmask, 32);
8852 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08008853 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
8854 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8855 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
8856 fwd_adapter->pool, adapter->num_rx_pools,
8857 fwd_adapter->rx_base_queue,
8858 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
8859 adapter->fwd_bitmask);
8860 kfree(fwd_adapter);
8861}
8862
Mark Rustadf467bc02015-06-15 11:33:20 -07008863#define IXGBE_MAX_TUNNEL_HDR_LEN 80
8864static netdev_features_t
8865ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
8866 netdev_features_t features)
8867{
8868 if (!skb->encapsulation)
8869 return features;
8870
8871 if (unlikely(skb_inner_mac_header(skb) - skb_transport_header(skb) >
8872 IXGBE_MAX_TUNNEL_HDR_LEN))
Tom Herberta1882222015-12-14 11:19:43 -08008873 return features & ~NETIF_F_CSUM_MASK;
Mark Rustadf467bc02015-06-15 11:33:20 -07008874
8875 return features;
8876}
8877
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008878static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00008879 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008880 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08008881 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008882 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00008883 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008884 .ndo_validate_addr = eth_validate_addr,
8885 .ndo_set_mac_address = ixgbe_set_mac,
8886 .ndo_change_mtu = ixgbe_change_mtu,
8887 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00008888 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008889 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
8890 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00008891 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00008892 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
8893 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04008894 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00008895 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03008896 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +00008897 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +00008898 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00008899 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -08008900 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008901#ifdef CONFIG_NET_POLL_CONTROLLER
8902 .ndo_poll_controller = ixgbe_netpoll,
8903#endif
Cong Wange0d10952013-08-01 11:10:25 +08008904#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03008905 .ndo_busy_poll = ixgbe_low_latency_recv,
Eliezer Tamir5a85e732013-06-10 11:40:20 +03008906#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008907#ifdef IXGBE_FCOE
8908 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00008909 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00008910 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00008911 .ndo_fcoe_enable = ixgbe_fcoe_enable,
8912 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00008913 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00008914 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00008915#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00008916 .ndo_set_features = ixgbe_set_features,
8917 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008918 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00008919 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
8920 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08008921 .ndo_dfwd_add_station = ixgbe_fwd_add,
8922 .ndo_dfwd_del_station = ixgbe_fwd_del,
Mark Rustad67359c32015-06-15 11:33:25 -07008923#ifdef CONFIG_IXGBE_VXLAN
Don Skidmore3f207802014-12-23 07:40:34 +00008924 .ndo_add_vxlan_port = ixgbe_add_vxlan_port,
8925 .ndo_del_vxlan_port = ixgbe_del_vxlan_port,
Mark Rustad67359c32015-06-15 11:33:25 -07008926#endif /* CONFIG_IXGBE_VXLAN */
Mark Rustadf467bc02015-06-15 11:33:20 -07008927 .ndo_features_check = ixgbe_features_check,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008928};
8929
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008930/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00008931 * ixgbe_enumerate_functions - Get the number of ports this device has
8932 * @adapter: adapter structure
8933 *
8934 * This function enumerates the phsyical functions co-located on a single slot,
8935 * in order to determine how many ports a device has. This is most useful in
8936 * determining the required GT/s of PCIe bandwidth necessary for optimal
8937 * performance.
8938 **/
8939static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
8940{
Jacob Kellercaafb952014-07-19 07:17:17 +00008941 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00008942 int physfns = 0;
8943
Jacob Kellerf1f96572013-08-31 02:45:38 +00008944 /* Some cards can not use the generic count PCIe functions method,
8945 * because they are behind a parent switch, so we hardcode these with
8946 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00008947 */
Jacob Keller88189702014-07-19 07:17:16 +00008948 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00008949 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00008950
8951 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
8952 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00008953 if (entry->is_virtfn)
8954 continue;
8955
8956 /* When the devices on the bus don't all match our device ID,
8957 * we can't reliably determine the correct number of
8958 * functions. This can occur if a function has been direct
8959 * attached to a virtual machine using VT-d, for example. In
8960 * this case, simply return -1 to indicate this.
8961 */
8962 if ((entry->vendor != pdev->vendor) ||
8963 (entry->device != pdev->device))
8964 return -1;
8965
8966 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00008967 }
8968
8969 return physfns;
8970}
8971
8972/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00008973 * ixgbe_wol_supported - Check whether device supports WoL
8974 * @hw: hw specific details
8975 * @device_id: the device ID
8976 * @subdev_id: the subsystem device ID
8977 *
8978 * This function is used by probe and ethtool to determine
8979 * which devices have WoL support
8980 *
8981 **/
8982int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
8983 u16 subdevice_id)
8984{
8985 struct ixgbe_hw *hw = &adapter->hw;
8986 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
8987 int is_wol_supported = 0;
8988
8989 switch (device_id) {
8990 case IXGBE_DEV_ID_82599_SFP:
8991 /* Only these subdevices could supports WOL */
8992 switch (subdevice_id) {
Mark Rustad87557442014-02-25 17:58:55 -08008993 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008994 case IXGBE_SUBDEV_ID_82599_560FLR:
8995 /* only support first port */
8996 if (hw->bus.func != 0)
8997 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00008998 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008999 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00009000 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00009001 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller979fe5f2013-04-03 04:41:37 +00009002 case IXGBE_SUBDEV_ID_82599_LOM_SFP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009003 is_wol_supported = 1;
9004 break;
9005 }
9006 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009007 case IXGBE_DEV_ID_82599EN_SFP:
9008 /* Only this subdevice supports WOL */
9009 switch (subdevice_id) {
9010 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
9011 is_wol_supported = 1;
9012 break;
9013 }
9014 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009015 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
9016 /* All except this subdevice support WOL */
9017 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
9018 is_wol_supported = 1;
9019 break;
9020 case IXGBE_DEV_ID_82599_KX4:
9021 is_wol_supported = 1;
9022 break;
9023 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00009024 case IXGBE_DEV_ID_X540T1:
Don Skidmoredf8c26f2015-06-09 16:00:17 -07009025 case IXGBE_DEV_ID_X550T:
Mark Rustada711ad82016-03-21 11:21:31 -07009026 case IXGBE_DEV_ID_X550T1:
Don Skidmoredf8c26f2015-06-09 16:00:17 -07009027 case IXGBE_DEV_ID_X550EM_X_KX4:
9028 case IXGBE_DEV_ID_X550EM_X_KR:
9029 case IXGBE_DEV_ID_X550EM_X_10G_T:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009030 /* check eeprom to see if enabled wol */
9031 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
9032 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
9033 (hw->bus.func == 0))) {
9034 is_wol_supported = 1;
9035 }
9036 break;
9037 }
9038
9039 return is_wol_supported;
9040}
9041
9042/**
Auke Kok9a799d72007-09-15 14:07:45 -07009043 * ixgbe_probe - Device Initialization Routine
9044 * @pdev: PCI device information struct
9045 * @ent: entry in ixgbe_pci_tbl
9046 *
9047 * Returns 0 on success, negative on failure
9048 *
9049 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
9050 * The OS initialization, configuring of the adapter private structure,
9051 * and a hardware reset occur.
9052 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00009053static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07009054{
9055 struct net_device *netdev;
9056 struct ixgbe_adapter *adapter = NULL;
9057 struct ixgbe_hw *hw;
9058 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +00009059 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009060 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00009061 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009062 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +00009063#ifdef IXGBE_FCOE
9064 u16 device_caps;
9065#endif
Don Skidmore289700db2010-12-03 03:32:58 +00009066 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07009067
Andy Gospodarekbded64a2010-07-21 06:40:31 +00009068 /* Catch broken hardware that put the wrong VF device ID in
9069 * the PCIe SR-IOV capability.
9070 */
9071 if (pdev->is_virtfn) {
9072 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
9073 pci_name(pdev), pdev->vendor, pdev->device);
9074 return -EINVAL;
9075 }
9076
gouji-new9ce77662009-05-06 10:44:45 +00009077 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009078 if (err)
9079 return err;
9080
Russell Kingf5f2eda2013-06-10 12:47:42 +01009081 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07009082 pci_using_dac = 1;
9083 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009084 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07009085 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009086 dev_err(&pdev->dev,
9087 "No usable DMA configuration, aborting\n");
9088 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07009089 }
9090 pci_using_dac = 0;
9091 }
9092
gouji-new9ce77662009-05-06 10:44:45 +00009093 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00009094 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07009095 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00009096 dev_err(&pdev->dev,
9097 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07009098 goto err_pci_reg;
9099 }
9100
Frans Pop19d5afd2009-10-02 10:04:12 -07009101 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009102
Auke Kok9a799d72007-09-15 14:07:45 -07009103 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07009104 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009105
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009106 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00009107#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009108 /* 8 TC w/ 4 queues per TC */
9109 indices = 4 * MAX_TRAFFIC_CLASS;
9110#else
9111 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00009112#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009113 }
John Fastabende901acd2011-04-26 07:26:08 +00009114
John Fastabendc85a2612010-02-25 23:15:21 +00009115 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07009116 if (!netdev) {
9117 err = -ENOMEM;
9118 goto err_alloc_etherdev;
9119 }
9120
Auke Kok9a799d72007-09-15 14:07:45 -07009121 SET_NETDEV_DEV(netdev, &pdev->dev);
9122
Auke Kok9a799d72007-09-15 14:07:45 -07009123 adapter = netdev_priv(netdev);
9124
9125 adapter->netdev = netdev;
9126 adapter->pdev = pdev;
9127 hw = &adapter->hw;
9128 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00009129 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07009130
Jeff Kirsher05857982008-09-11 19:57:00 -07009131 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00009132 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08009133 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07009134 if (!hw->hw_addr) {
9135 err = -EIO;
9136 goto err_ioremap;
9137 }
9138
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009139 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009140 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009141 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +00009142 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -07009143
Auke Kok9a799d72007-09-15 14:07:45 -07009144 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -08009145 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009146 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009147 hw->mvals = ii->mvals;
Auke Kok9a799d72007-09-15 14:07:45 -07009148
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009149 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -08009150 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009151 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +00009152 if (ixgbe_removed(hw->hw_addr)) {
9153 err = -EIO;
9154 goto err_ioremap;
9155 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009156 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
9157 if (!(eec & (1 << 8)))
9158 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
9159
9160 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -08009161 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009162 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00009163 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
9164 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
9165 hw->phy.mdio.mmds = 0;
9166 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9167 hw->phy.mdio.dev = netdev;
9168 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
9169 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009170
Don Skidmore8ca783a2009-05-26 20:40:47 -07009171 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07009172
9173 /* setup the private structure */
9174 err = ixgbe_sw_init(adapter);
9175 if (err)
9176 goto err_sw_init;
9177
Don Skidmoredbd15b82016-03-09 16:45:00 -05009178 /* Make sure the SWFW semaphore is in a valid state */
9179 if (hw->mac.ops.init_swfw_sync)
9180 hw->mac.ops.init_swfw_sync(hw);
9181
Don Skidmoree86bff02010-02-11 04:14:08 +00009182 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08009183 switch (adapter->hw.mac.type) {
9184 case ixgbe_mac_82599EB:
9185 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00009186 case ixgbe_mac_X550:
9187 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07009188 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +00009189 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08009190 break;
9191 default:
9192 break;
9193 }
Don Skidmoree86bff02010-02-11 04:14:08 +00009194
Don Skidmorebf069c92009-05-07 10:39:54 +00009195 /*
9196 * If there is a fan on this device and it has failed log the
9197 * failure.
9198 */
9199 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
9200 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
9201 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00009202 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00009203 }
9204
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00009205 if (allow_unsupported_sfp)
9206 hw->allow_unsupported_sfp = allow_unsupported_sfp;
9207
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009208 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009209 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009210 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009211 hw->phy.reset_if_overtemp = false;
Mark Rustad29a8dca2015-08-08 16:17:46 -07009212 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07009213 err = 0;
9214 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00009215 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
9216 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009217 goto err_sw_init;
9218 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009219 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009220 goto err_sw_init;
9221 }
9222
Alexander Duyck99d74482012-05-09 08:09:25 +00009223#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00009224 /* SR-IOV not supported on the 82598 */
9225 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
9226 goto skip_sriov;
9227 /* Mailbox */
9228 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -08009229 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -08009230 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ethan.zhao31ac9102014-01-16 19:41:05 -08009231 ixgbe_enable_sriov(adapter);
Greg Rose60a1a682012-12-11 08:26:33 +00009232skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009233
Alexander Duyck99d74482012-05-09 08:09:25 +00009234#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00009235 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +00009236 NETIF_F_TSO |
9237 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00009238 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -08009239 NETIF_F_RXCSUM |
9240 NETIF_F_HW_CSUM |
9241 NETIF_F_HW_VLAN_CTAG_TX |
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009242 NETIF_F_HW_VLAN_CTAG_RX |
9243 NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07009244
Alexander Duyck49763de2016-01-13 07:31:11 -08009245 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -08009246 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00009247
Alexander Duyck49763de2016-01-13 07:31:11 -08009248 /* copy netdev features into list of user selectable features */
9249 netdev->hw_features |= netdev->features;
9250 netdev->hw_features |= NETIF_F_RXALL |
9251 NETIF_F_HW_L2FW_DOFFLOAD;
9252
9253 if (hw->mac.type >= ixgbe_mac_82599EB)
9254 netdev->hw_features |= NETIF_F_NTUPLE |
9255 NETIF_F_HW_TC;
9256
Alexander Duyck49763de2016-01-13 07:31:11 -08009257 netdev->vlan_features |= NETIF_F_SG |
9258 NETIF_F_TSO |
9259 NETIF_F_TSO6 |
9260 NETIF_F_HW_CSUM |
9261 NETIF_F_SCTP_CRC;
Jeff Kirsherad31c402008-06-05 04:05:30 -07009262
Alexander Duyck49763de2016-01-13 07:31:11 -08009263 netdev->mpls_features |= NETIF_F_HW_CSUM;
9264 netdev->hw_enc_features |= NETIF_F_HW_CSUM;
Mark Rustadf467bc02015-06-15 11:33:20 -07009265
Jiri Pirko01789342011-08-16 06:29:00 +00009266 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00009267 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00009268
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08009269#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08009270 netdev->dcbnl_ops = &dcbnl_ops;
9271#endif
9272
Yi Zoueacd73f2009-05-13 13:11:06 +00009273#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00009274 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009275 unsigned int fcoe_l;
9276
Yi Zoueacd73f2009-05-13 13:11:06 +00009277 if (hw->mac.ops.get_device_caps) {
9278 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00009279 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
9280 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00009281 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009282
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009283
9284 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
9285 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009286
Alexander Duycka58915c2012-05-25 06:38:18 +00009287 netdev->features |= NETIF_F_FSO |
9288 NETIF_F_FCOE_CRC;
9289
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009290 netdev->vlan_features |= NETIF_F_FSO |
9291 NETIF_F_FCOE_CRC |
9292 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00009293 }
Yi Zoueacd73f2009-05-13 13:11:06 +00009294#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00009295 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07009296 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00009297 netdev->vlan_features |= NETIF_F_HIGHDMA;
9298 }
Auke Kok9a799d72007-09-15 14:07:45 -07009299
Don Skidmore082757a2011-07-21 05:55:00 +00009300 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
9301 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00009302 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00009303 netdev->features |= NETIF_F_LRO;
9304
Auke Kok9a799d72007-09-15 14:07:45 -07009305 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009306 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009307 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009308 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009309 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009310 }
9311
Sowmini Varadhanc7374b52016-01-12 19:32:30 -08009312 eth_platform_get_mac_address(&adapter->pdev->dev,
9313 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +00009314
Auke Kok9a799d72007-09-15 14:07:45 -07009315 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07009316
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00009317 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009318 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009319 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009320 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009321 }
9322
Tushar Dave56768042016-01-07 14:17:03 -08009323 /* Set hw->mac.addr to permanent MAC address */
9324 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07009325 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +00009326
Alexander Duyck70864002011-04-27 09:13:56 +00009327 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00009328 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009329
Mark Rustad58cf6632014-03-12 00:38:40 +00009330 if (ixgbe_removed(hw->hw_addr)) {
9331 err = -EIO;
9332 goto err_sw_init;
9333 }
Alexander Duyck70864002011-04-27 09:13:56 +00009334 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +00009335 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00009336 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009337
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009338 err = ixgbe_init_interrupt_scheme(adapter);
9339 if (err)
9340 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009341
Jacob Keller8e2813f2012-04-21 06:05:40 +00009342 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009343 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009344 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009345 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00009346 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009347 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00009348 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009349
PJ Waskiewicze8e26352009-02-27 15:45:05 +00009350 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
9351
Emil Tantilov15e52092011-09-29 05:01:29 +00009352 /* save off EEPROM version number */
9353 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
9354 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
9355
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009356 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +00009357 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00009358 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -04009359 else
9360 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009361
Jacob Kellere027d1a2013-07-31 06:53:31 +00009362 /* calculate the expected PCIe bandwidth required for optimal
9363 * performance. Note that some older parts will never have enough
9364 * bandwidth due to being older generation PCIe parts. We clamp these
9365 * parts to ensure no warning is displayed if it can't be fixed.
9366 */
9367 switch (hw->mac.type) {
9368 case ixgbe_mac_82598EB:
9369 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
9370 break;
9371 default:
9372 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
9373 break;
Auke Kok0c254d82008-02-11 09:25:56 -08009374 }
Jacob Kellercaafb952014-07-19 07:17:17 +00009375
9376 /* don't check link if we failed to enumerate functions */
9377 if (expected_gts > 0)
9378 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08009379
Mark Rustad339de302014-06-06 01:57:06 +00009380 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009381 if (err)
Mark Rustad339de302014-06-06 01:57:06 +00009382 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009383 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
9384 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
9385 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +00009386 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +00009387 else
9388 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
9389 hw->mac.type, hw->phy.type, part_str);
9390
9391 e_dev_info("%pM\n", netdev->dev_addr);
9392
Auke Kok9a799d72007-09-15 14:07:45 -07009393 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009394 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009395 if (err == IXGBE_ERR_EEPROM_VERSION) {
9396 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00009397 e_dev_warn("This device is a pre-production adapter/LOM. "
9398 "Please be aware there may be issues associated "
9399 "with your hardware. If you are experiencing "
9400 "problems please contact your Intel or hardware "
9401 "representative who provided you with this "
9402 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009403 }
Auke Kok9a799d72007-09-15 14:07:45 -07009404 strcpy(netdev->name, "eth%d");
9405 err = register_netdev(netdev);
9406 if (err)
9407 goto err_register;
9408
Emil Tantilov0fb6a552014-12-04 03:03:38 +00009409 pci_set_drvdata(pdev, adapter);
9410
Emil Tantilovec74a472012-09-20 03:33:56 +00009411 /* power down the optics for 82599 SFP+ fiber */
9412 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00009413 hw->mac.ops.disable_tx_laser(hw);
9414
Jesse Brandeburg54386462009-04-17 20:44:27 +00009415 /* carrier off reporting is important to ethtool even BEFORE open */
9416 netif_carrier_off(netdev);
9417
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009418#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03009419 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009420 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009421 ixgbe_setup_dca(adapter);
9422 }
9423#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009424 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00009425 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009426 for (i = 0; i < adapter->num_vfs; i++)
9427 ixgbe_vf_configuration(pdev, (i | 0x10000000));
9428 }
9429
Jacob Keller2466dd92011-09-08 03:50:54 +00009430 /* firmware requires driver version to be 0xFFFFFFFF
9431 * since os does not support feature
9432 */
Emil Tantilov9612de92011-05-07 07:40:20 +00009433 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00009434 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
9435 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00009436
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00009437 /* add san mac addr to netdev */
9438 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009439
Neerav Parikhea818752012-01-04 20:23:40 +00009440 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009441
Don Skidmore12109822012-05-04 06:07:08 +00009442#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009443 if (ixgbe_sysfs_init(adapter))
9444 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00009445#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009446
Catherine Sullivan00949162012-08-10 01:59:10 +00009447 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00009448
Emil Tantilovd1a35ee2014-05-13 08:24:00 +00009449 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
9450 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +00009451 hw->mac.ops.setup_link(hw,
9452 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
9453 true);
9454
Auke Kok9a799d72007-09-15 14:07:45 -07009455 return 0;
9456
9457err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08009458 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00009459 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009460err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00009461 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00009462 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -08009463 iounmap(adapter->io_addr);
Jacob Keller5d7daa32014-03-29 06:51:25 +00009464 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -07009465err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009466 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009467 free_netdev(netdev);
9468err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00009469 pci_release_selected_regions(pdev,
9470 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07009471err_pci_reg:
9472err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009473 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00009474 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009475 return err;
9476}
9477
9478/**
9479 * ixgbe_remove - Device Removal Routine
9480 * @pdev: PCI device information struct
9481 *
9482 * ixgbe_remove is called by the PCI subsystem to alert the driver
9483 * that it should release a PCI device. The could be caused by a
9484 * Hot-Plug event, or because the driver is going to be removed from
9485 * memory.
9486 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05009487static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07009488{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009489 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +00009490 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009491 bool disable_dev;
Auke Kok9a799d72007-09-15 14:07:45 -07009492
Emil Tantilov0fb6a552014-12-04 03:03:38 +00009493 /* if !adapter then we already cleaned up in probe */
9494 if (!adapter)
9495 return;
9496
9497 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +00009498 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00009499
Mark Rustad09f40ae2014-01-14 18:53:11 -08009500 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00009501 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07009502
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00009503
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009504#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009505 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
9506 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
9507 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -07009508 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
9509 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009510 }
9511
9512#endif
Don Skidmore12109822012-05-04 06:07:08 +00009513#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009514 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00009515#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009516
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00009517 /* remove the added san mac */
9518 ixgbe_del_sanmac_netdev(netdev);
9519
Greg Roseda36b642012-12-11 08:26:43 +00009520#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -06009521 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +00009522#endif
Alex Williamson6b010e92015-07-29 14:38:21 -06009523 if (netdev->reg_state == NETREG_REGISTERED)
9524 unregister_netdev(netdev);
9525
Alexander Duyck7a921c92009-05-06 10:43:28 +00009526 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08009527
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009528 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009529
Alexander Duyck2b1588c2012-03-17 02:39:16 +00009530#ifdef CONFIG_DCB
9531 kfree(adapter->ixgbe_ieee_pfc);
9532 kfree(adapter->ixgbe_ieee_ets);
9533
9534#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -08009535 iounmap(adapter->io_addr);
gouji-new9ce77662009-05-06 10:44:45 +00009536 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00009537 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07009538
Emil Tantilov849c4542010-06-03 16:53:41 +00009539 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009540
Jacob Keller5d7daa32014-03-29 06:51:25 +00009541 kfree(adapter->mac_table);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009542 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009543 free_netdev(netdev);
9544
Frans Pop19d5afd2009-10-02 10:04:12 -07009545 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009546
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009547 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00009548 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009549}
9550
9551/**
9552 * ixgbe_io_error_detected - called when PCI error is detected
9553 * @pdev: Pointer to PCI device
9554 * @state: The current pci connection state
9555 *
9556 * This function is called after a PCI bus error affecting
9557 * this device has been detected.
9558 */
9559static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00009560 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07009561{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009562 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
9563 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07009564
Greg Rose83c61fa2011-09-07 05:59:35 +00009565#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -08009566 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +00009567 struct pci_dev *bdev, *vfdev;
9568 u32 dw0, dw1, dw2, dw3;
9569 int vf, pos;
9570 u16 req_id, pf_func;
9571
9572 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
9573 adapter->num_vfs == 0)
9574 goto skip_bad_vf_detection;
9575
9576 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08009577 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00009578 bdev = bdev->bus->self;
9579
9580 if (!bdev)
9581 goto skip_bad_vf_detection;
9582
9583 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
9584 if (!pos)
9585 goto skip_bad_vf_detection;
9586
Mark Rustad14438462014-02-28 15:48:57 -08009587 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
9588 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
9589 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
9590 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
9591 if (ixgbe_removed(hw->hw_addr))
9592 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +00009593
9594 req_id = dw1 >> 16;
9595 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
9596 if (!(req_id & 0x0080))
9597 goto skip_bad_vf_detection;
9598
9599 pf_func = req_id & 0x01;
9600 if ((pf_func & 1) == (pdev->devfn & 1)) {
9601 unsigned int device_id;
9602
9603 vf = (req_id & 0x7F) >> 1;
9604 e_dev_err("VF %d has caused a PCIe error\n", vf);
9605 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
9606 "%8.8x\tdw3: %8.8x\n",
9607 dw0, dw1, dw2, dw3);
9608 switch (adapter->hw.mac.type) {
9609 case ixgbe_mac_82599EB:
9610 device_id = IXGBE_82599_VF_DEVICE_ID;
9611 break;
9612 case ixgbe_mac_X540:
9613 device_id = IXGBE_X540_VF_DEVICE_ID;
9614 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00009615 case ixgbe_mac_X550:
9616 device_id = IXGBE_DEV_ID_X550_VF;
9617 break;
9618 case ixgbe_mac_X550EM_x:
9619 device_id = IXGBE_DEV_ID_X550EM_X_VF;
9620 break;
Mark Rustad49425df2016-04-01 12:18:09 -07009621 case ixgbe_mac_x550em_a:
9622 device_id = IXGBE_DEV_ID_X550EM_A_VF;
9623 break;
Greg Rose83c61fa2011-09-07 05:59:35 +00009624 default:
9625 device_id = 0;
9626 break;
9627 }
9628
9629 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00009630 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00009631 while (vfdev) {
9632 if (vfdev->devfn == (req_id & 0xFF))
9633 break;
Jon Mason36e90312012-07-19 21:02:09 +00009634 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00009635 device_id, vfdev);
9636 }
9637 /*
9638 * There's a slim chance the VF could have been hot plugged,
9639 * so if it is no longer present we don't need to issue the
9640 * VFLR. Just clean up the AER in that case.
9641 */
9642 if (vfdev) {
Emil Tantilov9079e412014-11-19 03:18:19 +00009643 ixgbe_issue_vf_flr(adapter, vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +00009644 /* Free device reference count */
9645 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +00009646 }
9647
9648 pci_cleanup_aer_uncorrect_error_status(pdev);
9649 }
9650
9651 /*
9652 * Even though the error may have occurred on the other port
9653 * we still need to increment the vf error reference count for
9654 * both ports because the I/O resume function will be called
9655 * for both of them.
9656 */
9657 adapter->vferr_refcount++;
9658
9659 return PCI_ERS_RESULT_RECOVERED;
9660
9661skip_bad_vf_detection:
9662#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +00009663 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
9664 return PCI_ERS_RESULT_DISCONNECT;
9665
Mark Rustad41c62842014-03-12 00:38:35 +00009666 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07009667 netif_device_detach(netdev);
9668
Mark Rustad41c62842014-03-12 00:38:35 +00009669 if (state == pci_channel_io_perm_failure) {
9670 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +00009671 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +00009672 }
Breno Leitao3044b8d2009-05-06 10:44:26 +00009673
Auke Kok9a799d72007-09-15 14:07:45 -07009674 if (netif_running(netdev))
9675 ixgbe_down(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +00009676
9677 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
9678 pci_disable_device(pdev);
9679 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -07009680
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07009681 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07009682 return PCI_ERS_RESULT_NEED_RESET;
9683}
9684
9685/**
9686 * ixgbe_io_slot_reset - called after the pci bus has been reset.
9687 * @pdev: Pointer to PCI device
9688 *
9689 * Restart the card from scratch, as if from a cold-boot.
9690 */
9691static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
9692{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009693 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009694 pci_ers_result_t result;
9695 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07009696
gouji-new9ce77662009-05-06 10:44:45 +00009697 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00009698 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009699 result = PCI_ERS_RESULT_DISCONNECT;
9700 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +01009701 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00009702 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -08009703 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009704 pci_set_master(pdev);
9705 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00009706 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009707
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07009708 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009709
9710 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00009711 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009712 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07009713 }
Auke Kok9a799d72007-09-15 14:07:45 -07009714
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009715 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9716 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009717 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
9718 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009719 /* non-fatal, continue */
9720 }
Auke Kok9a799d72007-09-15 14:07:45 -07009721
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009722 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07009723}
9724
9725/**
9726 * ixgbe_io_resume - called when traffic can start flowing again.
9727 * @pdev: Pointer to PCI device
9728 *
9729 * This callback is called when the error recovery driver tells us that
9730 * its OK to resume normal operation.
9731 */
9732static void ixgbe_io_resume(struct pci_dev *pdev)
9733{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009734 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
9735 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07009736
Greg Rose83c61fa2011-09-07 05:59:35 +00009737#ifdef CONFIG_PCI_IOV
9738 if (adapter->vferr_refcount) {
9739 e_info(drv, "Resuming after VF err\n");
9740 adapter->vferr_refcount--;
9741 return;
9742 }
9743
9744#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00009745 if (netif_running(netdev))
9746 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009747
9748 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009749}
9750
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07009751static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07009752 .error_detected = ixgbe_io_error_detected,
9753 .slot_reset = ixgbe_io_slot_reset,
9754 .resume = ixgbe_io_resume,
9755};
9756
9757static struct pci_driver ixgbe_driver = {
9758 .name = ixgbe_driver_name,
9759 .id_table = ixgbe_pci_tbl,
9760 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05009761 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07009762#ifdef CONFIG_PM
9763 .suspend = ixgbe_suspend,
9764 .resume = ixgbe_resume,
9765#endif
9766 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +00009767 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -07009768 .err_handler = &ixgbe_err_handler
9769};
9770
9771/**
9772 * ixgbe_init_module - Driver Registration Routine
9773 *
9774 * ixgbe_init_module is the first routine called when the driver is
9775 * loaded. All it does is register with the PCI subsystem.
9776 **/
9777static int __init ixgbe_init_module(void)
9778{
9779 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00009780 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00009781 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07009782
Mark Rustad780484d2015-10-21 17:21:10 -07009783 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
9784 if (!ixgbe_wq) {
9785 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
9786 return -ENOMEM;
9787 }
9788
Catherine Sullivan00949162012-08-10 01:59:10 +00009789 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +00009790
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009791 ret = pci_register_driver(&ixgbe_driver);
9792 if (ret) {
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009793 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009794 return ret;
9795 }
9796
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009797#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009798 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009799#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009800
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009801 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07009802}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07009803
Auke Kok9a799d72007-09-15 14:07:45 -07009804module_init(ixgbe_init_module);
9805
9806/**
9807 * ixgbe_exit_module - Driver Exit Cleanup Routine
9808 *
9809 * ixgbe_exit_module is called just before the driver is removed
9810 * from memory.
9811 **/
9812static void __exit ixgbe_exit_module(void)
9813{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009814#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009815 dca_unregister_notify(&dca_notifier);
9816#endif
Auke Kok9a799d72007-09-15 14:07:45 -07009817 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00009818
Catherine Sullivan00949162012-08-10 01:59:10 +00009819 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -07009820 if (ixgbe_wq) {
9821 destroy_workqueue(ixgbe_wq);
9822 ixgbe_wq = NULL;
9823 }
Auke Kok9a799d72007-09-15 14:07:45 -07009824}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009825
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009826#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009827static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00009828 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009829{
9830 int ret_val;
9831
9832 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00009833 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009834
9835 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
9836}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009837
Alexander Duyckb4533682009-03-31 21:32:42 +00009838#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00009839
Auke Kok9a799d72007-09-15 14:07:45 -07009840module_exit(ixgbe_exit_module);
9841
9842/* ixgbe_main.c */