blob: b41a26fe57de87e435367007c5791c23857a0ef4 [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 Rustad10ef00f2016-04-01 12:18:51 -070073#define DRV_VERSION "4.4.0-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;
Mark Rustad2f2219b2016-04-07 10:43:50 -0700374 if (unlikely(hw->phy.nw_mng_if_sel &
375 IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) {
376 struct ixgbe_adapter *adapter;
377 int i;
378
379 for (i = 0; i < 200; ++i) {
380 value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
381 if (likely(!value))
382 goto writes_completed;
383 if (value == IXGBE_FAILED_READ_REG) {
384 ixgbe_remove_adapter(hw);
385 return IXGBE_FAILED_READ_REG;
386 }
387 udelay(5);
388 }
389
390 adapter = hw->back;
391 e_warn(hw, "register writes incomplete %08x\n", value);
392 }
393
394writes_completed:
Mark Rustadf8e24722014-03-18 07:03:40 +0000395 value = readl(reg_addr + reg);
396 if (unlikely(value == IXGBE_FAILED_READ_REG))
397 ixgbe_check_remove(hw, reg);
398 return value;
399}
400
Mark Rustad14438462014-02-28 15:48:57 -0800401static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
402{
403 u16 value;
404
405 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
406 if (value == IXGBE_FAILED_READ_CFG_WORD) {
407 ixgbe_remove_adapter(hw);
408 return true;
409 }
410 return false;
411}
412
413u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
414{
415 struct ixgbe_adapter *adapter = hw->back;
416 u16 value;
417
418 if (ixgbe_removed(hw->hw_addr))
419 return IXGBE_FAILED_READ_CFG_WORD;
420 pci_read_config_word(adapter->pdev, reg, &value);
421 if (value == IXGBE_FAILED_READ_CFG_WORD &&
422 ixgbe_check_cfg_remove(hw, adapter->pdev))
423 return IXGBE_FAILED_READ_CFG_WORD;
424 return value;
425}
426
427#ifdef CONFIG_PCI_IOV
428static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
429{
430 struct ixgbe_adapter *adapter = hw->back;
431 u32 value;
432
433 if (ixgbe_removed(hw->hw_addr))
434 return IXGBE_FAILED_READ_CFG_DWORD;
435 pci_read_config_dword(adapter->pdev, reg, &value);
436 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
437 ixgbe_check_cfg_remove(hw, adapter->pdev))
438 return IXGBE_FAILED_READ_CFG_DWORD;
439 return value;
440}
441#endif /* CONFIG_PCI_IOV */
442
Jacob Kellered192312014-02-22 01:23:53 +0000443void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
444{
445 struct ixgbe_adapter *adapter = hw->back;
446
447 if (ixgbe_removed(hw->hw_addr))
448 return;
449 pci_write_config_word(adapter->pdev, reg, value);
450}
451
Alexander Duyck70864002011-04-27 09:13:56 +0000452static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
453{
454 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
455
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000456 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100457 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000458 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
459}
460
Taku Izumidcd79ae2010-04-27 14:39:53 +0000461struct ixgbe_reg_info {
462 u32 ofs;
463 char *name;
464};
465
466static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
467
468 /* General Registers */
469 {IXGBE_CTRL, "CTRL"},
470 {IXGBE_STATUS, "STATUS"},
471 {IXGBE_CTRL_EXT, "CTRL_EXT"},
472
473 /* Interrupt Registers */
474 {IXGBE_EICR, "EICR"},
475
476 /* RX Registers */
477 {IXGBE_SRRCTL(0), "SRRCTL"},
478 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
479 {IXGBE_RDLEN(0), "RDLEN"},
480 {IXGBE_RDH(0), "RDH"},
481 {IXGBE_RDT(0), "RDT"},
482 {IXGBE_RXDCTL(0), "RXDCTL"},
483 {IXGBE_RDBAL(0), "RDBAL"},
484 {IXGBE_RDBAH(0), "RDBAH"},
485
486 /* TX Registers */
487 {IXGBE_TDBAL(0), "TDBAL"},
488 {IXGBE_TDBAH(0), "TDBAH"},
489 {IXGBE_TDLEN(0), "TDLEN"},
490 {IXGBE_TDH(0), "TDH"},
491 {IXGBE_TDT(0), "TDT"},
492 {IXGBE_TXDCTL(0), "TXDCTL"},
493
494 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000495 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000496};
497
498
499/*
500 * ixgbe_regdump - register printout routine
501 */
502static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
503{
504 int i = 0, j = 0;
505 char rname[16];
506 u32 regs[64];
507
508 switch (reginfo->ofs) {
509 case IXGBE_SRRCTL(0):
510 for (i = 0; i < 64; i++)
511 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
512 break;
513 case IXGBE_DCA_RXCTRL(0):
514 for (i = 0; i < 64; i++)
515 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
516 break;
517 case IXGBE_RDLEN(0):
518 for (i = 0; i < 64; i++)
519 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
520 break;
521 case IXGBE_RDH(0):
522 for (i = 0; i < 64; i++)
523 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
524 break;
525 case IXGBE_RDT(0):
526 for (i = 0; i < 64; i++)
527 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
528 break;
529 case IXGBE_RXDCTL(0):
530 for (i = 0; i < 64; i++)
531 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
532 break;
533 case IXGBE_RDBAL(0):
534 for (i = 0; i < 64; i++)
535 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
536 break;
537 case IXGBE_RDBAH(0):
538 for (i = 0; i < 64; i++)
539 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
540 break;
541 case IXGBE_TDBAL(0):
542 for (i = 0; i < 64; i++)
543 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
544 break;
545 case IXGBE_TDBAH(0):
546 for (i = 0; i < 64; i++)
547 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
548 break;
549 case IXGBE_TDLEN(0):
550 for (i = 0; i < 64; i++)
551 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
552 break;
553 case IXGBE_TDH(0):
554 for (i = 0; i < 64; i++)
555 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
556 break;
557 case IXGBE_TDT(0):
558 for (i = 0; i < 64; i++)
559 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
560 break;
561 case IXGBE_TXDCTL(0):
562 for (i = 0; i < 64; i++)
563 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
564 break;
565 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000566 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000567 IXGBE_READ_REG(hw, reginfo->ofs));
568 return;
569 }
570
571 for (i = 0; i < 8; i++) {
572 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000573 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000574 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000575 pr_cont(" %08x", regs[i*8+j]);
576 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000577 }
578
579}
580
581/*
582 * ixgbe_dump - Print registers, tx-rings and rx-rings
583 */
584static void ixgbe_dump(struct ixgbe_adapter *adapter)
585{
586 struct net_device *netdev = adapter->netdev;
587 struct ixgbe_hw *hw = &adapter->hw;
588 struct ixgbe_reg_info *reginfo;
589 int n = 0;
590 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000591 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000592 union ixgbe_adv_tx_desc *tx_desc;
593 struct my_u0 { u64 a; u64 b; } *u0;
594 struct ixgbe_ring *rx_ring;
595 union ixgbe_adv_rx_desc *rx_desc;
596 struct ixgbe_rx_buffer *rx_buffer_info;
597 u32 staterr;
598 int i = 0;
599
600 if (!netif_msg_hw(adapter))
601 return;
602
603 /* Print netdevice Info */
604 if (netdev) {
605 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000606 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000607 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000608 pr_info("%-15s %016lX %016lX %016lX\n",
609 netdev->name,
610 netdev->state,
611 netdev->trans_start,
612 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000613 }
614
615 /* Print Registers */
616 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000617 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000618 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
619 reginfo->name; reginfo++) {
620 ixgbe_regdump(hw, reginfo);
621 }
622
623 /* Print TX Ring Summary */
624 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000625 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000626
627 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000628 pr_info(" %s %s %s %s\n",
629 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
630 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000631 for (n = 0; n < adapter->num_tx_queues; n++) {
632 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000633 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000634 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000635 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000636 (u64)dma_unmap_addr(tx_buffer, dma),
637 dma_unmap_len(tx_buffer, len),
638 tx_buffer->next_to_watch,
639 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000640 }
641
642 /* Print TX Rings */
643 if (!netif_msg_tx_done(adapter))
644 goto rx_ring_summary;
645
646 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
647
648 /* Transmit Descriptor Formats
649 *
Josh Hay39ac8682012-09-26 05:59:36 +0000650 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000651 * +--------------------------------------------------------------+
652 * 0 | Buffer Address [63:0] |
653 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000654 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000655 * +--------------------------------------------------------------+
656 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000657 *
658 * 82598 Advanced Transmit Descriptor (Write-Back Format)
659 * +--------------------------------------------------------------+
660 * 0 | RSV [63:0] |
661 * +--------------------------------------------------------------+
662 * 8 | RSV | STA | NXTSEQ |
663 * +--------------------------------------------------------------+
664 * 63 36 35 32 31 0
665 *
666 * 82599+ Advanced Transmit Descriptor
667 * +--------------------------------------------------------------+
668 * 0 | Buffer Address [63:0] |
669 * +--------------------------------------------------------------+
670 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
671 * +--------------------------------------------------------------+
672 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
673 *
674 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
675 * +--------------------------------------------------------------+
676 * 0 | RSV [63:0] |
677 * +--------------------------------------------------------------+
678 * 8 | RSV | STA | RSV |
679 * +--------------------------------------------------------------+
680 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000681 */
682
683 for (n = 0; n < adapter->num_tx_queues; n++) {
684 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000685 pr_info("------------------------------------\n");
686 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
687 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000688 pr_info("%s%s %s %s %s %s\n",
689 "T [desc] [address 63:0 ] ",
690 "[PlPOIdStDDt Ln] [bi->dma ] ",
691 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000692
693 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000694 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000695 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000696 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000697 if (dma_unmap_len(tx_buffer, len) > 0) {
698 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
699 i,
700 le64_to_cpu(u0->a),
701 le64_to_cpu(u0->b),
702 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000703 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000704 tx_buffer->next_to_watch,
705 (u64)tx_buffer->time_stamp,
706 tx_buffer->skb);
707 if (i == tx_ring->next_to_use &&
708 i == tx_ring->next_to_clean)
709 pr_cont(" NTC/U\n");
710 else if (i == tx_ring->next_to_use)
711 pr_cont(" NTU\n");
712 else if (i == tx_ring->next_to_clean)
713 pr_cont(" NTC\n");
714 else
715 pr_cont("\n");
716
717 if (netif_msg_pktdata(adapter) &&
718 tx_buffer->skb)
719 print_hex_dump(KERN_INFO, "",
720 DUMP_PREFIX_ADDRESS, 16, 1,
721 tx_buffer->skb->data,
722 dma_unmap_len(tx_buffer, len),
723 true);
724 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000725 }
726 }
727
728 /* Print RX Rings Summary */
729rx_ring_summary:
730 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000731 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000732 for (n = 0; n < adapter->num_rx_queues; n++) {
733 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000734 pr_info("%5d %5X %5X\n",
735 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000736 }
737
738 /* Print RX Rings */
739 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000740 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000741
742 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
743
Josh Hay39ac8682012-09-26 05:59:36 +0000744 /* Receive Descriptor Formats
745 *
746 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000747 * 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 *
Josh Hay39ac8682012-09-26 05:59:36 +0000755 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000756 *
757 * 63 48 47 32 31 30 21 20 16 15 4 3 0
758 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000759 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
760 * | Packet | IP | | | | Type | Type |
761 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000762 * +------------------------------------------------------+
763 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
764 * +------------------------------------------------------+
765 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000766 *
767 * 82599+ Advanced Receive Descriptor (Read) Format
768 * 63 1 0
769 * +-----------------------------------------------------+
770 * 0 | Packet Buffer Address [63:1] |A0/NSE|
771 * +----------------------------------------------+------+
772 * 8 | Header Buffer Address [63:1] | DD |
773 * +-----------------------------------------------------+
774 *
775 *
776 * 82599+ Advanced Receive Descriptor (Write-Back) Format
777 *
778 * 63 48 47 32 31 30 21 20 17 16 4 3 0
779 * +------------------------------------------------------+
780 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
781 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
782 * |/ Flow Dir Flt ID | | | | | |
783 * +------------------------------------------------------+
784 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
785 * +------------------------------------------------------+
786 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000787 */
Josh Hay39ac8682012-09-26 05:59:36 +0000788
Taku Izumidcd79ae2010-04-27 14:39:53 +0000789 for (n = 0; n < adapter->num_rx_queues; n++) {
790 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000791 pr_info("------------------------------------\n");
792 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
793 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000794 pr_info("%s%s%s",
795 "R [desc] [ PktBuf A0] ",
796 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000797 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000798 pr_info("%s%s%s",
799 "RWB[desc] [PcsmIpSHl PtRs] ",
800 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000801 "<-- Adv Rx Write-Back format\n");
802
803 for (i = 0; i < rx_ring->count; i++) {
804 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000805 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000806 u0 = (struct my_u0 *)rx_desc;
807 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
808 if (staterr & IXGBE_RXD_STAT_DD) {
809 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000810 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000811 "%016llX ---------------- %p", i,
812 le64_to_cpu(u0->a),
813 le64_to_cpu(u0->b),
814 rx_buffer_info->skb);
815 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000816 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000817 "%016llX %016llX %p", i,
818 le64_to_cpu(u0->a),
819 le64_to_cpu(u0->b),
820 (u64)rx_buffer_info->dma,
821 rx_buffer_info->skb);
822
Emil Tantilov9c50c032012-07-26 01:21:24 +0000823 if (netif_msg_pktdata(adapter) &&
824 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000825 print_hex_dump(KERN_INFO, "",
826 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000827 page_address(rx_buffer_info->page) +
828 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000829 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000830 }
831 }
832
833 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000834 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000835 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000836 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000837 else
Joe Perchesc7689572010-09-07 21:35:17 +0000838 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000839
840 }
841 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000842}
843
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800844static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
845{
846 u32 ctrl_ext;
847
848 /* Let firmware take over control of h/w */
849 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
850 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000851 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800852}
853
854static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
855{
856 u32 ctrl_ext;
857
858 /* Let firmware know the driver has taken over */
859 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
860 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000861 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800862}
Auke Kok9a799d72007-09-15 14:07:45 -0700863
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000864/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000865 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
866 * @adapter: pointer to adapter struct
867 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
868 * @queue: queue to map the corresponding interrupt to
869 * @msix_vector: the vector to map to the corresponding queue
870 *
871 */
872static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000873 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700874{
875 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000876 struct ixgbe_hw *hw = &adapter->hw;
877 switch (hw->mac.type) {
878 case ixgbe_mac_82598EB:
879 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
880 if (direction == -1)
881 direction = 0;
882 index = (((direction * 64) + queue) >> 2) & 0x1F;
883 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
884 ivar &= ~(0xFF << (8 * (queue & 0x3)));
885 ivar |= (msix_vector << (8 * (queue & 0x3)));
886 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
887 break;
888 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800889 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000890 case ixgbe_mac_X550:
891 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700892 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000893 if (direction == -1) {
894 /* other causes */
895 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
896 index = ((queue & 1) * 8);
897 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
898 ivar &= ~(0xFF << index);
899 ivar |= (msix_vector << index);
900 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
901 break;
902 } else {
903 /* tx or rx causes */
904 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
905 index = ((16 * (queue & 1)) + (8 * direction));
906 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
907 ivar &= ~(0xFF << index);
908 ivar |= (msix_vector << index);
909 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
910 break;
911 }
912 default:
913 break;
914 }
Auke Kok9a799d72007-09-15 14:07:45 -0700915}
916
Alexander Duyckfe49f042009-06-04 16:00:09 +0000917static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000918 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000919{
920 u32 mask;
921
Alexander Duyckbd508172010-11-16 19:27:03 -0800922 switch (adapter->hw.mac.type) {
923 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000924 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
925 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800926 break;
927 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800928 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000929 case ixgbe_mac_X550:
930 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700931 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000932 mask = (qmask & 0xFFFFFFFF);
933 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
934 mask = (qmask >> 32);
935 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800936 break;
937 default:
938 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000939 }
940}
941
Alexander Duyck729739b2012-02-08 07:51:06 +0000942void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
943 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000944{
Alexander Duyck729739b2012-02-08 07:51:06 +0000945 if (tx_buffer->skb) {
946 dev_kfree_skb_any(tx_buffer->skb);
947 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000948 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000949 dma_unmap_addr(tx_buffer, dma),
950 dma_unmap_len(tx_buffer, len),
951 DMA_TO_DEVICE);
952 } else if (dma_unmap_len(tx_buffer, len)) {
953 dma_unmap_page(ring->dev,
954 dma_unmap_addr(tx_buffer, dma),
955 dma_unmap_len(tx_buffer, len),
956 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000957 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000958 tx_buffer->next_to_watch = NULL;
959 tx_buffer->skb = NULL;
960 dma_unmap_len_set(tx_buffer, len, 0);
961 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700962}
963
Alexander Duyck943561d2012-05-09 22:14:44 -0700964static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
965{
966 struct ixgbe_hw *hw = &adapter->hw;
967 struct ixgbe_hw_stats *hwstats = &adapter->stats;
968 int i;
969 u32 data;
970
971 if ((hw->fc.current_mode != ixgbe_fc_full) &&
972 (hw->fc.current_mode != ixgbe_fc_rx_pause))
973 return;
974
975 switch (hw->mac.type) {
976 case ixgbe_mac_82598EB:
977 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
978 break;
979 default:
980 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
981 }
982 hwstats->lxoffrxc += data;
983
984 /* refill credits (no tx hang) if we received xoff */
985 if (!data)
986 return;
987
988 for (i = 0; i < adapter->num_tx_queues; i++)
989 clear_bit(__IXGBE_HANG_CHECK_ARMED,
990 &adapter->tx_ring[i]->state);
991}
992
John Fastabendc84d3242010-11-16 19:27:12 -0800993static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700994{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700995 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800996 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800997 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000998 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800999 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -07001000 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001001
Alexander Duyck943561d2012-05-09 22:14:44 -07001002 if (adapter->ixgbe_ieee_pfc)
1003 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -08001004
Alexander Duyck943561d2012-05-09 22:14:44 -07001005 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
1006 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -08001007 return;
Alexander Duyck943561d2012-05-09 22:14:44 -07001008 }
John Fastabendc84d3242010-11-16 19:27:12 -08001009
1010 /* update stats for each tc, only valid with PFC enabled */
1011 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001012 u32 pxoffrxc;
1013
John Fastabendc84d3242010-11-16 19:27:12 -08001014 switch (hw->mac.type) {
1015 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001016 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001017 break;
1018 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001019 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001020 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001021 hwstats->pxoffrxc[i] += pxoffrxc;
1022 /* Get the TC for given UP */
1023 tc = netdev_get_prio_tc_map(adapter->netdev, i);
1024 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -07001025 }
1026
John Fastabendc84d3242010-11-16 19:27:12 -08001027 /* disarm tx queues that have received xoff frames */
1028 for (i = 0; i < adapter->num_tx_queues; i++) {
1029 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -08001030
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001031 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001032 if (xoff[tc])
1033 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1034 }
1035}
1036
1037static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1038{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001039 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001040}
1041
1042static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1043{
John Fastabend2a47fa42013-11-06 09:54:52 -08001044 struct ixgbe_adapter *adapter;
1045 struct ixgbe_hw *hw;
1046 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001047
John Fastabend2a47fa42013-11-06 09:54:52 -08001048 if (ring->l2_accel_priv)
1049 adapter = ring->l2_accel_priv->real_adapter;
1050 else
1051 adapter = netdev_priv(ring->netdev);
1052
1053 hw = &adapter->hw;
1054 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1055 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001056
1057 if (head != tail)
1058 return (head < tail) ?
1059 tail - head : (tail + ring->count - head);
1060
1061 return 0;
1062}
1063
1064static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1065{
1066 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1067 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1068 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001069
1070 clear_check_for_tx_hang(tx_ring);
1071
1072 /*
1073 * Check for a hung queue, but be thorough. This verifies
1074 * that a transmit has been completed since the previous
1075 * check AND there is at least one packet pending. The
1076 * ARMED bit is set to indicate a potential hang. The
1077 * bit is cleared if a pause frame is received to remove
1078 * false hang detection due to PFC or 802.3x frames. By
1079 * requiring this to fail twice we avoid races with
1080 * pfc clearing the ARMED bit and conditions where we
1081 * run the check_tx_hang logic with a transmit completion
1082 * pending but without time to complete it yet.
1083 */
Mark Rustade90dd262014-07-22 06:51:08 +00001084 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001085 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001086 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1087 &tx_ring->state);
1088 /* update completed stats and continue */
1089 tx_ring->tx_stats.tx_done_old = tx_done;
1090 /* reset the countdown */
1091 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001092
Mark Rustade90dd262014-07-22 06:51:08 +00001093 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001094}
1095
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001096/**
1097 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1098 * @adapter: driver private struct
1099 **/
1100static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1101{
1102
1103 /* Do the reset outside of interrupt context */
1104 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1105 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Jacob Keller12ff3f32012-12-01 07:57:17 +00001106 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001107 ixgbe_service_event_schedule(adapter);
1108 }
1109}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001110
Auke Kok9a799d72007-09-15 14:07:45 -07001111/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001112 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1113 **/
1114static int ixgbe_tx_maxrate(struct net_device *netdev,
1115 int queue_index, u32 maxrate)
1116{
1117 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1118 struct ixgbe_hw *hw = &adapter->hw;
1119 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1120
1121 if (!maxrate)
1122 return 0;
1123
1124 /* Calculate the rate factor values to set */
1125 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1126 bcnrc_val /= maxrate;
1127
1128 /* clear everything but the rate factor */
1129 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1130 IXGBE_RTTBCNRC_RF_DEC_MASK;
1131
1132 /* enable the rate scheduler */
1133 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1134
1135 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1136 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1137
1138 return 0;
1139}
1140
1141/**
Auke Kok9a799d72007-09-15 14:07:45 -07001142 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001143 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001144 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001145 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001146 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001147static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001148 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001149{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001150 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001151 struct ixgbe_tx_buffer *tx_buffer;
1152 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001153 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001154 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001155 unsigned int i = tx_ring->next_to_clean;
1156
1157 if (test_bit(__IXGBE_DOWN, &adapter->state))
1158 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001159
Alexander Duyckd3d00232011-07-15 02:31:25 +00001160 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001161 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001162 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001163
Alexander Duyck729739b2012-02-08 07:51:06 +00001164 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001165 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001166
Alexander Duyckd3d00232011-07-15 02:31:25 +00001167 /* if next_to_watch is not set then there is no work pending */
1168 if (!eop_desc)
1169 break;
1170
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001171 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001172 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001173
Alexander Duyckd3d00232011-07-15 02:31:25 +00001174 /* if DD is not set pending work has not been completed */
1175 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1176 break;
1177
Alexander Duyckd3d00232011-07-15 02:31:25 +00001178 /* clear next_to_watch to prevent false hangs */
1179 tx_buffer->next_to_watch = NULL;
1180
Alexander Duyck091a6242012-02-08 07:51:01 +00001181 /* update the statistics for this packet */
1182 total_bytes += tx_buffer->bytecount;
1183 total_packets += tx_buffer->gso_segs;
1184
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001185 /* free the skb */
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001186 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001187
Alexander Duyck729739b2012-02-08 07:51:06 +00001188 /* unmap skb header data */
1189 dma_unmap_single(tx_ring->dev,
1190 dma_unmap_addr(tx_buffer, dma),
1191 dma_unmap_len(tx_buffer, len),
1192 DMA_TO_DEVICE);
1193
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001194 /* clear tx_buffer data */
1195 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +00001196 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001197
Alexander Duyck729739b2012-02-08 07:51:06 +00001198 /* unmap remaining buffers */
1199 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001200 tx_buffer++;
1201 tx_desc++;
1202 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001203 if (unlikely(!i)) {
1204 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001205 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001206 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001207 }
1208
Alexander Duyck729739b2012-02-08 07:51:06 +00001209 /* unmap any remaining paged data */
1210 if (dma_unmap_len(tx_buffer, len)) {
1211 dma_unmap_page(tx_ring->dev,
1212 dma_unmap_addr(tx_buffer, dma),
1213 dma_unmap_len(tx_buffer, len),
1214 DMA_TO_DEVICE);
1215 dma_unmap_len_set(tx_buffer, len, 0);
1216 }
1217 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001218
Alexander Duyck729739b2012-02-08 07:51:06 +00001219 /* move us one more past the eop_desc for start of next pkt */
1220 tx_buffer++;
1221 tx_desc++;
1222 i++;
1223 if (unlikely(!i)) {
1224 i -= tx_ring->count;
1225 tx_buffer = tx_ring->tx_buffer_info;
1226 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1227 }
1228
1229 /* issue prefetch for next Tx descriptor */
1230 prefetch(tx_desc);
1231
1232 /* update budget accounting */
1233 budget--;
1234 } while (likely(budget));
1235
1236 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001237 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001238 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001239 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001240 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001241 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001242 q_vector->tx.total_bytes += total_bytes;
1243 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001244
John Fastabendc84d3242010-11-16 19:27:12 -08001245 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001246 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001247 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001248 e_err(drv, "Detected Tx Unit Hang\n"
1249 " Tx Queue <%d>\n"
1250 " TDH, TDT <%x>, <%x>\n"
1251 " next_to_use <%x>\n"
1252 " next_to_clean <%x>\n"
1253 "tx_buffer_info[next_to_clean]\n"
1254 " time_stamp <%lx>\n"
1255 " jiffies <%lx>\n",
1256 tx_ring->queue_index,
1257 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1258 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001259 tx_ring->next_to_use, i,
1260 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001261
1262 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1263
1264 e_info(probe,
1265 "tx hang %d detected on queue %d, resetting adapter\n",
1266 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1267
1268 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001269 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001270
1271 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001272 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001273 }
Auke Kok9a799d72007-09-15 14:07:45 -07001274
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001275 netdev_tx_completed_queue(txring_txq(tx_ring),
1276 total_packets, total_bytes);
1277
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001278#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001279 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001280 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001281 /* Make sure that anybody stopping the queue after this
1282 * sees the new next_to_clean.
1283 */
1284 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001285 if (__netif_subqueue_stopped(tx_ring->netdev,
1286 tx_ring->queue_index)
1287 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1288 netif_wake_subqueue(tx_ring->netdev,
1289 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001290 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001291 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001292 }
Auke Kok9a799d72007-09-15 14:07:45 -07001293
Alexander Duyck59224552011-08-31 00:01:06 +00001294 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001295}
1296
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001297#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001298static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001299 struct ixgbe_ring *tx_ring,
1300 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001301{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001302 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001303 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001304 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001305
Mark Rustad9de76052015-08-08 16:27:41 -07001306 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1307 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1308
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001309 switch (hw->mac.type) {
1310 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001311 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001312 break;
1313 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001314 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001315 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1316 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1317 break;
1318 default:
1319 /* for unknown hardware do not write register */
1320 return;
1321 }
1322
1323 /*
1324 * We can enable relaxed ordering for reads, but not writes when
1325 * DCA is enabled. This is due to a known issue in some chipsets
1326 * which will cause the DCA tag to be cleared.
1327 */
1328 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1329 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1330 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1331
1332 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1333}
1334
1335static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1336 struct ixgbe_ring *rx_ring,
1337 int cpu)
1338{
1339 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001340 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001341 u8 reg_idx = rx_ring->reg_idx;
1342
Mark Rustad9de76052015-08-08 16:27:41 -07001343 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1344 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001345
1346 switch (hw->mac.type) {
1347 case ixgbe_mac_82599EB:
1348 case ixgbe_mac_X540:
1349 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001350 break;
1351 default:
1352 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001353 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001354
1355 /*
1356 * We can enable relaxed ordering for reads, but not writes when
1357 * DCA is enabled. This is due to a known issue in some chipsets
1358 * which will cause the DCA tag to be cleared.
1359 */
1360 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Mark Rustad9de76052015-08-08 16:27:41 -07001361 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001362 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1363
1364 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001365}
1366
1367static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1368{
1369 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001370 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001371 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001372
1373 if (q_vector->cpu == cpu)
1374 goto out_no_update;
1375
Alexander Duycka5579282012-02-08 07:50:04 +00001376 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001377 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001378
Alexander Duycka5579282012-02-08 07:50:04 +00001379 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001380 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001381
1382 q_vector->cpu = cpu;
1383out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001384 put_cpu();
1385}
1386
1387static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1388{
1389 int i;
1390
Alexander Duycke35ec122009-05-21 13:07:12 +00001391 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001392 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1393 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1394 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1395 else
1396 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1397 IXGBE_DCA_CTRL_DCA_DISABLE);
Alexander Duycke35ec122009-05-21 13:07:12 +00001398
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001399 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001400 adapter->q_vector[i]->cpu = -1;
1401 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001402 }
1403}
1404
1405static int __ixgbe_notify_dca(struct device *dev, void *data)
1406{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001407 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001408 unsigned long event = *(unsigned long *)data;
1409
Don Skidmore2a72c312011-07-20 02:27:05 +00001410 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001411 return 0;
1412
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001413 switch (event) {
1414 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001415 /* if we're already enabled, don't do it again */
1416 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1417 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001418 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001419 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001420 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1421 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001422 break;
1423 }
1424 /* Fall Through since DCA is disabled. */
1425 case DCA_PROVIDER_REMOVE:
1426 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1427 dca_remove_requester(dev);
1428 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001429 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1430 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001431 }
1432 break;
1433 }
1434
Denis V. Lunev652f0932008-03-27 14:39:17 +03001435 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001436}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001437
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001438#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b2015-04-29 10:57:39 +08001439
1440#define IXGBE_RSS_L4_TYPES_MASK \
1441 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1442 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1443 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1444 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1445
Alexander Duyck8a0da212012-01-31 02:59:49 +00001446static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1447 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001448 struct sk_buff *skb)
1449{
Fan Du7edda4b2015-04-29 10:57:39 +08001450 u16 rss_type;
1451
1452 if (!(ring->netdev->features & NETIF_F_RXHASH))
1453 return;
1454
1455 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1456 IXGBE_RXDADV_RSSTYPE_MASK;
1457
1458 if (!rss_type)
1459 return;
1460
1461 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1462 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1463 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001464}
1465
Alexander Duyckf8003262012-03-03 02:35:52 +00001466#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001467/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001468 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001469 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001470 * @rx_desc: advanced rx descriptor
1471 *
1472 * Returns : true if it is FCoE pkt
1473 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001474static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001475 union ixgbe_adv_rx_desc *rx_desc)
1476{
1477 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1478
Alexander Duyck57efd442012-06-25 21:54:46 +00001479 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001480 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1481 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1482 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1483}
1484
Alexander Duyckf8003262012-03-03 02:35:52 +00001485#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001486/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001487 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001488 * @ring: structure containing ring specific data
1489 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001490 * @skb: skb currently being received and modified
1491 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001492static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001493 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001494 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001495{
Don Skidmore3f207802014-12-23 07:40:34 +00001496 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1497 __le16 hdr_info = rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
1498 bool encap_pkt = false;
1499
Alexander Duyck8a0da212012-01-31 02:59:49 +00001500 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001501
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001502 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001503 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001504 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001505
Don Skidmore3f207802014-12-23 07:40:34 +00001506 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) &&
1507 (hdr_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL >> 16))) {
1508 encap_pkt = true;
1509 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001510 }
1511
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001512 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001513 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1514 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001515 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001516 return;
1517 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001518
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001519 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001520 return;
1521
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001522 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001523 /*
1524 * 82599 errata, UDP frames with a 0 checksum can be marked as
1525 * checksum errors.
1526 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001527 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1528 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001529 return;
1530
Alexander Duyck8a0da212012-01-31 02:59:49 +00001531 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001532 return;
1533 }
1534
Auke Kok9a799d72007-09-15 14:07:45 -07001535 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001536 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001537 if (encap_pkt) {
1538 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1539 return;
1540
1541 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
Mark Rustadd4692512015-12-04 11:26:43 -08001542 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001543 return;
1544 }
1545 /* If we checked the outer header let the stack know */
1546 skb->csum_level = 1;
1547 }
Auke Kok9a799d72007-09-15 14:07:45 -07001548}
1549
Alexander Duyckf990b792012-01-31 02:59:34 +00001550static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1551 struct ixgbe_rx_buffer *bi)
1552{
1553 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001554 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001555
Alexander Duyckf8003262012-03-03 02:35:52 +00001556 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001557 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001558 return true;
1559
Alexander Duyckf8003262012-03-03 02:35:52 +00001560 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001561 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1562 if (unlikely(!page)) {
1563 rx_ring->rx_stats.alloc_rx_page_failed++;
1564 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001565 }
1566
Alexander Duyckf8003262012-03-03 02:35:52 +00001567 /* map page for use */
1568 dma = dma_map_page(rx_ring->dev, page, 0,
1569 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001570
Alexander Duyckf8003262012-03-03 02:35:52 +00001571 /*
1572 * if mapping failed free memory back to system since
1573 * there isn't much point in holding memory we can't use
1574 */
1575 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001576 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001577
Alexander Duyckf990b792012-01-31 02:59:34 +00001578 rx_ring->rx_stats.alloc_rx_page_failed++;
1579 return false;
1580 }
1581
Alexander Duyckf8003262012-03-03 02:35:52 +00001582 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001583 bi->page = page;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001584 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001585
Alexander Duyckf990b792012-01-31 02:59:34 +00001586 return true;
1587}
1588
Auke Kok9a799d72007-09-15 14:07:45 -07001589/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001590 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001591 * @rx_ring: ring to place buffers on
1592 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001593 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001594void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001595{
Auke Kok9a799d72007-09-15 14:07:45 -07001596 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001597 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001598 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001599
Alexander Duyckf8003262012-03-03 02:35:52 +00001600 /* nothing to do */
1601 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001602 return;
1603
Alexander Duycke4f74022012-01-31 02:59:44 +00001604 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001605 bi = &rx_ring->rx_buffer_info[i];
1606 i -= rx_ring->count;
1607
Alexander Duyckf8003262012-03-03 02:35:52 +00001608 do {
1609 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001610 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001611
Alexander Duyckf8003262012-03-03 02:35:52 +00001612 /*
1613 * Refresh the desc even if buffer_addrs didn't change
1614 * because each write-back erases this info.
1615 */
1616 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001617
Alexander Duyckf990b792012-01-31 02:59:34 +00001618 rx_desc++;
1619 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001620 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001621 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001622 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001623 bi = rx_ring->rx_buffer_info;
1624 i -= rx_ring->count;
1625 }
1626
Alexander Duyck18cb6522014-11-14 00:56:29 +00001627 /* clear the status bits for the next_to_use descriptor */
1628 rx_desc->wb.upper.status_error = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001629
1630 cleaned_count--;
1631 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001632
Alexander Duyckf990b792012-01-31 02:59:34 +00001633 i += rx_ring->count;
1634
Alexander Duyckad435ec2014-11-14 00:56:35 +00001635 if (rx_ring->next_to_use != i) {
1636 rx_ring->next_to_use = i;
1637
1638 /* update next to alloc since we have filled the ring */
1639 rx_ring->next_to_alloc = i;
1640
1641 /* Force memory writes to complete before letting h/w
1642 * know there are new descriptors to fetch. (Only
1643 * applicable for weak-ordered memory model archs,
1644 * such as IA-64).
1645 */
1646 wmb();
1647 writel(i, rx_ring->tail);
1648 }
Auke Kok9a799d72007-09-15 14:07:45 -07001649}
1650
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001651static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1652 struct sk_buff *skb)
1653{
Alexander Duyckf8003262012-03-03 02:35:52 +00001654 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001655
1656 /* set gso_size to avoid messing up TCP MSS */
1657 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1658 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001659 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001660}
1661
1662static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1663 struct sk_buff *skb)
1664{
1665 /* if append_cnt is 0 then frame is not RSC */
1666 if (!IXGBE_CB(skb)->append_cnt)
1667 return;
1668
1669 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1670 rx_ring->rx_stats.rsc_flush++;
1671
1672 ixgbe_set_rsc_gso_size(rx_ring, skb);
1673
1674 /* gso_size is computed using append_cnt so always clear it last */
1675 IXGBE_CB(skb)->append_cnt = 0;
1676}
1677
Alexander Duyck8a0da212012-01-31 02:59:49 +00001678/**
1679 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1680 * @rx_ring: rx descriptor ring packet is being transacted on
1681 * @rx_desc: pointer to the EOP Rx descriptor
1682 * @skb: pointer to current skb being populated
1683 *
1684 * This function checks the ring, descriptor, and packet information in
1685 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1686 * other fields within the skb.
1687 **/
1688static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1689 union ixgbe_adv_rx_desc *rx_desc,
1690 struct sk_buff *skb)
1691{
John Fastabend43e95f12012-05-15 06:12:17 +00001692 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001693 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001694
Alexander Duyck8a0da212012-01-31 02:59:49 +00001695 ixgbe_update_rsc_stats(rx_ring, skb);
1696
1697 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1698
1699 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1700
Mark Rustada9763f32015-10-27 09:58:07 -07001701 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1702 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001703
Patrick McHardyf6469682013-04-19 02:04:27 +00001704 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001705 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001706 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001707 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001708 }
1709
1710 skb_record_rx_queue(skb, rx_ring->queue_index);
1711
John Fastabend43e95f12012-05-15 06:12:17 +00001712 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001713}
1714
1715static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1716 struct sk_buff *skb)
1717{
Eric Dumazet93f93a42015-11-18 06:30:59 -08001718 skb_mark_napi_id(skb, &q_vector->napi);
Jacob Kellerb4640032013-10-01 04:33:54 -07001719 if (ixgbe_qv_busy_polling(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001720 netif_receive_skb(skb);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001721 else
Alexander Duyck856f6062015-02-25 17:45:54 +00001722 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001723}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001724
Alexander Duyckf8003262012-03-03 02:35:52 +00001725/**
1726 * ixgbe_is_non_eop - process handling of non-EOP buffers
1727 * @rx_ring: Rx ring being processed
1728 * @rx_desc: Rx descriptor for current buffer
1729 * @skb: Current socket buffer containing buffer in progress
1730 *
1731 * This function updates next to clean. If the buffer is an EOP buffer
1732 * this function exits returning false, otherwise it will place the
1733 * sk_buff in the next buffer to be chained and return true indicating
1734 * that this is in fact a non-EOP buffer.
1735 **/
1736static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1737 union ixgbe_adv_rx_desc *rx_desc,
1738 struct sk_buff *skb)
1739{
1740 u32 ntc = rx_ring->next_to_clean + 1;
1741
1742 /* fetch, update, and store next to clean */
1743 ntc = (ntc < rx_ring->count) ? ntc : 0;
1744 rx_ring->next_to_clean = ntc;
1745
1746 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1747
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001748 /* update RSC append count if present */
1749 if (ring_is_rsc_enabled(rx_ring)) {
1750 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1751 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1752
1753 if (unlikely(rsc_enabled)) {
1754 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1755
1756 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1757 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1758
1759 /* update ntc based on RSC value */
1760 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1761 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1762 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1763 }
1764 }
1765
1766 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001767 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1768 return false;
1769
Alexander Duyckf8003262012-03-03 02:35:52 +00001770 /* place skb in next buffer to be received */
1771 rx_ring->rx_buffer_info[ntc].skb = skb;
1772 rx_ring->rx_stats.non_eop_descs++;
1773
1774 return true;
1775}
1776
1777/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001778 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1779 * @rx_ring: rx descriptor ring packet is being transacted on
1780 * @skb: pointer to current skb being adjusted
1781 *
1782 * This function is an ixgbe specific version of __pskb_pull_tail. The
1783 * main difference between this version and the original function is that
1784 * this function can make several assumptions about the state of things
1785 * that allow for significant optimizations versus the standard function.
1786 * As a result we can do things like drop a frag and maintain an accurate
1787 * truesize for the skb.
1788 */
1789static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1790 struct sk_buff *skb)
1791{
1792 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1793 unsigned char *va;
1794 unsigned int pull_len;
1795
1796 /*
1797 * it is valid to use page_address instead of kmap since we are
1798 * working with pages allocated out of the lomem pool per
1799 * alloc_page(GFP_ATOMIC)
1800 */
1801 va = skb_frag_address(frag);
1802
1803 /*
1804 * we need the header to contain the greater of either ETH_HLEN or
1805 * 60 bytes if the skb->len is less than 60 for skb_pad.
1806 */
Alexander Duyck8496e332014-09-05 19:22:18 -04001807 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001808
1809 /* align pull length to size of long to optimize memcpy performance */
1810 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1811
1812 /* update all of the pointers */
1813 skb_frag_size_sub(frag, pull_len);
1814 frag->page_offset += pull_len;
1815 skb->data_len -= pull_len;
1816 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001817}
1818
1819/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001820 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1821 * @rx_ring: rx descriptor ring packet is being transacted on
1822 * @skb: pointer to current skb being updated
1823 *
1824 * This function provides a basic DMA sync up for the first fragment of an
1825 * skb. The reason for doing this is that the first fragment cannot be
1826 * unmapped until we have reached the end of packet descriptor for a buffer
1827 * chain.
1828 */
1829static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1830 struct sk_buff *skb)
1831{
1832 /* if the page was released unmap it, else just sync our portion */
1833 if (unlikely(IXGBE_CB(skb)->page_released)) {
1834 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1835 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1836 IXGBE_CB(skb)->page_released = false;
1837 } else {
1838 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1839
1840 dma_sync_single_range_for_cpu(rx_ring->dev,
1841 IXGBE_CB(skb)->dma,
1842 frag->page_offset,
1843 ixgbe_rx_bufsz(rx_ring),
1844 DMA_FROM_DEVICE);
1845 }
1846 IXGBE_CB(skb)->dma = 0;
1847}
1848
1849/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001850 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1851 * @rx_ring: rx descriptor ring packet is being transacted on
1852 * @rx_desc: pointer to the EOP Rx descriptor
1853 * @skb: pointer to current skb being fixed
1854 *
1855 * Check for corrupted packet headers caused by senders on the local L2
1856 * embedded NIC switch not setting up their Tx Descriptors right. These
1857 * should be very rare.
1858 *
1859 * Also address the case where we are pulling data in on pages only
1860 * and as such no data is present in the skb header.
1861 *
1862 * In addition if skb is not at least 60 bytes we need to pad it so that
1863 * it is large enough to qualify as a valid Ethernet frame.
1864 *
1865 * Returns true if an error was encountered and skb was freed.
1866 **/
1867static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1868 union ixgbe_adv_rx_desc *rx_desc,
1869 struct sk_buff *skb)
1870{
Alexander Duyckf8003262012-03-03 02:35:52 +00001871 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001872
1873 /* verify that the packet does not have any known errors */
1874 if (unlikely(ixgbe_test_staterr(rx_desc,
1875 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1876 !(netdev->features & NETIF_F_RXALL))) {
1877 dev_kfree_skb_any(skb);
1878 return true;
1879 }
1880
Alexander Duyck19861ce2012-07-20 08:08:33 +00001881 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001882 if (skb_is_nonlinear(skb))
1883 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001884
Alexander Duyck57efd442012-06-25 21:54:46 +00001885#ifdef IXGBE_FCOE
1886 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1887 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1888 return false;
1889
1890#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001891 /* if eth_skb_pad returns an error the skb was freed */
1892 if (eth_skb_pad(skb))
1893 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001894
1895 return false;
1896}
1897
1898/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001899 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1900 * @rx_ring: rx descriptor ring to store buffers on
1901 * @old_buff: donor buffer to have page reused
1902 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001903 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001904 **/
1905static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1906 struct ixgbe_rx_buffer *old_buff)
1907{
1908 struct ixgbe_rx_buffer *new_buff;
1909 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001910
1911 new_buff = &rx_ring->rx_buffer_info[nta];
1912
1913 /* update, and store next to alloc */
1914 nta++;
1915 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1916
1917 /* transfer page from old buffer to new buffer */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001918 *new_buff = *old_buff;
Alexander Duyckf8003262012-03-03 02:35:52 +00001919
1920 /* sync the buffer for use by the device */
1921 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001922 new_buff->page_offset,
1923 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001924 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001925}
1926
Alexander Duyck18cb6522014-11-14 00:56:29 +00001927static inline bool ixgbe_page_is_reserved(struct page *page)
1928{
Michal Hocko2f064f32015-08-21 14:11:51 -07001929 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001930}
1931
Alexander Duyckf8003262012-03-03 02:35:52 +00001932/**
1933 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1934 * @rx_ring: rx descriptor ring to transact packets on
1935 * @rx_buffer: buffer containing page to add
1936 * @rx_desc: descriptor containing length of buffer written by hardware
1937 * @skb: sk_buff to place the data into
1938 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001939 * This function will add the data contained in rx_buffer->page to the skb.
1940 * This is done either through a direct copy if the data in the buffer is
1941 * less than the skb header size, otherwise it will just attach the page as
1942 * a frag to the skb.
1943 *
1944 * The function will then update the page offset if necessary and return
1945 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001946 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001947static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001948 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001949 union ixgbe_adv_rx_desc *rx_desc,
1950 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001951{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001952 struct page *page = rx_buffer->page;
1953 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001954#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001955 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001956#else
1957 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1958 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1959 ixgbe_rx_bufsz(rx_ring);
1960#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001961
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001962 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1963 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1964
1965 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1966
Alexander Duyck18cb6522014-11-14 00:56:29 +00001967 /* page is not reserved, we can reuse buffer as-is */
1968 if (likely(!ixgbe_page_is_reserved(page)))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001969 return true;
1970
1971 /* this page cannot be reused so discard it */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001972 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001973 return false;
1974 }
1975
Alexander Duyck0549ae22012-07-20 08:08:18 +00001976 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1977 rx_buffer->page_offset, size, truesize);
1978
Alexander Duyck09816fb2012-07-20 08:08:23 +00001979 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001980 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001981 return false;
1982
1983#if (PAGE_SIZE < 8192)
1984 /* if we are only owner of page we can reuse it */
1985 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001986 return false;
1987
1988 /* flip page offset to other buffer */
1989 rx_buffer->page_offset ^= truesize;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001990#else
1991 /* move offset up to the next cache line */
1992 rx_buffer->page_offset += truesize;
1993
1994 if (rx_buffer->page_offset > last_offset)
1995 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001996#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001997
Alexander Duyck18cb6522014-11-14 00:56:29 +00001998 /* Even if we own the page, we are not allowed to use atomic_set()
1999 * This would break get_page_unless_zero() users.
2000 */
Joonsoo Kimfe896d12016-03-17 14:19:26 -07002001 page_ref_inc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00002002
Alexander Duyck0549ae22012-07-20 08:08:18 +00002003 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00002004}
2005
Alexander Duyck18806c92012-07-20 08:08:44 +00002006static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
2007 union ixgbe_adv_rx_desc *rx_desc)
2008{
2009 struct ixgbe_rx_buffer *rx_buffer;
2010 struct sk_buff *skb;
2011 struct page *page;
2012
2013 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
2014 page = rx_buffer->page;
2015 prefetchw(page);
2016
2017 skb = rx_buffer->skb;
2018
2019 if (likely(!skb)) {
2020 void *page_addr = page_address(page) +
2021 rx_buffer->page_offset;
2022
2023 /* prefetch first cache line of first page */
2024 prefetch(page_addr);
2025#if L1_CACHE_BYTES < 128
2026 prefetch(page_addr + L1_CACHE_BYTES);
2027#endif
2028
2029 /* allocate a skb to store the frags */
Alexander Duyck67fd8932014-12-09 19:40:56 -08002030 skb = napi_alloc_skb(&rx_ring->q_vector->napi,
2031 IXGBE_RX_HDR_SIZE);
Alexander Duyck18806c92012-07-20 08:08:44 +00002032 if (unlikely(!skb)) {
2033 rx_ring->rx_stats.alloc_rx_buff_failed++;
2034 return NULL;
2035 }
2036
2037 /*
2038 * we will be copying header into skb->data in
2039 * pskb_may_pull so it is in our interest to prefetch
2040 * it now to avoid a possible cache miss
2041 */
2042 prefetchw(skb->data);
2043
2044 /*
2045 * Delay unmapping of the first packet. It carries the
2046 * header information, HW may still access the header
2047 * after the writeback. Only unmap it when EOP is
2048 * reached
2049 */
2050 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
2051 goto dma_sync;
2052
2053 IXGBE_CB(skb)->dma = rx_buffer->dma;
2054 } else {
2055 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2056 ixgbe_dma_sync_frag(rx_ring, skb);
2057
2058dma_sync:
2059 /* we are reusing so sync this buffer for CPU use */
2060 dma_sync_single_range_for_cpu(rx_ring->dev,
2061 rx_buffer->dma,
2062 rx_buffer->page_offset,
2063 ixgbe_rx_bufsz(rx_ring),
2064 DMA_FROM_DEVICE);
Alexander Duyck18cb6522014-11-14 00:56:29 +00002065
2066 rx_buffer->skb = NULL;
Alexander Duyck18806c92012-07-20 08:08:44 +00002067 }
2068
2069 /* pull page into skb */
2070 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
2071 /* hand second half of page back to the ring */
2072 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
2073 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
2074 /* the page has been released from the ring */
2075 IXGBE_CB(skb)->page_released = true;
2076 } else {
2077 /* we are not reusing the buffer so unmap it */
2078 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
2079 ixgbe_rx_pg_size(rx_ring),
2080 DMA_FROM_DEVICE);
2081 }
2082
2083 /* clear contents of buffer_info */
Alexander Duyck18806c92012-07-20 08:08:44 +00002084 rx_buffer->page = NULL;
2085
2086 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002087}
2088
2089/**
2090 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2091 * @q_vector: structure containing interrupt and ring information
2092 * @rx_ring: rx descriptor ring to transact packets on
2093 * @budget: Total limit on number of packets to process
2094 *
2095 * This function provides a "bounce buffer" approach to Rx interrupt
2096 * processing. The advantage to this is that on systems that have
2097 * expensive overhead for IOMMU access this provides a means of avoiding
2098 * it by maintaining the mapping of the page to the syste.
2099 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002100 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002101 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002102static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002103 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002104 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002105{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002106 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00002107#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00002108 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00002109 int ddp_bytes;
2110 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002111#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002112 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002113
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002114 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002115 union ixgbe_adv_rx_desc *rx_desc;
2116 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002117
Alexander Duyckf8003262012-03-03 02:35:52 +00002118 /* return some buffers to hardware, one at a time is too slow */
2119 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2120 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2121 cleaned_count = 0;
2122 }
Auke Kok9a799d72007-09-15 14:07:45 -07002123
Alexander Duyck18806c92012-07-20 08:08:44 +00002124 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07002125
Alexander Duyck124b74c2014-12-11 15:02:28 -08002126 if (!rx_desc->wb.upper.status_error)
Alexander Duyckf8003262012-03-03 02:35:52 +00002127 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002128
Alexander Duyck124b74c2014-12-11 15:02:28 -08002129 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002130 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002131 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002132 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002133 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002134
Alexander Duyck18806c92012-07-20 08:08:44 +00002135 /* retrieve a buffer from the ring */
2136 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00002137
Alexander Duyck18806c92012-07-20 08:08:44 +00002138 /* exit if we failed to retrieve a buffer */
2139 if (!skb)
2140 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002141
Auke Kok9a799d72007-09-15 14:07:45 -07002142 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002143
Alexander Duyckf8003262012-03-03 02:35:52 +00002144 /* place incomplete frames back on ring for completion */
2145 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2146 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002147
Alexander Duyckf8003262012-03-03 02:35:52 +00002148 /* verify the packet layout is correct */
2149 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2150 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002151
2152 /* probably a little skewed due to removing CRC */
2153 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002154
Alexander Duyck8a0da212012-01-31 02:59:49 +00002155 /* populate checksum, timestamp, VLAN, and protocol */
2156 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2157
Yi Zou332d4a72009-05-13 13:11:53 +00002158#ifdef IXGBE_FCOE
2159 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002160 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002161 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002162 /* include DDPed FCoE data */
2163 if (ddp_bytes > 0) {
2164 if (!mss) {
2165 mss = rx_ring->netdev->mtu -
2166 sizeof(struct fcoe_hdr) -
2167 sizeof(struct fc_frame_header) -
2168 sizeof(struct fcoe_crc_eof);
2169 if (mss > 512)
2170 mss &= ~511;
2171 }
2172 total_rx_bytes += ddp_bytes;
2173 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2174 mss);
2175 }
David S. Miller823dcd22011-08-20 10:39:12 -07002176 if (!ddp_bytes) {
2177 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002178 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002179 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002180 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002181
Yi Zou332d4a72009-05-13 13:11:53 +00002182#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002183 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002184
Alexander Duyckf8003262012-03-03 02:35:52 +00002185 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002186 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002187 }
Auke Kok9a799d72007-09-15 14:07:45 -07002188
Alexander Duyckc267fc12010-11-16 19:27:00 -08002189 u64_stats_update_begin(&rx_ring->syncp);
2190 rx_ring->stats.packets += total_rx_packets;
2191 rx_ring->stats.bytes += total_rx_bytes;
2192 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002193 q_vector->rx.total_packets += total_rx_packets;
2194 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002195
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002196 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002197}
2198
Cong Wange0d10952013-08-01 11:10:25 +08002199#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002200/* must be called with local_bh_disable()d */
2201static int ixgbe_low_latency_recv(struct napi_struct *napi)
2202{
2203 struct ixgbe_q_vector *q_vector =
2204 container_of(napi, struct ixgbe_q_vector, napi);
2205 struct ixgbe_adapter *adapter = q_vector->adapter;
2206 struct ixgbe_ring *ring;
2207 int found = 0;
2208
2209 if (test_bit(__IXGBE_DOWN, &adapter->state))
2210 return LL_FLUSH_FAILED;
2211
2212 if (!ixgbe_qv_lock_poll(q_vector))
2213 return LL_FLUSH_BUSY;
2214
2215 ixgbe_for_each_ring(ring, q_vector->rx) {
2216 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
Jacob Kellerb4640032013-10-01 04:33:54 -07002217#ifdef BP_EXTENDED_STATS
Eliezer Tamir7e15b902013-06-10 11:40:31 +03002218 if (found)
2219 ring->stats.cleaned += found;
2220 else
2221 ring->stats.misses++;
2222#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002223 if (found)
2224 break;
2225 }
2226
2227 ixgbe_qv_unlock_poll(q_vector);
2228
2229 return found;
2230}
Cong Wange0d10952013-08-01 11:10:25 +08002231#endif /* CONFIG_NET_RX_BUSY_POLL */
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002232
Auke Kok9a799d72007-09-15 14:07:45 -07002233/**
2234 * ixgbe_configure_msix - Configure MSI-X hardware
2235 * @adapter: board private structure
2236 *
2237 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2238 * interrupts.
2239 **/
2240static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2241{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002242 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002243 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002245
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002246 /* Populate MSIX to EITR Select */
2247 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002248 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002249 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2250 }
2251
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002252 /*
2253 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002254 * corresponding register.
2255 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002256 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002257 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002258 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002259
Alexander Duycka5579282012-02-08 07:50:04 +00002260 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002261 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002262
Alexander Duycka5579282012-02-08 07:50:04 +00002263 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002264 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002265
Alexander Duyckfe49f042009-06-04 16:00:09 +00002266 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002267 }
2268
Alexander Duyckbd508172010-11-16 19:27:03 -08002269 switch (adapter->hw.mac.type) {
2270 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002271 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002272 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002273 break;
2274 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002275 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002276 case ixgbe_mac_X550:
2277 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002278 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002279 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002280 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002281 default:
2282 break;
2283 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002284 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002285
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002286 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002287 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002288 mask &= ~(IXGBE_EIMS_OTHER |
2289 IXGBE_EIMS_MAILBOX |
2290 IXGBE_EIMS_LSC);
2291
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002292 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002293}
2294
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002295enum latency_range {
2296 lowest_latency = 0,
2297 low_latency = 1,
2298 bulk_latency = 2,
2299 latency_invalid = 255
2300};
2301
2302/**
2303 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002304 * @q_vector: structure containing interrupt and ring information
2305 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002306 *
2307 * Stores a new ITR value based on packets and byte
2308 * counts during the last interrupt. The advantage of per interrupt
2309 * computation is faster updates and more accurate ITR for the current
2310 * traffic pattern. Constants in this function were computed
2311 * based on theoretical maximum wire speed and thresholds were set based
2312 * on testing data as well as attempting to minimize response time
2313 * while increasing bulk throughput.
2314 * this functionality is controlled by the InterruptThrottleRate module
2315 * parameter (see ixgbe_param.c)
2316 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002317static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2318 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002319{
Alexander Duyckbd198052011-06-11 01:45:08 +00002320 int bytes = ring_container->total_bytes;
2321 int packets = ring_container->total_packets;
2322 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002323 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002324 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002325
2326 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002327 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002328
2329 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002330 * 0-10MB/s lowest (100000 ints/s)
2331 * 10-20MB/s low (20000 ints/s)
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002332 * 20-1249MB/s bulk (12000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002333 */
2334 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002335 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002336 if (timepassed_us == 0)
2337 return;
2338
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002339 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2340
2341 switch (itr_setting) {
2342 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002343 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002344 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002345 break;
2346 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002347 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002348 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002349 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002350 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002351 break;
2352 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002353 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002354 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002355 break;
2356 }
2357
Alexander Duyckbd198052011-06-11 01:45:08 +00002358 /* clear work counters since we have the values we need */
2359 ring_container->total_bytes = 0;
2360 ring_container->total_packets = 0;
2361
2362 /* write updated itr to ring container */
2363 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002364}
2365
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002366/**
2367 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002368 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002369 *
2370 * This function is made to be called by ethtool and by the driver
2371 * when it needs to update EITR registers at runtime. Hardware
2372 * specific quirks/differences are taken care of here.
2373 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002374void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002375{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002376 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002377 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002378 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002379 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002380
Alexander Duyckbd508172010-11-16 19:27:03 -08002381 switch (adapter->hw.mac.type) {
2382 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002383 /* must write high and low 16 bits to reset counter */
2384 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002385 break;
2386 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002387 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002388 case ixgbe_mac_X550:
2389 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002390 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002391 /*
2392 * set the WDIS bit to not clear the timer bits and cause an
2393 * immediate assertion of the interrupt
2394 */
2395 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002396 break;
2397 default:
2398 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002399 }
2400 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2401}
2402
Alexander Duyckbd198052011-06-11 01:45:08 +00002403static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002404{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002405 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002406 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002407
Alexander Duyckbd198052011-06-11 01:45:08 +00002408 ixgbe_update_itr(q_vector, &q_vector->tx);
2409 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002410
Alexander Duyck08c88332011-06-11 01:45:03 +00002411 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002412
2413 switch (current_itr) {
2414 /* counts and packets in update_itr are dependent on these numbers */
2415 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002416 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002417 break;
2418 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002419 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002420 break;
2421 case bulk_latency:
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002422 new_itr = IXGBE_12K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002423 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002424 default:
2425 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002426 }
2427
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002428 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002429 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002430 new_itr = (10 * new_itr * q_vector->itr) /
2431 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002432
Alexander Duyckbd198052011-06-11 01:45:08 +00002433 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002434 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002435
2436 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002437 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002438}
2439
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002440/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002441 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002442 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002443 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002444static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002445{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002446 struct ixgbe_hw *hw = &adapter->hw;
2447 u32 eicr = adapter->interrupt_event;
2448
Alexander Duyckf0f97782011-04-22 04:08:09 +00002449 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002450 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002451
Alexander Duyckf0f97782011-04-22 04:08:09 +00002452 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2453 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2454 return;
2455
2456 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2457
Joe Perches7ca647b2010-09-07 21:35:40 +00002458 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002459 case IXGBE_DEV_ID_82599_T3_LOM:
2460 /*
2461 * Since the warning interrupt is for both ports
2462 * we don't have to check if:
2463 * - This interrupt wasn't for our port.
2464 * - We may have missed the interrupt so always have to
2465 * check if we got a LSC
2466 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002467 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002468 !(eicr & IXGBE_EICR_LSC))
2469 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002470
Alexander Duyckf0f97782011-04-22 04:08:09 +00002471 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002472 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002473 bool link_up = false;
2474
Josh Hay3d292262012-12-15 03:28:19 +00002475 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002476
Alexander Duyckf0f97782011-04-22 04:08:09 +00002477 if (link_up)
2478 return;
2479 }
2480
2481 /* Check if this is not due to overtemp */
2482 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2483 return;
2484
2485 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002486 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002487 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2488 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002489 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002490 return;
2491 break;
2492 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002493 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002494
2495 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002496}
2497
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002498static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2499{
2500 struct ixgbe_hw *hw = &adapter->hw;
2501
2502 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002503 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002504 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002505 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002506 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002507 }
2508}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002509
Jacob Keller4f51bf72011-08-20 04:49:45 +00002510static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2511{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002512 struct ixgbe_hw *hw = &adapter->hw;
2513
Jacob Keller4f51bf72011-08-20 04:49:45 +00002514 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2515 return;
2516
2517 switch (adapter->hw.mac.type) {
2518 case ixgbe_mac_82599EB:
2519 /*
2520 * Need to check link state so complete overtemp check
2521 * on service task
2522 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002523 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2524 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002525 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2526 adapter->interrupt_event = eicr;
2527 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2528 ixgbe_service_event_schedule(adapter);
2529 return;
2530 }
2531 return;
2532 case ixgbe_mac_X540:
2533 if (!(eicr & IXGBE_EICR_TS))
2534 return;
2535 break;
2536 default:
2537 return;
2538 }
2539
Don Skidmoref44e7512015-06-09 16:36:23 -07002540 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002541}
2542
Don Skidmore45788d22015-06-09 16:59:04 -07002543static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2544{
2545 switch (hw->mac.type) {
2546 case ixgbe_mac_82598EB:
2547 if (hw->phy.type == ixgbe_phy_nl)
2548 return true;
2549 return false;
2550 case ixgbe_mac_82599EB:
2551 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002552 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002553 switch (hw->mac.ops.get_media_type(hw)) {
2554 case ixgbe_media_type_fiber:
2555 case ixgbe_media_type_fiber_qsfp:
2556 return true;
2557 default:
2558 return false;
2559 }
2560 default:
2561 return false;
2562 }
2563}
2564
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002565static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2566{
2567 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002568 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002569
Don Skidmore4ccc6502015-09-02 13:47:54 -07002570 if (!ixgbe_is_sfp(hw))
2571 return;
2572
2573 /* Later MAC's use different SDP */
2574 if (hw->mac.type >= ixgbe_mac_X540)
2575 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2576
2577 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002578 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002579 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002580 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2581 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002582 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002583 ixgbe_service_event_schedule(adapter);
2584 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002585 }
2586
Don Skidmore4ccc6502015-09-02 13:47:54 -07002587 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2588 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002589 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002590 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002591 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2592 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2593 ixgbe_service_event_schedule(adapter);
2594 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002595 }
2596}
2597
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002598static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2599{
2600 struct ixgbe_hw *hw = &adapter->hw;
2601
2602 adapter->lsc_int++;
2603 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2604 adapter->link_check_timeout = jiffies;
2605 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2606 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002607 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002608 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002609 }
2610}
2611
Alexander Duyckfe49f042009-06-04 16:00:09 +00002612static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2613 u64 qmask)
2614{
2615 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002616 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002617
Alexander Duyckbd508172010-11-16 19:27:03 -08002618 switch (hw->mac.type) {
2619 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002620 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002621 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2622 break;
2623 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002624 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002625 case ixgbe_mac_X550:
2626 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002627 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002628 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002629 if (mask)
2630 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002631 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002632 if (mask)
2633 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2634 break;
2635 default:
2636 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002637 }
2638 /* skip the flush */
2639}
2640
2641static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002642 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002643{
2644 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002645 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002646
Alexander Duyckbd508172010-11-16 19:27:03 -08002647 switch (hw->mac.type) {
2648 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002649 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002650 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2651 break;
2652 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002653 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002654 case ixgbe_mac_X550:
2655 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002656 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002657 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002658 if (mask)
2659 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002660 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002661 if (mask)
2662 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2663 break;
2664 default:
2665 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002666 }
2667 /* skip the flush */
2668}
2669
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002670/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002671 * ixgbe_irq_enable - Enable default interrupt generation settings
2672 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002673 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002674static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2675 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002676{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002677 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002678 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002679
Alexander Duyck2c4af692011-07-15 07:29:55 +00002680 /* don't reenable LSC while waiting for link */
2681 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2682 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002683
Alexander Duyck2c4af692011-07-15 07:29:55 +00002684 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002685 switch (adapter->hw.mac.type) {
2686 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002687 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002688 break;
2689 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002690 case ixgbe_mac_X550:
2691 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002692 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002693 mask |= IXGBE_EIMS_TS;
2694 break;
2695 default:
2696 break;
2697 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002698 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002699 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002700 switch (adapter->hw.mac.type) {
2701 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002702 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2703 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002704 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00002705 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002706 case ixgbe_mac_X550:
2707 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002708 case ixgbe_mac_x550em_a:
2709 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07002710 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07002711 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07002712 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07002713 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
2714 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00002715 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002716 mask |= IXGBE_EIMS_MAILBOX;
2717 break;
2718 default:
2719 break;
2720 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002721
Alexander Duyck2c4af692011-07-15 07:29:55 +00002722 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2723 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2724 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002725
Alexander Duyck2c4af692011-07-15 07:29:55 +00002726 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2727 if (queues)
2728 ixgbe_irq_enable_queues(adapter, ~0);
2729 if (flush)
2730 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002731}
2732
Alexander Duyck2c4af692011-07-15 07:29:55 +00002733static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002734{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002735 struct ixgbe_adapter *adapter = data;
2736 struct ixgbe_hw *hw = &adapter->hw;
2737 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002738
Alexander Duyck2c4af692011-07-15 07:29:55 +00002739 /*
2740 * Workaround for Silicon errata. Use clear-by-write instead
2741 * of clear-by-read. Reading with EICS will return the
2742 * interrupt causes without clearing, which later be done
2743 * with the write to EICR.
2744 */
2745 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002746
2747 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08002748 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00002749 * the bits are high when ixgbe_msix_other is called. There is a race
2750 * condition otherwise which results in possible performance loss
2751 * especially if the ixgbe_msix_other interrupt is triggering
2752 * consistently (as it would when PPS is turned on for the X540 device)
2753 */
2754 eicr &= 0xFFFF0000;
2755
Alexander Duyck2c4af692011-07-15 07:29:55 +00002756 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002757
Alexander Duyck2c4af692011-07-15 07:29:55 +00002758 if (eicr & IXGBE_EICR_LSC)
2759 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002760
Alexander Duyck2c4af692011-07-15 07:29:55 +00002761 if (eicr & IXGBE_EICR_MAILBOX)
2762 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002763
Alexander Duyck2c4af692011-07-15 07:29:55 +00002764 switch (hw->mac.type) {
2765 case ixgbe_mac_82599EB:
2766 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002767 case ixgbe_mac_X550:
2768 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002769 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07002770 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
2771 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
2772 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
2773 ixgbe_service_event_schedule(adapter);
2774 IXGBE_WRITE_REG(hw, IXGBE_EICR,
2775 IXGBE_EICR_GPI_SDP0_X540);
2776 }
Don Skidmored773ce22014-02-25 17:58:53 -08002777 if (eicr & IXGBE_EICR_ECC) {
2778 e_info(link, "Received ECC Err, initiating reset\n");
2779 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2780 ixgbe_service_event_schedule(adapter);
2781 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2782 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002783 /* Handle Flow Director Full threshold interrupt */
2784 if (eicr & IXGBE_EICR_FLOW_DIR) {
2785 int reinit_count = 0;
2786 int i;
2787 for (i = 0; i < adapter->num_tx_queues; i++) {
2788 struct ixgbe_ring *ring = adapter->tx_ring[i];
2789 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2790 &ring->state))
2791 reinit_count++;
2792 }
2793 if (reinit_count) {
2794 /* no more flow director interrupts until after init */
2795 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2796 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2797 ixgbe_service_event_schedule(adapter);
2798 }
2799 }
2800 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002801 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002802 break;
2803 default:
2804 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002805 }
2806
Alexander Duyck2c4af692011-07-15 07:29:55 +00002807 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002808
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002809 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07002810 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002811
Alexander Duyck2c4af692011-07-15 07:29:55 +00002812 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002813 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002814 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002815
Alexander Duyck2c4af692011-07-15 07:29:55 +00002816 return IRQ_HANDLED;
2817}
2818
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002819static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002820{
2821 struct ixgbe_q_vector *q_vector = data;
2822
Auke Kok9a799d72007-09-15 14:07:45 -07002823 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002824
2825 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07002826 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002827
2828 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002829}
2830
Auke Kok9a799d72007-09-15 14:07:45 -07002831/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002832 * ixgbe_poll - NAPI Rx polling callback
2833 * @napi: structure for representing this polling device
2834 * @budget: how many packets driver is allowed to clean
2835 *
2836 * This function is used for legacy and MSI, NAPI mode
2837 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002838int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002839{
2840 struct ixgbe_q_vector *q_vector =
2841 container_of(napi, struct ixgbe_q_vector, napi);
2842 struct ixgbe_adapter *adapter = q_vector->adapter;
2843 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002844 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00002845 bool clean_complete = true;
2846
2847#ifdef CONFIG_IXGBE_DCA
2848 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2849 ixgbe_update_dca(q_vector);
2850#endif
2851
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002852 ixgbe_for_each_ring(ring, q_vector->tx) {
2853 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
2854 clean_complete = false;
2855 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002856
Alexander Duyck5d6002b2015-09-22 14:35:41 -07002857 /* Exit if we are called by netpoll or busy polling is active */
2858 if ((budget <= 0) || !ixgbe_qv_lock_napi(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002859 return budget;
2860
Alexander Duyckeb01b972012-02-08 07:51:27 +00002861 /* attempt to distribute budget to each queue fairly, but don't allow
2862 * the budget to go below 1 because we'll exit polling */
2863 if (q_vector->rx.count > 1)
2864 per_ring_budget = max(budget/q_vector->rx.count, 1);
2865 else
2866 per_ring_budget = budget;
2867
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002868 ixgbe_for_each_ring(ring, q_vector->rx) {
2869 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
2870 per_ring_budget);
2871
2872 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002873 if (cleaned >= per_ring_budget)
2874 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002875 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002876
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002877 ixgbe_qv_unlock_napi(q_vector);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002878 /* If all work not completed, return budget and keep polling */
2879 if (!clean_complete)
2880 return budget;
2881
2882 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002883 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002884 if (adapter->rx_itr_setting & 1)
2885 ixgbe_set_itr(q_vector);
2886 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002887 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00002888
2889 return 0;
2890}
2891
2892/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002893 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2894 * @adapter: board private structure
2895 *
2896 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2897 * interrupts from the kernel.
2898 **/
2899static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2900{
2901 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002902 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002903 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002904
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002905 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002906 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002907 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002908
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002909 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002910 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002911 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002912 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002913 } else if (q_vector->rx.ring) {
2914 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2915 "%s-%s-%d", netdev->name, "rx", ri++);
2916 } else if (q_vector->tx.ring) {
2917 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2918 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002919 } else {
2920 /* skip this unused q_vector */
2921 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002922 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002923 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2924 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002925 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002926 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002927 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002928 goto free_queue_irqs;
2929 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002930 /* If Flow Director is enabled, set interrupt affinity */
2931 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2932 /* assign the mask for this irq */
2933 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002934 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002935 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002936 }
2937
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002938 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002939 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002940 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002941 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002942 goto free_queue_irqs;
2943 }
2944
2945 return 0;
2946
2947free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002948 while (vector) {
2949 vector--;
2950 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2951 NULL);
2952 free_irq(adapter->msix_entries[vector].vector,
2953 adapter->q_vector[vector]);
2954 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002955 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2956 pci_disable_msix(adapter->pdev);
2957 kfree(adapter->msix_entries);
2958 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002959 return err;
2960}
2961
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002962/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002963 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002964 * @irq: interrupt number
2965 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002966 **/
2967static irqreturn_t ixgbe_intr(int irq, void *data)
2968{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002969 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002970 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002971 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002972 u32 eicr;
2973
Don Skidmore54037502009-02-21 15:42:56 -08002974 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002975 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002976 * before the read of EICR.
2977 */
2978 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2979
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002980 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002981 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002982 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002983 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002984 /*
2985 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002986 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002987 * have disabled interrupts due to EIAM
2988 * finish the workaround of silicon errata on 82598. Unmask
2989 * the interrupt that we masked before the EICR read.
2990 */
2991 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2992 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002993 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002994 }
Auke Kok9a799d72007-09-15 14:07:45 -07002995
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002996 if (eicr & IXGBE_EICR_LSC)
2997 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002998
Alexander Duyckbd508172010-11-16 19:27:03 -08002999 switch (hw->mac.type) {
3000 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003001 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003002 /* Fall through */
3003 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003004 case ixgbe_mac_X550:
3005 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003006 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003007 if (eicr & IXGBE_EICR_ECC) {
3008 e_info(link, "Received ECC Err, initiating reset\n");
3009 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
3010 ixgbe_service_event_schedule(adapter);
3011 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3012 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003013 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003014 break;
3015 default:
3016 break;
3017 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003018
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003019 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003020 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003021 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003022
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003023 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003024 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003025
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003026 /*
3027 * re-enable link(maybe) and non-queue interrupts, no flush.
3028 * ixgbe_poll will re-enable the queue interrupts
3029 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003030 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3031 ixgbe_irq_enable(adapter, false, false);
3032
Auke Kok9a799d72007-09-15 14:07:45 -07003033 return IRQ_HANDLED;
3034}
3035
3036/**
3037 * ixgbe_request_irq - initialize interrupts
3038 * @adapter: board private structure
3039 *
3040 * Attempts to configure interrupts using the best available
3041 * capabilities of the hardware and kernel.
3042 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003043static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003044{
3045 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003046 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003047
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003048 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003049 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003050 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003051 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003052 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003053 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003054 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003055 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003056
Alexander Duyckde88eee2012-02-08 07:49:59 +00003057 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003058 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003059
Auke Kok9a799d72007-09-15 14:07:45 -07003060 return err;
3061}
3062
3063static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3064{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003065 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003066
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003067 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003068 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003069 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003070 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003071
3072 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3073 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3074 struct msix_entry *entry = &adapter->msix_entries[vector];
3075
3076 /* free only the irqs that were actually requested */
3077 if (!q_vector->rx.ring && !q_vector->tx.ring)
3078 continue;
3079
3080 /* clear the affinity_mask in the IRQ descriptor */
3081 irq_set_affinity_hint(entry->vector, NULL);
3082
3083 free_irq(entry->vector, q_vector);
3084 }
3085
3086 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003087}
3088
3089/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003090 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3091 * @adapter: board private structure
3092 **/
3093static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3094{
Alexander Duyckbd508172010-11-16 19:27:03 -08003095 switch (adapter->hw.mac.type) {
3096 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003097 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003098 break;
3099 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003100 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003101 case ixgbe_mac_X550:
3102 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003103 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003104 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3105 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003106 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003107 break;
3108 default:
3109 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003110 }
3111 IXGBE_WRITE_FLUSH(&adapter->hw);
3112 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003113 int vector;
3114
3115 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3116 synchronize_irq(adapter->msix_entries[vector].vector);
3117
3118 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003119 } else {
3120 synchronize_irq(adapter->pdev->irq);
3121 }
3122}
3123
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003124/**
Auke Kok9a799d72007-09-15 14:07:45 -07003125 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3126 *
3127 **/
3128static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3129{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003130 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003131
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003132 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003133
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003134 ixgbe_set_ivar(adapter, 0, 0, 0);
3135 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003136
Emil Tantilov396e7992010-07-01 20:05:12 +00003137 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003138}
3139
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003140/**
3141 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3142 * @adapter: board private structure
3143 * @ring: structure containing ring specific data
3144 *
3145 * Configure the Tx descriptor ring after a reset.
3146 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003147void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3148 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003149{
3150 struct ixgbe_hw *hw = &adapter->hw;
3151 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003152 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003153 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003154 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003155
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003156 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003157 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003158 IXGBE_WRITE_FLUSH(hw);
3159
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003160 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003161 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003162 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3163 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3164 ring->count * sizeof(union ixgbe_adv_tx_desc));
3165 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3166 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003167 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003168
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003169 /*
3170 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003171 * higher than 1 when:
3172 * - ITR is 0 as it could cause false TX hangs
3173 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003174 *
3175 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3176 * to or less than the number of on chip descriptors, which is
3177 * currently 40.
3178 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003179 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003180 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003181 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003182 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003183
Alexander Duycke954b372012-02-08 07:49:38 +00003184 /*
3185 * Setting PTHRESH to 32 both improves performance
3186 * and avoids a TX hang with DFP enabled
3187 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003188 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003189 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003190
3191 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003192 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003193 ring->atr_sample_rate = adapter->atr_sample_rate;
3194 ring->atr_count = 0;
3195 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3196 } else {
3197 ring->atr_sample_rate = 0;
3198 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003199
Alexander Duyckfd786b72013-01-12 06:33:31 +00003200 /* initialize XPS */
3201 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3202 struct ixgbe_q_vector *q_vector = ring->q_vector;
3203
3204 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003205 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003206 &q_vector->affinity_mask,
3207 ring->queue_index);
3208 }
3209
John Fastabendc84d3242010-11-16 19:27:12 -08003210 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3211
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003212 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003213 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3214
3215 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3216 if (hw->mac.type == ixgbe_mac_82598EB &&
3217 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3218 return;
3219
3220 /* poll to verify queue is enabled */
3221 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003222 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003223 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3224 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3225 if (!wait_loop)
3226 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003227}
3228
Alexander Duyck120ff942010-08-19 13:34:50 +00003229static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3230{
3231 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003232 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003233 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003234
3235 if (hw->mac.type == ixgbe_mac_82598EB)
3236 return;
3237
3238 /* disable the arbiter while setting MTQC */
3239 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3240 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3241 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3242
3243 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003244 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3245 mtqc = IXGBE_MTQC_VT_ENA;
3246 if (tcs > 4)
3247 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3248 else if (tcs > 1)
3249 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3250 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3251 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003252 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003253 mtqc |= IXGBE_MTQC_64VF;
3254 } else {
3255 if (tcs > 4)
3256 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3257 else if (tcs > 1)
3258 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3259 else
3260 mtqc = IXGBE_MTQC_64Q_1PB;
3261 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003262
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003263 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003264
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003265 /* Enable Security TX Buffer IFG for multiple pb */
3266 if (tcs) {
3267 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3268 sectx |= IXGBE_SECTX_DCB;
3269 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003270 }
3271
3272 /* re-enable the arbiter */
3273 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3274 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3275}
3276
Auke Kok9a799d72007-09-15 14:07:45 -07003277/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003278 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003279 * @adapter: board private structure
3280 *
3281 * Configure the Tx unit of the MAC after a reset.
3282 **/
3283static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3284{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003285 struct ixgbe_hw *hw = &adapter->hw;
3286 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003287 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003288
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003289 ixgbe_setup_mtqc(adapter);
3290
3291 if (hw->mac.type != ixgbe_mac_82598EB) {
3292 /* DMATXCTL.EN must be before Tx queues are enabled */
3293 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3294 dmatxctl |= IXGBE_DMATXCTL_TE;
3295 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3296 }
3297
Auke Kok9a799d72007-09-15 14:07:45 -07003298 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003299 for (i = 0; i < adapter->num_tx_queues; i++)
3300 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003301}
3302
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003303static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3304 struct ixgbe_ring *ring)
3305{
3306 struct ixgbe_hw *hw = &adapter->hw;
3307 u8 reg_idx = ring->reg_idx;
3308 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3309
3310 srrctl |= IXGBE_SRRCTL_DROP_EN;
3311
3312 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3313}
3314
3315static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3316 struct ixgbe_ring *ring)
3317{
3318 struct ixgbe_hw *hw = &adapter->hw;
3319 u8 reg_idx = ring->reg_idx;
3320 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3321
3322 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3323
3324 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3325}
3326
3327#ifdef CONFIG_IXGBE_DCB
3328void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3329#else
3330static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3331#endif
3332{
3333 int i;
3334 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3335
3336 if (adapter->ixgbe_ieee_pfc)
3337 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3338
3339 /*
3340 * We should set the drop enable bit if:
3341 * SR-IOV is enabled
3342 * or
3343 * Number of Rx queues > 1 and flow control is disabled
3344 *
3345 * This allows us to avoid head of line blocking for security
3346 * and performance reasons.
3347 */
3348 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3349 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3350 for (i = 0; i < adapter->num_rx_queues; i++)
3351 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3352 } else {
3353 for (i = 0; i < adapter->num_rx_queues; i++)
3354 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3355 }
3356}
3357
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003358#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003359
Yi Zoua6616b42009-08-06 13:05:23 +00003360static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003361 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003362{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003363 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003364 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003365 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003366
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003367 if (hw->mac.type == ixgbe_mac_82598EB) {
3368 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3369
3370 /*
3371 * if VMDq is not active we must program one srrctl register
3372 * per RSS queue since we have enabled RDRXCTL.MVMEN
3373 */
3374 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003375 }
3376
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003377 /* configure header buffer length, needed for RSC */
3378 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003379
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003380 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00003381 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003382
3383 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003384 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003385
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003386 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003387}
3388
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003389/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003390 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003391 * @adapter: device handle
3392 *
3393 * - 82598/82599/X540: 128
3394 * - X550(non-SRIOV mode): 512
3395 * - X550(SRIOV mode): 64
3396 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003397u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003398{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003399 if (adapter->hw.mac.type < ixgbe_mac_X550)
3400 return 128;
3401 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3402 return 64;
3403 else
3404 return 512;
3405}
3406
3407/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003408 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003409 * @adapter: device handle
3410 *
3411 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3412 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003413void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003414{
3415 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003416 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003417 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003418 u32 indices_multi;
3419 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003420
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003421 /* Fill out the redirection table as follows:
3422 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3423 * indices.
3424 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3425 * - X550: 8 bit wide entries containing 6 bit RSS index
3426 */
3427 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3428 indices_multi = 0x11;
3429 else
3430 indices_multi = 0x1;
3431
3432 /* Write redirection table to HW */
3433 for (i = 0; i < reta_entries; i++) {
3434 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3435 if ((i & 3) == 3) {
3436 if (i < 128)
3437 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3438 else
3439 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3440 reta);
3441 reta = 0;
3442 }
3443 }
3444}
3445
3446/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003447 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003448 * @adapter: device handle
3449 *
3450 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3451 */
3452static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3453{
3454 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3455 struct ixgbe_hw *hw = &adapter->hw;
3456 u32 vfreta = 0;
3457 unsigned int pf_pool = adapter->num_vfs;
3458
3459 /* Write redirection table to HW */
3460 for (i = 0; i < reta_entries; i++) {
3461 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3462 if ((i & 3) == 3) {
3463 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3464 vfreta);
3465 vfreta = 0;
3466 }
3467 }
3468}
3469
3470static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3471{
3472 struct ixgbe_hw *hw = &adapter->hw;
3473 u32 i, j;
3474 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3475 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3476
3477 /* Program table for at least 2 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003478 * make full use of any rings they may have. We will use the
3479 * PSRTYPE register to control how many rings we use within the PF.
3480 */
3481 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3482 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003483
Alexander Duyck05abb122010-08-19 13:35:41 +00003484 /* Fill out hash function seeds */
3485 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003486 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003487
Alexander Duyck05abb122010-08-19 13:35:41 +00003488 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003489 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3490
Don Skidmore0f9b2322014-11-18 09:35:08 +00003491 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003492 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003493 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003494
3495 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003496 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003497
3498 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003499}
3500
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003501static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003502{
3503 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003504 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3505 unsigned int pf_pool = adapter->num_vfs;
3506 int i, j;
3507
3508 /* Fill out hash function seeds */
3509 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003510 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
3511 adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003512
3513 /* Fill out the redirection table */
3514 for (i = 0, j = 0; i < 64; i++, j++) {
3515 if (j == rss_i)
3516 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003517
3518 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003519 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003520
3521 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003522}
3523
3524static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3525{
3526 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003527 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003528 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003529
3530 /* Disable indicating checksum in descriptor, enables RSS hash */
3531 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3532 rxcsum |= IXGBE_RXCSUM_PCSD;
3533 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3534
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003535 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003536 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003537 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003538 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003539 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003540
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003541 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3542 if (tcs > 4)
3543 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3544 else if (tcs > 1)
3545 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3546 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3547 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3548 else
3549 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3550 } else {
3551 if (tcs > 4)
3552 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3553 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003554 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3555 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003556 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003557 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003558 }
3559
Alexander Duyck05abb122010-08-19 13:35:41 +00003560 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003561 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3562 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3563 IXGBE_MRQC_RSS_FIELD_IPV6 |
3564 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003565
Alexander Duyckef6afc02012-02-08 07:51:53 +00003566 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003567 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003568 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003569 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003570
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003571 netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003572 if ((hw->mac.type >= ixgbe_mac_X550) &&
3573 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3574 unsigned int pf_pool = adapter->num_vfs;
3575
3576 /* Enable VF RSS mode */
3577 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3578 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3579
3580 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003581 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003582 vfmrqc = IXGBE_MRQC_RSSEN;
3583 vfmrqc |= rss_field;
3584 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3585 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003586 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003587 mrqc |= rss_field;
3588 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3589 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003590}
3591
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003592/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003593 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3594 * @adapter: address of board private structure
3595 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003596 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003597static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003598 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003599{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003600 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003601 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003602 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003603
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003604 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003605 return;
3606
Alexander Duyck73670962010-08-19 13:38:34 +00003607 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003608 rscctrl |= IXGBE_RSCCTL_RSCEN;
3609 /*
3610 * we must limit the number of descriptors so that the
3611 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003612 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003613 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003614 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003615 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003616}
3617
Alexander Duyck9e10e042010-08-19 13:40:06 +00003618#define IXGBE_MAX_RX_DESC_POLL 10
3619static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3620 struct ixgbe_ring *ring)
3621{
3622 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003623 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3624 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003625 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003626
Mark Rustadb0483c82014-01-14 18:53:17 -08003627 if (ixgbe_removed(hw->hw_addr))
3628 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003629 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3630 if (hw->mac.type == ixgbe_mac_82598EB &&
3631 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3632 return;
3633
3634 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003635 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003636 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3637 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3638
3639 if (!wait_loop) {
3640 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3641 "the polling period\n", reg_idx);
3642 }
3643}
3644
Yi Zou2d39d572011-01-06 14:29:56 +00003645void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3646 struct ixgbe_ring *ring)
3647{
3648 struct ixgbe_hw *hw = &adapter->hw;
3649 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3650 u32 rxdctl;
3651 u8 reg_idx = ring->reg_idx;
3652
Mark Rustadb0483c82014-01-14 18:53:17 -08003653 if (ixgbe_removed(hw->hw_addr))
3654 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003655 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3656 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3657
3658 /* write value back with RXDCTL.ENABLE bit cleared */
3659 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3660
3661 if (hw->mac.type == ixgbe_mac_82598EB &&
3662 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3663 return;
3664
3665 /* the hardware may take up to 100us to really disable the rx queue */
3666 do {
3667 udelay(10);
3668 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3669 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3670
3671 if (!wait_loop) {
3672 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3673 "the polling period\n", reg_idx);
3674 }
3675}
3676
Alexander Duyck84418e32010-08-19 13:40:54 +00003677void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3678 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003679{
3680 struct ixgbe_hw *hw = &adapter->hw;
3681 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003682 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003683 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003684
Alexander Duyck9e10e042010-08-19 13:40:06 +00003685 /* disable queue to avoid issues while updating state */
3686 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003687 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003688
Alexander Duyckacd37172010-08-19 13:36:05 +00003689 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3690 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3691 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3692 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08003693 /* Force flushing of IXGBE_RDLEN to prevent MDD */
3694 IXGBE_WRITE_FLUSH(hw);
3695
Alexander Duyckacd37172010-08-19 13:36:05 +00003696 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3697 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003698 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003699
3700 ixgbe_configure_srrctl(adapter, ring);
3701 ixgbe_configure_rscctl(adapter, ring);
3702
3703 if (hw->mac.type == ixgbe_mac_82598EB) {
3704 /*
3705 * enable cache line friendly hardware writes:
3706 * PTHRESH=32 descriptors (half the internal cache),
3707 * this also removes ugly rx_no_buffer_count increment
3708 * HTHRESH=4 descriptors (to minimize latency on fetch)
3709 * WTHRESH=8 burst writeback up to two cache lines
3710 */
3711 rxdctl &= ~0x3FFFFF;
3712 rxdctl |= 0x080420;
3713 }
3714
3715 /* enable receive descriptor ring */
3716 rxdctl |= IXGBE_RXDCTL_ENABLE;
3717 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3718
3719 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003720 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003721}
3722
Alexander Duyck48654522010-08-19 13:36:27 +00003723static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3724{
3725 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003726 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003727 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003728
3729 /* PSRTYPE must be initialized in non 82598 adapters */
3730 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003731 IXGBE_PSRTYPE_UDPHDR |
3732 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003733 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003734 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003735
3736 if (hw->mac.type == ixgbe_mac_82598EB)
3737 return;
3738
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003739 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003740 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003741 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003742 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003743
John Fastabend2a47fa42013-11-06 09:54:52 -08003744 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3745 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003746}
3747
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003748static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3749{
3750 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003751 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003752 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003753 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003754
3755 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3756 return;
3757
3758 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003759 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3760 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003761 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003762 vmdctl |= IXGBE_VT_CTL_REPLEN;
3763 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003764
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003765 vf_shift = VMDQ_P(0) % 32;
3766 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003767
3768 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003769 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3770 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3771 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3772 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07003773 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00003774 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003775
3776 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003777 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003778
Alexander Duyck16369562015-11-02 17:10:13 -08003779 /* clear VLAN promisc flag so VFTA will be updated if necessary */
3780 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
3781
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003782 /*
3783 * Set up VF register offsets for selected VT Mode,
3784 * i.e. 32 or 64 VFs for SR-IOV
3785 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003786 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3787 case IXGBE_82599_VMDQ_8Q_MASK:
3788 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3789 break;
3790 case IXGBE_82599_VMDQ_4Q_MASK:
3791 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3792 break;
3793 default:
3794 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3795 break;
3796 }
3797
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003798 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3799
Greg Rosede4c7f62011-09-29 05:57:33 +00003800 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07003801 /* configure spoof checking */
3802 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
3803 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03003804
3805 /* Enable/Disable RSS query feature */
3806 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
3807 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00003808 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003809}
3810
Alexander Duyck477de6e2010-08-19 13:38:11 +00003811static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003812{
Auke Kok9a799d72007-09-15 14:07:45 -07003813 struct ixgbe_hw *hw = &adapter->hw;
3814 struct net_device *netdev = adapter->netdev;
3815 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003816 struct ixgbe_ring *rx_ring;
3817 int i;
3818 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003819
Alexander Duyck477de6e2010-08-19 13:38:11 +00003820#ifdef IXGBE_FCOE
3821 /* adjust max frame to be able to do baby jumbo for FCoE */
3822 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3823 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3824 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3825
3826#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003827
3828 /* adjust max frame to be at least the size of a standard frame */
3829 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3830 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3831
Alexander Duyck477de6e2010-08-19 13:38:11 +00003832 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3833 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3834 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3835 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3836
3837 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003838 }
3839
Auke Kok9a799d72007-09-15 14:07:45 -07003840 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003841 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3842 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003843 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3844
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003845 /*
3846 * Setup the HW Rx Head and Tail Descriptor Pointers and
3847 * the Base and Length of the Rx Descriptor Ring
3848 */
Auke Kok9a799d72007-09-15 14:07:45 -07003849 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003850 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003851 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3852 set_ring_rsc_enabled(rx_ring);
3853 else
3854 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003855 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003856}
3857
Alexander Duyck73670962010-08-19 13:38:34 +00003858static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3859{
3860 struct ixgbe_hw *hw = &adapter->hw;
3861 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3862
3863 switch (hw->mac.type) {
3864 case ixgbe_mac_82598EB:
3865 /*
3866 * For VMDq support of different descriptor types or
3867 * buffer sizes through the use of multiple SRRCTL
3868 * registers, RDRXCTL.MVMEN must be set to 1
3869 *
3870 * also, the manual doesn't mention it clearly but DCA hints
3871 * will only use queue 0's tags unless this bit is set. Side
3872 * effects of setting this bit are only that SRRCTL must be
3873 * fully programmed [0..15]
3874 */
3875 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3876 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07003877 case ixgbe_mac_X550:
3878 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003879 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07003880 if (adapter->num_vfs)
3881 rdrxctl |= IXGBE_RDRXCTL_PSP;
3882 /* fall through for older HW */
Alexander Duyck73670962010-08-19 13:38:34 +00003883 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003884 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003885 /* Disable RSC for ACK packets */
3886 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3887 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3888 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3889 /* hardware requires some bits to be set by default */
3890 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3891 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3892 break;
3893 default:
3894 /* We should do nothing since we don't know this hardware */
3895 return;
3896 }
3897
3898 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3899}
3900
Alexander Duyck477de6e2010-08-19 13:38:11 +00003901/**
3902 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3903 * @adapter: board private structure
3904 *
3905 * Configure the Rx unit of the MAC after a reset.
3906 **/
3907static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3908{
3909 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003910 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003911 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003912
3913 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07003914 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003915
3916 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003917 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003918
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003919 /* RSC Setup */
3920 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
3921 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
3922 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
3923 rfctl |= IXGBE_RFCTL_RSC_DIS;
3924 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
3925
Alexander Duyck9e10e042010-08-19 13:40:06 +00003926 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003927 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003928
Alexander Duyck477de6e2010-08-19 13:38:11 +00003929 /* set_rx_buffer_len must be called before ring initialization */
3930 ixgbe_set_rx_buffer_len(adapter);
3931
3932 /*
3933 * Setup the HW Rx Head and Tail Descriptor Pointers and
3934 * the Base and Length of the Rx Descriptor Ring
3935 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003936 for (i = 0; i < adapter->num_rx_queues; i++)
3937 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003938
Don Skidmore1f9ac572015-03-13 13:54:30 -07003939 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003940 /* disable drop enable for 82598 parts */
3941 if (hw->mac.type == ixgbe_mac_82598EB)
3942 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3943
3944 /* enable all receives */
3945 rxctrl |= IXGBE_RXCTRL_RXEN;
3946 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003947}
3948
Patrick McHardy80d5c362013-04-19 02:04:28 +00003949static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3950 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003951{
3952 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003953 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003954
3955 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08003956 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
3957 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
3958
Jesse Grossf62bbb52010-10-20 13:56:10 +00003959 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003960
3961 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003962}
3963
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08003964static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
3965{
3966 u32 vlvf;
3967 int idx;
3968
3969 /* short cut the special case */
3970 if (vlan == 0)
3971 return 0;
3972
3973 /* Search for the vlan id in the VLVF entries */
3974 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
3975 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
3976 if ((vlvf & VLAN_VID_MASK) == vlan)
3977 break;
3978 }
3979
3980 return idx;
3981}
3982
3983void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
3984{
3985 struct ixgbe_hw *hw = &adapter->hw;
3986 u32 bits, word;
3987 int idx;
3988
3989 idx = ixgbe_find_vlvf_entry(hw, vid);
3990 if (!idx)
3991 return;
3992
3993 /* See if any other pools are set for this VLAN filter
3994 * entry other than the PF.
3995 */
3996 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003997 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08003998 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
3999
4000 /* Disable the filter so this falls into the default pool. */
4001 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4002 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4003 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4004 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4005 }
4006}
4007
Patrick McHardy80d5c362013-04-19 02:04:28 +00004008static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4009 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004010{
4011 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004012 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004013
Auke Kok9a799d72007-09-15 14:07:45 -07004014 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004015 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004016 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4017
Jesse Grossf62bbb52010-10-20 13:56:10 +00004018 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004019
4020 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004021}
4022
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004023/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004024 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4025 * @adapter: driver data
4026 */
4027static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4028{
4029 struct ixgbe_hw *hw = &adapter->hw;
4030 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004031 int i, j;
4032
4033 switch (hw->mac.type) {
4034 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004035 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4036 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004037 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4038 break;
4039 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004040 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004041 case ixgbe_mac_X550:
4042 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004043 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004044 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004045 struct ixgbe_ring *ring = adapter->rx_ring[i];
4046
4047 if (ring->l2_accel_priv)
4048 continue;
4049 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004050 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4051 vlnctrl &= ~IXGBE_RXDCTL_VME;
4052 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4053 }
4054 break;
4055 default:
4056 break;
4057 }
4058}
4059
4060/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004061 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004062 * @adapter: driver data
4063 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004064static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004065{
4066 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004067 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004068 int i, j;
4069
4070 switch (hw->mac.type) {
4071 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004072 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4073 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004074 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4075 break;
4076 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004077 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004078 case ixgbe_mac_X550:
4079 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004080 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004081 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004082 struct ixgbe_ring *ring = adapter->rx_ring[i];
4083
4084 if (ring->l2_accel_priv)
4085 continue;
4086 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004087 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4088 vlnctrl |= IXGBE_RXDCTL_VME;
4089 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4090 }
4091 break;
4092 default:
4093 break;
4094 }
4095}
4096
Alexander Duyck16369562015-11-02 17:10:13 -08004097static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4098{
4099 struct ixgbe_hw *hw = &adapter->hw;
4100 u32 vlnctrl, i;
4101
4102 switch (hw->mac.type) {
4103 case ixgbe_mac_82599EB:
4104 case ixgbe_mac_X540:
4105 case ixgbe_mac_X550:
4106 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004107 case ixgbe_mac_x550em_a:
Alexander Duyck16369562015-11-02 17:10:13 -08004108 default:
4109 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED)
4110 break;
4111 /* fall through */
4112 case ixgbe_mac_82598EB:
4113 /* legacy case, we can just disable VLAN filtering */
4114 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4115 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
4116 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4117 return;
4118 }
4119
4120 /* We are already in VLAN promisc, nothing to do */
4121 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4122 return;
4123
4124 /* Set flag so we don't redo unnecessary work */
4125 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4126
4127 /* Add PF to all active pools */
4128 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4129 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4130 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4131
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004132 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004133 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4134 }
4135
4136 /* Set all bits in the VLAN filter table array */
4137 for (i = hw->mac.vft_size; i--;)
4138 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4139}
4140
4141#define VFTA_BLOCK_SIZE 8
4142static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4143{
4144 struct ixgbe_hw *hw = &adapter->hw;
4145 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4146 u32 vid_start = vfta_offset * 32;
4147 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4148 u32 i, vid, word, bits;
4149
4150 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4151 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4152
4153 /* pull VLAN ID from VLVF */
4154 vid = vlvf & VLAN_VID_MASK;
4155
4156 /* only concern outselves with a certain range */
4157 if (vid < vid_start || vid >= vid_end)
4158 continue;
4159
4160 if (vlvf) {
4161 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004162 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004163
4164 /* if PF is part of this then continue */
4165 if (test_bit(vid, adapter->active_vlans))
4166 continue;
4167 }
4168
4169 /* remove PF from the pool */
4170 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004171 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004172 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4173 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4174 }
4175
4176 /* extract values from active_vlans and write back to VFTA */
4177 for (i = VFTA_BLOCK_SIZE; i--;) {
4178 vid = (vfta_offset + i) * 32;
4179 word = vid / BITS_PER_LONG;
4180 bits = vid % BITS_PER_LONG;
4181
4182 vfta[i] |= adapter->active_vlans[word] >> bits;
4183
4184 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4185 }
4186}
4187
4188static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4189{
4190 struct ixgbe_hw *hw = &adapter->hw;
4191 u32 vlnctrl, i;
4192
4193 switch (hw->mac.type) {
4194 case ixgbe_mac_82599EB:
4195 case ixgbe_mac_X540:
4196 case ixgbe_mac_X550:
4197 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004198 case ixgbe_mac_x550em_a:
Alexander Duyck16369562015-11-02 17:10:13 -08004199 default:
4200 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED)
4201 break;
4202 /* fall through */
4203 case ixgbe_mac_82598EB:
4204 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4205 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
4206 vlnctrl |= IXGBE_VLNCTRL_VFE;
4207 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4208 return;
4209 }
4210
4211 /* We are not in VLAN promisc, nothing to do */
4212 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4213 return;
4214
4215 /* Set flag so we don't redo unnecessary work */
4216 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4217
4218 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4219 ixgbe_scrub_vfta(adapter, i);
4220}
4221
Auke Kok9a799d72007-09-15 14:07:45 -07004222static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4223{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004224 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004225
Patrick McHardy80d5c362013-04-19 02:04:28 +00004226 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004227
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004228 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004229 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004230}
4231
4232/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004233 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4234 * @netdev: network interface device structure
4235 *
4236 * Writes multicast address list to the MTA hash table.
4237 * Returns: -ENOMEM on failure
4238 * 0 on no addresses written
4239 * X on writing X addresses to MTA
4240 **/
4241static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4242{
4243 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4244 struct ixgbe_hw *hw = &adapter->hw;
4245
4246 if (!netif_running(netdev))
4247 return 0;
4248
4249 if (hw->mac.ops.update_mc_addr_list)
4250 hw->mac.ops.update_mc_addr_list(hw, netdev);
4251 else
4252 return -ENOMEM;
4253
4254#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004255 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004256#endif
4257
4258 return netdev_mc_count(netdev);
4259}
4260
Jacob Keller5d7daa32014-03-29 06:51:25 +00004261#ifdef CONFIG_PCI_IOV
4262void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4263{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004264 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004265 struct ixgbe_hw *hw = &adapter->hw;
4266 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004267
4268 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4269 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4270
4271 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4272 hw->mac.ops.set_rar(hw, i,
4273 mac_table->addr,
4274 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004275 IXGBE_RAH_AV);
4276 else
4277 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004278 }
4279}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004280
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004281#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004282static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4283{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004284 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004285 struct ixgbe_hw *hw = &adapter->hw;
4286 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004287
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004288 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4289 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4290 continue;
4291
4292 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4293
4294 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4295 hw->mac.ops.set_rar(hw, i,
4296 mac_table->addr,
4297 mac_table->pool,
4298 IXGBE_RAH_AV);
4299 else
4300 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004301 }
4302}
4303
4304static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4305{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004306 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004307 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004308 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004309
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004310 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4311 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4312 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004313 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004314
Jacob Keller5d7daa32014-03-29 06:51:25 +00004315 ixgbe_sync_mac_table(adapter);
4316}
4317
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004318static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004319{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004320 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004321 struct ixgbe_hw *hw = &adapter->hw;
4322 int i, count = 0;
4323
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004324 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4325 /* do not count default RAR as available */
4326 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4327 continue;
4328
4329 /* only count unused and addresses that belong to us */
4330 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4331 if (mac_table->pool != pool)
4332 continue;
4333 }
4334
4335 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004336 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004337
Jacob Keller5d7daa32014-03-29 06:51:25 +00004338 return count;
4339}
4340
4341/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004342static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004343{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004344 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004345 struct ixgbe_hw *hw = &adapter->hw;
4346
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004347 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4348 mac_table->pool = VMDQ_P(0);
4349
4350 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4351
4352 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004353 IXGBE_RAH_AV);
4354}
4355
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004356int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4357 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004358{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004359 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004360 struct ixgbe_hw *hw = &adapter->hw;
4361 int i;
4362
4363 if (is_zero_ether_addr(addr))
4364 return -EINVAL;
4365
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004366 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4367 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004368 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004369
4370 ether_addr_copy(mac_table->addr, addr);
4371 mac_table->pool = pool;
4372
4373 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4374 IXGBE_MAC_STATE_IN_USE;
4375
Jacob Keller5d7daa32014-03-29 06:51:25 +00004376 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004377
Jacob Keller5d7daa32014-03-29 06:51:25 +00004378 return i;
4379 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004380
Jacob Keller5d7daa32014-03-29 06:51:25 +00004381 return -ENOMEM;
4382}
4383
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004384int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4385 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004386{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004387 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004388 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004389 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004390
4391 if (is_zero_ether_addr(addr))
4392 return -EINVAL;
4393
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004394 /* search table for addr, if found clear IN_USE flag and sync */
4395 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4396 /* we can only delete an entry if it is in use */
4397 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4398 continue;
4399 /* we only care about entries that belong to the given pool */
4400 if (mac_table->pool != pool)
4401 continue;
4402 /* we only care about a specific MAC address */
4403 if (!ether_addr_equal(addr, mac_table->addr))
4404 continue;
4405
4406 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4407 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4408
4409 ixgbe_sync_mac_table(adapter);
4410
4411 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004412 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004413
Jacob Keller5d7daa32014-03-29 06:51:25 +00004414 return -ENOMEM;
4415}
Jacob Kellerb335e752014-03-25 07:45:27 +00004416/**
Alexander Duyck28500622010-06-15 09:25:48 +00004417 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4418 * @netdev: network interface device structure
4419 *
4420 * Writes unicast address list to the RAR table.
4421 * Returns: -ENOMEM on failure/insufficient address space
4422 * 0 on no addresses written
4423 * X on writing X addresses to the RAR table
4424 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004425static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004426{
4427 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004428 int count = 0;
4429
4430 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004431 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004432 return -ENOMEM;
4433
John Fastabend95447462012-05-31 12:42:26 +00004434 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004435 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004436 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004437 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4438 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004439 count++;
4440 }
4441 }
Alexander Duyck28500622010-06-15 09:25:48 +00004442 return count;
4443}
4444
Alexander Duyck0f079d22015-10-22 16:26:36 -07004445static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4446{
4447 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4448 int ret;
4449
4450 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4451
4452 return min_t(int, ret, 0);
4453}
4454
4455static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4456{
4457 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4458
4459 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4460
4461 return 0;
4462}
4463
Alexander Duyck28500622010-06-15 09:25:48 +00004464/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004465 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004466 * @netdev: network interface device structure
4467 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004468 * The set_rx_method entry point is called whenever the unicast/multicast
4469 * address list or the network interface flags are updated. This routine is
4470 * responsible for configuring the hardware for proper unicast, multicast and
4471 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004472 **/
Greg Rose7f870472010-01-09 02:25:29 +00004473void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004474{
4475 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4476 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004477 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004478 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004479 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004480
4481 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004482 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4483
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004484 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004485 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004486 fctrl |= IXGBE_FCTRL_BAM;
4487 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4488 fctrl |= IXGBE_FCTRL_PMCF;
4489
Alexander Duyck28500622010-06-15 09:25:48 +00004490 /* clear the bits we are changing the status of */
4491 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004492 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004493 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004494 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004495 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004496 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004497 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004498 if (netdev->flags & IFF_ALLMULTI) {
4499 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004500 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004501 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004502 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004503 }
4504
4505 /*
4506 * Write addresses to available RAR registers, if there is not
4507 * sufficient space to store all the addresses then enable
4508 * unicast promiscuous mode
4509 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004510 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004511 fctrl |= IXGBE_FCTRL_UPE;
4512 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004513 }
4514
Emil Tantilovcf789592013-10-26 08:13:20 +00004515 /* Write addresses to the MTA, if the attempt fails
4516 * then we should just turn on promiscuous mode so
4517 * that we can at least receive multicast traffic
4518 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004519 count = ixgbe_write_mc_addr_list(netdev);
4520 if (count < 0) {
4521 fctrl |= IXGBE_FCTRL_MPE;
4522 vmolr |= IXGBE_VMOLR_MPE;
4523 } else if (count) {
4524 vmolr |= IXGBE_VMOLR_ROMPE;
4525 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004526
4527 if (hw->mac.type != ixgbe_mac_82598EB) {
4528 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004529 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4530 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004531 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004532 }
4533
Ben Greear3f2d1c02012-03-08 08:28:41 +00004534 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004535 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004536 /* UPE and MPE will be handled by normal PROMISC logic
4537 * in e1000e_set_rx_mode */
4538 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4539 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4540 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4541
4542 fctrl &= ~(IXGBE_FCTRL_DPF);
4543 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4544 }
4545
Auke Kok9a799d72007-09-15 14:07:45 -07004546 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004547
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004548 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004549 ixgbe_vlan_strip_enable(adapter);
4550 else
4551 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004552
4553 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4554 ixgbe_vlan_promisc_disable(adapter);
4555 else
4556 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004557}
4558
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004559static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4560{
4561 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004562
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004563 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
4564 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004565 napi_enable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004566 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004567}
4568
4569static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4570{
4571 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004572
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004573 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004574 napi_disable(&adapter->q_vector[q_idx]->napi);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004575 while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) {
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004576 pr_info("QV %d locked\n", q_idx);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004577 usleep_range(1000, 20000);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004578 }
4579 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004580}
4581
Mark Rustad67359c32015-06-15 11:33:25 -07004582static void ixgbe_clear_vxlan_port(struct ixgbe_adapter *adapter)
4583{
4584 switch (adapter->hw.mac.type) {
4585 case ixgbe_mac_X550:
4586 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004587 case ixgbe_mac_x550em_a:
Mark Rustad67359c32015-06-15 11:33:25 -07004588 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VXLANCTRL, 0);
Mark Rustad67359c32015-06-15 11:33:25 -07004589 adapter->vxlan_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07004590 break;
4591 default:
4592 break;
4593 }
4594}
4595
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004596#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004597/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004598 * ixgbe_configure_dcb - Configure DCB hardware
4599 * @adapter: ixgbe adapter struct
4600 *
4601 * This is called by the driver on open to configure the DCB hardware.
4602 * This is also called by the gennetlink interface when reconfiguring
4603 * the DCB state.
4604 */
4605static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4606{
4607 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00004608 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004609
Alexander Duyck67ebd792010-08-19 13:34:04 +00004610 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4611 if (hw->mac.type == ixgbe_mac_82598EB)
4612 netif_set_gso_max_size(adapter->netdev, 65536);
4613 return;
4614 }
4615
4616 if (hw->mac.type == ixgbe_mac_82598EB)
4617 netif_set_gso_max_size(adapter->netdev, 32768);
4618
John Fastabendb1208182011-10-15 05:00:10 +00004619#ifdef IXGBE_FCOE
4620 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4621 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4622#endif
4623
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004624 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004625 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004626 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4627 DCB_TX_CONFIG);
4628 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4629 DCB_RX_CONFIG);
4630 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004631 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4632 ixgbe_dcb_hw_ets(&adapter->hw,
4633 adapter->ixgbe_ieee_ets,
4634 max_frame);
4635 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4636 adapter->ixgbe_ieee_pfc->pfc_en,
4637 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004638 }
John Fastabend8187cd42011-02-23 05:58:08 +00004639
4640 /* Enable RSS Hash per TC */
4641 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004642 u32 msb = 0;
4643 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004644
Alexander Duyckd411a932012-06-30 00:14:01 +00004645 while (rss_i) {
4646 msb++;
4647 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004648 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004649
Alexander Duyck4ae63732012-06-22 06:46:33 +00004650 /* write msb to all 8 TCs in one write */
4651 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004652 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004653}
John Fastabend9da712d2011-08-23 03:14:22 +00004654#endif
4655
4656/* Additional bittime to account for IXGBE framing */
4657#define IXGBE_ETH_FRAMING 20
4658
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004659/**
John Fastabend9da712d2011-08-23 03:14:22 +00004660 * ixgbe_hpbthresh - calculate high water mark for flow control
4661 *
4662 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004663 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004664 */
4665static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4666{
4667 struct ixgbe_hw *hw = &adapter->hw;
4668 struct net_device *dev = adapter->netdev;
4669 int link, tc, kb, marker;
4670 u32 dv_id, rx_pba;
4671
4672 /* Calculate max LAN frame size */
4673 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4674
4675#ifdef IXGBE_FCOE
4676 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004677 if ((dev->features & NETIF_F_FCOE_MTU) &&
4678 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4679 (pb == ixgbe_fcoe_get_tc(adapter)))
4680 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004681#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004682
John Fastabend9da712d2011-08-23 03:14:22 +00004683 /* Calculate delay value for device */
4684 switch (hw->mac.type) {
4685 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004686 case ixgbe_mac_X550:
4687 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004688 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004689 dv_id = IXGBE_DV_X540(link, tc);
4690 break;
4691 default:
4692 dv_id = IXGBE_DV(link, tc);
4693 break;
4694 }
4695
4696 /* Loopback switch introduces additional latency */
4697 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4698 dv_id += IXGBE_B2BT(tc);
4699
4700 /* Delay value is calculated in bit times convert to KB */
4701 kb = IXGBE_BT2KB(dv_id);
4702 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4703
4704 marker = rx_pba - kb;
4705
4706 /* It is possible that the packet buffer is not large enough
4707 * to provide required headroom. In this case throw an error
4708 * to user and a do the best we can.
4709 */
4710 if (marker < 0) {
4711 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4712 "headroom to support flow control."
4713 "Decrease MTU or number of traffic classes\n", pb);
4714 marker = tc + 1;
4715 }
4716
4717 return marker;
4718}
4719
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004720/**
John Fastabend9da712d2011-08-23 03:14:22 +00004721 * ixgbe_lpbthresh - calculate low water mark for for flow control
4722 *
4723 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004724 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004725 */
Jacob Kellere5776622014-04-05 02:35:52 +00004726static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00004727{
4728 struct ixgbe_hw *hw = &adapter->hw;
4729 struct net_device *dev = adapter->netdev;
4730 int tc;
4731 u32 dv_id;
4732
4733 /* Calculate max LAN frame size */
4734 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4735
Jacob Kellere5776622014-04-05 02:35:52 +00004736#ifdef IXGBE_FCOE
4737 /* FCoE traffic class uses FCOE jumbo frames */
4738 if ((dev->features & NETIF_F_FCOE_MTU) &&
4739 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4740 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4741 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4742#endif
4743
John Fastabend9da712d2011-08-23 03:14:22 +00004744 /* Calculate delay value for device */
4745 switch (hw->mac.type) {
4746 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004747 case ixgbe_mac_X550:
4748 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004749 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004750 dv_id = IXGBE_LOW_DV_X540(tc);
4751 break;
4752 default:
4753 dv_id = IXGBE_LOW_DV(tc);
4754 break;
4755 }
4756
4757 /* Delay value is calculated in bit times convert to KB */
4758 return IXGBE_BT2KB(dv_id);
4759}
4760
4761/*
4762 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4763 */
4764static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4765{
4766 struct ixgbe_hw *hw = &adapter->hw;
4767 int num_tc = netdev_get_num_tc(adapter->netdev);
4768 int i;
4769
4770 if (!num_tc)
4771 num_tc = 1;
4772
John Fastabend9da712d2011-08-23 03:14:22 +00004773 for (i = 0; i < num_tc; i++) {
4774 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00004775 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00004776
4777 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00004778 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4779 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004780 }
Jacob Kellere5776622014-04-05 02:35:52 +00004781
4782 for (; i < MAX_TRAFFIC_CLASS; i++)
4783 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004784}
John Fastabend80605c652011-05-02 12:34:10 +00004785
4786static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4787{
John Fastabend80605c652011-05-02 12:34:10 +00004788 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004789 int hdrm;
4790 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004791
4792 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4793 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004794 hdrm = 32 << adapter->fdir_pballoc;
4795 else
4796 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004797
Alexander Duyckf7e10272011-07-21 00:40:35 +00004798 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004799 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004800}
4801
Alexander Duycke4911d52011-05-11 07:18:52 +00004802static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4803{
4804 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004805 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004806 struct ixgbe_fdir_filter *filter;
4807
4808 spin_lock(&adapter->fdir_perfect_lock);
4809
4810 if (!hlist_empty(&adapter->fdir_filter_list))
4811 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4812
Sasha Levinb67bfe02013-02-27 17:06:00 -08004813 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004814 &adapter->fdir_filter_list, fdir_node) {
4815 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004816 &filter->filter,
4817 filter->sw_idx,
4818 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4819 IXGBE_FDIR_DROP_QUEUE :
4820 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004821 }
4822
4823 spin_unlock(&adapter->fdir_perfect_lock);
4824}
4825
John Fastabend2a47fa42013-11-06 09:54:52 -08004826static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4827 struct ixgbe_adapter *adapter)
4828{
4829 struct ixgbe_hw *hw = &adapter->hw;
4830 u32 vmolr;
4831
4832 /* No unicast promiscuous support for VMDQ devices. */
4833 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4834 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4835
4836 /* clear the affected bit */
4837 vmolr &= ~IXGBE_VMOLR_MPE;
4838
4839 if (dev->flags & IFF_ALLMULTI) {
4840 vmolr |= IXGBE_VMOLR_MPE;
4841 } else {
4842 vmolr |= IXGBE_VMOLR_ROMPE;
4843 hw->mac.ops.update_mc_addr_list(hw, dev);
4844 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00004845 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08004846 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4847}
4848
John Fastabend2a47fa42013-11-06 09:54:52 -08004849static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4850{
4851 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004852 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004853 struct ixgbe_hw *hw = &adapter->hw;
4854 u16 pool = vadapter->pool;
4855 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4856 IXGBE_PSRTYPE_UDPHDR |
4857 IXGBE_PSRTYPE_IPV4HDR |
4858 IXGBE_PSRTYPE_L2HDR |
4859 IXGBE_PSRTYPE_IPV6HDR;
4860
4861 if (hw->mac.type == ixgbe_mac_82598EB)
4862 return;
4863
4864 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004865 psrtype |= 2u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004866 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004867 psrtype |= 1u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004868
4869 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4870}
4871
4872/**
4873 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4874 * @rx_ring: ring to free buffers from
4875 **/
4876static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4877{
4878 struct device *dev = rx_ring->dev;
4879 unsigned long size;
4880 u16 i;
4881
4882 /* ring already cleared, nothing to do */
4883 if (!rx_ring->rx_buffer_info)
4884 return;
4885
4886 /* Free all the Rx ring sk_buffs */
4887 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyck18cb6522014-11-14 00:56:29 +00004888 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08004889
John Fastabend2a47fa42013-11-06 09:54:52 -08004890 if (rx_buffer->skb) {
4891 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00004892 if (IXGBE_CB(skb)->page_released)
John Fastabend2a47fa42013-11-06 09:54:52 -08004893 dma_unmap_page(dev,
4894 IXGBE_CB(skb)->dma,
4895 ixgbe_rx_bufsz(rx_ring),
4896 DMA_FROM_DEVICE);
John Fastabend2a47fa42013-11-06 09:54:52 -08004897 dev_kfree_skb(skb);
Junwei Zhang4d2fcfb2014-10-22 15:29:03 +00004898 rx_buffer->skb = NULL;
John Fastabend2a47fa42013-11-06 09:54:52 -08004899 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00004900
4901 if (!rx_buffer->page)
4902 continue;
4903
4904 dma_unmap_page(dev, rx_buffer->dma,
4905 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
4906 __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring));
4907
John Fastabend2a47fa42013-11-06 09:54:52 -08004908 rx_buffer->page = NULL;
4909 }
4910
4911 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4912 memset(rx_ring->rx_buffer_info, 0, size);
4913
4914 /* Zero out the descriptor ring */
4915 memset(rx_ring->desc, 0, rx_ring->size);
4916
4917 rx_ring->next_to_alloc = 0;
4918 rx_ring->next_to_clean = 0;
4919 rx_ring->next_to_use = 0;
4920}
4921
4922static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
4923 struct ixgbe_ring *rx_ring)
4924{
4925 struct ixgbe_adapter *adapter = vadapter->real_adapter;
4926 int index = rx_ring->queue_index + vadapter->rx_base_queue;
4927
4928 /* shutdown specific queue receive and wait for dma to settle */
4929 ixgbe_disable_rx_queue(adapter, rx_ring);
4930 usleep_range(10000, 20000);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004931 ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
John Fastabend2a47fa42013-11-06 09:54:52 -08004932 ixgbe_clean_rx_ring(rx_ring);
4933 rx_ring->l2_accel_priv = NULL;
4934}
4935
John Fastabendae72c8d2013-11-09 07:11:26 +00004936static int ixgbe_fwd_ring_down(struct net_device *vdev,
4937 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08004938{
4939 struct ixgbe_adapter *adapter = accel->real_adapter;
4940 unsigned int rxbase = accel->rx_base_queue;
4941 unsigned int txbase = accel->tx_base_queue;
4942 int i;
4943
4944 netif_tx_stop_all_queues(vdev);
4945
4946 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4947 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4948 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
4949 }
4950
4951 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4952 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
4953 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
4954 }
4955
4956
4957 return 0;
4958}
4959
4960static int ixgbe_fwd_ring_up(struct net_device *vdev,
4961 struct ixgbe_fwd_adapter *accel)
4962{
4963 struct ixgbe_adapter *adapter = accel->real_adapter;
4964 unsigned int rxbase, txbase, queues;
4965 int i, baseq, err = 0;
4966
4967 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
4968 return 0;
4969
4970 baseq = accel->pool * adapter->num_rx_queues_per_pool;
4971 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4972 accel->pool, adapter->num_rx_pools,
4973 baseq, baseq + adapter->num_rx_queues_per_pool,
4974 adapter->fwd_bitmask);
4975
4976 accel->netdev = vdev;
4977 accel->rx_base_queue = rxbase = baseq;
4978 accel->tx_base_queue = txbase = baseq;
4979
4980 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
4981 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4982
4983 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4984 adapter->rx_ring[rxbase + i]->netdev = vdev;
4985 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
4986 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
4987 }
4988
4989 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4990 adapter->tx_ring[txbase + i]->netdev = vdev;
4991 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
4992 }
4993
4994 queues = min_t(unsigned int,
4995 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
4996 err = netif_set_real_num_tx_queues(vdev, queues);
4997 if (err)
4998 goto fwd_queue_err;
4999
John Fastabend2a47fa42013-11-06 09:54:52 -08005000 err = netif_set_real_num_rx_queues(vdev, queues);
5001 if (err)
5002 goto fwd_queue_err;
5003
5004 if (is_valid_ether_addr(vdev->dev_addr))
5005 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
5006
5007 ixgbe_fwd_psrtype(accel);
5008 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
5009 return err;
5010fwd_queue_err:
5011 ixgbe_fwd_ring_down(vdev, accel);
5012 return err;
5013}
5014
5015static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5016{
5017 struct net_device *upper;
5018 struct list_head *iter;
5019 int err;
5020
5021 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
5022 if (netif_is_macvlan(upper)) {
5023 struct macvlan_dev *dfwd = netdev_priv(upper);
5024 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5025
5026 if (dfwd->fwd_priv) {
5027 err = ixgbe_fwd_ring_up(upper, vadapter);
5028 if (err)
5029 continue;
5030 }
5031 }
5032 }
5033}
5034
Auke Kok9a799d72007-09-15 14:07:45 -07005035static void ixgbe_configure(struct ixgbe_adapter *adapter)
5036{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005037 struct ixgbe_hw *hw = &adapter->hw;
5038
John Fastabend80605c652011-05-02 12:34:10 +00005039 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005040#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005041 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005042#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005043 /*
5044 * We must restore virtualization before VLANs or else
5045 * the VLVF registers will not be populated
5046 */
5047 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005048
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005049 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005050 ixgbe_restore_vlan(adapter);
5051
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005052 switch (hw->mac.type) {
5053 case ixgbe_mac_82599EB:
5054 case ixgbe_mac_X540:
5055 hw->mac.ops.disable_rx_buff(hw);
5056 break;
5057 default:
5058 break;
5059 }
5060
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005061 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005062 ixgbe_init_fdir_signature_82599(&adapter->hw,
5063 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005064 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5065 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5066 adapter->fdir_pballoc);
5067 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005068 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005069
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005070 switch (hw->mac.type) {
5071 case ixgbe_mac_82599EB:
5072 case ixgbe_mac_X540:
5073 hw->mac.ops.enable_rx_buff(hw);
5074 break;
5075 default:
5076 break;
5077 }
5078
Mark Rustad9de76052015-08-08 16:27:41 -07005079#ifdef CONFIG_IXGBE_DCA
5080 /* configure DCA */
5081 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5082 ixgbe_setup_dca(adapter);
5083#endif /* CONFIG_IXGBE_DCA */
5084
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005085#ifdef IXGBE_FCOE
5086 /* configure FCoE L2 filters, redirection table, and Rx control */
5087 ixgbe_configure_fcoe(adapter);
5088
5089#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005090 ixgbe_configure_tx(adapter);
5091 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005092 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005093}
5094
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005095/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005096 * ixgbe_sfp_link_config - set up SFP+ link
5097 * @adapter: pointer to private adapter struct
5098 **/
5099static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5100{
Alexander Duyck70864002011-04-27 09:13:56 +00005101 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005102 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005103 * is that an SFP was inserted/removed after the reset
5104 * but before SFP detection was enabled. As such the best
5105 * solution is to just start searching as soon as we start
5106 */
5107 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5108 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005109
Alexander Duyck70864002011-04-27 09:13:56 +00005110 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005111 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005112}
5113
5114/**
5115 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005116 * @hw: pointer to private hardware struct
5117 *
5118 * Returns 0 on success, negative on failure
5119 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005120static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005121{
Josh Hay3d292262012-12-15 03:28:19 +00005122 u32 speed;
5123 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005124 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005125
5126 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005127 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005128
5129 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005130 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005131
Josh Hay3d292262012-12-15 03:28:19 +00005132 speed = hw->phy.autoneg_advertised;
5133 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5134 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5135 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005136 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005137 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005138
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005139 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005140 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005141
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005142 return ret;
5143}
5144
Alexander Duycka34bcff2010-08-19 13:39:20 +00005145static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005146{
Auke Kok9a799d72007-09-15 14:07:45 -07005147 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005148 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005149
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005150 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005151 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5152 IXGBE_GPIE_OCD;
5153 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005154 /*
5155 * use EIAM to auto-mask when MSI-X interrupt is asserted
5156 * this saves a register write for every interrupt
5157 */
5158 switch (hw->mac.type) {
5159 case ixgbe_mac_82598EB:
5160 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5161 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005162 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005163 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005164 case ixgbe_mac_X550:
5165 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005166 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005167 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005168 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5169 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5170 break;
5171 }
5172 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005173 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5174 * specifically only auto mask tx and rx interrupts */
5175 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005176 }
5177
Alexander Duycka34bcff2010-08-19 13:39:20 +00005178 /* XXX: to interrupt immediately for EICS writes, enable this */
5179 /* gpie |= IXGBE_GPIE_EIMEN; */
5180
5181 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5182 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005183
5184 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5185 case IXGBE_82599_VMDQ_8Q_MASK:
5186 gpie |= IXGBE_GPIE_VTMODE_16;
5187 break;
5188 case IXGBE_82599_VMDQ_4Q_MASK:
5189 gpie |= IXGBE_GPIE_VTMODE_32;
5190 break;
5191 default:
5192 gpie |= IXGBE_GPIE_VTMODE_64;
5193 break;
5194 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005195 }
5196
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005197 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005198 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5199 switch (adapter->hw.mac.type) {
5200 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005201 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005202 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005203 default:
5204 break;
5205 }
5206 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005207
Alexander Duycka34bcff2010-08-19 13:39:20 +00005208 /* Enable fan failure interrupt */
5209 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005210 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005211
Don Skidmorea023bbd2015-06-24 16:38:53 -04005212 switch (hw->mac.type) {
5213 case ixgbe_mac_82599EB:
5214 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5215 break;
5216 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005217 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005218 gpie |= IXGBE_SDP0_GPIEN_X540;
5219 break;
5220 default:
5221 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005222 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005223
5224 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5225}
5226
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005227static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005228{
5229 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005230 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005231 u32 ctrl_ext;
5232
5233 ixgbe_get_hw_control(adapter);
5234 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005235
Auke Kok9a799d72007-09-15 14:07:45 -07005236 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5237 ixgbe_configure_msix(adapter);
5238 else
5239 ixgbe_configure_msi_and_legacy(adapter);
5240
Emil Tantilovec74a472012-09-20 03:33:56 +00005241 /* enable the optics for 82599 SFP+ fiber */
5242 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005243 hw->mac.ops.enable_tx_laser(hw);
5244
Don Skidmore961fac82015-06-09 16:09:47 -07005245 if (hw->phy.ops.set_phy_power)
5246 hw->phy.ops.set_phy_power(hw, true);
5247
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005248 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005249 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005250 ixgbe_napi_enable_all(adapter);
5251
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005252 if (ixgbe_is_sfp(hw)) {
5253 ixgbe_sfp_link_config(adapter);
5254 } else {
5255 err = ixgbe_non_sfp_link_config(hw);
5256 if (err)
5257 e_err(probe, "link_config FAILED %d\n", err);
5258 }
5259
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005260 /* clear any pending interrupts, may auto mask */
5261 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005262 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005263
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005264 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005265 * If this adapter has a fan, check to see if we had a failure
5266 * before we enabled the interrupt.
5267 */
5268 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5269 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5270 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005271 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005272 }
5273
Auke Kok9a799d72007-09-15 14:07:45 -07005274 /* bring the link up in the watchdog, this could race with our first
5275 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005276 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5277 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005278 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005279
5280 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5281 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5282 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5283 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005284}
5285
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005286void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5287{
5288 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005289 /* put off any impending NetWatchDogTimeout */
5290 adapter->netdev->trans_start = jiffies;
5291
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005292 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005293 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005294 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005295 /*
5296 * If SR-IOV enabled then wait a bit before bringing the adapter
5297 * back up to give the VFs time to respond to the reset. The
5298 * two second wait is based upon the watchdog timer cycle in
5299 * the VF driver.
5300 */
5301 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5302 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005303 ixgbe_up(adapter);
5304 clear_bit(__IXGBE_RESETTING, &adapter->state);
5305}
5306
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005307void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005308{
5309 /* hardware has been reset, we need to reload some things */
5310 ixgbe_configure(adapter);
5311
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005312 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005313}
5314
5315void ixgbe_reset(struct ixgbe_adapter *adapter)
5316{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005317 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005318 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005319 int err;
5320
Mark Rustadb0483c82014-01-14 18:53:17 -08005321 if (ixgbe_removed(hw->hw_addr))
5322 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005323 /* lock SFP init bit to prevent race conditions with the watchdog */
5324 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5325 usleep_range(1000, 2000);
5326
5327 /* clear all SFP and link config related flags while holding SFP_INIT */
5328 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5329 IXGBE_FLAG2_SFP_NEEDS_RESET);
5330 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5331
Don Skidmore8ca783a2009-05-26 20:40:47 -07005332 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005333 switch (err) {
5334 case 0:
5335 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005336 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005337 break;
5338 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005339 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005340 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005341 case IXGBE_ERR_EEPROM_VERSION:
5342 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005343 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005344 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005345 "your hardware. If you are experiencing problems "
5346 "please contact your Intel or hardware "
5347 "representative who provided you with this "
5348 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005349 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005350 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005351 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005352 }
Auke Kok9a799d72007-09-15 14:07:45 -07005353
Alexander Duyck70864002011-04-27 09:13:56 +00005354 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005355
5356 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005357 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005358 __dev_uc_unsync(netdev, NULL);
5359
5360 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005361 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005362
5363 /* update SAN MAC vmdq pool selection */
5364 if (hw->mac.san_mac_rar_index)
5365 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005366
Jacob Keller8fecf672013-06-21 08:14:32 +00005367 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005368 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005369
5370 if (hw->phy.ops.set_phy_power) {
5371 if (!netif_running(adapter->netdev) && !adapter->wol)
5372 hw->phy.ops.set_phy_power(hw, false);
5373 else
5374 hw->phy.ops.set_phy_power(hw, true);
5375 }
Auke Kok9a799d72007-09-15 14:07:45 -07005376}
5377
Auke Kok9a799d72007-09-15 14:07:45 -07005378/**
Auke Kok9a799d72007-09-15 14:07:45 -07005379 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005380 * @tx_ring: ring to be cleaned
5381 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005382static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005383{
5384 struct ixgbe_tx_buffer *tx_buffer_info;
5385 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005386 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07005387
Alexander Duyck84418e32010-08-19 13:40:54 +00005388 /* ring already cleared, nothing to do */
5389 if (!tx_ring->tx_buffer_info)
5390 return;
Auke Kok9a799d72007-09-15 14:07:45 -07005391
Alexander Duyck84418e32010-08-19 13:40:54 +00005392 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07005393 for (i = 0; i < tx_ring->count; i++) {
5394 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005395 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07005396 }
5397
John Fastabenddad8a3b2012-04-23 12:22:39 +00005398 netdev_tx_reset_queue(txring_txq(tx_ring));
5399
Auke Kok9a799d72007-09-15 14:07:45 -07005400 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5401 memset(tx_ring->tx_buffer_info, 0, size);
5402
5403 /* Zero out the descriptor ring */
5404 memset(tx_ring->desc, 0, tx_ring->size);
5405
5406 tx_ring->next_to_use = 0;
5407 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005408}
5409
5410/**
Auke Kok9a799d72007-09-15 14:07:45 -07005411 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5412 * @adapter: board private structure
5413 **/
5414static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5415{
5416 int i;
5417
5418 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005419 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005420}
5421
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005422/**
5423 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5424 * @adapter: board private structure
5425 **/
5426static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5427{
5428 int i;
5429
5430 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005431 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005432}
5433
Alexander Duycke4911d52011-05-11 07:18:52 +00005434static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5435{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005436 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005437 struct ixgbe_fdir_filter *filter;
5438
5439 spin_lock(&adapter->fdir_perfect_lock);
5440
Sasha Levinb67bfe02013-02-27 17:06:00 -08005441 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005442 &adapter->fdir_filter_list, fdir_node) {
5443 hlist_del(&filter->fdir_node);
5444 kfree(filter);
5445 }
5446 adapter->fdir_filter_count = 0;
5447
5448 spin_unlock(&adapter->fdir_perfect_lock);
5449}
5450
Auke Kok9a799d72007-09-15 14:07:45 -07005451void ixgbe_down(struct ixgbe_adapter *adapter)
5452{
5453 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005454 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08005455 struct net_device *upper;
5456 struct list_head *iter;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005457 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005458
5459 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005460 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5461 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005462
5463 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005464 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005465
Yi Zou2d39d572011-01-06 14:29:56 +00005466 /* disable all enabled rx queues */
5467 for (i = 0; i < adapter->num_rx_queues; i++)
5468 /* this call also flushes the previous write */
5469 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5470
Don Skidmore032b4322011-03-18 09:32:53 +00005471 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005472
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005473 netif_tx_stop_all_queues(netdev);
5474
Alexander Duyck70864002011-04-27 09:13:56 +00005475 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005476 netif_carrier_off(netdev);
5477 netif_tx_disable(netdev);
5478
John Fastabend2a47fa42013-11-06 09:54:52 -08005479 /* disable any upper devices */
5480 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
5481 if (netif_is_macvlan(upper)) {
5482 struct macvlan_dev *vlan = netdev_priv(upper);
5483
5484 if (vlan->fwd_priv) {
5485 netif_tx_stop_all_queues(upper);
5486 netif_carrier_off(upper);
5487 netif_tx_disable(upper);
5488 }
5489 }
5490 }
5491
John Fastabendc0dfb902010-04-27 02:13:39 +00005492 ixgbe_irq_disable(adapter);
5493
5494 ixgbe_napi_disable_all(adapter);
5495
Alexander Duyckd034acf2011-04-27 09:25:34 +00005496 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
5497 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00005498 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5499
5500 del_timer_sync(&adapter->service_timer);
5501
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005502 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005503 /* Clear EITR Select mapping */
5504 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5505
5506 /* Mark all the VFs as inactive */
5507 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005508 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005509
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005510 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005511 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005512
Auke Kok9a799d72007-09-15 14:07:45 -07005513 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005514 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005515 }
5516
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005517 /* disable transmits in the hardware now that interrupts are off */
5518 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005519 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005520 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005521 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005522
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005523 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005524 switch (hw->mac.type) {
5525 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005526 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005527 case ixgbe_mac_X550:
5528 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005529 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005530 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005531 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5532 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005533 break;
5534 default:
5535 break;
5536 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005537
Paul Larson6f4a0e42008-06-24 17:00:56 -07005538 if (!pci_channel_offline(adapter->pdev))
5539 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005540
Emil Tantilovec74a472012-09-20 03:33:56 +00005541 /* power down the optics for 82599 SFP+ fiber */
5542 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005543 hw->mac.ops.disable_tx_laser(hw);
5544
Auke Kok9a799d72007-09-15 14:07:45 -07005545 ixgbe_clean_all_tx_rings(adapter);
5546 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005547}
5548
Auke Kok9a799d72007-09-15 14:07:45 -07005549/**
Auke Kok9a799d72007-09-15 14:07:45 -07005550 * ixgbe_tx_timeout - Respond to a Tx Hang
5551 * @netdev: network interface device structure
5552 **/
5553static void ixgbe_tx_timeout(struct net_device *netdev)
5554{
5555 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5556
5557 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005558 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005559}
5560
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005561/**
Auke Kok9a799d72007-09-15 14:07:45 -07005562 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5563 * @adapter: board private structure to initialize
5564 *
5565 * ixgbe_sw_init initializes the Adapter private data structure.
5566 * Fields are initialized based on PCI device information and
5567 * OS network device settings (MTU size).
5568 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05005569static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005570{
5571 struct ixgbe_hw *hw = &adapter->hw;
5572 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005573 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005574 u32 fwsm;
Don Skidmore4319a792016-04-12 19:25:10 -04005575 u16 device_caps;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005576#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005577 int j;
5578 struct tc_configuration *tc;
5579#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005580
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005581 /* PCI config space info */
5582
5583 hw->vendor_id = pdev->vendor;
5584 hw->device_id = pdev->device;
5585 hw->revision_id = pdev->revision;
5586 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5587 hw->subsystem_device_id = pdev->subsystem_device;
5588
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005589 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00005590 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005591 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005592 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005593 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5594 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005595 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5596 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005597 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5598#ifdef CONFIG_IXGBE_DCA
5599 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5600#endif
5601#ifdef IXGBE_FCOE
5602 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5603 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5604#ifdef CONFIG_IXGBE_DCB
5605 /* Default traffic class to use for FCoE */
5606 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5607#endif /* CONFIG_IXGBE_DCB */
5608#endif /* IXGBE_FCOE */
5609
John Fastabendb82b17d2016-02-16 21:18:53 -08005610 /* initialize static ixgbe jump table entries */
5611 adapter->jump_tables[0] = ixgbe_ipv4_fields;
5612
Jacob Keller5d7daa32014-03-29 06:51:25 +00005613 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5614 hw->mac.num_rar_entries,
5615 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08005616 if (!adapter->mac_table)
5617 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005618
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005619 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005620 switch (hw->mac.type) {
5621 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005622 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005623
Don Skidmorebf069c92009-05-07 10:39:54 +00005624 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5625 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005626
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005627 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005628 adapter->ring_feature[RING_F_FDIR].limit = 0;
5629 adapter->atr_sample_rate = 0;
5630 adapter->fdir_pballoc = 0;
5631#ifdef IXGBE_FCOE
5632 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5633 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5634#ifdef CONFIG_IXGBE_DCB
5635 adapter->fcoe.up = 0;
5636#endif /* IXGBE_DCB */
5637#endif /* IXGBE_FCOE */
5638 break;
5639 case ixgbe_mac_82599EB:
5640 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5641 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005642 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005643 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005644 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005645 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5646 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005647 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005648 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005649 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005650 case ixgbe_mac_X550:
5651#ifdef CONFIG_IXGBE_DCA
5652 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
5653#endif
Mark Rustad67359c32015-06-15 11:33:25 -07005654#ifdef CONFIG_IXGBE_VXLAN
5655 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
5656#endif
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005657 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08005658 default:
5659 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005660 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005661
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005662#ifdef IXGBE_FCOE
5663 /* FCoE support exists, always init the FCoE lock */
5664 spin_lock_init(&adapter->fcoe.lock);
5665
5666#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005667 /* n-tuple support exists, always init our spinlock */
5668 spin_lock_init(&adapter->fdir_perfect_lock);
5669
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005670#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005671 switch (hw->mac.type) {
5672 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005673 case ixgbe_mac_X550:
5674 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005675 case ixgbe_mac_x550em_a:
John Fastabend4de2a022011-09-27 03:52:01 +00005676 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5677 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5678 break;
5679 default:
5680 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5681 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5682 break;
5683 }
5684
Alexander Duyck2f90b862008-11-20 20:52:10 -08005685 /* Configure DCB traffic classes */
5686 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5687 tc = &adapter->dcb_cfg.tc_config[j];
5688 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5689 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5690 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5691 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5692 tc->dcb_pfc = pfc_disabled;
5693 }
John Fastabend4de2a022011-09-27 03:52:01 +00005694
5695 /* Initialize default user to priority mapping, UPx->TC0 */
5696 tc = &adapter->dcb_cfg.tc_config[0];
5697 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5698 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5699
Alexander Duyck2f90b862008-11-20 20:52:10 -08005700 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5701 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005702 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005703 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005704 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00005705 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5706 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08005707
5708#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005709
5710 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005711 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005712 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005713 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005714 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5715 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005716 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005717
Alexander Duyck99d74482012-05-09 08:09:25 +00005718#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005719 if (max_vfs > 0)
5720 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 +00005721
Jacob Keller170e8542013-11-09 04:52:32 -08005722 /* assign number of SR-IOV VFs */
5723 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005724 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Jacob Keller170e8542013-11-09 04:52:32 -08005725 adapter->num_vfs = 0;
5726 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5727 } else {
5728 adapter->num_vfs = max_vfs;
5729 }
5730 }
5731#endif /* CONFIG_PCI_IOV */
5732
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005733 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005734 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005735 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005736
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005737 /* set default ring sizes */
5738 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5739 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5740
Don Skidmore4319a792016-04-12 19:25:10 -04005741 /* Cache bit indicating need for crosstalk fix */
5742 switch (hw->mac.type) {
5743 case ixgbe_mac_82599EB:
5744 case ixgbe_mac_X550EM_x:
5745 case ixgbe_mac_x550em_a:
5746 hw->mac.ops.get_device_caps(hw, &device_caps);
5747 if (device_caps & IXGBE_DEVICE_CAPS_NO_CROSSTALK_WR)
5748 adapter->need_crosstalk_fix = false;
5749 else
5750 adapter->need_crosstalk_fix = true;
5751 break;
5752 default:
5753 adapter->need_crosstalk_fix = false;
5754 break;
5755 }
5756
Alexander Duyckbd198052011-06-11 01:45:08 +00005757 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005758 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005759
Auke Kok9a799d72007-09-15 14:07:45 -07005760 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005761 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005762 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005763 return -EIO;
5764 }
5765
John Fastabend2a47fa42013-11-06 09:54:52 -08005766 /* PF holds first pool slot */
5767 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005768 set_bit(__IXGBE_DOWN, &adapter->state);
5769
5770 return 0;
5771}
5772
5773/**
5774 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005775 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005776 *
5777 * Return 0 on success, negative on failure
5778 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005779int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005780{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005781 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005782 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005783 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005784 int size;
5785
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005786 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005787
5788 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005789 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005790
Mark Rustadca8dfe22014-07-24 06:19:24 +00005791 tx_ring->tx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005792 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005793 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005794 if (!tx_ring->tx_buffer_info)
5795 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005796
John Stultz827da442013-10-07 15:51:58 -07005797 u64_stats_init(&tx_ring->syncp);
5798
Auke Kok9a799d72007-09-15 14:07:45 -07005799 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005800 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005801 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005802
Mark Rustadca8dfe22014-07-24 06:19:24 +00005803 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005804 tx_ring->desc = dma_alloc_coherent(dev,
5805 tx_ring->size,
5806 &tx_ring->dma,
5807 GFP_KERNEL);
5808 set_dev_node(dev, orig_node);
5809 if (!tx_ring->desc)
5810 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5811 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005812 if (!tx_ring->desc)
5813 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005814
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005815 tx_ring->next_to_use = 0;
5816 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005817 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005818
5819err:
5820 vfree(tx_ring->tx_buffer_info);
5821 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005822 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005823 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005824}
5825
5826/**
Alexander Duyck69888672008-09-11 20:05:39 -07005827 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5828 * @adapter: board private structure
5829 *
5830 * If this function returns with an error, then it's possible one or
5831 * more of the rings is populated (while the rest are not). It is the
5832 * callers duty to clean those orphaned rings.
5833 *
5834 * Return 0 on success, negative on failure
5835 **/
5836static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5837{
5838 int i, err = 0;
5839
5840 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005841 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005842 if (!err)
5843 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005844
Emil Tantilov396e7992010-07-01 20:05:12 +00005845 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005846 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07005847 }
5848
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005849 return 0;
5850err_setup_tx:
5851 /* rewind the index freeing the rings as we go */
5852 while (i--)
5853 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005854 return err;
5855}
5856
5857/**
Auke Kok9a799d72007-09-15 14:07:45 -07005858 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005859 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005860 *
5861 * Returns 0 on success, negative on failure
5862 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005863int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005864{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005865 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005866 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005867 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005868 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005869
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005870 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005871
5872 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005873 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005874
Mark Rustadca8dfe22014-07-24 06:19:24 +00005875 rx_ring->rx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005876 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005877 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005878 if (!rx_ring->rx_buffer_info)
5879 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005880
John Stultz827da442013-10-07 15:51:58 -07005881 u64_stats_init(&rx_ring->syncp);
5882
Auke Kok9a799d72007-09-15 14:07:45 -07005883 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005884 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5885 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005886
Mark Rustadca8dfe22014-07-24 06:19:24 +00005887 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005888 rx_ring->desc = dma_alloc_coherent(dev,
5889 rx_ring->size,
5890 &rx_ring->dma,
5891 GFP_KERNEL);
5892 set_dev_node(dev, orig_node);
5893 if (!rx_ring->desc)
5894 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5895 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005896 if (!rx_ring->desc)
5897 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005898
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005899 rx_ring->next_to_clean = 0;
5900 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005901
5902 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005903err:
5904 vfree(rx_ring->rx_buffer_info);
5905 rx_ring->rx_buffer_info = NULL;
5906 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005907 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005908}
5909
5910/**
Alexander Duyck69888672008-09-11 20:05:39 -07005911 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5912 * @adapter: board private structure
5913 *
5914 * If this function returns with an error, then it's possible one or
5915 * more of the rings is populated (while the rest are not). It is the
5916 * callers duty to clean those orphaned rings.
5917 *
5918 * Return 0 on success, negative on failure
5919 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005920static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5921{
5922 int i, err = 0;
5923
5924 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005925 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005926 if (!err)
5927 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005928
Emil Tantilov396e7992010-07-01 20:05:12 +00005929 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005930 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07005931 }
5932
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005933#ifdef IXGBE_FCOE
5934 err = ixgbe_setup_fcoe_ddp_resources(adapter);
5935 if (!err)
5936#endif
5937 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005938err_setup_rx:
5939 /* rewind the index freeing the rings as we go */
5940 while (i--)
5941 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005942 return err;
5943}
5944
5945/**
Auke Kok9a799d72007-09-15 14:07:45 -07005946 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005947 * @tx_ring: Tx descriptor ring for a specific queue
5948 *
5949 * Free all transmit software resources
5950 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005951void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005952{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005953 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005954
5955 vfree(tx_ring->tx_buffer_info);
5956 tx_ring->tx_buffer_info = NULL;
5957
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005958 /* if not set, then don't free */
5959 if (!tx_ring->desc)
5960 return;
5961
5962 dma_free_coherent(tx_ring->dev, tx_ring->size,
5963 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005964
5965 tx_ring->desc = NULL;
5966}
5967
5968/**
5969 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5970 * @adapter: board private structure
5971 *
5972 * Free all transmit software resources
5973 **/
5974static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5975{
5976 int i;
5977
5978 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005979 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005980 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005981}
5982
5983/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005984 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005985 * @rx_ring: ring to clean the resources from
5986 *
5987 * Free all receive software resources
5988 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005989void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005990{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005991 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005992
5993 vfree(rx_ring->rx_buffer_info);
5994 rx_ring->rx_buffer_info = NULL;
5995
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005996 /* if not set, then don't free */
5997 if (!rx_ring->desc)
5998 return;
5999
6000 dma_free_coherent(rx_ring->dev, rx_ring->size,
6001 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006002
6003 rx_ring->desc = NULL;
6004}
6005
6006/**
6007 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6008 * @adapter: board private structure
6009 *
6010 * Free all receive software resources
6011 **/
6012static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6013{
6014 int i;
6015
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006016#ifdef IXGBE_FCOE
6017 ixgbe_free_fcoe_ddp_resources(adapter);
6018
6019#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006020 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006021 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006022 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006023}
6024
6025/**
Auke Kok9a799d72007-09-15 14:07:45 -07006026 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6027 * @netdev: network interface device structure
6028 * @new_mtu: new value for maximum frame size
6029 *
6030 * Returns 0 on success, negative on failure
6031 **/
6032static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6033{
6034 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6035 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
6036
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07006037 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00006038 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
6039 return -EINVAL;
6040
6041 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006042 * For 82599EB we cannot allow legacy VFs to enable their receive
6043 * paths when MTU greater than 1500 is configured. So display a
6044 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006045 */
6046 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6047 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Alexander Duyckc5604512013-01-09 08:50:42 +00006048 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck872844d2012-08-15 02:10:43 +00006049 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006050
Emil Tantilov396e7992010-07-01 20:05:12 +00006051 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006052
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006053 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006054 netdev->mtu = new_mtu;
6055
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006056 if (netif_running(netdev))
6057 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006058
6059 return 0;
6060}
6061
6062/**
6063 * ixgbe_open - Called when a network interface is made active
6064 * @netdev: network interface device structure
6065 *
6066 * Returns 0 on success, negative value on failure
6067 *
6068 * The open entry point is called when a network interface is made
6069 * active by the system (IFF_UP). At this point all resources needed
6070 * for transmit and receive operations are allocated, the interrupt
6071 * handler is registered with the OS, the watchdog timer is started,
6072 * and the stack is notified that the interface is ready.
6073 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006074int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006075{
6076 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006077 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006078 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006079
Auke Kok4bebfaa2008-02-11 09:26:01 -08006080 /* disallow open during test */
6081 if (test_bit(__IXGBE_TESTING, &adapter->state))
6082 return -EBUSY;
6083
Jesse Brandeburg54386462009-04-17 20:44:27 +00006084 netif_carrier_off(netdev);
6085
Auke Kok9a799d72007-09-15 14:07:45 -07006086 /* allocate transmit descriptors */
6087 err = ixgbe_setup_all_tx_resources(adapter);
6088 if (err)
6089 goto err_setup_tx;
6090
Auke Kok9a799d72007-09-15 14:07:45 -07006091 /* allocate receive descriptors */
6092 err = ixgbe_setup_all_rx_resources(adapter);
6093 if (err)
6094 goto err_setup_rx;
6095
6096 ixgbe_configure(adapter);
6097
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006098 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006099 if (err)
6100 goto err_req_irq;
6101
Alexander Duyckac802f52012-07-12 05:52:53 +00006102 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08006103 if (adapter->num_rx_pools > 1)
6104 queues = adapter->num_rx_queues_per_pool;
6105 else
6106 queues = adapter->num_tx_queues;
6107
6108 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006109 if (err)
6110 goto err_set_queues;
6111
John Fastabend2a47fa42013-11-06 09:54:52 -08006112 if (adapter->num_rx_pools > 1 &&
6113 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
6114 queues = IXGBE_MAX_L2A_QUEUES;
6115 else
6116 queues = adapter->num_rx_queues;
6117 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006118 if (err)
6119 goto err_set_queues;
6120
Jacob Keller1a71ab22012-08-25 03:54:19 +00006121 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006122
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006123 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006124
Mark Rustad67359c32015-06-15 11:33:25 -07006125 ixgbe_clear_vxlan_port(adapter);
6126#ifdef CONFIG_IXGBE_VXLAN
Don Skidmore3f207802014-12-23 07:40:34 +00006127 vxlan_get_rx_port(netdev);
Don Skidmore3f207802014-12-23 07:40:34 +00006128#endif
Mark Rustad67359c32015-06-15 11:33:25 -07006129
Auke Kok9a799d72007-09-15 14:07:45 -07006130 return 0;
6131
Alexander Duyckac802f52012-07-12 05:52:53 +00006132err_set_queues:
6133 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006134err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006135 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006136 if (hw->phy.ops.set_phy_power && !adapter->wol)
6137 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006138err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006139 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006140err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006141 ixgbe_reset(adapter);
6142
6143 return err;
6144}
6145
Jacob Kellera0cccce2014-05-16 05:12:29 +00006146static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6147{
6148 ixgbe_ptp_suspend(adapter);
6149
Don Skidmore6ac74392015-06-17 17:34:31 -04006150 if (adapter->hw.phy.ops.enter_lplu) {
6151 adapter->hw.phy.reset_disable = true;
6152 ixgbe_down(adapter);
6153 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6154 adapter->hw.phy.reset_disable = false;
6155 } else {
6156 ixgbe_down(adapter);
6157 }
6158
Jacob Kellera0cccce2014-05-16 05:12:29 +00006159 ixgbe_free_irq(adapter);
6160
6161 ixgbe_free_all_tx_resources(adapter);
6162 ixgbe_free_all_rx_resources(adapter);
6163}
6164
Auke Kok9a799d72007-09-15 14:07:45 -07006165/**
6166 * ixgbe_close - Disables a network interface
6167 * @netdev: network interface device structure
6168 *
6169 * Returns 0, this is not allowed to fail
6170 *
6171 * The close entry point is called when an interface is de-activated
6172 * by the OS. The hardware is still under the drivers control, but
6173 * needs to be disabled. A global MAC reset is issued to stop the
6174 * hardware, and all transmit and receive resources are freed.
6175 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006176int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006177{
6178 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006179
Jacob Keller1a71ab22012-08-25 03:54:19 +00006180 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006181
Jacob Kellera0cccce2014-05-16 05:12:29 +00006182 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006183
Alexander Duycke4911d52011-05-11 07:18:52 +00006184 ixgbe_fdir_filter_exit(adapter);
6185
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006186 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006187
6188 return 0;
6189}
6190
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006191#ifdef CONFIG_PM
6192static int ixgbe_resume(struct pci_dev *pdev)
6193{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006194 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6195 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006196 u32 err;
6197
Mark Rustad0391bbe2014-02-28 15:48:55 -08006198 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006199 pci_set_power_state(pdev, PCI_D0);
6200 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006201 /*
6202 * pci_restore_state clears dev->state_saved so call
6203 * pci_save_state to restore it.
6204 */
6205 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006206
6207 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006208 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006209 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006210 return err;
6211 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006212 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006213 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006214 pci_set_master(pdev);
6215
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006216 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006217
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006218 ixgbe_reset(adapter);
6219
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006220 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6221
Alexander Duyckac802f52012-07-12 05:52:53 +00006222 rtnl_lock();
6223 err = ixgbe_init_interrupt_scheme(adapter);
6224 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006225 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006226
6227 rtnl_unlock();
6228
6229 if (err)
6230 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006231
6232 netif_device_attach(netdev);
6233
6234 return 0;
6235}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006236#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006237
6238static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006239{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006240 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6241 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006242 struct ixgbe_hw *hw = &adapter->hw;
6243 u32 ctrl, fctrl;
6244 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006245#ifdef CONFIG_PM
6246 int retval = 0;
6247#endif
6248
6249 netif_device_detach(netdev);
6250
akepner499ab5c2013-03-13 14:54:58 +00006251 rtnl_lock();
Jacob Kellera0cccce2014-05-16 05:12:29 +00006252 if (netif_running(netdev))
6253 ixgbe_close_suspend(adapter);
akepner499ab5c2013-03-13 14:54:58 +00006254 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006255
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006256 ixgbe_clear_interrupt_scheme(adapter);
6257
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006258#ifdef CONFIG_PM
6259 retval = pci_save_state(pdev);
6260 if (retval)
6261 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006262
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006263#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006264 if (hw->mac.ops.stop_link_on_d3)
6265 hw->mac.ops.stop_link_on_d3(hw);
6266
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006267 if (wufc) {
6268 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006269
Emil Tantilovec74a472012-09-20 03:33:56 +00006270 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6271 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006272 hw->mac.ops.enable_tx_laser(hw);
6273
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006274 /* turn on all-multi mode if wake on multicast is enabled */
6275 if (wufc & IXGBE_WUFC_MC) {
6276 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6277 fctrl |= IXGBE_FCTRL_MPE;
6278 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
6279 }
6280
6281 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6282 ctrl |= IXGBE_CTRL_GIO_DIS;
6283 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6284
6285 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6286 } else {
6287 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6288 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6289 }
6290
Alexander Duyckbd508172010-11-16 19:27:03 -08006291 switch (hw->mac.type) {
6292 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006293 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006294 break;
6295 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006296 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006297 case ixgbe_mac_X550:
6298 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006299 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006300 pci_wake_from_d3(pdev, !!wufc);
6301 break;
6302 default:
6303 break;
6304 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006305
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006306 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006307 if (hw->phy.ops.set_phy_power && !*enable_wake)
6308 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006309
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006310 ixgbe_release_hw_control(adapter);
6311
Mark Rustad41c62842014-03-12 00:38:35 +00006312 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6313 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006314
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006315 return 0;
6316}
6317
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006318#ifdef CONFIG_PM
6319static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6320{
6321 int retval;
6322 bool wake;
6323
6324 retval = __ixgbe_shutdown(pdev, &wake);
6325 if (retval)
6326 return retval;
6327
6328 if (wake) {
6329 pci_prepare_to_sleep(pdev);
6330 } else {
6331 pci_wake_from_d3(pdev, false);
6332 pci_set_power_state(pdev, PCI_D3hot);
6333 }
6334
6335 return 0;
6336}
6337#endif /* CONFIG_PM */
6338
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006339static void ixgbe_shutdown(struct pci_dev *pdev)
6340{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006341 bool wake;
6342
6343 __ixgbe_shutdown(pdev, &wake);
6344
6345 if (system_state == SYSTEM_POWER_OFF) {
6346 pci_wake_from_d3(pdev, wake);
6347 pci_set_power_state(pdev, PCI_D3hot);
6348 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006349}
6350
6351/**
Auke Kok9a799d72007-09-15 14:07:45 -07006352 * ixgbe_update_stats - Update the board statistics counters.
6353 * @adapter: board private structure
6354 **/
6355void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6356{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006357 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006358 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006359 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006360 u64 total_mpc = 0;
6361 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006362 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6363 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006364 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006365
Don Skidmored08935c2010-06-11 13:20:29 +00006366 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6367 test_bit(__IXGBE_RESETTING, &adapter->state))
6368 return;
6369
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006370 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006371 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006372 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006373 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006374 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6375 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006376 }
6377 adapter->rsc_total_count = rsc_count;
6378 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006379 }
6380
Alexander Duyck5b7da512010-11-16 19:26:50 -08006381 for (i = 0; i < adapter->num_rx_queues; i++) {
6382 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6383 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
6384 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6385 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006386 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006387 bytes += rx_ring->stats.bytes;
6388 packets += rx_ring->stats.packets;
6389 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006390 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006391 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6392 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006393 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006394 netdev->stats.rx_bytes = bytes;
6395 netdev->stats.rx_packets = packets;
6396
6397 bytes = 0;
6398 packets = 0;
6399 /* gather some stats to the adapter struct that are per queue */
6400 for (i = 0; i < adapter->num_tx_queues; i++) {
6401 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6402 restart_queue += tx_ring->tx_stats.restart_queue;
6403 tx_busy += tx_ring->tx_stats.tx_busy;
6404 bytes += tx_ring->stats.bytes;
6405 packets += tx_ring->stats.packets;
6406 }
6407 adapter->restart_queue = restart_queue;
6408 adapter->tx_busy = tx_busy;
6409 netdev->stats.tx_bytes = bytes;
6410 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006411
Joe Perches7ca647b2010-09-07 21:35:40 +00006412 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006413
6414 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006415 for (i = 0; i < 8; i++) {
6416 /* for packet buffers not used, the register should read 0 */
6417 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6418 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006419 hwstats->mpc[i] += mpc;
6420 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006421 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6422 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006423 switch (hw->mac.type) {
6424 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006425 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6426 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6427 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006428 hwstats->pxonrxc[i] +=
6429 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006430 break;
6431 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006432 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006433 case ixgbe_mac_X550:
6434 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006435 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006436 hwstats->pxonrxc[i] +=
6437 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006438 break;
6439 default:
6440 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006441 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006442 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006443
6444 /*16 register reads */
6445 for (i = 0; i < 16; i++) {
6446 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6447 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6448 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006449 (hw->mac.type == ixgbe_mac_X540) ||
6450 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006451 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6452 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006453 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6454 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6455 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6456 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6457 }
6458 }
6459
Joe Perches7ca647b2010-09-07 21:35:40 +00006460 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006461 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006462 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006463
John Fastabendc84d3242010-11-16 19:27:12 -08006464 ixgbe_update_xoff_received(adapter);
6465
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006466 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006467 switch (hw->mac.type) {
6468 case ixgbe_mac_82598EB:
6469 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006470 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6471 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6472 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6473 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006474 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006475 case ixgbe_mac_X550:
6476 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006477 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006478 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006479 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6480 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6481 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6482 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6483 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006484 for (i = 0; i < 16; i++)
6485 adapter->hw_rx_no_dma_resources +=
6486 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006487 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006488 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006489 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006490 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006491 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006492 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006493 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006494 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6495 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006496#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006497 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6498 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6499 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6500 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6501 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6502 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006503 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006504 if (adapter->fcoe.ddp_pool) {
6505 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6506 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6507 unsigned int cpu;
6508 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006509 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006510 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6511 noddp += ddp_pool->noddp;
6512 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006513 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006514 hwstats->fcoe_noddp = noddp;
6515 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006516 }
Yi Zou6d455222009-05-13 13:12:16 +00006517#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006518 break;
6519 default:
6520 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006521 }
Auke Kok9a799d72007-09-15 14:07:45 -07006522 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006523 hwstats->bprc += bprc;
6524 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006525 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006526 hwstats->mprc -= bprc;
6527 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6528 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6529 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6530 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6531 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6532 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6533 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6534 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006535 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006536 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006537 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006538 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006539 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6540 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006541 /*
6542 * 82598 errata - tx of flow control packets is included in tx counters
6543 */
6544 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006545 hwstats->gptc -= xon_off_tot;
6546 hwstats->mptc -= xon_off_tot;
6547 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6548 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6549 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6550 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6551 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6552 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6553 hwstats->ptc64 -= xon_off_tot;
6554 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6555 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6556 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6557 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6558 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6559 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006560
6561 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006562 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006563
6564 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006565 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006566 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006567 netdev->stats.rx_length_errors = hwstats->rlec;
6568 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006569 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006570}
6571
6572/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006573 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006574 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006575 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006576static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006577{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006578 struct ixgbe_hw *hw = &adapter->hw;
6579 int i;
6580
Alexander Duyckd034acf2011-04-27 09:25:34 +00006581 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6582 return;
6583
6584 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6585
6586 /* if interface is down do nothing */
6587 if (test_bit(__IXGBE_DOWN, &adapter->state))
6588 return;
6589
6590 /* do nothing if we are not using signature filters */
6591 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6592 return;
6593
6594 adapter->fdir_overflow++;
6595
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006596 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6597 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006598 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00006599 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006600 /* re-enable flow director interrupts */
6601 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006602 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006603 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006604 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006605 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006606}
6607
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006608/**
6609 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006610 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006611 *
6612 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006613 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006614 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006615 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006616 */
6617static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6618{
Auke Kok9a799d72007-09-15 14:07:45 -07006619 struct ixgbe_hw *hw = &adapter->hw;
6620 u64 eics = 0;
6621 int i;
6622
Mark Rustad09f40ae2014-01-14 18:53:11 -08006623 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006624 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006625 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006626 test_bit(__IXGBE_RESETTING, &adapter->state))
6627 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006628
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006629 /* Force detection of hung controller */
6630 if (netif_carrier_ok(adapter->netdev)) {
6631 for (i = 0; i < adapter->num_tx_queues; i++)
6632 set_check_for_tx_hang(adapter->tx_ring[i]);
6633 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006634
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006635 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006636 /*
6637 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006638 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006639 * would set *both* EIMS and EICS for any bit in EIAM
6640 */
6641 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6642 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006643 } else {
6644 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006645 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006646 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006647 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07006648 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006649 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006650 }
6651
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006652 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006653 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00006654}
6655
6656/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006657 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006658 * @adapter: pointer to the device adapter structure
6659 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006660 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006661static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006662{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006663 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006664 u32 link_speed = adapter->link_speed;
6665 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006666 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006667
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006668 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6669 return;
6670
6671 if (hw->mac.ops.check_link) {
6672 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006673 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006674 /* always assume link is up, if no check link function */
6675 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6676 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006677 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006678
Don Skidmore4319a792016-04-12 19:25:10 -04006679 /* If Crosstalk fix enabled do the sanity check of making sure
6680 * the SFP+ cage is empty.
6681 */
6682 if (adapter->need_crosstalk_fix) {
6683 u32 sfp_cage_full;
6684
6685 sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) &
6686 IXGBE_ESDP_SDP2;
6687 if (ixgbe_is_sfp(hw) && link_up && !sfp_cage_full)
6688 link_up = false;
6689 }
6690
Alexander Duyck041441d2012-04-19 17:48:48 +00006691 if (adapter->ixgbe_ieee_pfc)
6692 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6693
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006694 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006695 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006696 ixgbe_set_rx_drop_en(adapter);
6697 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006698
6699 if (link_up ||
6700 time_after(jiffies, (adapter->link_check_timeout +
6701 IXGBE_TRY_LINK_TIMEOUT))) {
6702 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6703 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6704 IXGBE_WRITE_FLUSH(hw);
6705 }
6706
6707 adapter->link_up = link_up;
6708 adapter->link_speed = link_speed;
6709}
6710
Alexander Duyck107d3012012-10-02 00:17:03 +00006711static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6712{
6713#ifdef CONFIG_IXGBE_DCB
6714 struct net_device *netdev = adapter->netdev;
6715 struct dcb_app app = {
6716 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6717 .protocol = 0,
6718 };
6719 u8 up = 0;
6720
6721 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6722 up = dcb_ieee_getapp_mask(netdev, &app);
6723
6724 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6725#endif
6726}
6727
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006728/**
6729 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6730 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006731 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006732 **/
6733static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6734{
6735 struct net_device *netdev = adapter->netdev;
6736 struct ixgbe_hw *hw = &adapter->hw;
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006737 struct net_device *upper;
6738 struct list_head *iter;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006739 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07006740 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006741 bool flow_rx, flow_tx;
6742
6743 /* only continue if link was previously down */
6744 if (netif_carrier_ok(netdev))
6745 return;
6746
6747 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6748
6749 switch (hw->mac.type) {
6750 case ixgbe_mac_82598EB: {
6751 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6752 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6753 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6754 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6755 }
6756 break;
6757 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006758 case ixgbe_mac_X550:
6759 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006760 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006761 case ixgbe_mac_82599EB: {
6762 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6763 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6764 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6765 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6766 }
6767 break;
6768 default:
6769 flow_tx = false;
6770 flow_rx = false;
6771 break;
6772 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006773
Jacob Keller6cb562d2012-12-05 07:24:41 +00006774 adapter->last_rx_ptp_check = jiffies;
6775
Jacob Keller8fecf672013-06-21 08:14:32 +00006776 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006777 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006778
Mark Rustad454adb02015-07-10 14:19:22 -07006779 switch (link_speed) {
6780 case IXGBE_LINK_SPEED_10GB_FULL:
6781 speed_str = "10 Gbps";
6782 break;
6783 case IXGBE_LINK_SPEED_2_5GB_FULL:
6784 speed_str = "2.5 Gbps";
6785 break;
6786 case IXGBE_LINK_SPEED_1GB_FULL:
6787 speed_str = "1 Gbps";
6788 break;
6789 case IXGBE_LINK_SPEED_100_FULL:
6790 speed_str = "100 Mbps";
6791 break;
6792 default:
6793 speed_str = "unknown speed";
6794 break;
6795 }
6796 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006797 ((flow_rx && flow_tx) ? "RX/TX" :
6798 (flow_rx ? "RX" :
6799 (flow_tx ? "TX" : "None"))));
6800
6801 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006802 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006803
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006804 /* enable transmits */
6805 netif_tx_wake_all_queues(adapter->netdev);
6806
6807 /* enable any upper devices */
6808 rtnl_lock();
6809 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
6810 if (netif_is_macvlan(upper)) {
6811 struct macvlan_dev *vlan = netdev_priv(upper);
6812
6813 if (vlan->fwd_priv)
6814 netif_tx_wake_all_queues(upper);
6815 }
6816 }
6817 rtnl_unlock();
6818
Alexander Duyck107d3012012-10-02 00:17:03 +00006819 /* update the default user priority for VFs */
6820 ixgbe_update_default_up(adapter);
6821
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006822 /* ping all the active vfs to let them know link has changed */
6823 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006824}
6825
6826/**
6827 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6828 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006829 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006830 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00006831static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006832{
6833 struct net_device *netdev = adapter->netdev;
6834 struct ixgbe_hw *hw = &adapter->hw;
6835
6836 adapter->link_up = false;
6837 adapter->link_speed = 0;
6838
6839 /* only continue if link was up previously */
6840 if (!netif_carrier_ok(netdev))
6841 return;
6842
6843 /* poll for SFP+ cable when link is down */
6844 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6845 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6846
Jacob Keller8fecf672013-06-21 08:14:32 +00006847 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006848 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006849
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006850 e_info(drv, "NIC Link is Down\n");
6851 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006852
6853 /* ping all the active vfs to let them know link has changed */
6854 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006855}
6856
Emil Tantilov07923c12014-08-12 07:12:08 +00006857static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
6858{
6859 int i;
6860
6861 for (i = 0; i < adapter->num_tx_queues; i++) {
6862 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6863
6864 if (tx_ring->next_to_use != tx_ring->next_to_clean)
6865 return true;
6866 }
6867
6868 return false;
6869}
6870
6871static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
6872{
6873 struct ixgbe_hw *hw = &adapter->hw;
6874 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
6875 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
6876
6877 int i, j;
6878
6879 if (!adapter->num_vfs)
6880 return false;
6881
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006882 /* resetting the PF is only needed for MAC before X550 */
6883 if (hw->mac.type >= ixgbe_mac_X550)
6884 return false;
6885
Emil Tantilov07923c12014-08-12 07:12:08 +00006886 for (i = 0; i < adapter->num_vfs; i++) {
6887 for (j = 0; j < q_per_pool; j++) {
6888 u32 h, t;
6889
6890 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
6891 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
6892
6893 if (h != t)
6894 return true;
6895 }
6896 }
6897
6898 return false;
6899}
6900
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006901/**
6902 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006903 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006904 **/
6905static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6906{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006907 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00006908 if (ixgbe_ring_tx_pending(adapter) ||
6909 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006910 /* We've lost link, so the controller stops DMA,
6911 * but we've got queued Tx work that's never going
6912 * to get done, so reset controller to flush Tx.
6913 * (Do the reset outside of interrupt context).
6914 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00006915 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006916 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006917 }
6918 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006919}
6920
Emil Tantilov9079e412014-11-19 03:18:19 +00006921#ifdef CONFIG_PCI_IOV
6922static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
6923 struct pci_dev *vfdev)
6924{
6925 if (!pci_wait_for_pending_transaction(vfdev))
6926 e_dev_warn("Issuing VFLR with pending transactions\n");
6927
6928 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
6929 pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
6930
6931 msleep(100);
6932}
6933
6934static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6935{
6936 struct ixgbe_hw *hw = &adapter->hw;
6937 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07006938 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00006939 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00006940
6941 if (!(netif_carrier_ok(adapter->netdev)))
6942 return;
6943
6944 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6945 if (gpc) /* If incrementing then no need for the check below */
6946 return;
6947 /* Check to see if a bad DMA write target from an errant or
6948 * malicious VF has caused a PCIe error. If so then we can
6949 * issue a VFLR to the offending VF(s) and then resume without
6950 * requesting a full slot reset.
6951 */
6952
6953 if (!pdev)
6954 return;
6955
Emil Tantilov9079e412014-11-19 03:18:19 +00006956 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07006957 for (vf = 0; vf < adapter->num_vfs; ++vf) {
6958 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
6959 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00006960
Mark Rustad988d1302015-10-30 15:29:34 -07006961 if (!vfdev)
6962 continue;
6963 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
6964 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
6965 status_reg & PCI_STATUS_REC_MASTER_ABORT)
6966 ixgbe_issue_vf_flr(adapter, vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00006967 }
6968}
6969
Greg Rosea985b6c32010-11-18 03:02:52 +00006970static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6971{
6972 u32 ssvpc;
6973
Greg Rose0584d992012-08-08 00:00:58 +00006974 /* Do not perform spoof check for 82598 or if not in IOV mode */
6975 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
6976 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00006977 return;
6978
6979 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6980
6981 /*
6982 * ssvpc register is cleared on read, if zero then no
6983 * spoofed packets in the last interval.
6984 */
6985 if (!ssvpc)
6986 return;
6987
Emil Tantilovd6ea0752012-08-08 06:28:37 +00006988 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00006989}
Emil Tantilov9079e412014-11-19 03:18:19 +00006990#else
6991static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
6992{
6993}
6994
6995static void
6996ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
6997{
6998}
6999#endif /* CONFIG_PCI_IOV */
7000
Greg Rosea985b6c32010-11-18 03:02:52 +00007001
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007002/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007003 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007004 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007005 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007006static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007007{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007008 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007009 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007010 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007011 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007012 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007013
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007014 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007015
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007016 if (adapter->link_up)
7017 ixgbe_watchdog_link_is_up(adapter);
7018 else
7019 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007020
Emil Tantilov9079e412014-11-19 03:18:19 +00007021 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007022 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007023 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007024
7025 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007026}
7027
Alexander Duyck70864002011-04-27 09:13:56 +00007028/**
7029 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007030 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007031 **/
7032static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7033{
7034 struct ixgbe_hw *hw = &adapter->hw;
7035 s32 err;
7036
Don Skidmore4319a792016-04-12 19:25:10 -04007037 /* If crosstalk fix enabled verify the SFP+ cage is full */
7038 if (adapter->need_crosstalk_fix) {
7039 u32 sfp_cage_full;
7040
7041 sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) &
7042 IXGBE_ESDP_SDP2;
7043 if (!sfp_cage_full)
7044 return;
7045 }
7046
Alexander Duyck70864002011-04-27 09:13:56 +00007047 /* not searching for SFP so there is nothing to do here */
7048 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7049 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7050 return;
7051
Mark Rustad58e7cd22015-08-08 16:18:48 -07007052 if (adapter->sfp_poll_time &&
7053 time_after(adapter->sfp_poll_time, jiffies))
7054 return; /* If not yet time to poll for SFP */
7055
Alexander Duyck70864002011-04-27 09:13:56 +00007056 /* someone else is in init, wait until next service event */
7057 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7058 return;
7059
Mark Rustad58e7cd22015-08-08 16:18:48 -07007060 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7061
Alexander Duyck70864002011-04-27 09:13:56 +00007062 err = hw->phy.ops.identify_sfp(hw);
7063 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7064 goto sfp_out;
7065
7066 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7067 /* If no cable is present, then we need to reset
7068 * the next time we find a good cable. */
7069 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7070 }
7071
7072 /* exit on error */
7073 if (err)
7074 goto sfp_out;
7075
7076 /* exit if reset not needed */
7077 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7078 goto sfp_out;
7079
7080 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7081
7082 /*
7083 * A module may be identified correctly, but the EEPROM may not have
7084 * support for that module. setup_sfp() will fail in that case, so
7085 * we should not allow that module to load.
7086 */
7087 if (hw->mac.type == ixgbe_mac_82598EB)
7088 err = hw->phy.ops.reset(hw);
7089 else
7090 err = hw->mac.ops.setup_sfp(hw);
7091
7092 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7093 goto sfp_out;
7094
7095 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7096 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7097
7098sfp_out:
7099 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7100
7101 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7102 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7103 e_dev_err("failed to initialize because an unsupported "
7104 "SFP+ module type was detected.\n");
7105 e_dev_err("Reload the driver after installing a "
7106 "supported module.\n");
7107 unregister_netdev(adapter->netdev);
7108 }
7109}
7110
7111/**
7112 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007113 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007114 **/
7115static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7116{
7117 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00007118 u32 speed;
7119 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007120
7121 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7122 return;
7123
7124 /* someone else is in init, wait until next service event */
7125 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7126 return;
7127
7128 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7129
Josh Hay3d292262012-12-15 03:28:19 +00007130 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00007131 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00007132 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007133
7134 /* setup the highest link when no autoneg */
7135 if (!autoneg) {
7136 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
7137 speed = IXGBE_LINK_SPEED_10GB_FULL;
7138 }
7139 }
7140
Alexander Duyck70864002011-04-27 09:13:56 +00007141 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007142 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007143
7144 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7145 adapter->link_check_timeout = jiffies;
7146 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7147}
7148
7149/**
7150 * ixgbe_service_timer - Timer Call-back
7151 * @data: pointer to adapter cast into an unsigned long
7152 **/
7153static void ixgbe_service_timer(unsigned long data)
7154{
7155 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
7156 unsigned long next_event_offset;
7157
7158 /* poll faster when waiting for link */
7159 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7160 next_event_offset = HZ / 10;
7161 else
7162 next_event_offset = HZ * 2;
7163
7164 /* Reset the timer */
7165 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7166
Emil Tantilov9079e412014-11-19 03:18:19 +00007167 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007168}
7169
Don Skidmore597f22d2015-06-09 16:52:02 -07007170static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7171{
7172 struct ixgbe_hw *hw = &adapter->hw;
7173 u32 status;
7174
7175 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7176 return;
7177
7178 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7179
7180 if (!hw->phy.ops.handle_lasi)
7181 return;
7182
7183 status = hw->phy.ops.handle_lasi(&adapter->hw);
7184 if (status != IXGBE_ERR_OVERTEMP)
7185 return;
7186
7187 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7188}
7189
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007190static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7191{
7192 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
7193 return;
7194
7195 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
7196
Mark Rustad09f40ae2014-01-14 18:53:11 -08007197 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007198 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007199 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007200 test_bit(__IXGBE_RESETTING, &adapter->state))
7201 return;
7202
7203 ixgbe_dump(adapter);
7204 netdev_err(adapter->netdev, "Reset adapter\n");
7205 adapter->tx_timeout_count++;
7206
John Fastabend8f4c5c92014-01-16 02:30:05 -08007207 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007208 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007209 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007210}
7211
Alexander Duyck70864002011-04-27 09:13:56 +00007212/**
7213 * ixgbe_service_task - manages and runs subtasks
7214 * @work: pointer to work_struct containing our data
7215 **/
7216static void ixgbe_service_task(struct work_struct *work)
7217{
7218 struct ixgbe_adapter *adapter = container_of(work,
7219 struct ixgbe_adapter,
7220 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007221 if (ixgbe_removed(adapter->hw.hw_addr)) {
7222 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7223 rtnl_lock();
7224 ixgbe_down(adapter);
7225 rtnl_unlock();
7226 }
7227 ixgbe_service_event_complete(adapter);
7228 return;
7229 }
Mark Rustad67359c32015-06-15 11:33:25 -07007230#ifdef CONFIG_IXGBE_VXLAN
Hannes Frederic Sowab1f99a72016-04-18 21:19:45 +02007231 rtnl_lock();
Mark Rustad67359c32015-06-15 11:33:25 -07007232 if (adapter->flags2 & IXGBE_FLAG2_VXLAN_REREG_NEEDED) {
7233 adapter->flags2 &= ~IXGBE_FLAG2_VXLAN_REREG_NEEDED;
7234 vxlan_get_rx_port(adapter->netdev);
7235 }
Hannes Frederic Sowab1f99a72016-04-18 21:19:45 +02007236 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007237#endif /* CONFIG_IXGBE_VXLAN */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007238 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007239 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007240 ixgbe_sfp_detection_subtask(adapter);
7241 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007242 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007243 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007244 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007245 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007246
Jacob Keller8fecf672013-06-21 08:14:32 +00007247 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007248 ixgbe_ptp_overflow_check(adapter);
7249 ixgbe_ptp_rx_hang(adapter);
7250 }
Alexander Duyck70864002011-04-27 09:13:56 +00007251
7252 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007253}
7254
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007255static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7256 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007257 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007258{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007259 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007260 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007261 u32 mss_l4len_idx, l4len;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007262 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007263
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007264 if (skb->ip_summed != CHECKSUM_PARTIAL)
7265 return 0;
7266
Alexander Duyck897ab152011-05-27 05:31:47 +00007267 if (!skb_is_gso(skb))
7268 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007269
Francois Romieu2049e1f2014-03-30 03:14:27 +00007270 err = skb_cow_head(skb, 0);
7271 if (err < 0)
7272 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007273
Alexander Duyck897ab152011-05-27 05:31:47 +00007274 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7275 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7276
Joe Perchesa1108ff2014-03-13 05:19:25 +00007277 if (first->protocol == htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007278 struct iphdr *iph = ip_hdr(skb);
7279 iph->tot_len = 0;
7280 iph->check = 0;
7281 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
7282 iph->daddr, 0,
7283 IPPROTO_TCP,
7284 0);
7285 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007286 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7287 IXGBE_TX_FLAGS_CSUM |
7288 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00007289 } else if (skb_is_gso_v6(skb)) {
7290 ipv6_hdr(skb)->payload_len = 0;
7291 tcp_hdr(skb)->check =
7292 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
7293 &ipv6_hdr(skb)->daddr,
7294 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00007295 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7296 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007297 }
7298
Alexander Duyck091a6242012-02-08 07:51:01 +00007299 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00007300 l4len = tcp_hdrlen(skb);
7301 *hdr_len = skb_transport_offset(skb) + l4len;
7302
Alexander Duyck091a6242012-02-08 07:51:01 +00007303 /* update gso size and bytecount with header size */
7304 first->gso_segs = skb_shinfo(skb)->gso_segs;
7305 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7306
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007307 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00007308 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
7309 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007310
7311 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
7312 vlan_macip_lens = skb_network_header_len(skb);
7313 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007314 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007315
7316 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007317 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007318
7319 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007320}
7321
Alexander Duyck49763de2016-01-13 07:31:11 -08007322static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7323{
7324 unsigned int offset = 0;
7325
7326 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7327
7328 return offset == skb_checksum_start_offset(skb);
7329}
7330
Alexander Duyck244e27a2012-02-08 07:51:11 +00007331static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7332 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007333{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007334 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007335 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007336 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007337
Alexander Duyck897ab152011-05-27 05:31:47 +00007338 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007339csum_failed:
7340 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7341 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007342 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007343 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007344 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007345
Alexander Duyck49763de2016-01-13 07:31:11 -08007346 switch (skb->csum_offset) {
7347 case offsetof(struct tcphdr, check):
7348 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7349 /* fall through */
7350 case offsetof(struct udphdr, check):
7351 break;
7352 case offsetof(struct sctphdr, checksum):
7353 /* validate that this is actually an SCTP request */
7354 if (((first->protocol == htons(ETH_P_IP)) &&
7355 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7356 ((first->protocol == htons(ETH_P_IPV6)) &&
7357 ixgbe_ipv6_csum_is_sctp(skb))) {
7358 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7359 break;
7360 }
7361 /* fall through */
7362 default:
7363 skb_checksum_help(skb);
7364 goto csum_failed;
7365 }
7366
7367 /* update TX checksum flag */
7368 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7369 vlan_macip_lens = skb_checksum_start_offset(skb) -
7370 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007371no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007372 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007373 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007374 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007375
Alexander Duyck49763de2016-01-13 07:31:11 -08007376 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007377}
7378
Alexander Duyck472148c2012-11-07 02:34:28 +00007379#define IXGBE_SET_FLAG(_input, _flag, _result) \
7380 ((_flag <= _result) ? \
7381 ((u32)(_input & _flag) * (_result / _flag)) : \
7382 ((u32)(_input & _flag) / (_flag / _result)))
7383
7384static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007385{
7386 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007387 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7388 IXGBE_ADVTXD_DCMD_DEXT |
7389 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007390
7391 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007392 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7393 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007394
Alexander Duyckd3d00232011-07-15 02:31:25 +00007395 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007396 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7397 IXGBE_ADVTXD_DCMD_TSE);
7398
7399 /* set timestamp bit if present */
7400 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7401 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007402
Alexander Duyck62748b72012-07-20 08:09:01 +00007403 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007404 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007405
Alexander Duyckd3d00232011-07-15 02:31:25 +00007406 return cmd_type;
7407}
7408
Alexander Duyck729739b2012-02-08 07:51:06 +00007409static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7410 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007411{
Alexander Duyck472148c2012-11-07 02:34:28 +00007412 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007413
7414 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007415 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7416 IXGBE_TX_FLAGS_CSUM,
7417 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007418
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007419 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007420 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7421 IXGBE_TX_FLAGS_IPV4,
7422 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007423
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007424 /*
7425 * Check Context must be set if Tx switch is enabled, which it
7426 * always is for case where virtual functions are running
7427 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007428 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7429 IXGBE_TX_FLAGS_CC,
7430 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007431
Alexander Duyck472148c2012-11-07 02:34:28 +00007432 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007433}
7434
Daniel Borkmann2367a172014-08-26 19:34:18 +02007435static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7436{
7437 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7438
7439 /* Herbert's original patch had:
7440 * smp_mb__after_netif_stop_queue();
7441 * but since that doesn't exist yet, just open code it.
7442 */
7443 smp_mb();
7444
7445 /* We need to check again in a case another CPU has just
7446 * made room available.
7447 */
7448 if (likely(ixgbe_desc_unused(tx_ring) < size))
7449 return -EBUSY;
7450
7451 /* A reprieve! - use start_queue because it doesn't call schedule */
7452 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7453 ++tx_ring->tx_stats.restart_queue;
7454 return 0;
7455}
7456
7457static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7458{
7459 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7460 return 0;
7461
7462 return __ixgbe_maybe_stop_tx(tx_ring, size);
7463}
7464
Alexander Duyckd3d00232011-07-15 02:31:25 +00007465#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7466 IXGBE_TXD_CMD_RS)
7467
7468static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007469 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007470 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007471{
Alexander Duyck729739b2012-02-08 07:51:06 +00007472 struct sk_buff *skb = first->skb;
7473 struct ixgbe_tx_buffer *tx_buffer;
7474 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007475 struct skb_frag_struct *frag;
7476 dma_addr_t dma;
7477 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007478 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007479 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007480 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007481
Alexander Duyck729739b2012-02-08 07:51:06 +00007482 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7483
Alexander Duyckec718252012-10-30 06:01:55 +00007484 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7485
7486 size = skb_headlen(skb);
7487 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007488
Alexander Duyckd3d00232011-07-15 02:31:25 +00007489#ifdef IXGBE_FCOE
7490 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007491 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007492 size -= sizeof(struct fcoe_crc_eof) - data_len;
7493 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007494 } else {
7495 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007496 }
Auke Kok9a799d72007-09-15 14:07:45 -07007497 }
7498
Alexander Duyckd3d00232011-07-15 02:31:25 +00007499#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007500 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007501
Alexander Duyckec718252012-10-30 06:01:55 +00007502 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007503
Alexander Duyckec718252012-10-30 06:01:55 +00007504 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7505 if (dma_mapping_error(tx_ring->dev, dma))
7506 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007507
Alexander Duyckec718252012-10-30 06:01:55 +00007508 /* record length, and DMA address */
7509 dma_unmap_len_set(tx_buffer, len, size);
7510 dma_unmap_addr_set(tx_buffer, dma, dma);
7511
7512 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7513
Alexander Duyck729739b2012-02-08 07:51:06 +00007514 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007515 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007516 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007517
Alexander Duyckd3d00232011-07-15 02:31:25 +00007518 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007519 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007520 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007521 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007522 i = 0;
7523 }
Alexander Duyckec718252012-10-30 06:01:55 +00007524 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007525
7526 dma += IXGBE_MAX_DATA_PER_TXD;
7527 size -= IXGBE_MAX_DATA_PER_TXD;
7528
7529 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007530 }
7531
Alexander Duyck729739b2012-02-08 07:51:06 +00007532 if (likely(!data_len))
7533 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007534
Alexander Duyck472148c2012-11-07 02:34:28 +00007535 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007536
Alexander Duyck729739b2012-02-08 07:51:06 +00007537 i++;
7538 tx_desc++;
7539 if (i == tx_ring->count) {
7540 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7541 i = 0;
7542 }
Alexander Duyckec718252012-10-30 06:01:55 +00007543 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007544
Alexander Duyckd3d00232011-07-15 02:31:25 +00007545#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007546 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007547#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007548 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007549#endif
7550 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007551
Alexander Duyck729739b2012-02-08 07:51:06 +00007552 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7553 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007554
Alexander Duyck729739b2012-02-08 07:51:06 +00007555 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007556 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007557
Alexander Duyck729739b2012-02-08 07:51:06 +00007558 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007559 cmd_type |= size | IXGBE_TXD_CMD;
7560 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007561
Alexander Duyck091a6242012-02-08 07:51:01 +00007562 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007563
Alexander Duyckd3d00232011-07-15 02:31:25 +00007564 /* set the timestamp */
7565 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007566
7567 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007568 * Force memory writes to complete before letting h/w know there
7569 * are new descriptors to fetch. (Only applicable for weak-ordered
7570 * memory model archs, such as IA-64).
7571 *
7572 * We also need this memory barrier to make certain all of the
7573 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007574 */
7575 wmb();
7576
Alexander Duyckd3d00232011-07-15 02:31:25 +00007577 /* set next_to_watch value indicating a packet is present */
7578 first->next_to_watch = tx_desc;
7579
Alexander Duyck729739b2012-02-08 07:51:06 +00007580 i++;
7581 if (i == tx_ring->count)
7582 i = 0;
7583
7584 tx_ring->next_to_use = i;
7585
Daniel Borkmann2367a172014-08-26 19:34:18 +02007586 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7587
7588 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00007589 writel(i, tx_ring->tail);
7590
7591 /* we need this if more than one processor can write to our tail
7592 * at a time, it synchronizes IO on IA64/Altix systems
7593 */
7594 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02007595 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02007596
Alexander Duyckd3d00232011-07-15 02:31:25 +00007597 return;
7598dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00007599 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00007600
7601 /* clear dma mappings for failed tx_buffer_info map */
7602 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007603 tx_buffer = &tx_ring->tx_buffer_info[i];
7604 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
7605 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007606 break;
7607 if (i == 0)
7608 i = tx_ring->count;
7609 i--;
7610 }
7611
Alexander Duyckd3d00232011-07-15 02:31:25 +00007612 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07007613}
7614
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007615static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007616 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007617{
Alexander Duyck69830522011-01-06 14:29:58 +00007618 struct ixgbe_q_vector *q_vector = ring->q_vector;
7619 union ixgbe_atr_hash_dword input = { .dword = 0 };
7620 union ixgbe_atr_hash_dword common = { .dword = 0 };
7621 union {
7622 unsigned char *network;
7623 struct iphdr *ipv4;
7624 struct ipv6hdr *ipv6;
7625 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007626 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08007627 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07007628 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00007629 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08007630 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007631
Alexander Duyck69830522011-01-06 14:29:58 +00007632 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7633 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00007634 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007635
Alexander Duyck69830522011-01-06 14:29:58 +00007636 /* do nothing if sampling is disabled */
7637 if (!ring->atr_sample_rate)
7638 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007639
Alexander Duyck69830522011-01-06 14:29:58 +00007640 ring->atr_count++;
7641
Alexander Duycke2873d42016-01-25 19:39:40 -08007642 /* currently only IPv4/IPv6 with TCP is supported */
7643 if ((first->protocol != htons(ETH_P_IP)) &&
7644 (first->protocol != htons(ETH_P_IPV6)))
7645 return;
7646
Alexander Duyck69830522011-01-06 14:29:58 +00007647 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07007648 skb = first->skb;
7649 hdr.network = skb_network_header(skb);
Mark Rustad67359c32015-06-15 11:33:25 -07007650#ifdef CONFIG_IXGBE_VXLAN
Alexander Duyck9f12df92016-01-25 19:36:29 -08007651 if (skb->encapsulation &&
7652 first->protocol == htons(ETH_P_IP) &&
7653 hdr.ipv4->protocol != IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07007654 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00007655
Alexander Duyck9f12df92016-01-25 19:36:29 -08007656 /* verify the port is recognized as VXLAN */
7657 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08007658 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08007659 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08007660 }
Alexander Duyck9f12df92016-01-25 19:36:29 -08007661#endif /* CONFIG_IXGBE_VXLAN */
Mark Rustade19dcde2015-12-09 14:55:37 -08007662
7663 /* Currently only IPv4/IPv6 with TCP is supported */
7664 switch (hdr.ipv4->version) {
7665 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08007666 /* access ihl as u8 to avoid unaligned access on ia64 */
7667 hlen = (hdr.network[0] & 0x0F) << 2;
7668 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08007669 break;
7670 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08007671 hlen = hdr.network - skb->data;
7672 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
7673 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08007674 break;
7675 default:
7676 return;
Mark Rustad67359c32015-06-15 11:33:25 -07007677 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007678
Alexander Duycke2873d42016-01-25 19:39:40 -08007679 if (l4_proto != IPPROTO_TCP)
7680 return;
7681
7682 th = (struct tcphdr *)(hdr.network + hlen);
7683
7684 /* skip this packet since the socket is closing */
7685 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00007686 return;
7687
7688 /* sample on all syn packets or once every atr sample count */
7689 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
7690 return;
7691
7692 /* reset sample count */
7693 ring->atr_count = 0;
7694
Alexander Duyck244e27a2012-02-08 07:51:11 +00007695 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00007696
7697 /*
7698 * src and dst are inverted, think how the receiver sees them
7699 *
7700 * The input is broken into two sections, a non-compressed section
7701 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7702 * is XORed together and stored in the compressed dword.
7703 */
7704 input.formatted.vlan_id = vlan_id;
7705
7706 /*
7707 * since src port and flex bytes occupy the same word XOR them together
7708 * and write the value to source port portion of compressed dword
7709 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007710 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00007711 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00007712 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00007713 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00007714 common.port.dst ^= th->source;
7715
Mark Rustade19dcde2015-12-09 14:55:37 -08007716 switch (hdr.ipv4->version) {
7717 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00007718 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7719 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08007720 break;
7721 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00007722 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7723 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7724 hdr.ipv6->saddr.s6_addr32[1] ^
7725 hdr.ipv6->saddr.s6_addr32[2] ^
7726 hdr.ipv6->saddr.s6_addr32[3] ^
7727 hdr.ipv6->daddr.s6_addr32[0] ^
7728 hdr.ipv6->daddr.s6_addr32[1] ^
7729 hdr.ipv6->daddr.s6_addr32[2] ^
7730 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08007731 break;
7732 default:
7733 break;
Alexander Duyck69830522011-01-06 14:29:58 +00007734 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007735
Alexander Duyck9f12df92016-01-25 19:36:29 -08007736 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07007737 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07007738
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007739 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007740 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7741 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007742}
7743
Jason Wangf663dd92014-01-10 16:18:26 +08007744static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01007745 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007746{
Jason Wangf663dd92014-01-10 16:18:26 +08007747 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7748#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00007749 struct ixgbe_adapter *adapter;
7750 struct ixgbe_ring_feature *f;
7751 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08007752#endif
7753
7754 if (fwd_adapter)
7755 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7756
7757#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00007758
Alexander Duyck97488bd2013-01-12 06:33:37 +00007759 /*
7760 * only execute the code below if protocol is FCoE
7761 * or FIP and we have FCoE enabled on the adapter
7762 */
7763 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00007764 case htons(ETH_P_FCOE):
7765 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00007766 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00007767
Alexander Duyck97488bd2013-01-12 06:33:37 +00007768 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7769 break;
7770 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01007771 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007772 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007773
Alexander Duyck97488bd2013-01-12 06:33:37 +00007774 f = &adapter->ring_feature[RING_F_FCOE];
7775
7776 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7777 smp_processor_id();
7778
7779 while (txq >= f->indices)
7780 txq -= f->indices;
7781
7782 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08007783#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01007784 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08007785#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007786}
7787
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007788netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007789 struct ixgbe_adapter *adapter,
7790 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007791{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007792 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007793 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007794 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007795 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00007796 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007797 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007798 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007799
Alexander Duycka535c302011-05-27 05:31:52 +00007800 /*
7801 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007802 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007803 * + 2 desc gap to keep tail from touching head,
7804 * + 1 desc for context descriptor,
7805 * otherwise try next time
7806 */
Alexander Duycka535c302011-05-27 05:31:52 +00007807 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7808 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00007809
Alexander Duycka535c302011-05-27 05:31:52 +00007810 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7811 tx_ring->tx_stats.tx_busy++;
7812 return NETDEV_TX_BUSY;
7813 }
7814
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007815 /* record the location of the first descriptor for this packet */
7816 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7817 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00007818 first->bytecount = skb->len;
7819 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007820
Alexander Duyck66f32a82011-06-29 05:43:22 +00007821 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01007822 if (skb_vlan_tag_present(skb)) {
7823 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007824 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7825 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007826 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007827 struct vlan_hdr *vhdr, _vhdr;
7828 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7829 if (!vhdr)
7830 goto out_drop;
7831
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007832 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7833 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007834 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007835 }
Toshiaki Makita02136682015-01-29 20:37:09 +09007836 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00007837
Mark Rustadd5234932014-08-09 07:02:09 +00007838 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
7839 adapter->ptp_clock &&
7840 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
7841 &adapter->state)) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007842 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
7843 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00007844
7845 /* schedule check for Tx timestamp */
7846 adapter->ptp_tx_skb = skb_get(skb);
7847 adapter->ptp_tx_start = jiffies;
7848 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007849 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007850
Jakub Kicinskiff29a862014-03-15 14:55:16 +00007851 skb_tx_timestamp(skb);
7852
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007853#ifdef CONFIG_PCI_IOV
7854 /*
7855 * Use the l2switch_enable flag - would be false if the DMA
7856 * Tx switch had been disabled.
7857 */
7858 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00007859 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007860
7861#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007862 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007863 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007864 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7865 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007866 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007867 tx_flags |= (skb->priority & 0x7) <<
7868 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007869 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7870 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007871
7872 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00007873 goto out_drop;
7874 vhdr = (struct vlan_ethhdr *)skb->data;
7875 vhdr->h_vlan_TCI = htons(tx_flags >>
7876 IXGBE_TX_FLAGS_VLAN_SHIFT);
7877 } else {
7878 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7879 }
7880 }
Alexander Duycka535c302011-05-27 05:31:52 +00007881
Alexander Duyck244e27a2012-02-08 07:51:11 +00007882 /* record initial flags and protocol */
7883 first->tx_flags = tx_flags;
7884 first->protocol = protocol;
7885
Yi Zoueacd73f2009-05-13 13:11:06 +00007886#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007887 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007888 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00007889 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00007890 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00007891 if (tso < 0)
7892 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07007893
Alexander Duyck66f32a82011-06-29 05:43:22 +00007894 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007895 }
Auke Kok9a799d72007-09-15 14:07:45 -07007896
Auke Kok9a799d72007-09-15 14:07:45 -07007897#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007898 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007899 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007900 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007901 else if (!tso)
7902 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007903
7904 /* add the ATR filter if ATR is on */
7905 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00007906 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007907
7908#ifdef IXGBE_FCOE
7909xmit_fcoe:
7910#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007911 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007912
Auke Kok9a799d72007-09-15 14:07:45 -07007913 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007914
7915out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007916 dev_kfree_skb_any(first->skb);
7917 first->skb = NULL;
7918
Alexander Duyck897ab152011-05-27 05:31:47 +00007919 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007920}
7921
John Fastabend2a47fa42013-11-06 09:54:52 -08007922static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
7923 struct net_device *netdev,
7924 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007925{
7926 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007927 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07007928
Alexander Duycka50c29d2012-02-08 07:50:40 +00007929 /*
7930 * The minimum packet size for olinfo paylen is 17 so pad the skb
7931 * in order to meet this minimum size requirement.
7932 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08007933 if (skb_put_padto(skb, 17))
7934 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00007935
John Fastabend2a47fa42013-11-06 09:54:52 -08007936 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
7937
Auke Kok9a799d72007-09-15 14:07:45 -07007938 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7939}
7940
John Fastabend2a47fa42013-11-06 09:54:52 -08007941static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7942 struct net_device *netdev)
7943{
7944 return __ixgbe_xmit_frame(skb, netdev, NULL);
7945}
7946
Auke Kok9a799d72007-09-15 14:07:45 -07007947/**
7948 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7949 * @netdev: network interface device structure
7950 * @p: pointer to an address structure
7951 *
7952 * Returns 0 on success, negative on failure
7953 **/
7954static int ixgbe_set_mac(struct net_device *netdev, void *p)
7955{
7956 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7957 struct ixgbe_hw *hw = &adapter->hw;
7958 struct sockaddr *addr = p;
7959
7960 if (!is_valid_ether_addr(addr->sa_data))
7961 return -EADDRNOTAVAIL;
7962
7963 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007964 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007965
Alexander Duyckc9f53e62015-10-22 16:26:30 -07007966 ixgbe_mac_set_default_filter(adapter);
7967
7968 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007969}
7970
Ben Hutchings6b73e102009-04-29 08:08:58 +00007971static int
7972ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7973{
7974 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7975 struct ixgbe_hw *hw = &adapter->hw;
7976 u16 value;
7977 int rc;
7978
7979 if (prtad != hw->phy.mdio.prtad)
7980 return -EINVAL;
7981 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7982 if (!rc)
7983 rc = value;
7984 return rc;
7985}
7986
7987static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7988 u16 addr, u16 value)
7989{
7990 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7991 struct ixgbe_hw *hw = &adapter->hw;
7992
7993 if (prtad != hw->phy.mdio.prtad)
7994 return -EINVAL;
7995 return hw->phy.ops.write_reg(hw, addr, devad, value);
7996}
7997
7998static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7999{
8000 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8001
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008002 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008003 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008004 return ixgbe_ptp_set_ts_config(adapter, req);
8005 case SIOCGHWTSTAMP:
8006 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008007 default:
8008 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8009 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008010}
8011
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008012/**
8013 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008014 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008015 * @netdev: network interface device structure
8016 *
8017 * Returns non-zero on failure
8018 **/
8019static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8020{
8021 int err = 0;
8022 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008023 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008024
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008025 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008026 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008027 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008028 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008029
8030 /* update SAN MAC vmdq pool selection */
8031 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008032 }
8033 return err;
8034}
8035
8036/**
8037 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008038 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008039 * @netdev: network interface device structure
8040 *
8041 * Returns non-zero on failure
8042 **/
8043static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8044{
8045 int err = 0;
8046 struct ixgbe_adapter *adapter = netdev_priv(dev);
8047 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8048
8049 if (is_valid_ether_addr(mac->san_addr)) {
8050 rtnl_lock();
8051 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8052 rtnl_unlock();
8053 }
8054 return err;
8055}
8056
Auke Kok9a799d72007-09-15 14:07:45 -07008057#ifdef CONFIG_NET_POLL_CONTROLLER
8058/*
8059 * Polling 'interrupt' - used by things like netconsole to send skbs
8060 * without having to re-enable interrupts. It's not called while
8061 * the interrupt routine is executing.
8062 */
8063static void ixgbe_netpoll(struct net_device *netdev)
8064{
8065 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008066 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008067
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008068 /* if interface is down do nothing */
8069 if (test_bit(__IXGBE_DOWN, &adapter->state))
8070 return;
8071
Alexander Duyck856f6062015-02-25 17:45:54 +00008072 /* loop through and schedule all active queues */
8073 for (i = 0; i < adapter->num_q_vectors; i++)
8074 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008075}
Auke Kok9a799d72007-09-15 14:07:45 -07008076
Alexander Duyck581330b2012-02-08 07:51:47 +00008077#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00008078static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
8079 struct rtnl_link_stats64 *stats)
8080{
8081 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8082 int i;
8083
Eric Dumazet1a515022010-11-16 19:26:42 -08008084 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008085 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08008086 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008087 u64 bytes, packets;
8088 unsigned int start;
8089
Eric Dumazet1a515022010-11-16 19:26:42 -08008090 if (ring) {
8091 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008092 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008093 packets = ring->stats.packets;
8094 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008095 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008096 stats->rx_packets += packets;
8097 stats->rx_bytes += bytes;
8098 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008099 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008100
8101 for (i = 0; i < adapter->num_tx_queues; i++) {
8102 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
8103 u64 bytes, packets;
8104 unsigned int start;
8105
8106 if (ring) {
8107 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008108 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008109 packets = ring->stats.packets;
8110 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008111 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008112 stats->tx_packets += packets;
8113 stats->tx_bytes += bytes;
8114 }
8115 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008116 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008117 /* following stats updated by ixgbe_watchdog_task() */
8118 stats->multicast = netdev->stats.multicast;
8119 stats->rx_errors = netdev->stats.rx_errors;
8120 stats->rx_length_errors = netdev->stats.rx_length_errors;
8121 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8122 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
8123 return stats;
8124}
8125
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008126#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008127/**
8128 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8129 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008130 * @tc: number of traffic classes currently enabled
8131 *
8132 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8133 * 802.1Q priority maps to a packet buffer that exists.
8134 */
8135static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8136{
8137 struct ixgbe_hw *hw = &adapter->hw;
8138 u32 reg, rsave;
8139 int i;
8140
8141 /* 82598 have a static priority to TC mapping that can not
8142 * be changed so no validation is needed.
8143 */
8144 if (hw->mac.type == ixgbe_mac_82598EB)
8145 return;
8146
8147 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8148 rsave = reg;
8149
8150 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8151 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8152
8153 /* If up2tc is out of bounds default to zero */
8154 if (up2tc > tc)
8155 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8156 }
8157
8158 if (reg != rsave)
8159 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8160
8161 return;
8162}
8163
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008164/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008165 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8166 * @adapter: Pointer to adapter struct
8167 *
8168 * Populate the netdev user priority to tc map
8169 */
8170static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8171{
8172 struct net_device *dev = adapter->netdev;
8173 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8174 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8175 u8 prio;
8176
8177 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8178 u8 tc = 0;
8179
8180 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8181 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8182 else if (ets)
8183 tc = ets->prio_tc[prio];
8184
8185 netdev_set_prio_tc_map(dev, prio, tc);
8186 }
8187}
8188
Alexander Duyckcca73c52013-01-12 06:33:44 +00008189#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008190/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008191 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008192 *
8193 * @netdev: net device to configure
8194 * @tc: number of traffic classes to enable
8195 */
8196int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8197{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008198 struct ixgbe_adapter *adapter = netdev_priv(dev);
8199 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08008200 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008201
John Fastabend8b1c0b22011-05-03 02:26:48 +00008202 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008203 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8204 return -EINVAL;
8205
8206 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008207 return -EINVAL;
8208
John Fastabend2a47fa42013-11-06 09:54:52 -08008209 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
8210 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
8211 return -EBUSY;
8212
John Fastabend8b1c0b22011-05-03 02:26:48 +00008213 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008214 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008215 * hardware is not flexible enough to do this dynamically.
8216 */
8217 if (netif_running(dev))
8218 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008219 else
8220 ixgbe_reset(adapter);
8221
John Fastabend8b1c0b22011-05-03 02:26:48 +00008222 ixgbe_clear_interrupt_scheme(adapter);
8223
Alexander Duyckcca73c52013-01-12 06:33:44 +00008224#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008225 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008226 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008227 ixgbe_set_prio_tc_map(adapter);
8228
John Fastabende7589ea2011-07-18 22:38:36 +00008229 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008230
Alexander Duyck943561d2012-05-09 22:14:44 -07008231 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8232 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008233 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008234 }
John Fastabende7589ea2011-07-18 22:38:36 +00008235 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008236 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008237
Alexander Duyck943561d2012-05-09 22:14:44 -07008238 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8239 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008240
8241 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008242
8243 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8244 adapter->dcb_cfg.pfc_mode_enable = false;
8245 }
8246
John Fastabend8b1c0b22011-05-03 02:26:48 +00008247 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008248
8249#endif /* CONFIG_IXGBE_DCB */
8250 ixgbe_init_interrupt_scheme(adapter);
8251
John Fastabend8b1c0b22011-05-03 02:26:48 +00008252 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008253 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008254
8255 return 0;
8256}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008257
John Fastabendb82b17d2016-02-16 21:18:53 -08008258static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8259 struct tc_cls_u32_offload *cls)
8260{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008261 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
8262 u32 loc;
John Fastabendb82b17d2016-02-16 21:18:53 -08008263 int err;
8264
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008265 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8266 return -EINVAL;
8267
8268 loc = cls->knode.handle & 0xfffff;
8269
John Fastabendb82b17d2016-02-16 21:18:53 -08008270 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008271 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008272 spin_unlock(&adapter->fdir_perfect_lock);
8273 return err;
8274}
8275
John Fastabenddb956ae2016-02-16 21:19:19 -08008276static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
8277 __be16 protocol,
8278 struct tc_cls_u32_offload *cls)
8279{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008280 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8281
8282 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8283 return -EINVAL;
8284
John Fastabenddb956ae2016-02-16 21:19:19 -08008285 /* This ixgbe devices do not support hash tables at the moment
8286 * so abort when given hash tables.
8287 */
8288 if (cls->hnode.divisor > 0)
8289 return -EINVAL;
8290
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008291 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008292 return 0;
8293}
8294
8295static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8296 struct tc_cls_u32_offload *cls)
8297{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008298 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8299
8300 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8301 return -EINVAL;
8302
8303 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008304 return 0;
8305}
8306
John Fastabendb82b17d2016-02-16 21:18:53 -08008307static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
8308 __be16 protocol,
8309 struct tc_cls_u32_offload *cls)
8310{
8311 u32 loc = cls->knode.handle & 0xfffff;
8312 struct ixgbe_hw *hw = &adapter->hw;
8313 struct ixgbe_mat_field *field_ptr;
8314 struct ixgbe_fdir_filter *input;
8315 union ixgbe_atr_input mask;
8316#ifdef CONFIG_NET_CLS_ACT
8317 const struct tc_action *a;
8318#endif
8319 int i, err = 0;
8320 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008321 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08008322
8323 memset(&mask, 0, sizeof(union ixgbe_atr_input));
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008324 uhtid = TC_U32_USERHTID(cls->knode.handle);
8325 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08008326
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008327 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08008328 * L2 headers. The canonical method to match L2 frames is to use
8329 * negative values. However this is error prone at best but really
8330 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008331 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08008332 * headers when needed.
8333 */
8334 if (protocol != htons(ETH_P_IP))
8335 return -EINVAL;
8336
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008337 if (link_uhtid) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008338 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
John Fastabendb82b17d2016-02-16 21:18:53 -08008339
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008340 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
8341 return -EINVAL;
8342
8343 if (!test_bit(link_uhtid - 1, &adapter->tables))
John Fastabenddb956ae2016-02-16 21:19:19 -08008344 return -EINVAL;
8345
John Fastabendb82b17d2016-02-16 21:18:53 -08008346 for (i = 0; nexthdr[i].jump; i++) {
Amritha Nambiar4ae78342016-03-09 18:32:16 -05008347 if (nexthdr[i].o != cls->knode.sel->offoff ||
8348 nexthdr[i].s != cls->knode.sel->offshift ||
8349 nexthdr[i].m != cls->knode.sel->offmask ||
John Fastabendb82b17d2016-02-16 21:18:53 -08008350 /* do not support multiple key jumps its just mad */
8351 cls->knode.sel->nkeys > 1)
8352 return -EINVAL;
8353
Amritha Nambiar4ae78342016-03-09 18:32:16 -05008354 if (nexthdr[i].off == cls->knode.sel->keys[0].off &&
8355 nexthdr[i].val == cls->knode.sel->keys[0].val &&
8356 nexthdr[i].mask == cls->knode.sel->keys[0].mask) {
8357 adapter->jump_tables[link_uhtid] =
8358 nexthdr[i].jump;
8359 break;
8360 }
John Fastabendb82b17d2016-02-16 21:18:53 -08008361 }
8362 return 0;
8363 }
8364
8365 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
8366 e_err(drv, "Location out of range\n");
8367 return -EINVAL;
8368 }
8369
8370 /* cls u32 is a graph starting at root node 0x800. The driver tracks
8371 * links and also the fields used to advance the parser across each
8372 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
8373 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
8374 * To add support for new nodes update ixgbe_model.h parse structures
8375 * this function _should_ be generic try not to hardcode values here.
8376 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008377 if (uhtid == 0x800) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008378 field_ptr = adapter->jump_tables[0];
8379 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008380 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
John Fastabendb82b17d2016-02-16 21:18:53 -08008381 return -EINVAL;
8382
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008383 field_ptr = adapter->jump_tables[uhtid];
John Fastabendb82b17d2016-02-16 21:18:53 -08008384 }
8385
8386 if (!field_ptr)
8387 return -EINVAL;
8388
8389 input = kzalloc(sizeof(*input), GFP_KERNEL);
8390 if (!input)
8391 return -ENOMEM;
8392
8393 for (i = 0; i < cls->knode.sel->nkeys; i++) {
8394 int off = cls->knode.sel->keys[i].off;
8395 __be32 val = cls->knode.sel->keys[i].val;
8396 __be32 m = cls->knode.sel->keys[i].mask;
8397 bool found_entry = false;
8398 int j;
8399
8400 for (j = 0; field_ptr[j].val; j++) {
Sridhar Samudralaebd83ad2016-03-07 09:41:48 -08008401 if (field_ptr[j].off == off) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008402 field_ptr[j].val(input, &mask, val, m);
8403 input->filter.formatted.flow_type |=
8404 field_ptr[j].type;
8405 found_entry = true;
8406 break;
8407 }
8408 }
8409
8410 if (!found_entry)
8411 goto err_out;
8412 }
8413
8414 mask.formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
8415 IXGBE_ATR_L4TYPE_MASK;
8416
8417 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
8418 mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
8419
8420#ifdef CONFIG_NET_CLS_ACT
8421 if (list_empty(&cls->knode.exts->actions))
8422 goto err_out;
8423
8424 list_for_each_entry(a, &cls->knode.exts->actions, list) {
8425 if (!is_tcf_gact_shot(a))
8426 goto err_out;
8427 }
8428#endif
8429
8430 input->action = IXGBE_FDIR_DROP_QUEUE;
8431 queue = IXGBE_FDIR_DROP_QUEUE;
8432 input->sw_idx = loc;
8433
8434 spin_lock(&adapter->fdir_perfect_lock);
8435
8436 if (hlist_empty(&adapter->fdir_filter_list)) {
8437 memcpy(&adapter->fdir_mask, &mask, sizeof(mask));
8438 err = ixgbe_fdir_set_input_mask_82599(hw, &mask);
8439 if (err)
8440 goto err_out_w_lock;
8441 } else if (memcmp(&adapter->fdir_mask, &mask, sizeof(mask))) {
8442 err = -EINVAL;
8443 goto err_out_w_lock;
8444 }
8445
8446 ixgbe_atr_compute_perfect_hash_82599(&input->filter, &mask);
8447 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
8448 input->sw_idx, queue);
8449 if (!err)
8450 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
8451 spin_unlock(&adapter->fdir_perfect_lock);
8452
8453 return err;
8454err_out_w_lock:
8455 spin_unlock(&adapter->fdir_perfect_lock);
8456err_out:
8457 kfree(input);
8458 return -EINVAL;
8459}
8460
Emil Tantilov6e2a60b2016-02-17 15:55:06 -08008461static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
8462 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08008463{
John Fastabendb82b17d2016-02-16 21:18:53 -08008464 struct ixgbe_adapter *adapter = netdev_priv(dev);
8465
8466 if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
8467 tc->type == TC_SETUP_CLSU32) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008468 switch (tc->cls_u32->command) {
8469 case TC_CLSU32_NEW_KNODE:
8470 case TC_CLSU32_REPLACE_KNODE:
8471 return ixgbe_configure_clsu32(adapter,
8472 proto, tc->cls_u32);
8473 case TC_CLSU32_DELETE_KNODE:
8474 return ixgbe_delete_clsu32(adapter, tc->cls_u32);
John Fastabenddb956ae2016-02-16 21:19:19 -08008475 case TC_CLSU32_NEW_HNODE:
8476 case TC_CLSU32_REPLACE_HNODE:
8477 return ixgbe_configure_clsu32_add_hnode(adapter, proto,
8478 tc->cls_u32);
8479 case TC_CLSU32_DELETE_HNODE:
8480 return ixgbe_configure_clsu32_del_hnode(adapter,
8481 tc->cls_u32);
John Fastabendb82b17d2016-02-16 21:18:53 -08008482 default:
8483 return -EINVAL;
8484 }
8485 }
8486
John Fastabend5eb4dce2016-02-29 11:26:13 -08008487 if (tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08008488 return -EINVAL;
8489
John Fastabend16e5cc62016-02-16 21:16:43 -08008490 return ixgbe_setup_tc(dev, tc->tc);
John Fastabende4c67342016-02-16 21:16:15 -08008491}
8492
Greg Roseda36b642012-12-11 08:26:43 +00008493#ifdef CONFIG_PCI_IOV
8494void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
8495{
8496 struct net_device *netdev = adapter->netdev;
8497
8498 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00008499 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00008500 rtnl_unlock();
8501}
8502
8503#endif
Don Skidmore082757a2011-07-21 05:55:00 +00008504void ixgbe_do_reset(struct net_device *netdev)
8505{
8506 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8507
8508 if (netif_running(netdev))
8509 ixgbe_reinit_locked(adapter);
8510 else
8511 ixgbe_reset(adapter);
8512}
8513
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008514static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008515 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008516{
8517 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8518
Don Skidmore082757a2011-07-21 05:55:00 +00008519 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00008520 if (!(features & NETIF_F_RXCSUM))
8521 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00008522
Alexander Duyck567d2de2012-02-11 07:18:57 +00008523 /* Turn off LRO if not RSC capable */
8524 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
8525 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008526
Alexander Duyck567d2de2012-02-11 07:18:57 +00008527 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00008528}
8529
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008530static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008531 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008532{
8533 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00008534 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00008535 bool need_reset = false;
8536
Don Skidmore082757a2011-07-21 05:55:00 +00008537 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00008538 if (!(features & NETIF_F_LRO)) {
8539 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00008540 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00008541 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
8542 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
8543 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
8544 if (adapter->rx_itr_setting == 1 ||
8545 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
8546 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
8547 need_reset = true;
8548 } else if ((changed ^ features) & NETIF_F_LRO) {
8549 e_info(probe, "rx-usecs set too low, "
8550 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00008551 }
8552 }
8553
8554 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08008555 * Check if Flow Director n-tuple support or hw_tc support was
8556 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00008557 */
John Fastabendb82b17d2016-02-16 21:18:53 -08008558 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00008559 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00008560 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
8561 need_reset = true;
8562
Alexander Duyck567d2de2012-02-11 07:18:57 +00008563 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
8564 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08008565 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00008566 /* turn off perfect filters, enable ATR and reset */
8567 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
8568 need_reset = true;
8569
8570 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
8571
8572 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08008573 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
8574 /* We cannot enable ATR if we have 2 or more tcs */
8575 (netdev_get_num_tc(netdev) > 1) ||
8576 /* We cannot enable ATR if RSS is disabled */
8577 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
8578 /* A sample rate of 0 indicates ATR disabled */
8579 (!adapter->atr_sample_rate))
8580 ; /* do nothing not supported */
8581 else /* otherwise supported and set the flag */
8582 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00008583 }
8584
Ben Greear3f2d1c02012-03-08 08:28:41 +00008585 if (changed & NETIF_F_RXALL)
8586 need_reset = true;
8587
Alexander Duyck567d2de2012-02-11 07:18:57 +00008588 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07008589
8590#ifdef CONFIG_IXGBE_VXLAN
8591 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
8592 if (features & NETIF_F_RXCSUM)
8593 adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED;
8594 else
8595 ixgbe_clear_vxlan_port(adapter);
8596 }
8597#endif /* CONFIG_IXGBE_VXLAN */
8598
Don Skidmore082757a2011-07-21 05:55:00 +00008599 if (need_reset)
8600 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08008601 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
8602 NETIF_F_HW_VLAN_CTAG_FILTER))
8603 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00008604
8605 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00008606}
8607
Mark Rustad67359c32015-06-15 11:33:25 -07008608#ifdef CONFIG_IXGBE_VXLAN
Don Skidmore3f207802014-12-23 07:40:34 +00008609/**
8610 * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up
8611 * @dev: The port's netdev
8612 * @sa_family: Socket Family that VXLAN is notifiying us about
8613 * @port: New UDP port number that VXLAN started listening to
8614 **/
8615static void ixgbe_add_vxlan_port(struct net_device *dev, sa_family_t sa_family,
8616 __be16 port)
8617{
8618 struct ixgbe_adapter *adapter = netdev_priv(dev);
8619 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore3f207802014-12-23 07:40:34 +00008620
Mark Rustad67359c32015-06-15 11:33:25 -07008621 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
8622 return;
8623
Don Skidmore3f207802014-12-23 07:40:34 +00008624 if (sa_family == AF_INET6)
8625 return;
8626
Alexander Duyck9f12df92016-01-25 19:36:29 -08008627 if (adapter->vxlan_port == port)
Don Skidmore3f207802014-12-23 07:40:34 +00008628 return;
Don Skidmore3f207802014-12-23 07:40:34 +00008629
8630 if (adapter->vxlan_port) {
8631 netdev_info(dev,
Mark Rustad67359c32015-06-15 11:33:25 -07008632 "Hit Max num of VXLAN ports, not adding port %d\n",
Alexander Duyck9f12df92016-01-25 19:36:29 -08008633 ntohs(port));
Don Skidmore3f207802014-12-23 07:40:34 +00008634 return;
8635 }
8636
Alexander Duyck9f12df92016-01-25 19:36:29 -08008637 adapter->vxlan_port = port;
8638 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, ntohs(port));
Don Skidmore3f207802014-12-23 07:40:34 +00008639}
8640
8641/**
8642 * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away
8643 * @dev: The port's netdev
8644 * @sa_family: Socket Family that VXLAN is notifying us about
8645 * @port: UDP port number that VXLAN stopped listening to
8646 **/
8647static void ixgbe_del_vxlan_port(struct net_device *dev, sa_family_t sa_family,
8648 __be16 port)
8649{
8650 struct ixgbe_adapter *adapter = netdev_priv(dev);
Don Skidmore3f207802014-12-23 07:40:34 +00008651
Mark Rustad67359c32015-06-15 11:33:25 -07008652 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
8653 return;
8654
Don Skidmore3f207802014-12-23 07:40:34 +00008655 if (sa_family == AF_INET6)
8656 return;
8657
Alexander Duyck9f12df92016-01-25 19:36:29 -08008658 if (adapter->vxlan_port != port) {
Don Skidmore3f207802014-12-23 07:40:34 +00008659 netdev_info(dev, "Port %d was not found, not deleting\n",
Alexander Duyck9f12df92016-01-25 19:36:29 -08008660 ntohs(port));
Don Skidmore3f207802014-12-23 07:40:34 +00008661 return;
8662 }
8663
Mark Rustad67359c32015-06-15 11:33:25 -07008664 ixgbe_clear_vxlan_port(adapter);
8665 adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00008666}
Mark Rustad67359c32015-06-15 11:33:25 -07008667#endif /* CONFIG_IXGBE_VXLAN */
Don Skidmore3f207802014-12-23 07:40:34 +00008668
stephen hemmingeredc7d572012-10-01 12:32:33 +00008669static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008670 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01008671 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008672 u16 flags)
8673{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00008674 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00008675 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07008676 struct ixgbe_adapter *adapter = netdev_priv(dev);
8677 u16 pool = VMDQ_P(0);
8678
8679 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00008680 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008681 }
8682
Jiri Pirkof6f64242014-11-28 14:34:15 +01008683 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008684}
8685
Don Skidmore219efe92015-04-09 22:03:22 -07008686/**
8687 * ixgbe_configure_bridge_mode - set various bridge modes
8688 * @adapter - the private structure
8689 * @mode - requested bridge mode
8690 *
8691 * Configure some settings require for various bridge modes.
8692 **/
8693static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
8694 __u16 mode)
8695{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008696 struct ixgbe_hw *hw = &adapter->hw;
8697 unsigned int p, num_pools;
8698 u32 vmdctl;
8699
Don Skidmore219efe92015-04-09 22:03:22 -07008700 switch (mode) {
8701 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008702 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07008703 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008704
8705 /* must enable Rx switching replication to allow multicast
8706 * packet reception on all VFs, and to enable source address
8707 * pruning.
8708 */
8709 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
8710 vmdctl |= IXGBE_VT_CTL_REPLEN;
8711 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
8712
8713 /* enable Rx source address pruning. Note, this requires
8714 * replication to be enabled or else it does nothing.
8715 */
8716 num_pools = adapter->num_vfs + adapter->num_rx_pools;
8717 for (p = 0; p < num_pools; p++) {
8718 if (hw->mac.ops.set_source_address_pruning)
8719 hw->mac.ops.set_source_address_pruning(hw,
8720 true,
8721 p);
8722 }
Don Skidmore219efe92015-04-09 22:03:22 -07008723 break;
8724 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008725 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07008726 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
8727 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008728
8729 /* disable Rx switching replication unless we have SR-IOV
8730 * virtual functions
8731 */
8732 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
8733 if (!adapter->num_vfs)
8734 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
8735 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
8736
8737 /* disable Rx source address pruning, since we don't expect to
8738 * be receiving external loopback of our transmitted frames.
8739 */
8740 num_pools = adapter->num_vfs + adapter->num_rx_pools;
8741 for (p = 0; p < num_pools; p++) {
8742 if (hw->mac.ops.set_source_address_pruning)
8743 hw->mac.ops.set_source_address_pruning(hw,
8744 false,
8745 p);
8746 }
Don Skidmore219efe92015-04-09 22:03:22 -07008747 break;
8748 default:
8749 return -EINVAL;
8750 }
8751
8752 adapter->bridge_mode = mode;
8753
8754 e_info(drv, "enabling bridge mode: %s\n",
8755 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
8756
8757 return 0;
8758}
8759
John Fastabend815cccb2012-10-24 08:13:09 +00008760static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08008761 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00008762{
8763 struct ixgbe_adapter *adapter = netdev_priv(dev);
8764 struct nlattr *attr, *br_spec;
8765 int rem;
8766
8767 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8768 return -EOPNOTSUPP;
8769
8770 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01008771 if (!br_spec)
8772 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00008773
8774 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07008775 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00008776 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00008777
8778 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8779 continue;
8780
Thomas Grafb7c1a312014-11-26 13:42:17 +01008781 if (nla_len(attr) < sizeof(mode))
8782 return -EINVAL;
8783
John Fastabend815cccb2012-10-24 08:13:09 +00008784 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07008785 status = ixgbe_configure_bridge_mode(adapter, mode);
8786 if (status)
8787 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07008788
8789 break;
John Fastabend815cccb2012-10-24 08:13:09 +00008790 }
8791
8792 return 0;
8793}
8794
8795static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00008796 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02008797 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00008798{
8799 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00008800
8801 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8802 return 0;
8803
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07008804 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07008805 adapter->bridge_mode, 0, 0, nlflags,
8806 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00008807}
8808
John Fastabend2a47fa42013-11-06 09:54:52 -08008809static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
8810{
8811 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
8812 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00008813 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08008814 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08008815 int pool, err;
8816
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00008817 /* Hardware has a limited number of available pools. Each VF, and the
8818 * PF require a pool. Check to ensure we don't attempt to use more
8819 * then the available number of pools.
8820 */
8821 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
8822 return ERR_PTR(-EINVAL);
8823
John Fastabend219354d2013-11-08 00:50:32 -08008824#ifdef CONFIG_RPS
8825 if (vdev->num_rx_queues != vdev->num_tx_queues) {
8826 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
8827 vdev->name);
8828 return ERR_PTR(-EINVAL);
8829 }
8830#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08008831 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08008832 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08008833 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
8834 netdev_info(pdev,
8835 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
8836 pdev->name);
8837 return ERR_PTR(-EINVAL);
8838 }
8839
8840 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
8841 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
8842 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
8843 return ERR_PTR(-EBUSY);
8844
Maninder Singhbc52f952015-06-19 09:37:55 +05308845 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08008846 if (!fwd_adapter)
8847 return ERR_PTR(-ENOMEM);
8848
8849 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
8850 adapter->num_rx_pools++;
8851 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08008852 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08008853
8854 /* Enable VMDq flag so device will be set in VM mode */
8855 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08008856 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08008857 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08008858
8859 /* Force reinit of ring allocation with VMDQ enabled */
8860 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8861 if (err)
8862 goto fwd_add_err;
8863 fwd_adapter->pool = pool;
8864 fwd_adapter->real_adapter = adapter;
8865 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
8866 if (err)
8867 goto fwd_add_err;
8868 netif_tx_start_all_queues(vdev);
8869 return fwd_adapter;
8870fwd_add_err:
8871 /* unwind counter and free adapter struct */
8872 netdev_info(pdev,
8873 "%s: dfwd hardware acceleration failed\n", vdev->name);
8874 clear_bit(pool, &adapter->fwd_bitmask);
8875 adapter->num_rx_pools--;
8876 kfree(fwd_adapter);
8877 return ERR_PTR(err);
8878}
8879
8880static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
8881{
8882 struct ixgbe_fwd_adapter *fwd_adapter = priv;
8883 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08008884 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08008885
8886 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
8887 adapter->num_rx_pools--;
8888
John Fastabend51f37732013-11-08 00:51:10 -08008889 limit = find_last_bit(&adapter->fwd_bitmask, 32);
8890 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08008891 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
8892 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8893 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
8894 fwd_adapter->pool, adapter->num_rx_pools,
8895 fwd_adapter->rx_base_queue,
8896 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
8897 adapter->fwd_bitmask);
8898 kfree(fwd_adapter);
8899}
8900
Mark Rustadf467bc02015-06-15 11:33:20 -07008901#define IXGBE_MAX_TUNNEL_HDR_LEN 80
8902static netdev_features_t
8903ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
8904 netdev_features_t features)
8905{
8906 if (!skb->encapsulation)
8907 return features;
8908
8909 if (unlikely(skb_inner_mac_header(skb) - skb_transport_header(skb) >
8910 IXGBE_MAX_TUNNEL_HDR_LEN))
Tom Herberta1882222015-12-14 11:19:43 -08008911 return features & ~NETIF_F_CSUM_MASK;
Mark Rustadf467bc02015-06-15 11:33:20 -07008912
8913 return features;
8914}
8915
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008916static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00008917 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008918 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08008919 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008920 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00008921 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008922 .ndo_validate_addr = eth_validate_addr,
8923 .ndo_set_mac_address = ixgbe_set_mac,
8924 .ndo_change_mtu = ixgbe_change_mtu,
8925 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00008926 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008927 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
8928 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00008929 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00008930 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
8931 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04008932 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00008933 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03008934 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +00008935 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +00008936 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00008937 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -08008938 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008939#ifdef CONFIG_NET_POLL_CONTROLLER
8940 .ndo_poll_controller = ixgbe_netpoll,
8941#endif
Cong Wange0d10952013-08-01 11:10:25 +08008942#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03008943 .ndo_busy_poll = ixgbe_low_latency_recv,
Eliezer Tamir5a85e732013-06-10 11:40:20 +03008944#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008945#ifdef IXGBE_FCOE
8946 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00008947 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00008948 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00008949 .ndo_fcoe_enable = ixgbe_fcoe_enable,
8950 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00008951 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00008952 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00008953#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00008954 .ndo_set_features = ixgbe_set_features,
8955 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008956 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00008957 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
8958 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08008959 .ndo_dfwd_add_station = ixgbe_fwd_add,
8960 .ndo_dfwd_del_station = ixgbe_fwd_del,
Mark Rustad67359c32015-06-15 11:33:25 -07008961#ifdef CONFIG_IXGBE_VXLAN
Don Skidmore3f207802014-12-23 07:40:34 +00008962 .ndo_add_vxlan_port = ixgbe_add_vxlan_port,
8963 .ndo_del_vxlan_port = ixgbe_del_vxlan_port,
Mark Rustad67359c32015-06-15 11:33:25 -07008964#endif /* CONFIG_IXGBE_VXLAN */
Mark Rustadf467bc02015-06-15 11:33:20 -07008965 .ndo_features_check = ixgbe_features_check,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008966};
8967
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008968/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00008969 * ixgbe_enumerate_functions - Get the number of ports this device has
8970 * @adapter: adapter structure
8971 *
8972 * This function enumerates the phsyical functions co-located on a single slot,
8973 * in order to determine how many ports a device has. This is most useful in
8974 * determining the required GT/s of PCIe bandwidth necessary for optimal
8975 * performance.
8976 **/
8977static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
8978{
Jacob Kellercaafb952014-07-19 07:17:17 +00008979 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00008980 int physfns = 0;
8981
Jacob Kellerf1f96572013-08-31 02:45:38 +00008982 /* Some cards can not use the generic count PCIe functions method,
8983 * because they are behind a parent switch, so we hardcode these with
8984 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00008985 */
Jacob Keller88189702014-07-19 07:17:16 +00008986 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00008987 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00008988
8989 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
8990 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00008991 if (entry->is_virtfn)
8992 continue;
8993
8994 /* When the devices on the bus don't all match our device ID,
8995 * we can't reliably determine the correct number of
8996 * functions. This can occur if a function has been direct
8997 * attached to a virtual machine using VT-d, for example. In
8998 * this case, simply return -1 to indicate this.
8999 */
9000 if ((entry->vendor != pdev->vendor) ||
9001 (entry->device != pdev->device))
9002 return -1;
9003
9004 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009005 }
9006
9007 return physfns;
9008}
9009
9010/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00009011 * ixgbe_wol_supported - Check whether device supports WoL
9012 * @hw: hw specific details
9013 * @device_id: the device ID
9014 * @subdev_id: the subsystem device ID
9015 *
9016 * This function is used by probe and ethtool to determine
9017 * which devices have WoL support
9018 *
9019 **/
9020int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
9021 u16 subdevice_id)
9022{
9023 struct ixgbe_hw *hw = &adapter->hw;
9024 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
9025 int is_wol_supported = 0;
9026
9027 switch (device_id) {
9028 case IXGBE_DEV_ID_82599_SFP:
9029 /* Only these subdevices could supports WOL */
9030 switch (subdevice_id) {
Mark Rustad87557442014-02-25 17:58:55 -08009031 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009032 case IXGBE_SUBDEV_ID_82599_560FLR:
9033 /* only support first port */
9034 if (hw->bus.func != 0)
9035 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00009036 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009037 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00009038 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00009039 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller979fe5f2013-04-03 04:41:37 +00009040 case IXGBE_SUBDEV_ID_82599_LOM_SFP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009041 is_wol_supported = 1;
9042 break;
9043 }
9044 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009045 case IXGBE_DEV_ID_82599EN_SFP:
9046 /* Only this subdevice supports WOL */
9047 switch (subdevice_id) {
9048 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
9049 is_wol_supported = 1;
9050 break;
9051 }
9052 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009053 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
9054 /* All except this subdevice support WOL */
9055 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
9056 is_wol_supported = 1;
9057 break;
9058 case IXGBE_DEV_ID_82599_KX4:
9059 is_wol_supported = 1;
9060 break;
9061 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00009062 case IXGBE_DEV_ID_X540T1:
Don Skidmoredf8c26f2015-06-09 16:00:17 -07009063 case IXGBE_DEV_ID_X550T:
Mark Rustada711ad82016-03-21 11:21:31 -07009064 case IXGBE_DEV_ID_X550T1:
Don Skidmoredf8c26f2015-06-09 16:00:17 -07009065 case IXGBE_DEV_ID_X550EM_X_KX4:
9066 case IXGBE_DEV_ID_X550EM_X_KR:
9067 case IXGBE_DEV_ID_X550EM_X_10G_T:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009068 /* check eeprom to see if enabled wol */
9069 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
9070 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
9071 (hw->bus.func == 0))) {
9072 is_wol_supported = 1;
9073 }
9074 break;
9075 }
9076
9077 return is_wol_supported;
9078}
9079
9080/**
Auke Kok9a799d72007-09-15 14:07:45 -07009081 * ixgbe_probe - Device Initialization Routine
9082 * @pdev: PCI device information struct
9083 * @ent: entry in ixgbe_pci_tbl
9084 *
9085 * Returns 0 on success, negative on failure
9086 *
9087 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
9088 * The OS initialization, configuring of the adapter private structure,
9089 * and a hardware reset occur.
9090 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00009091static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07009092{
9093 struct net_device *netdev;
9094 struct ixgbe_adapter *adapter = NULL;
9095 struct ixgbe_hw *hw;
9096 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +00009097 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009098 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00009099 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009100 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +00009101#ifdef IXGBE_FCOE
9102 u16 device_caps;
9103#endif
Don Skidmore289700db2010-12-03 03:32:58 +00009104 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07009105
Andy Gospodarekbded64a2010-07-21 06:40:31 +00009106 /* Catch broken hardware that put the wrong VF device ID in
9107 * the PCIe SR-IOV capability.
9108 */
9109 if (pdev->is_virtfn) {
9110 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
9111 pci_name(pdev), pdev->vendor, pdev->device);
9112 return -EINVAL;
9113 }
9114
gouji-new9ce77662009-05-06 10:44:45 +00009115 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009116 if (err)
9117 return err;
9118
Russell Kingf5f2eda2013-06-10 12:47:42 +01009119 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07009120 pci_using_dac = 1;
9121 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009122 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07009123 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009124 dev_err(&pdev->dev,
9125 "No usable DMA configuration, aborting\n");
9126 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07009127 }
9128 pci_using_dac = 0;
9129 }
9130
gouji-new9ce77662009-05-06 10:44:45 +00009131 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00009132 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07009133 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00009134 dev_err(&pdev->dev,
9135 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07009136 goto err_pci_reg;
9137 }
9138
Frans Pop19d5afd2009-10-02 10:04:12 -07009139 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009140
Auke Kok9a799d72007-09-15 14:07:45 -07009141 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07009142 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009143
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009144 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00009145#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009146 /* 8 TC w/ 4 queues per TC */
9147 indices = 4 * MAX_TRAFFIC_CLASS;
9148#else
9149 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00009150#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009151 }
John Fastabende901acd2011-04-26 07:26:08 +00009152
John Fastabendc85a2612010-02-25 23:15:21 +00009153 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07009154 if (!netdev) {
9155 err = -ENOMEM;
9156 goto err_alloc_etherdev;
9157 }
9158
Auke Kok9a799d72007-09-15 14:07:45 -07009159 SET_NETDEV_DEV(netdev, &pdev->dev);
9160
Auke Kok9a799d72007-09-15 14:07:45 -07009161 adapter = netdev_priv(netdev);
9162
9163 adapter->netdev = netdev;
9164 adapter->pdev = pdev;
9165 hw = &adapter->hw;
9166 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00009167 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07009168
Jeff Kirsher05857982008-09-11 19:57:00 -07009169 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00009170 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08009171 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07009172 if (!hw->hw_addr) {
9173 err = -EIO;
9174 goto err_ioremap;
9175 }
9176
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009177 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009178 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009179 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +00009180 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -07009181
Auke Kok9a799d72007-09-15 14:07:45 -07009182 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -08009183 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009184 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009185 hw->mvals = ii->mvals;
Auke Kok9a799d72007-09-15 14:07:45 -07009186
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009187 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -08009188 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009189 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +00009190 if (ixgbe_removed(hw->hw_addr)) {
9191 err = -EIO;
9192 goto err_ioremap;
9193 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009194 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07009195 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009196 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
9197
9198 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -08009199 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009200 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00009201 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
9202 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
9203 hw->phy.mdio.mmds = 0;
9204 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9205 hw->phy.mdio.dev = netdev;
9206 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
9207 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009208
Don Skidmore8ca783a2009-05-26 20:40:47 -07009209 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07009210
9211 /* setup the private structure */
9212 err = ixgbe_sw_init(adapter);
9213 if (err)
9214 goto err_sw_init;
9215
Don Skidmoredbd15b82016-03-09 16:45:00 -05009216 /* Make sure the SWFW semaphore is in a valid state */
9217 if (hw->mac.ops.init_swfw_sync)
9218 hw->mac.ops.init_swfw_sync(hw);
9219
Don Skidmoree86bff02010-02-11 04:14:08 +00009220 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08009221 switch (adapter->hw.mac.type) {
9222 case ixgbe_mac_82599EB:
9223 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00009224 case ixgbe_mac_X550:
9225 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07009226 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +00009227 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08009228 break;
9229 default:
9230 break;
9231 }
Don Skidmoree86bff02010-02-11 04:14:08 +00009232
Don Skidmorebf069c92009-05-07 10:39:54 +00009233 /*
9234 * If there is a fan on this device and it has failed log the
9235 * failure.
9236 */
9237 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
9238 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
9239 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00009240 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00009241 }
9242
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00009243 if (allow_unsupported_sfp)
9244 hw->allow_unsupported_sfp = allow_unsupported_sfp;
9245
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009246 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009247 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009248 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009249 hw->phy.reset_if_overtemp = false;
Mark Rustad29a8dca2015-08-08 16:17:46 -07009250 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07009251 err = 0;
9252 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00009253 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
9254 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009255 goto err_sw_init;
9256 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009257 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009258 goto err_sw_init;
9259 }
9260
Alexander Duyck99d74482012-05-09 08:09:25 +00009261#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00009262 /* SR-IOV not supported on the 82598 */
9263 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
9264 goto skip_sriov;
9265 /* Mailbox */
9266 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -08009267 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -08009268 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ethan.zhao31ac9102014-01-16 19:41:05 -08009269 ixgbe_enable_sriov(adapter);
Greg Rose60a1a682012-12-11 08:26:33 +00009270skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009271
Alexander Duyck99d74482012-05-09 08:09:25 +00009272#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00009273 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +00009274 NETIF_F_TSO |
9275 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00009276 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -08009277 NETIF_F_RXCSUM |
9278 NETIF_F_HW_CSUM |
9279 NETIF_F_HW_VLAN_CTAG_TX |
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009280 NETIF_F_HW_VLAN_CTAG_RX |
9281 NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07009282
Alexander Duyck49763de2016-01-13 07:31:11 -08009283 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -08009284 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00009285
Alexander Duyck49763de2016-01-13 07:31:11 -08009286 /* copy netdev features into list of user selectable features */
9287 netdev->hw_features |= netdev->features;
9288 netdev->hw_features |= NETIF_F_RXALL |
9289 NETIF_F_HW_L2FW_DOFFLOAD;
9290
9291 if (hw->mac.type >= ixgbe_mac_82599EB)
9292 netdev->hw_features |= NETIF_F_NTUPLE |
9293 NETIF_F_HW_TC;
9294
Alexander Duyck49763de2016-01-13 07:31:11 -08009295 netdev->vlan_features |= NETIF_F_SG |
9296 NETIF_F_TSO |
9297 NETIF_F_TSO6 |
9298 NETIF_F_HW_CSUM |
9299 NETIF_F_SCTP_CRC;
Jeff Kirsherad31c402008-06-05 04:05:30 -07009300
Alexander Duyck49763de2016-01-13 07:31:11 -08009301 netdev->mpls_features |= NETIF_F_HW_CSUM;
9302 netdev->hw_enc_features |= NETIF_F_HW_CSUM;
Mark Rustadf467bc02015-06-15 11:33:20 -07009303
Jiri Pirko01789342011-08-16 06:29:00 +00009304 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00009305 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00009306
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08009307#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08009308 netdev->dcbnl_ops = &dcbnl_ops;
9309#endif
9310
Yi Zoueacd73f2009-05-13 13:11:06 +00009311#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00009312 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009313 unsigned int fcoe_l;
9314
Yi Zoueacd73f2009-05-13 13:11:06 +00009315 if (hw->mac.ops.get_device_caps) {
9316 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00009317 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
9318 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00009319 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009320
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009321
9322 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
9323 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009324
Alexander Duycka58915c2012-05-25 06:38:18 +00009325 netdev->features |= NETIF_F_FSO |
9326 NETIF_F_FCOE_CRC;
9327
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009328 netdev->vlan_features |= NETIF_F_FSO |
9329 NETIF_F_FCOE_CRC |
9330 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00009331 }
Yi Zoueacd73f2009-05-13 13:11:06 +00009332#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00009333 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07009334 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00009335 netdev->vlan_features |= NETIF_F_HIGHDMA;
9336 }
Auke Kok9a799d72007-09-15 14:07:45 -07009337
Don Skidmore082757a2011-07-21 05:55:00 +00009338 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
9339 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00009340 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00009341 netdev->features |= NETIF_F_LRO;
9342
Auke Kok9a799d72007-09-15 14:07:45 -07009343 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009344 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009345 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009346 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009347 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009348 }
9349
Sowmini Varadhanc7374b52016-01-12 19:32:30 -08009350 eth_platform_get_mac_address(&adapter->pdev->dev,
9351 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +00009352
Auke Kok9a799d72007-09-15 14:07:45 -07009353 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07009354
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00009355 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009356 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009357 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009358 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009359 }
9360
Tushar Dave56768042016-01-07 14:17:03 -08009361 /* Set hw->mac.addr to permanent MAC address */
9362 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07009363 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +00009364
Alexander Duyck70864002011-04-27 09:13:56 +00009365 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00009366 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009367
Mark Rustad58cf6632014-03-12 00:38:40 +00009368 if (ixgbe_removed(hw->hw_addr)) {
9369 err = -EIO;
9370 goto err_sw_init;
9371 }
Alexander Duyck70864002011-04-27 09:13:56 +00009372 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +00009373 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00009374 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009375
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009376 err = ixgbe_init_interrupt_scheme(adapter);
9377 if (err)
9378 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009379
Jacob Keller8e2813f2012-04-21 06:05:40 +00009380 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009381 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009382 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009383 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00009384 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009385 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00009386 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009387
PJ Waskiewicze8e26352009-02-27 15:45:05 +00009388 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
9389
Emil Tantilov15e52092011-09-29 05:01:29 +00009390 /* save off EEPROM version number */
9391 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
9392 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
9393
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009394 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +00009395 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00009396 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -04009397 else
9398 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009399
Jacob Kellere027d1a2013-07-31 06:53:31 +00009400 /* calculate the expected PCIe bandwidth required for optimal
9401 * performance. Note that some older parts will never have enough
9402 * bandwidth due to being older generation PCIe parts. We clamp these
9403 * parts to ensure no warning is displayed if it can't be fixed.
9404 */
9405 switch (hw->mac.type) {
9406 case ixgbe_mac_82598EB:
9407 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
9408 break;
9409 default:
9410 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
9411 break;
Auke Kok0c254d82008-02-11 09:25:56 -08009412 }
Jacob Kellercaafb952014-07-19 07:17:17 +00009413
9414 /* don't check link if we failed to enumerate functions */
9415 if (expected_gts > 0)
9416 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08009417
Mark Rustad339de302014-06-06 01:57:06 +00009418 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009419 if (err)
Mark Rustad339de302014-06-06 01:57:06 +00009420 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009421 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
9422 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
9423 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +00009424 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +00009425 else
9426 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
9427 hw->mac.type, hw->phy.type, part_str);
9428
9429 e_dev_info("%pM\n", netdev->dev_addr);
9430
Auke Kok9a799d72007-09-15 14:07:45 -07009431 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009432 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009433 if (err == IXGBE_ERR_EEPROM_VERSION) {
9434 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00009435 e_dev_warn("This device is a pre-production adapter/LOM. "
9436 "Please be aware there may be issues associated "
9437 "with your hardware. If you are experiencing "
9438 "problems please contact your Intel or hardware "
9439 "representative who provided you with this "
9440 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009441 }
Auke Kok9a799d72007-09-15 14:07:45 -07009442 strcpy(netdev->name, "eth%d");
9443 err = register_netdev(netdev);
9444 if (err)
9445 goto err_register;
9446
Emil Tantilov0fb6a552014-12-04 03:03:38 +00009447 pci_set_drvdata(pdev, adapter);
9448
Emil Tantilovec74a472012-09-20 03:33:56 +00009449 /* power down the optics for 82599 SFP+ fiber */
9450 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00009451 hw->mac.ops.disable_tx_laser(hw);
9452
Jesse Brandeburg54386462009-04-17 20:44:27 +00009453 /* carrier off reporting is important to ethtool even BEFORE open */
9454 netif_carrier_off(netdev);
9455
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009456#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03009457 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009458 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009459 ixgbe_setup_dca(adapter);
9460 }
9461#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009462 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00009463 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009464 for (i = 0; i < adapter->num_vfs; i++)
9465 ixgbe_vf_configuration(pdev, (i | 0x10000000));
9466 }
9467
Jacob Keller2466dd92011-09-08 03:50:54 +00009468 /* firmware requires driver version to be 0xFFFFFFFF
9469 * since os does not support feature
9470 */
Emil Tantilov9612de92011-05-07 07:40:20 +00009471 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00009472 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
9473 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00009474
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00009475 /* add san mac addr to netdev */
9476 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009477
Neerav Parikhea818752012-01-04 20:23:40 +00009478 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009479
Don Skidmore12109822012-05-04 06:07:08 +00009480#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009481 if (ixgbe_sysfs_init(adapter))
9482 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00009483#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009484
Catherine Sullivan00949162012-08-10 01:59:10 +00009485 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00009486
Emil Tantilovd1a35ee2014-05-13 08:24:00 +00009487 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
9488 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +00009489 hw->mac.ops.setup_link(hw,
9490 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
9491 true);
9492
Auke Kok9a799d72007-09-15 14:07:45 -07009493 return 0;
9494
9495err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08009496 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00009497 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009498err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00009499 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00009500 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -08009501 iounmap(adapter->io_addr);
Jacob Keller5d7daa32014-03-29 06:51:25 +00009502 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -07009503err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009504 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009505 free_netdev(netdev);
9506err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00009507 pci_release_selected_regions(pdev,
9508 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07009509err_pci_reg:
9510err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009511 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00009512 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009513 return err;
9514}
9515
9516/**
9517 * ixgbe_remove - Device Removal Routine
9518 * @pdev: PCI device information struct
9519 *
9520 * ixgbe_remove is called by the PCI subsystem to alert the driver
9521 * that it should release a PCI device. The could be caused by a
9522 * Hot-Plug event, or because the driver is going to be removed from
9523 * memory.
9524 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05009525static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07009526{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009527 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +00009528 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009529 bool disable_dev;
Auke Kok9a799d72007-09-15 14:07:45 -07009530
Emil Tantilov0fb6a552014-12-04 03:03:38 +00009531 /* if !adapter then we already cleaned up in probe */
9532 if (!adapter)
9533 return;
9534
9535 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +00009536 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00009537
Mark Rustad09f40ae2014-01-14 18:53:11 -08009538 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00009539 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07009540
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00009541
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009542#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009543 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
9544 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
9545 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -07009546 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
9547 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009548 }
9549
9550#endif
Don Skidmore12109822012-05-04 06:07:08 +00009551#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009552 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00009553#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009554
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00009555 /* remove the added san mac */
9556 ixgbe_del_sanmac_netdev(netdev);
9557
Greg Roseda36b642012-12-11 08:26:43 +00009558#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -06009559 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +00009560#endif
Alex Williamson6b010e92015-07-29 14:38:21 -06009561 if (netdev->reg_state == NETREG_REGISTERED)
9562 unregister_netdev(netdev);
9563
Alexander Duyck7a921c92009-05-06 10:43:28 +00009564 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08009565
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009566 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009567
Alexander Duyck2b1588c2012-03-17 02:39:16 +00009568#ifdef CONFIG_DCB
9569 kfree(adapter->ixgbe_ieee_pfc);
9570 kfree(adapter->ixgbe_ieee_ets);
9571
9572#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -08009573 iounmap(adapter->io_addr);
gouji-new9ce77662009-05-06 10:44:45 +00009574 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00009575 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07009576
Emil Tantilov849c4542010-06-03 16:53:41 +00009577 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009578
Jacob Keller5d7daa32014-03-29 06:51:25 +00009579 kfree(adapter->mac_table);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009580 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009581 free_netdev(netdev);
9582
Frans Pop19d5afd2009-10-02 10:04:12 -07009583 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009584
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009585 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00009586 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009587}
9588
9589/**
9590 * ixgbe_io_error_detected - called when PCI error is detected
9591 * @pdev: Pointer to PCI device
9592 * @state: The current pci connection state
9593 *
9594 * This function is called after a PCI bus error affecting
9595 * this device has been detected.
9596 */
9597static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00009598 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07009599{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009600 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
9601 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07009602
Greg Rose83c61fa2011-09-07 05:59:35 +00009603#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -08009604 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +00009605 struct pci_dev *bdev, *vfdev;
9606 u32 dw0, dw1, dw2, dw3;
9607 int vf, pos;
9608 u16 req_id, pf_func;
9609
9610 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
9611 adapter->num_vfs == 0)
9612 goto skip_bad_vf_detection;
9613
9614 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08009615 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00009616 bdev = bdev->bus->self;
9617
9618 if (!bdev)
9619 goto skip_bad_vf_detection;
9620
9621 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
9622 if (!pos)
9623 goto skip_bad_vf_detection;
9624
Mark Rustad14438462014-02-28 15:48:57 -08009625 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
9626 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
9627 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
9628 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
9629 if (ixgbe_removed(hw->hw_addr))
9630 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +00009631
9632 req_id = dw1 >> 16;
9633 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
9634 if (!(req_id & 0x0080))
9635 goto skip_bad_vf_detection;
9636
9637 pf_func = req_id & 0x01;
9638 if ((pf_func & 1) == (pdev->devfn & 1)) {
9639 unsigned int device_id;
9640
9641 vf = (req_id & 0x7F) >> 1;
9642 e_dev_err("VF %d has caused a PCIe error\n", vf);
9643 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
9644 "%8.8x\tdw3: %8.8x\n",
9645 dw0, dw1, dw2, dw3);
9646 switch (adapter->hw.mac.type) {
9647 case ixgbe_mac_82599EB:
9648 device_id = IXGBE_82599_VF_DEVICE_ID;
9649 break;
9650 case ixgbe_mac_X540:
9651 device_id = IXGBE_X540_VF_DEVICE_ID;
9652 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00009653 case ixgbe_mac_X550:
9654 device_id = IXGBE_DEV_ID_X550_VF;
9655 break;
9656 case ixgbe_mac_X550EM_x:
9657 device_id = IXGBE_DEV_ID_X550EM_X_VF;
9658 break;
Mark Rustad49425df2016-04-01 12:18:09 -07009659 case ixgbe_mac_x550em_a:
9660 device_id = IXGBE_DEV_ID_X550EM_A_VF;
9661 break;
Greg Rose83c61fa2011-09-07 05:59:35 +00009662 default:
9663 device_id = 0;
9664 break;
9665 }
9666
9667 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00009668 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00009669 while (vfdev) {
9670 if (vfdev->devfn == (req_id & 0xFF))
9671 break;
Jon Mason36e90312012-07-19 21:02:09 +00009672 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00009673 device_id, vfdev);
9674 }
9675 /*
9676 * There's a slim chance the VF could have been hot plugged,
9677 * so if it is no longer present we don't need to issue the
9678 * VFLR. Just clean up the AER in that case.
9679 */
9680 if (vfdev) {
Emil Tantilov9079e412014-11-19 03:18:19 +00009681 ixgbe_issue_vf_flr(adapter, vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +00009682 /* Free device reference count */
9683 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +00009684 }
9685
9686 pci_cleanup_aer_uncorrect_error_status(pdev);
9687 }
9688
9689 /*
9690 * Even though the error may have occurred on the other port
9691 * we still need to increment the vf error reference count for
9692 * both ports because the I/O resume function will be called
9693 * for both of them.
9694 */
9695 adapter->vferr_refcount++;
9696
9697 return PCI_ERS_RESULT_RECOVERED;
9698
9699skip_bad_vf_detection:
9700#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +00009701 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
9702 return PCI_ERS_RESULT_DISCONNECT;
9703
Mark Rustad41c62842014-03-12 00:38:35 +00009704 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07009705 netif_device_detach(netdev);
9706
Mark Rustad41c62842014-03-12 00:38:35 +00009707 if (state == pci_channel_io_perm_failure) {
9708 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +00009709 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +00009710 }
Breno Leitao3044b8d2009-05-06 10:44:26 +00009711
Auke Kok9a799d72007-09-15 14:07:45 -07009712 if (netif_running(netdev))
9713 ixgbe_down(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +00009714
9715 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
9716 pci_disable_device(pdev);
9717 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -07009718
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07009719 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07009720 return PCI_ERS_RESULT_NEED_RESET;
9721}
9722
9723/**
9724 * ixgbe_io_slot_reset - called after the pci bus has been reset.
9725 * @pdev: Pointer to PCI device
9726 *
9727 * Restart the card from scratch, as if from a cold-boot.
9728 */
9729static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
9730{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009731 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009732 pci_ers_result_t result;
9733 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07009734
gouji-new9ce77662009-05-06 10:44:45 +00009735 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00009736 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009737 result = PCI_ERS_RESULT_DISCONNECT;
9738 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +01009739 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00009740 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -08009741 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009742 pci_set_master(pdev);
9743 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00009744 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009745
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07009746 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009747
9748 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00009749 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009750 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07009751 }
Auke Kok9a799d72007-09-15 14:07:45 -07009752
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009753 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9754 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009755 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
9756 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009757 /* non-fatal, continue */
9758 }
Auke Kok9a799d72007-09-15 14:07:45 -07009759
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009760 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07009761}
9762
9763/**
9764 * ixgbe_io_resume - called when traffic can start flowing again.
9765 * @pdev: Pointer to PCI device
9766 *
9767 * This callback is called when the error recovery driver tells us that
9768 * its OK to resume normal operation.
9769 */
9770static void ixgbe_io_resume(struct pci_dev *pdev)
9771{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009772 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
9773 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07009774
Greg Rose83c61fa2011-09-07 05:59:35 +00009775#ifdef CONFIG_PCI_IOV
9776 if (adapter->vferr_refcount) {
9777 e_info(drv, "Resuming after VF err\n");
9778 adapter->vferr_refcount--;
9779 return;
9780 }
9781
9782#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00009783 if (netif_running(netdev))
9784 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009785
9786 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009787}
9788
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07009789static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07009790 .error_detected = ixgbe_io_error_detected,
9791 .slot_reset = ixgbe_io_slot_reset,
9792 .resume = ixgbe_io_resume,
9793};
9794
9795static struct pci_driver ixgbe_driver = {
9796 .name = ixgbe_driver_name,
9797 .id_table = ixgbe_pci_tbl,
9798 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05009799 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07009800#ifdef CONFIG_PM
9801 .suspend = ixgbe_suspend,
9802 .resume = ixgbe_resume,
9803#endif
9804 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +00009805 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -07009806 .err_handler = &ixgbe_err_handler
9807};
9808
9809/**
9810 * ixgbe_init_module - Driver Registration Routine
9811 *
9812 * ixgbe_init_module is the first routine called when the driver is
9813 * loaded. All it does is register with the PCI subsystem.
9814 **/
9815static int __init ixgbe_init_module(void)
9816{
9817 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00009818 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00009819 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07009820
Mark Rustad780484d2015-10-21 17:21:10 -07009821 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
9822 if (!ixgbe_wq) {
9823 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
9824 return -ENOMEM;
9825 }
9826
Catherine Sullivan00949162012-08-10 01:59:10 +00009827 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +00009828
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009829 ret = pci_register_driver(&ixgbe_driver);
9830 if (ret) {
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009831 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009832 return ret;
9833 }
9834
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009835#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009836 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009837#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009838
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009839 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07009840}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07009841
Auke Kok9a799d72007-09-15 14:07:45 -07009842module_init(ixgbe_init_module);
9843
9844/**
9845 * ixgbe_exit_module - Driver Exit Cleanup Routine
9846 *
9847 * ixgbe_exit_module is called just before the driver is removed
9848 * from memory.
9849 **/
9850static void __exit ixgbe_exit_module(void)
9851{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009852#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009853 dca_unregister_notify(&dca_notifier);
9854#endif
Auke Kok9a799d72007-09-15 14:07:45 -07009855 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00009856
Catherine Sullivan00949162012-08-10 01:59:10 +00009857 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -07009858 if (ixgbe_wq) {
9859 destroy_workqueue(ixgbe_wq);
9860 ixgbe_wq = NULL;
9861 }
Auke Kok9a799d72007-09-15 14:07:45 -07009862}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009863
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009864#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009865static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00009866 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009867{
9868 int ret_val;
9869
9870 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00009871 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009872
9873 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
9874}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009875
Alexander Duyckb4533682009-03-31 21:32:42 +00009876#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00009877
Auke Kok9a799d72007-09-15 14:07:45 -07009878module_exit(ixgbe_exit_module);
9879
9880/* ixgbe_main.c */