blob: 536dd9b1ad97cd5167ad4abdaad78f29c80a94a9 [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>
Alexander Duyckb3a49552016-06-16 12:22:19 -070053#include <net/udp_tunnel.h>
John Fastabendb82b17d2016-02-16 21:18:53 -080054#include <net/pkt_cls.h>
55#include <net/tc_act/tc_gact.h>
Sridhar Samudrala947f8a42016-04-05 10:39:07 -070056#include <net/tc_act/tc_mirred.h>
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -070057#include <net/vxlan.h>
Auke Kok9a799d72007-09-15 14:07:45 -070058
59#include "ixgbe.h"
60#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000061#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000062#include "ixgbe_sriov.h"
John Fastabendb82b17d2016-02-16 21:18:53 -080063#include "ixgbe_model.h"
Auke Kok9a799d72007-09-15 14:07:45 -070064
65char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070066static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000067 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000068#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000069char ixgbe_default_device_descr[] =
70 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000071#else
72static char ixgbe_default_device_descr[] =
73 "Intel(R) 10 Gigabit Network Connection";
74#endif
Mark Rustad17332842016-12-12 15:08:13 -080075#define DRV_VERSION "5.0.0-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070076const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000077static const char ixgbe_copyright[] =
Mark Rustad49425df2016-04-01 12:18:09 -070078 "Copyright (c) 1999-2016 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070079
Don Skidmoref44e7512015-06-09 16:36:23 -070080static 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";
81
Auke Kok9a799d72007-09-15 14:07:45 -070082static const struct ixgbe_info *ixgbe_info_tbl[] = {
Don Skidmore6a14ee02014-12-05 03:59:50 +000083 [board_82598] = &ixgbe_82598_info,
84 [board_82599] = &ixgbe_82599_info,
85 [board_X540] = &ixgbe_X540_info,
86 [board_X550] = &ixgbe_X550_info,
87 [board_X550EM_x] = &ixgbe_X550EM_x_info,
Mark Rustad49425df2016-04-01 12:18:09 -070088 [board_x550em_a] = &ixgbe_x550em_a_info,
Mark Rustadb3eb4e12016-12-14 11:02:16 -080089 [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info,
Auke Kok9a799d72007-09-15 14:07:45 -070090};
91
92/* ixgbe_pci_tbl - PCI Device ID Table
93 *
94 * Wildcard entries (PCI_ANY_ID) should come last
95 * Last entry must be all 0s
96 *
97 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
98 * Class, Class Mask, private data (not used) }
99 */
Benoit Taine9baa3c32014-08-08 15:56:03 +0200100static const struct pci_device_id ixgbe_pci_tbl[] = {
Alexander Duyck54239c62011-07-15 03:06:06 +0000101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Don Skidmore8f583322013-07-27 06:25:38 +0000127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Don Skidmore6a14ee02014-12-05 03:59:50 +0000131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
Mark Rustada711ad82016-03-21 11:21:31 -0700132 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
Don Skidmore6a14ee02014-12-05 03:59:50 +0000133 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
Don Skidmore18e01ee2016-12-30 21:07:58 -0500134 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x},
Don Skidmore6a14ee02014-12-05 03:59:50 +0000135 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
Don Skidmorededa5622015-06-09 17:39:46 -0700136 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
Mark Rustad018d7142015-08-08 16:19:19 -0700137 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
Mark Rustadf572b2c2016-04-01 12:18:46 -0700138 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
139 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
Mark Rustad49425df2016-04-01 12:18:09 -0700140 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
Mark Rustad200157c2016-04-01 12:18:40 -0700141 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
142 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
Don Skidmore92ed8432016-08-17 20:34:40 -0400143 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
Mark Rustad2d40cd12016-04-01 12:18:35 -0700144 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800145 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw },
146 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw },
Auke Kok9a799d72007-09-15 14:07:45 -0700147 /* required last entry */
148 {0, }
149};
150MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
151
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400152#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800153static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000154 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800155static struct notifier_block dca_notifier = {
156 .notifier_call = ixgbe_notify_dca,
157 .next = NULL,
158 .priority = 0
159};
160#endif
161
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000162#ifdef CONFIG_PCI_IOV
163static unsigned int max_vfs;
164module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000165MODULE_PARM_DESC(max_vfs,
Jacob Keller170e8542013-11-09 04:52:32 -0800166 "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 +0000167#endif /* CONFIG_PCI_IOV */
168
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000169static unsigned int allow_unsupported_sfp;
170module_param(allow_unsupported_sfp, uint, 0);
171MODULE_PARM_DESC(allow_unsupported_sfp,
172 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
173
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000174#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
175static int debug = -1;
176module_param(debug, int, 0);
177MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
178
Auke Kok9a799d72007-09-15 14:07:45 -0700179MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
180MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
181MODULE_LICENSE("GPL");
182MODULE_VERSION(DRV_VERSION);
183
Mark Rustad780484d2015-10-21 17:21:10 -0700184static struct workqueue_struct *ixgbe_wq;
185
Mark Rustad14438462014-02-28 15:48:57 -0800186static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800187static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
Mark Rustad14438462014-02-28 15:48:57 -0800188
Jacob Kellerb8e82002013-04-09 07:20:09 +0000189static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
190 u32 reg, u16 *value)
191{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000192 struct pci_dev *parent_dev;
193 struct pci_bus *parent_bus;
194
195 parent_bus = adapter->pdev->bus->parent;
196 if (!parent_bus)
197 return -1;
198
199 parent_dev = parent_bus->self;
200 if (!parent_dev)
201 return -1;
202
Yijing Wangc0798ed2013-09-04 17:30:08 +0000203 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000204 return -1;
205
Yijing Wangc0798ed2013-09-04 17:30:08 +0000206 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800207 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
208 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
209 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000210 return 0;
211}
212
213static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
214{
215 struct ixgbe_hw *hw = &adapter->hw;
216 u16 link_status = 0;
217 int err;
218
219 hw->bus.type = ixgbe_bus_type_pci_express;
220
221 /* Get the negotiated link width and speed from PCI config space of the
222 * parent, as this device is behind a switch
223 */
224 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
225
226 /* assume caller will handle error case */
227 if (err)
228 return err;
229
230 hw->bus.width = ixgbe_convert_bus_width(link_status);
231 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
232
233 return 0;
234}
235
Jacob Kellere027d1a2013-07-31 06:53:31 +0000236/**
237 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
238 * @hw: hw specific details
239 *
240 * This function is used by probe to determine whether a device's PCI-Express
241 * bandwidth details should be gathered from the parent bus instead of from the
242 * device. Used to ensure that various locations all have the correct device ID
243 * checks.
244 */
245static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
246{
247 switch (hw->device_id) {
248 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000249 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000250 return true;
251 default:
252 return false;
253 }
254}
255
256static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
257 int expected_gts)
258{
Don Skidmoref9328bc2015-06-18 13:24:06 -0400259 struct ixgbe_hw *hw = &adapter->hw;
Jacob Kellere027d1a2013-07-31 06:53:31 +0000260 int max_gts = 0;
261 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
262 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
263 struct pci_dev *pdev;
264
Don Skidmoref9328bc2015-06-18 13:24:06 -0400265 /* Some devices are not connected over PCIe and thus do not negotiate
266 * speed. These devices do not have valid bus info, and thus any report
267 * we generate may not be correct.
268 */
269 if (hw->bus.type == ixgbe_bus_type_internal)
270 return;
271
Jacob Keller56d13922015-06-10 11:44:45 -0700272 /* determine whether to use the parent device */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000273 if (ixgbe_pcie_from_parent(&adapter->hw))
274 pdev = adapter->pdev->bus->parent->self;
275 else
276 pdev = adapter->pdev;
277
278 if (pcie_get_minimum_link(pdev, &speed, &width) ||
279 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
280 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
281 return;
282 }
283
284 switch (speed) {
285 case PCIE_SPEED_2_5GT:
286 /* 8b/10b encoding reduces max throughput by 20% */
287 max_gts = 2 * width;
288 break;
289 case PCIE_SPEED_5_0GT:
290 /* 8b/10b encoding reduces max throughput by 20% */
291 max_gts = 4 * width;
292 break;
293 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000294 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000295 max_gts = 8 * width;
296 break;
297 default:
298 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
299 return;
300 }
301
302 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
303 max_gts);
304 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
305 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
306 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
307 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
308 "Unknown"),
309 width,
310 (speed == PCIE_SPEED_2_5GT ? "20%" :
311 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000312 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000313 "Unknown"));
314
315 if (max_gts < expected_gts) {
316 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
317 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
318 expected_gts);
319 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
320 }
321}
322
Alexander Duyck70864002011-04-27 09:13:56 +0000323static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
324{
325 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800326 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000327 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
Mark Rustad780484d2015-10-21 17:21:10 -0700328 queue_work(ixgbe_wq, &adapter->service_task);
Alexander Duyck70864002011-04-27 09:13:56 +0000329}
330
Mark Rustad2a1a0912014-01-14 18:53:15 -0800331static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
332{
333 struct ixgbe_adapter *adapter = hw->back;
334
335 if (!hw->hw_addr)
336 return;
337 hw->hw_addr = NULL;
338 e_dev_err("Adapter removed\n");
Mark Rustad58cf6632014-03-12 00:38:40 +0000339 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
340 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800341}
342
Mark Rustadf8e24722014-03-18 07:03:40 +0000343static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800344{
345 u32 value;
346
347 /* The following check not only optimizes a bit by not
348 * performing a read on the status register when the
349 * register just read was a status register read that
350 * returned IXGBE_FAILED_READ_REG. It also blocks any
351 * potential recursion.
352 */
353 if (reg == IXGBE_STATUS) {
354 ixgbe_remove_adapter(hw);
355 return;
356 }
357 value = ixgbe_read_reg(hw, IXGBE_STATUS);
358 if (value == IXGBE_FAILED_READ_REG)
359 ixgbe_remove_adapter(hw);
360}
361
Mark Rustadf8e24722014-03-18 07:03:40 +0000362/**
363 * ixgbe_read_reg - Read from device register
364 * @hw: hw specific details
365 * @reg: offset of register to read
366 *
367 * Returns : value read or IXGBE_FAILED_READ_REG if removed
368 *
369 * This function is used to read device registers. It checks for device
370 * removal by confirming any read that returns all ones by checking the
371 * status register value for all ones. This function avoids reading from
372 * the hardware if a removal was previously detected in which case it
373 * returns IXGBE_FAILED_READ_REG (all ones).
374 */
375u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
376{
377 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
378 u32 value;
379
380 if (ixgbe_removed(reg_addr))
381 return IXGBE_FAILED_READ_REG;
Mark Rustad2f2219b2016-04-07 10:43:50 -0700382 if (unlikely(hw->phy.nw_mng_if_sel &
383 IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) {
384 struct ixgbe_adapter *adapter;
385 int i;
386
387 for (i = 0; i < 200; ++i) {
388 value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
389 if (likely(!value))
390 goto writes_completed;
391 if (value == IXGBE_FAILED_READ_REG) {
392 ixgbe_remove_adapter(hw);
393 return IXGBE_FAILED_READ_REG;
394 }
395 udelay(5);
396 }
397
398 adapter = hw->back;
399 e_warn(hw, "register writes incomplete %08x\n", value);
400 }
401
402writes_completed:
Mark Rustadf8e24722014-03-18 07:03:40 +0000403 value = readl(reg_addr + reg);
404 if (unlikely(value == IXGBE_FAILED_READ_REG))
405 ixgbe_check_remove(hw, reg);
406 return value;
407}
408
Mark Rustad14438462014-02-28 15:48:57 -0800409static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
410{
411 u16 value;
412
413 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
414 if (value == IXGBE_FAILED_READ_CFG_WORD) {
415 ixgbe_remove_adapter(hw);
416 return true;
417 }
418 return false;
419}
420
421u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
422{
423 struct ixgbe_adapter *adapter = hw->back;
424 u16 value;
425
426 if (ixgbe_removed(hw->hw_addr))
427 return IXGBE_FAILED_READ_CFG_WORD;
428 pci_read_config_word(adapter->pdev, reg, &value);
429 if (value == IXGBE_FAILED_READ_CFG_WORD &&
430 ixgbe_check_cfg_remove(hw, adapter->pdev))
431 return IXGBE_FAILED_READ_CFG_WORD;
432 return value;
433}
434
435#ifdef CONFIG_PCI_IOV
436static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
437{
438 struct ixgbe_adapter *adapter = hw->back;
439 u32 value;
440
441 if (ixgbe_removed(hw->hw_addr))
442 return IXGBE_FAILED_READ_CFG_DWORD;
443 pci_read_config_dword(adapter->pdev, reg, &value);
444 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
445 ixgbe_check_cfg_remove(hw, adapter->pdev))
446 return IXGBE_FAILED_READ_CFG_DWORD;
447 return value;
448}
449#endif /* CONFIG_PCI_IOV */
450
Jacob Kellered192312014-02-22 01:23:53 +0000451void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
452{
453 struct ixgbe_adapter *adapter = hw->back;
454
455 if (ixgbe_removed(hw->hw_addr))
456 return;
457 pci_write_config_word(adapter->pdev, reg, value);
458}
459
Alexander Duyck70864002011-04-27 09:13:56 +0000460static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
461{
462 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
463
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000464 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100465 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000466 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
467}
468
Taku Izumidcd79ae2010-04-27 14:39:53 +0000469struct ixgbe_reg_info {
470 u32 ofs;
471 char *name;
472};
473
474static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
475
476 /* General Registers */
477 {IXGBE_CTRL, "CTRL"},
478 {IXGBE_STATUS, "STATUS"},
479 {IXGBE_CTRL_EXT, "CTRL_EXT"},
480
481 /* Interrupt Registers */
482 {IXGBE_EICR, "EICR"},
483
484 /* RX Registers */
485 {IXGBE_SRRCTL(0), "SRRCTL"},
486 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
487 {IXGBE_RDLEN(0), "RDLEN"},
488 {IXGBE_RDH(0), "RDH"},
489 {IXGBE_RDT(0), "RDT"},
490 {IXGBE_RXDCTL(0), "RXDCTL"},
491 {IXGBE_RDBAL(0), "RDBAL"},
492 {IXGBE_RDBAH(0), "RDBAH"},
493
494 /* TX Registers */
495 {IXGBE_TDBAL(0), "TDBAL"},
496 {IXGBE_TDBAH(0), "TDBAH"},
497 {IXGBE_TDLEN(0), "TDLEN"},
498 {IXGBE_TDH(0), "TDH"},
499 {IXGBE_TDT(0), "TDT"},
500 {IXGBE_TXDCTL(0), "TXDCTL"},
501
502 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000503 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000504};
505
506
507/*
508 * ixgbe_regdump - register printout routine
509 */
510static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
511{
Joe Perches332f2352017-01-03 07:28:11 -0800512 int i;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000513 char rname[16];
514 u32 regs[64];
515
516 switch (reginfo->ofs) {
517 case IXGBE_SRRCTL(0):
518 for (i = 0; i < 64; i++)
519 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
520 break;
521 case IXGBE_DCA_RXCTRL(0):
522 for (i = 0; i < 64; i++)
523 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
524 break;
525 case IXGBE_RDLEN(0):
526 for (i = 0; i < 64; i++)
527 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
528 break;
529 case IXGBE_RDH(0):
530 for (i = 0; i < 64; i++)
531 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
532 break;
533 case IXGBE_RDT(0):
534 for (i = 0; i < 64; i++)
535 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
536 break;
537 case IXGBE_RXDCTL(0):
538 for (i = 0; i < 64; i++)
539 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
540 break;
541 case IXGBE_RDBAL(0):
542 for (i = 0; i < 64; i++)
543 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
544 break;
545 case IXGBE_RDBAH(0):
546 for (i = 0; i < 64; i++)
547 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
548 break;
549 case IXGBE_TDBAL(0):
550 for (i = 0; i < 64; i++)
551 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
552 break;
553 case IXGBE_TDBAH(0):
554 for (i = 0; i < 64; i++)
555 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
556 break;
557 case IXGBE_TDLEN(0):
558 for (i = 0; i < 64; i++)
559 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
560 break;
561 case IXGBE_TDH(0):
562 for (i = 0; i < 64; i++)
563 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
564 break;
565 case IXGBE_TDT(0):
566 for (i = 0; i < 64; i++)
567 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
568 break;
569 case IXGBE_TXDCTL(0):
570 for (i = 0; i < 64; i++)
571 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
572 break;
573 default:
Joe Perches332f2352017-01-03 07:28:11 -0800574 pr_info("%-15s %08x\n",
575 reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000576 return;
577 }
578
Joe Perches332f2352017-01-03 07:28:11 -0800579 i = 0;
580 while (i < 64) {
581 int j;
582 char buf[9 * 8 + 1];
583 char *p = buf;
584
585 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000586 for (j = 0; j < 8; j++)
Joe Perches332f2352017-01-03 07:28:11 -0800587 p += sprintf(p, " %08x", regs[i++]);
588 pr_err("%-15s%s\n", rname, buf);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000589 }
590
591}
592
593/*
594 * ixgbe_dump - Print registers, tx-rings and rx-rings
595 */
596static void ixgbe_dump(struct ixgbe_adapter *adapter)
597{
598 struct net_device *netdev = adapter->netdev;
599 struct ixgbe_hw *hw = &adapter->hw;
600 struct ixgbe_reg_info *reginfo;
601 int n = 0;
602 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000603 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000604 union ixgbe_adv_tx_desc *tx_desc;
605 struct my_u0 { u64 a; u64 b; } *u0;
606 struct ixgbe_ring *rx_ring;
607 union ixgbe_adv_rx_desc *rx_desc;
608 struct ixgbe_rx_buffer *rx_buffer_info;
609 u32 staterr;
610 int i = 0;
611
612 if (!netif_msg_hw(adapter))
613 return;
614
615 /* Print netdevice Info */
616 if (netdev) {
617 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000618 pr_info("Device Name state "
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100619 "trans_start\n");
620 pr_info("%-15s %016lX %016lX\n",
Joe Perchesc7689572010-09-07 21:35:17 +0000621 netdev->name,
622 netdev->state,
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100623 dev_trans_start(netdev));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000624 }
625
626 /* Print Registers */
627 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000628 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000629 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
630 reginfo->name; reginfo++) {
631 ixgbe_regdump(hw, reginfo);
632 }
633
634 /* Print TX Ring Summary */
635 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000636 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000637
638 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000639 pr_info(" %s %s %s %s\n",
640 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
641 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000642 for (n = 0; n < adapter->num_tx_queues; n++) {
643 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000644 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000645 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000646 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000647 (u64)dma_unmap_addr(tx_buffer, dma),
648 dma_unmap_len(tx_buffer, len),
649 tx_buffer->next_to_watch,
650 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000651 }
652
653 /* Print TX Rings */
654 if (!netif_msg_tx_done(adapter))
655 goto rx_ring_summary;
656
657 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
658
659 /* Transmit Descriptor Formats
660 *
Josh Hay39ac8682012-09-26 05:59:36 +0000661 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000662 * +--------------------------------------------------------------+
663 * 0 | Buffer Address [63:0] |
664 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000665 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000666 * +--------------------------------------------------------------+
667 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000668 *
669 * 82598 Advanced Transmit Descriptor (Write-Back Format)
670 * +--------------------------------------------------------------+
671 * 0 | RSV [63:0] |
672 * +--------------------------------------------------------------+
673 * 8 | RSV | STA | NXTSEQ |
674 * +--------------------------------------------------------------+
675 * 63 36 35 32 31 0
676 *
677 * 82599+ Advanced Transmit Descriptor
678 * +--------------------------------------------------------------+
679 * 0 | Buffer Address [63:0] |
680 * +--------------------------------------------------------------+
681 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
682 * +--------------------------------------------------------------+
683 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
684 *
685 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
686 * +--------------------------------------------------------------+
687 * 0 | RSV [63:0] |
688 * +--------------------------------------------------------------+
689 * 8 | RSV | STA | RSV |
690 * +--------------------------------------------------------------+
691 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000692 */
693
694 for (n = 0; n < adapter->num_tx_queues; n++) {
695 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000696 pr_info("------------------------------------\n");
697 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
698 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000699 pr_info("%s%s %s %s %s %s\n",
700 "T [desc] [address 63:0 ] ",
701 "[PlPOIdStDDt Ln] [bi->dma ] ",
702 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000703
704 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000705 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000706 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000707 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000708 if (dma_unmap_len(tx_buffer, len) > 0) {
Joe Perches332f2352017-01-03 07:28:11 -0800709 const char *ring_desc;
710
711 if (i == tx_ring->next_to_use &&
712 i == tx_ring->next_to_clean)
713 ring_desc = " NTC/U";
714 else if (i == tx_ring->next_to_use)
715 ring_desc = " NTU";
716 else if (i == tx_ring->next_to_clean)
717 ring_desc = " NTC";
718 else
719 ring_desc = "";
720 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
Josh Hay8ad88e32012-09-26 05:59:41 +0000721 i,
722 le64_to_cpu(u0->a),
723 le64_to_cpu(u0->b),
724 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000725 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000726 tx_buffer->next_to_watch,
727 (u64)tx_buffer->time_stamp,
Joe Perches332f2352017-01-03 07:28:11 -0800728 tx_buffer->skb,
729 ring_desc);
Josh Hay8ad88e32012-09-26 05:59:41 +0000730
731 if (netif_msg_pktdata(adapter) &&
732 tx_buffer->skb)
733 print_hex_dump(KERN_INFO, "",
734 DUMP_PREFIX_ADDRESS, 16, 1,
735 tx_buffer->skb->data,
736 dma_unmap_len(tx_buffer, len),
737 true);
738 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000739 }
740 }
741
742 /* Print RX Rings Summary */
743rx_ring_summary:
744 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000745 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000746 for (n = 0; n < adapter->num_rx_queues; n++) {
747 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000748 pr_info("%5d %5X %5X\n",
749 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000750 }
751
752 /* Print RX Rings */
753 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000754 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000755
756 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
757
Josh Hay39ac8682012-09-26 05:59:36 +0000758 /* Receive Descriptor Formats
759 *
760 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000761 * 63 1 0
762 * +-----------------------------------------------------+
763 * 0 | Packet Buffer Address [63:1] |A0/NSE|
764 * +----------------------------------------------+------+
765 * 8 | Header Buffer Address [63:1] | DD |
766 * +-----------------------------------------------------+
767 *
768 *
Josh Hay39ac8682012-09-26 05:59:36 +0000769 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000770 *
771 * 63 48 47 32 31 30 21 20 16 15 4 3 0
772 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000773 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
774 * | Packet | IP | | | | Type | Type |
775 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000776 * +------------------------------------------------------+
777 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
778 * +------------------------------------------------------+
779 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000780 *
781 * 82599+ Advanced Receive Descriptor (Read) Format
782 * 63 1 0
783 * +-----------------------------------------------------+
784 * 0 | Packet Buffer Address [63:1] |A0/NSE|
785 * +----------------------------------------------+------+
786 * 8 | Header Buffer Address [63:1] | DD |
787 * +-----------------------------------------------------+
788 *
789 *
790 * 82599+ Advanced Receive Descriptor (Write-Back) Format
791 *
792 * 63 48 47 32 31 30 21 20 17 16 4 3 0
793 * +------------------------------------------------------+
794 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
795 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
796 * |/ Flow Dir Flt ID | | | | | |
797 * +------------------------------------------------------+
798 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
799 * +------------------------------------------------------+
800 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000801 */
Josh Hay39ac8682012-09-26 05:59:36 +0000802
Taku Izumidcd79ae2010-04-27 14:39:53 +0000803 for (n = 0; n < adapter->num_rx_queues; n++) {
804 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000805 pr_info("------------------------------------\n");
806 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
807 pr_info("------------------------------------\n");
Joe Perches332f2352017-01-03 07:28:11 -0800808 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000809 "R [desc] [ PktBuf A0] ",
810 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800811 "<-- Adv Rx Read format");
812 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000813 "RWB[desc] [PcsmIpSHl PtRs] ",
814 "[vl er S cks ln] ---------------- [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800815 "<-- Adv Rx Write-Back format");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000816
817 for (i = 0; i < rx_ring->count; i++) {
Joe Perches332f2352017-01-03 07:28:11 -0800818 const char *ring_desc;
819
820 if (i == rx_ring->next_to_use)
821 ring_desc = " NTU";
822 else if (i == rx_ring->next_to_clean)
823 ring_desc = " NTC";
824 else
825 ring_desc = "";
826
Taku Izumidcd79ae2010-04-27 14:39:53 +0000827 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000828 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000829 u0 = (struct my_u0 *)rx_desc;
830 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
831 if (staterr & IXGBE_RXD_STAT_DD) {
832 /* Descriptor Done */
Joe Perches332f2352017-01-03 07:28:11 -0800833 pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
834 i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000835 le64_to_cpu(u0->a),
836 le64_to_cpu(u0->b),
Joe Perches332f2352017-01-03 07:28:11 -0800837 rx_buffer_info->skb,
838 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000839 } else {
Joe Perches332f2352017-01-03 07:28:11 -0800840 pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
841 i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000842 le64_to_cpu(u0->a),
843 le64_to_cpu(u0->b),
844 (u64)rx_buffer_info->dma,
Joe Perches332f2352017-01-03 07:28:11 -0800845 rx_buffer_info->skb,
846 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000847
Emil Tantilov9c50c032012-07-26 01:21:24 +0000848 if (netif_msg_pktdata(adapter) &&
849 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000850 print_hex_dump(KERN_INFO, "",
851 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000852 page_address(rx_buffer_info->page) +
853 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000854 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000855 }
856 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000857 }
858 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000859}
860
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800861static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
862{
863 u32 ctrl_ext;
864
865 /* Let firmware take over control of h/w */
866 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
867 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000868 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800869}
870
871static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
872{
873 u32 ctrl_ext;
874
875 /* Let firmware know the driver has taken over */
876 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
877 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000878 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800879}
Auke Kok9a799d72007-09-15 14:07:45 -0700880
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000881/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000882 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
883 * @adapter: pointer to adapter struct
884 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
885 * @queue: queue to map the corresponding interrupt to
886 * @msix_vector: the vector to map to the corresponding queue
887 *
888 */
889static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000890 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700891{
892 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000893 struct ixgbe_hw *hw = &adapter->hw;
894 switch (hw->mac.type) {
895 case ixgbe_mac_82598EB:
896 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
897 if (direction == -1)
898 direction = 0;
899 index = (((direction * 64) + queue) >> 2) & 0x1F;
900 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
901 ivar &= ~(0xFF << (8 * (queue & 0x3)));
902 ivar |= (msix_vector << (8 * (queue & 0x3)));
903 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
904 break;
905 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800906 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000907 case ixgbe_mac_X550:
908 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700909 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000910 if (direction == -1) {
911 /* other causes */
912 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
913 index = ((queue & 1) * 8);
914 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
915 ivar &= ~(0xFF << index);
916 ivar |= (msix_vector << index);
917 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
918 break;
919 } else {
920 /* tx or rx causes */
921 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
922 index = ((16 * (queue & 1)) + (8 * direction));
923 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
924 ivar &= ~(0xFF << index);
925 ivar |= (msix_vector << index);
926 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
927 break;
928 }
929 default:
930 break;
931 }
Auke Kok9a799d72007-09-15 14:07:45 -0700932}
933
Alexander Duyckfe49f042009-06-04 16:00:09 +0000934static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000935 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000936{
937 u32 mask;
938
Alexander Duyckbd508172010-11-16 19:27:03 -0800939 switch (adapter->hw.mac.type) {
940 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000941 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
942 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800943 break;
944 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800945 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000946 case ixgbe_mac_X550:
947 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700948 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000949 mask = (qmask & 0xFFFFFFFF);
950 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
951 mask = (qmask >> 32);
952 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800953 break;
954 default:
955 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000956 }
957}
958
Alexander Duyck943561d2012-05-09 22:14:44 -0700959static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
960{
961 struct ixgbe_hw *hw = &adapter->hw;
962 struct ixgbe_hw_stats *hwstats = &adapter->stats;
963 int i;
964 u32 data;
965
966 if ((hw->fc.current_mode != ixgbe_fc_full) &&
967 (hw->fc.current_mode != ixgbe_fc_rx_pause))
968 return;
969
970 switch (hw->mac.type) {
971 case ixgbe_mac_82598EB:
972 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
973 break;
974 default:
975 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
976 }
977 hwstats->lxoffrxc += data;
978
979 /* refill credits (no tx hang) if we received xoff */
980 if (!data)
981 return;
982
983 for (i = 0; i < adapter->num_tx_queues; i++)
984 clear_bit(__IXGBE_HANG_CHECK_ARMED,
985 &adapter->tx_ring[i]->state);
986}
987
John Fastabendc84d3242010-11-16 19:27:12 -0800988static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700989{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700990 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800991 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800992 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000993 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800994 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700995 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700996
Alexander Duyck943561d2012-05-09 22:14:44 -0700997 if (adapter->ixgbe_ieee_pfc)
998 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800999
Alexander Duyck943561d2012-05-09 22:14:44 -07001000 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
1001 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -08001002 return;
Alexander Duyck943561d2012-05-09 22:14:44 -07001003 }
John Fastabendc84d3242010-11-16 19:27:12 -08001004
1005 /* update stats for each tc, only valid with PFC enabled */
1006 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001007 u32 pxoffrxc;
1008
John Fastabendc84d3242010-11-16 19:27:12 -08001009 switch (hw->mac.type) {
1010 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001011 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001012 break;
1013 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001014 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001015 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001016 hwstats->pxoffrxc[i] += pxoffrxc;
1017 /* Get the TC for given UP */
1018 tc = netdev_get_prio_tc_map(adapter->netdev, i);
1019 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -07001020 }
1021
John Fastabendc84d3242010-11-16 19:27:12 -08001022 /* disarm tx queues that have received xoff frames */
1023 for (i = 0; i < adapter->num_tx_queues; i++) {
1024 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -08001025
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001026 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001027 if (xoff[tc])
1028 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1029 }
1030}
1031
1032static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1033{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001034 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001035}
1036
1037static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1038{
John Fastabend2a47fa42013-11-06 09:54:52 -08001039 struct ixgbe_adapter *adapter;
1040 struct ixgbe_hw *hw;
1041 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001042
John Fastabend2a47fa42013-11-06 09:54:52 -08001043 if (ring->l2_accel_priv)
1044 adapter = ring->l2_accel_priv->real_adapter;
1045 else
1046 adapter = netdev_priv(ring->netdev);
1047
1048 hw = &adapter->hw;
1049 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1050 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001051
1052 if (head != tail)
1053 return (head < tail) ?
1054 tail - head : (tail + ring->count - head);
1055
1056 return 0;
1057}
1058
1059static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1060{
1061 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1062 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1063 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001064
1065 clear_check_for_tx_hang(tx_ring);
1066
1067 /*
1068 * Check for a hung queue, but be thorough. This verifies
1069 * that a transmit has been completed since the previous
1070 * check AND there is at least one packet pending. The
1071 * ARMED bit is set to indicate a potential hang. The
1072 * bit is cleared if a pause frame is received to remove
1073 * false hang detection due to PFC or 802.3x frames. By
1074 * requiring this to fail twice we avoid races with
1075 * pfc clearing the ARMED bit and conditions where we
1076 * run the check_tx_hang logic with a transmit completion
1077 * pending but without time to complete it yet.
1078 */
Mark Rustade90dd262014-07-22 06:51:08 +00001079 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001080 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001081 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1082 &tx_ring->state);
1083 /* update completed stats and continue */
1084 tx_ring->tx_stats.tx_done_old = tx_done;
1085 /* reset the countdown */
1086 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001087
Mark Rustade90dd262014-07-22 06:51:08 +00001088 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001089}
1090
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001091/**
1092 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1093 * @adapter: driver private struct
1094 **/
1095static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1096{
1097
1098 /* Do the reset outside of interrupt context */
1099 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
Emil Tantilov57ca2a42016-07-29 14:46:31 -07001100 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Jacob Keller12ff3f32012-12-01 07:57:17 +00001101 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001102 ixgbe_service_event_schedule(adapter);
1103 }
1104}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001105
Auke Kok9a799d72007-09-15 14:07:45 -07001106/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001107 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1108 **/
1109static int ixgbe_tx_maxrate(struct net_device *netdev,
1110 int queue_index, u32 maxrate)
1111{
1112 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1113 struct ixgbe_hw *hw = &adapter->hw;
1114 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1115
1116 if (!maxrate)
1117 return 0;
1118
1119 /* Calculate the rate factor values to set */
1120 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1121 bcnrc_val /= maxrate;
1122
1123 /* clear everything but the rate factor */
1124 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1125 IXGBE_RTTBCNRC_RF_DEC_MASK;
1126
1127 /* enable the rate scheduler */
1128 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1129
1130 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1131 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1132
1133 return 0;
1134}
1135
1136/**
Auke Kok9a799d72007-09-15 14:07:45 -07001137 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001138 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001139 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001140 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001141 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001142static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001143 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001144{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001145 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001146 struct ixgbe_tx_buffer *tx_buffer;
1147 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001148 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001149 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001150 unsigned int i = tx_ring->next_to_clean;
1151
1152 if (test_bit(__IXGBE_DOWN, &adapter->state))
1153 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001154
Alexander Duyckd3d00232011-07-15 02:31:25 +00001155 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001156 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001157 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001158
Alexander Duyck729739b2012-02-08 07:51:06 +00001159 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001160 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001161
Alexander Duyckd3d00232011-07-15 02:31:25 +00001162 /* if next_to_watch is not set then there is no work pending */
1163 if (!eop_desc)
1164 break;
1165
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001166 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001167 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001168
Alexander Duyckd3d00232011-07-15 02:31:25 +00001169 /* if DD is not set pending work has not been completed */
1170 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1171 break;
1172
Alexander Duyckd3d00232011-07-15 02:31:25 +00001173 /* clear next_to_watch to prevent false hangs */
1174 tx_buffer->next_to_watch = NULL;
1175
Alexander Duyck091a6242012-02-08 07:51:01 +00001176 /* update the statistics for this packet */
1177 total_bytes += tx_buffer->bytecount;
1178 total_packets += tx_buffer->gso_segs;
1179
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001180 /* free the skb */
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001181 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001182
Alexander Duyck729739b2012-02-08 07:51:06 +00001183 /* unmap skb header data */
1184 dma_unmap_single(tx_ring->dev,
1185 dma_unmap_addr(tx_buffer, dma),
1186 dma_unmap_len(tx_buffer, len),
1187 DMA_TO_DEVICE);
1188
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001189 /* clear tx_buffer data */
Alexander Duyck729739b2012-02-08 07:51:06 +00001190 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001191
Alexander Duyck729739b2012-02-08 07:51:06 +00001192 /* unmap remaining buffers */
1193 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001194 tx_buffer++;
1195 tx_desc++;
1196 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001197 if (unlikely(!i)) {
1198 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001199 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001200 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001201 }
1202
Alexander Duyck729739b2012-02-08 07:51:06 +00001203 /* unmap any remaining paged data */
1204 if (dma_unmap_len(tx_buffer, len)) {
1205 dma_unmap_page(tx_ring->dev,
1206 dma_unmap_addr(tx_buffer, dma),
1207 dma_unmap_len(tx_buffer, len),
1208 DMA_TO_DEVICE);
1209 dma_unmap_len_set(tx_buffer, len, 0);
1210 }
1211 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001212
Alexander Duyck729739b2012-02-08 07:51:06 +00001213 /* move us one more past the eop_desc for start of next pkt */
1214 tx_buffer++;
1215 tx_desc++;
1216 i++;
1217 if (unlikely(!i)) {
1218 i -= tx_ring->count;
1219 tx_buffer = tx_ring->tx_buffer_info;
1220 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1221 }
1222
1223 /* issue prefetch for next Tx descriptor */
1224 prefetch(tx_desc);
1225
1226 /* update budget accounting */
1227 budget--;
1228 } while (likely(budget));
1229
1230 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001231 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001232 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001233 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001234 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001235 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001236 q_vector->tx.total_bytes += total_bytes;
1237 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001238
John Fastabendc84d3242010-11-16 19:27:12 -08001239 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001240 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001241 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001242 e_err(drv, "Detected Tx Unit Hang\n"
1243 " Tx Queue <%d>\n"
1244 " TDH, TDT <%x>, <%x>\n"
1245 " next_to_use <%x>\n"
1246 " next_to_clean <%x>\n"
1247 "tx_buffer_info[next_to_clean]\n"
1248 " time_stamp <%lx>\n"
1249 " jiffies <%lx>\n",
1250 tx_ring->queue_index,
1251 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1252 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001253 tx_ring->next_to_use, i,
1254 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001255
1256 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1257
1258 e_info(probe,
1259 "tx hang %d detected on queue %d, resetting adapter\n",
1260 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1261
1262 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001263 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001264
1265 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001266 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001267 }
Auke Kok9a799d72007-09-15 14:07:45 -07001268
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001269 netdev_tx_completed_queue(txring_txq(tx_ring),
1270 total_packets, total_bytes);
1271
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001272#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001273 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001274 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001275 /* Make sure that anybody stopping the queue after this
1276 * sees the new next_to_clean.
1277 */
1278 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001279 if (__netif_subqueue_stopped(tx_ring->netdev,
1280 tx_ring->queue_index)
1281 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1282 netif_wake_subqueue(tx_ring->netdev,
1283 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001284 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001285 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001286 }
Auke Kok9a799d72007-09-15 14:07:45 -07001287
Alexander Duyck59224552011-08-31 00:01:06 +00001288 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001289}
1290
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001291#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001292static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001293 struct ixgbe_ring *tx_ring,
1294 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001295{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001296 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001297 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001298 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001299
Mark Rustad9de76052015-08-08 16:27:41 -07001300 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1301 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1302
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001303 switch (hw->mac.type) {
1304 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001305 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001306 break;
1307 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001308 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001309 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1310 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1311 break;
1312 default:
1313 /* for unknown hardware do not write register */
1314 return;
1315 }
1316
1317 /*
1318 * We can enable relaxed ordering for reads, but not writes when
1319 * DCA is enabled. This is due to a known issue in some chipsets
1320 * which will cause the DCA tag to be cleared.
1321 */
1322 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1323 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1324 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1325
1326 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1327}
1328
1329static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1330 struct ixgbe_ring *rx_ring,
1331 int cpu)
1332{
1333 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001334 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001335 u8 reg_idx = rx_ring->reg_idx;
1336
Mark Rustad9de76052015-08-08 16:27:41 -07001337 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1338 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001339
1340 switch (hw->mac.type) {
1341 case ixgbe_mac_82599EB:
1342 case ixgbe_mac_X540:
1343 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001344 break;
1345 default:
1346 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001347 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001348
1349 /*
1350 * We can enable relaxed ordering for reads, but not writes when
1351 * DCA is enabled. This is due to a known issue in some chipsets
1352 * which will cause the DCA tag to be cleared.
1353 */
1354 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Mark Rustad9de76052015-08-08 16:27:41 -07001355 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001356 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1357
1358 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001359}
1360
1361static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1362{
1363 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001364 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001365 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001366
1367 if (q_vector->cpu == cpu)
1368 goto out_no_update;
1369
Alexander Duycka5579282012-02-08 07:50:04 +00001370 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001371 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001372
Alexander Duycka5579282012-02-08 07:50:04 +00001373 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001374 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001375
1376 q_vector->cpu = cpu;
1377out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001378 put_cpu();
1379}
1380
1381static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1382{
1383 int i;
1384
Alexander Duycke35ec122009-05-21 13:07:12 +00001385 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001386 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1387 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1388 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1389 else
1390 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1391 IXGBE_DCA_CTRL_DCA_DISABLE);
Alexander Duycke35ec122009-05-21 13:07:12 +00001392
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001393 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001394 adapter->q_vector[i]->cpu = -1;
1395 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001396 }
1397}
1398
1399static int __ixgbe_notify_dca(struct device *dev, void *data)
1400{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001401 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001402 unsigned long event = *(unsigned long *)data;
1403
Don Skidmore2a72c312011-07-20 02:27:05 +00001404 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001405 return 0;
1406
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001407 switch (event) {
1408 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001409 /* if we're already enabled, don't do it again */
1410 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1411 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001412 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001413 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001414 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1415 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001416 break;
1417 }
1418 /* Fall Through since DCA is disabled. */
1419 case DCA_PROVIDER_REMOVE:
1420 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1421 dca_remove_requester(dev);
1422 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001423 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1424 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001425 }
1426 break;
1427 }
1428
Denis V. Lunev652f0932008-03-27 14:39:17 +03001429 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001430}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001431
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001432#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b82015-04-29 10:57:39 +08001433
1434#define IXGBE_RSS_L4_TYPES_MASK \
1435 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1436 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1437 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1438 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1439
Alexander Duyck8a0da212012-01-31 02:59:49 +00001440static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1441 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001442 struct sk_buff *skb)
1443{
Fan Du7edda4b82015-04-29 10:57:39 +08001444 u16 rss_type;
1445
1446 if (!(ring->netdev->features & NETIF_F_RXHASH))
1447 return;
1448
1449 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1450 IXGBE_RXDADV_RSSTYPE_MASK;
1451
1452 if (!rss_type)
1453 return;
1454
1455 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1456 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1457 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001458}
1459
Alexander Duyckf8003262012-03-03 02:35:52 +00001460#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001461/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001462 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001463 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001464 * @rx_desc: advanced rx descriptor
1465 *
1466 * Returns : true if it is FCoE pkt
1467 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001468static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001469 union ixgbe_adv_rx_desc *rx_desc)
1470{
1471 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1472
Alexander Duyck57efd442012-06-25 21:54:46 +00001473 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001474 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1475 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1476 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1477}
1478
Alexander Duyckf8003262012-03-03 02:35:52 +00001479#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001480/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001481 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001482 * @ring: structure containing ring specific data
1483 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001484 * @skb: skb currently being received and modified
1485 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001486static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001487 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001488 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001489{
Don Skidmore3f207802014-12-23 07:40:34 +00001490 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore3f207802014-12-23 07:40:34 +00001491 bool encap_pkt = false;
1492
Alexander Duyck8a0da212012-01-31 02:59:49 +00001493 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001494
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001495 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001496 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001497 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001498
Emil Tantilova21d0822016-08-10 11:19:23 -07001499 /* check for VXLAN and Geneve packets */
1500 if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
Don Skidmore3f207802014-12-23 07:40:34 +00001501 encap_pkt = true;
1502 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001503 }
1504
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001505 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001506 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1507 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001508 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001509 return;
1510 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001511
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001512 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001513 return;
1514
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001515 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001516 /*
1517 * 82599 errata, UDP frames with a 0 checksum can be marked as
1518 * checksum errors.
1519 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001520 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1521 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001522 return;
1523
Alexander Duyck8a0da212012-01-31 02:59:49 +00001524 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001525 return;
1526 }
1527
Auke Kok9a799d72007-09-15 14:07:45 -07001528 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001529 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001530 if (encap_pkt) {
1531 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1532 return;
1533
1534 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
Mark Rustadd4692512015-12-04 11:26:43 -08001535 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001536 return;
1537 }
1538 /* If we checked the outer header let the stack know */
1539 skb->csum_level = 1;
1540 }
Auke Kok9a799d72007-09-15 14:07:45 -07001541}
1542
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001543static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
1544{
1545 return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
1546}
1547
Alexander Duyckf990b792012-01-31 02:59:34 +00001548static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1549 struct ixgbe_rx_buffer *bi)
1550{
1551 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001552 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001553
Alexander Duyckf8003262012-03-03 02:35:52 +00001554 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001555 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001556 return true;
1557
Alexander Duyckf8003262012-03-03 02:35:52 +00001558 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001559 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1560 if (unlikely(!page)) {
1561 rx_ring->rx_stats.alloc_rx_page_failed++;
1562 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001563 }
1564
Alexander Duyckf8003262012-03-03 02:35:52 +00001565 /* map page for use */
Alexander Duyckf3213d92017-01-17 08:35:54 -08001566 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
1567 ixgbe_rx_pg_size(rx_ring),
1568 DMA_FROM_DEVICE,
1569 IXGBE_RX_DMA_ATTR);
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 Duyck2de6aa32017-01-17 08:36:54 -08001584 bi->page_offset = ixgbe_rx_offset(rx_ring);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001585 bi->pagecnt_bias = 1;
Alexander Duyckf8003262012-03-03 02:35:52 +00001586
Alexander Duyckf990b792012-01-31 02:59:34 +00001587 return true;
1588}
1589
Auke Kok9a799d72007-09-15 14:07:45 -07001590/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001591 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001592 * @rx_ring: ring to place buffers on
1593 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001594 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001595void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001596{
Auke Kok9a799d72007-09-15 14:07:45 -07001597 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001598 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001599 u16 i = rx_ring->next_to_use;
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001600 u16 bufsz;
Auke Kok9a799d72007-09-15 14:07:45 -07001601
Alexander Duyckf8003262012-03-03 02:35:52 +00001602 /* nothing to do */
1603 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001604 return;
1605
Alexander Duycke4f74022012-01-31 02:59:44 +00001606 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001607 bi = &rx_ring->rx_buffer_info[i];
1608 i -= rx_ring->count;
1609
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001610 bufsz = ixgbe_rx_bufsz(rx_ring);
1611
Alexander Duyckf8003262012-03-03 02:35:52 +00001612 do {
1613 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001614 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001615
Alexander Duyckf3213d92017-01-17 08:35:54 -08001616 /* sync the buffer for use by the device */
1617 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001618 bi->page_offset, bufsz,
Alexander Duyckf3213d92017-01-17 08:35:54 -08001619 DMA_FROM_DEVICE);
1620
Alexander Duyckf8003262012-03-03 02:35:52 +00001621 /*
1622 * Refresh the desc even if buffer_addrs didn't change
1623 * because each write-back erases this info.
1624 */
1625 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001626
Alexander Duyckf990b792012-01-31 02:59:34 +00001627 rx_desc++;
1628 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001629 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001630 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001631 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001632 bi = rx_ring->rx_buffer_info;
1633 i -= rx_ring->count;
1634 }
1635
Alexander Duyckc3630cc2017-01-17 08:36:28 -08001636 /* clear the length for the next_to_use descriptor */
1637 rx_desc->wb.upper.length = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001638
1639 cleaned_count--;
1640 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001641
Alexander Duyckf990b792012-01-31 02:59:34 +00001642 i += rx_ring->count;
1643
Alexander Duyckad435ec2014-11-14 00:56:35 +00001644 if (rx_ring->next_to_use != i) {
1645 rx_ring->next_to_use = i;
1646
1647 /* update next to alloc since we have filled the ring */
1648 rx_ring->next_to_alloc = i;
1649
1650 /* Force memory writes to complete before letting h/w
1651 * know there are new descriptors to fetch. (Only
1652 * applicable for weak-ordered memory model archs,
1653 * such as IA-64).
1654 */
1655 wmb();
1656 writel(i, rx_ring->tail);
1657 }
Auke Kok9a799d72007-09-15 14:07:45 -07001658}
1659
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001660static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1661 struct sk_buff *skb)
1662{
Alexander Duyckf8003262012-03-03 02:35:52 +00001663 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001664
1665 /* set gso_size to avoid messing up TCP MSS */
1666 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1667 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001668 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001669}
1670
1671static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1672 struct sk_buff *skb)
1673{
1674 /* if append_cnt is 0 then frame is not RSC */
1675 if (!IXGBE_CB(skb)->append_cnt)
1676 return;
1677
1678 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1679 rx_ring->rx_stats.rsc_flush++;
1680
1681 ixgbe_set_rsc_gso_size(rx_ring, skb);
1682
1683 /* gso_size is computed using append_cnt so always clear it last */
1684 IXGBE_CB(skb)->append_cnt = 0;
1685}
1686
Alexander Duyck8a0da212012-01-31 02:59:49 +00001687/**
1688 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1689 * @rx_ring: rx descriptor ring packet is being transacted on
1690 * @rx_desc: pointer to the EOP Rx descriptor
1691 * @skb: pointer to current skb being populated
1692 *
1693 * This function checks the ring, descriptor, and packet information in
1694 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1695 * other fields within the skb.
1696 **/
1697static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1698 union ixgbe_adv_rx_desc *rx_desc,
1699 struct sk_buff *skb)
1700{
John Fastabend43e95f12012-05-15 06:12:17 +00001701 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001702 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001703
Alexander Duyck8a0da212012-01-31 02:59:49 +00001704 ixgbe_update_rsc_stats(rx_ring, skb);
1705
1706 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1707
1708 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1709
Mark Rustada9763f32015-10-27 09:58:07 -07001710 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1711 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001712
Patrick McHardyf6469682013-04-19 02:04:27 +00001713 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001714 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001715 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001716 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001717 }
1718
1719 skb_record_rx_queue(skb, rx_ring->queue_index);
1720
John Fastabend43e95f12012-05-15 06:12:17 +00001721 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001722}
1723
1724static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1725 struct sk_buff *skb)
1726{
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08001727 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001728}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001729
Alexander Duyckf8003262012-03-03 02:35:52 +00001730/**
1731 * ixgbe_is_non_eop - process handling of non-EOP buffers
1732 * @rx_ring: Rx ring being processed
1733 * @rx_desc: Rx descriptor for current buffer
1734 * @skb: Current socket buffer containing buffer in progress
1735 *
1736 * This function updates next to clean. If the buffer is an EOP buffer
1737 * this function exits returning false, otherwise it will place the
1738 * sk_buff in the next buffer to be chained and return true indicating
1739 * that this is in fact a non-EOP buffer.
1740 **/
1741static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1742 union ixgbe_adv_rx_desc *rx_desc,
1743 struct sk_buff *skb)
1744{
1745 u32 ntc = rx_ring->next_to_clean + 1;
1746
1747 /* fetch, update, and store next to clean */
1748 ntc = (ntc < rx_ring->count) ? ntc : 0;
1749 rx_ring->next_to_clean = ntc;
1750
1751 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1752
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001753 /* update RSC append count if present */
1754 if (ring_is_rsc_enabled(rx_ring)) {
1755 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1756 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1757
1758 if (unlikely(rsc_enabled)) {
1759 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1760
1761 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1762 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1763
1764 /* update ntc based on RSC value */
1765 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1766 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1767 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1768 }
1769 }
1770
1771 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001772 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1773 return false;
1774
Alexander Duyckf8003262012-03-03 02:35:52 +00001775 /* place skb in next buffer to be received */
1776 rx_ring->rx_buffer_info[ntc].skb = skb;
1777 rx_ring->rx_stats.non_eop_descs++;
1778
1779 return true;
1780}
1781
1782/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001783 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1784 * @rx_ring: rx descriptor ring packet is being transacted on
1785 * @skb: pointer to current skb being adjusted
1786 *
1787 * This function is an ixgbe specific version of __pskb_pull_tail. The
1788 * main difference between this version and the original function is that
1789 * this function can make several assumptions about the state of things
1790 * that allow for significant optimizations versus the standard function.
1791 * As a result we can do things like drop a frag and maintain an accurate
1792 * truesize for the skb.
1793 */
1794static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1795 struct sk_buff *skb)
1796{
1797 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1798 unsigned char *va;
1799 unsigned int pull_len;
1800
1801 /*
1802 * it is valid to use page_address instead of kmap since we are
1803 * working with pages allocated out of the lomem pool per
1804 * alloc_page(GFP_ATOMIC)
1805 */
1806 va = skb_frag_address(frag);
1807
1808 /*
1809 * we need the header to contain the greater of either ETH_HLEN or
1810 * 60 bytes if the skb->len is less than 60 for skb_pad.
1811 */
Alexander Duyck8496e3382014-09-05 19:22:18 -04001812 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001813
1814 /* align pull length to size of long to optimize memcpy performance */
1815 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1816
1817 /* update all of the pointers */
1818 skb_frag_size_sub(frag, pull_len);
1819 frag->page_offset += pull_len;
1820 skb->data_len -= pull_len;
1821 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001822}
1823
1824/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001825 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1826 * @rx_ring: rx descriptor ring packet is being transacted on
1827 * @skb: pointer to current skb being updated
1828 *
1829 * This function provides a basic DMA sync up for the first fragment of an
1830 * skb. The reason for doing this is that the first fragment cannot be
1831 * unmapped until we have reached the end of packet descriptor for a buffer
1832 * chain.
1833 */
1834static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1835 struct sk_buff *skb)
1836{
1837 /* if the page was released unmap it, else just sync our portion */
1838 if (unlikely(IXGBE_CB(skb)->page_released)) {
Alexander Duyckf3213d92017-01-17 08:35:54 -08001839 dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
1840 ixgbe_rx_pg_size(rx_ring),
1841 DMA_FROM_DEVICE,
1842 IXGBE_RX_DMA_ATTR);
Alexander Duyck42073d92012-07-20 08:08:28 +00001843 } else {
1844 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1845
1846 dma_sync_single_range_for_cpu(rx_ring->dev,
1847 IXGBE_CB(skb)->dma,
1848 frag->page_offset,
Alexander Duyckf215af82017-01-17 08:35:44 -08001849 skb_frag_size(frag),
Alexander Duyck42073d92012-07-20 08:08:28 +00001850 DMA_FROM_DEVICE);
1851 }
Alexander Duyck42073d92012-07-20 08:08:28 +00001852}
1853
1854/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001855 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1856 * @rx_ring: rx descriptor ring packet is being transacted on
1857 * @rx_desc: pointer to the EOP Rx descriptor
1858 * @skb: pointer to current skb being fixed
1859 *
1860 * Check for corrupted packet headers caused by senders on the local L2
1861 * embedded NIC switch not setting up their Tx Descriptors right. These
1862 * should be very rare.
1863 *
1864 * Also address the case where we are pulling data in on pages only
1865 * and as such no data is present in the skb header.
1866 *
1867 * In addition if skb is not at least 60 bytes we need to pad it so that
1868 * it is large enough to qualify as a valid Ethernet frame.
1869 *
1870 * Returns true if an error was encountered and skb was freed.
1871 **/
1872static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1873 union ixgbe_adv_rx_desc *rx_desc,
1874 struct sk_buff *skb)
1875{
Alexander Duyckf8003262012-03-03 02:35:52 +00001876 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001877
1878 /* verify that the packet does not have any known errors */
1879 if (unlikely(ixgbe_test_staterr(rx_desc,
1880 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1881 !(netdev->features & NETIF_F_RXALL))) {
1882 dev_kfree_skb_any(skb);
1883 return true;
1884 }
1885
Alexander Duyck19861ce2012-07-20 08:08:33 +00001886 /* place header in linear portion of buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08001887 if (!skb_headlen(skb))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001888 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001889
Alexander Duyck57efd442012-06-25 21:54:46 +00001890#ifdef IXGBE_FCOE
1891 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1892 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1893 return false;
1894
1895#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001896 /* if eth_skb_pad returns an error the skb was freed */
1897 if (eth_skb_pad(skb))
1898 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001899
1900 return false;
1901}
1902
1903/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001904 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1905 * @rx_ring: rx descriptor ring to store buffers on
1906 * @old_buff: donor buffer to have page reused
1907 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001908 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001909 **/
1910static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1911 struct ixgbe_rx_buffer *old_buff)
1912{
1913 struct ixgbe_rx_buffer *new_buff;
1914 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001915
1916 new_buff = &rx_ring->rx_buffer_info[nta];
1917
1918 /* update, and store next to alloc */
1919 nta++;
1920 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1921
Alexander Duyck3fd218762017-01-17 08:36:45 -08001922 /* Transfer page from old buffer to new buffer.
1923 * Move each member individually to avoid possible store
1924 * forwarding stalls and unnecessary copy of skb.
1925 */
1926 new_buff->dma = old_buff->dma;
1927 new_buff->page = old_buff->page;
1928 new_buff->page_offset = old_buff->page_offset;
1929 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
Alexander Duyckf8003262012-03-03 02:35:52 +00001930}
1931
Alexander Duyck18cb6522014-11-14 00:56:29 +00001932static inline bool ixgbe_page_is_reserved(struct page *page)
1933{
Michal Hocko2f064f32015-08-21 14:11:51 -07001934 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001935}
1936
Alexander Duyck3fd218762017-01-17 08:36:45 -08001937static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
Alexander Duyckf8003262012-03-03 02:35:52 +00001938{
Alexander Duyck3fd218762017-01-17 08:36:45 -08001939 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
1940 struct page *page = rx_buffer->page;
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001941
Alexander Duyck09816fb2012-07-20 08:08:23 +00001942 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001943 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001944 return false;
1945
1946#if (PAGE_SIZE < 8192)
1947 /* if we are only owner of page we can reuse it */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001948 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001949 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001950#else
Alexander Duyck3fd218762017-01-17 08:36:45 -08001951 /* The last offset is a bit aggressive in that we assume the
1952 * worst case of FCoE being enabled and using a 3K buffer.
1953 * However this should have minimal impact as the 1K extra is
1954 * still less than one buffer in size.
1955 */
1956#define IXGBE_LAST_OFFSET \
1957 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
1958 if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
Alexander Duyck09816fb2012-07-20 08:08:23 +00001959 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001960#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001961
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001962 /* If we have drained the page fragment pool we need to update
1963 * the pagecnt_bias and page count so that we fully restock the
1964 * number of references the driver holds.
Alexander Duyck18cb6522014-11-14 00:56:29 +00001965 */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001966 if (unlikely(!pagecnt_bias)) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001967 page_ref_add(page, USHRT_MAX);
1968 rx_buffer->pagecnt_bias = USHRT_MAX;
1969 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00001970
Alexander Duyck0549ae22012-07-20 08:08:18 +00001971 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001972}
1973
Alexander Duyckaf43da02017-01-17 08:35:34 -08001974/**
1975 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1976 * @rx_ring: rx descriptor ring to transact packets on
1977 * @rx_buffer: buffer containing page to add
1978 * @rx_desc: descriptor containing length of buffer written by hardware
1979 * @skb: sk_buff to place the data into
1980 *
1981 * This function will add the data contained in rx_buffer->page to the skb.
1982 * This is done either through a direct copy if the data in the buffer is
1983 * less than the skb header size, otherwise it will just attach the page as
1984 * a frag to the skb.
1985 *
1986 * The function will then update the page offset if necessary and return
1987 * true if the buffer can be reused by the adapter.
1988 **/
Alexander Duyck3fd218762017-01-17 08:36:45 -08001989static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckaf43da02017-01-17 08:35:34 -08001990 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck3fd218762017-01-17 08:36:45 -08001991 struct sk_buff *skb,
1992 unsigned int size)
Alexander Duyckaf43da02017-01-17 08:35:34 -08001993{
Alexander Duyckaf43da02017-01-17 08:35:34 -08001994#if (PAGE_SIZE < 8192)
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001995 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
Alexander Duyckaf43da02017-01-17 08:35:34 -08001996#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001997 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
1998 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
1999 SKB_DATA_ALIGN(size);
Alexander Duyckaf43da02017-01-17 08:35:34 -08002000#endif
Alexander Duyck3fd218762017-01-17 08:36:45 -08002001 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
Alexander Duyckaf43da02017-01-17 08:35:34 -08002002 rx_buffer->page_offset, size, truesize);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002003#if (PAGE_SIZE < 8192)
2004 rx_buffer->page_offset ^= truesize;
2005#else
2006 rx_buffer->page_offset += truesize;
2007#endif
Alexander Duyckaf43da02017-01-17 08:35:34 -08002008}
2009
Alexander Duyck3fd218762017-01-17 08:36:45 -08002010static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
2011 union ixgbe_adv_rx_desc *rx_desc,
2012 struct sk_buff **skb,
2013 const unsigned int size)
Alexander Duyck18806c92012-07-20 08:08:44 +00002014{
2015 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyck18806c92012-07-20 08:08:44 +00002016
2017 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
Alexander Duyck3fd218762017-01-17 08:36:45 -08002018 prefetchw(rx_buffer->page);
2019 *skb = rx_buffer->skb;
Alexander Duyck18806c92012-07-20 08:08:44 +00002020
Alexander Duyck3fd218762017-01-17 08:36:45 -08002021 /* Delay unmapping of the first packet. It carries the header
2022 * information, HW may still access the header after the writeback.
2023 * Only unmap it when EOP is reached
2024 */
2025 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
2026 if (!*skb)
2027 goto skip_sync;
Alexander Duyck18806c92012-07-20 08:08:44 +00002028 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002029 if (*skb)
2030 ixgbe_dma_sync_frag(rx_ring, *skb);
Alexander Duyck18806c92012-07-20 08:08:44 +00002031 }
2032
Alexander Duyck3fd218762017-01-17 08:36:45 -08002033 /* we are reusing so sync this buffer for CPU use */
2034 dma_sync_single_range_for_cpu(rx_ring->dev,
2035 rx_buffer->dma,
2036 rx_buffer->page_offset,
2037 size,
2038 DMA_FROM_DEVICE);
2039skip_sync:
2040 rx_buffer->pagecnt_bias--;
2041
2042 return rx_buffer;
2043}
2044
2045static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
2046 struct ixgbe_rx_buffer *rx_buffer,
2047 struct sk_buff *skb)
2048{
2049 if (ixgbe_can_reuse_rx_page(rx_buffer)) {
Alexander Duyck18806c92012-07-20 08:08:44 +00002050 /* hand second half of page back to the ring */
2051 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
Alexander Duyck18806c92012-07-20 08:08:44 +00002052 } else {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002053 if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
2054 /* the page has been released from the ring */
2055 IXGBE_CB(skb)->page_released = true;
2056 } else {
2057 /* we are not reusing the buffer so unmap it */
2058 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
2059 ixgbe_rx_pg_size(rx_ring),
2060 DMA_FROM_DEVICE,
2061 IXGBE_RX_DMA_ATTR);
2062 }
Alexander Duyck3fd218762017-01-17 08:36:45 -08002063 __page_frag_cache_drain(rx_buffer->page,
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002064 rx_buffer->pagecnt_bias);
Alexander Duyck18806c92012-07-20 08:08:44 +00002065 }
2066
Alexander Duyck3fd218762017-01-17 08:36:45 -08002067 /* clear contents of rx_buffer */
Alexander Duyck18806c92012-07-20 08:08:44 +00002068 rx_buffer->page = NULL;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002069 rx_buffer->skb = NULL;
2070}
2071
2072static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
2073 struct ixgbe_rx_buffer *rx_buffer,
2074 union ixgbe_adv_rx_desc *rx_desc,
2075 unsigned int size)
2076{
2077 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
2078#if (PAGE_SIZE < 8192)
2079 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2080#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08002081 unsigned int truesize = SKB_DATA_ALIGN(size);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002082#endif
2083 struct sk_buff *skb;
2084
2085 /* prefetch first cache line of first page */
2086 prefetch(va);
2087#if L1_CACHE_BYTES < 128
2088 prefetch(va + L1_CACHE_BYTES);
2089#endif
2090
2091 /* allocate a skb to store the frags */
2092 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
2093 if (unlikely(!skb))
2094 return NULL;
2095
2096 if (size > IXGBE_RX_HDR_SIZE) {
2097 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2098 IXGBE_CB(skb)->dma = rx_buffer->dma;
2099
2100 skb_add_rx_frag(skb, 0, rx_buffer->page,
2101 rx_buffer->page_offset,
2102 size, truesize);
2103#if (PAGE_SIZE < 8192)
2104 rx_buffer->page_offset ^= truesize;
2105#else
2106 rx_buffer->page_offset += truesize;
2107#endif
2108 } else {
2109 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
2110 rx_buffer->pagecnt_bias++;
2111 }
Alexander Duyck18806c92012-07-20 08:08:44 +00002112
2113 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002114}
2115
Alexander Duyck6f429222017-01-17 08:37:13 -08002116static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
2117 struct ixgbe_rx_buffer *rx_buffer,
2118 union ixgbe_adv_rx_desc *rx_desc,
2119 unsigned int size)
2120{
2121 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
2122#if (PAGE_SIZE < 8192)
2123 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2124#else
2125 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
2126 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size);
2127#endif
2128 struct sk_buff *skb;
2129
2130 /* prefetch first cache line of first page */
2131 prefetch(va);
2132#if L1_CACHE_BYTES < 128
2133 prefetch(va + L1_CACHE_BYTES);
2134#endif
2135
Alexander Duyck3a1eb6d2017-02-15 09:15:59 -08002136 /* build an skb around the page buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08002137 skb = build_skb(va - IXGBE_SKB_PAD, truesize);
2138 if (unlikely(!skb))
2139 return NULL;
2140
2141 /* update pointers within the skb to store the data */
2142 skb_reserve(skb, IXGBE_SKB_PAD);
2143 __skb_put(skb, size);
2144
2145 /* record DMA address if this is the start of a chain of buffers */
2146 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2147 IXGBE_CB(skb)->dma = rx_buffer->dma;
2148
2149 /* update buffer offset */
2150#if (PAGE_SIZE < 8192)
2151 rx_buffer->page_offset ^= truesize;
2152#else
2153 rx_buffer->page_offset += truesize;
2154#endif
2155
2156 return skb;
2157}
2158
Alexander Duyckf8003262012-03-03 02:35:52 +00002159/**
2160 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2161 * @q_vector: structure containing interrupt and ring information
2162 * @rx_ring: rx descriptor ring to transact packets on
2163 * @budget: Total limit on number of packets to process
2164 *
2165 * This function provides a "bounce buffer" approach to Rx interrupt
2166 * processing. The advantage to this is that on systems that have
2167 * expensive overhead for IOMMU access this provides a means of avoiding
2168 * it by maintaining the mapping of the page to the syste.
2169 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002170 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002171 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002172static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002173 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002174 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002175{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002176 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00002177#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00002178 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00002179 int ddp_bytes;
2180 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002181#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002182 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002183
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002184 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002185 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002186 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyckf8003262012-03-03 02:35:52 +00002187 struct sk_buff *skb;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002188 unsigned int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002189
Alexander Duyckf8003262012-03-03 02:35:52 +00002190 /* return some buffers to hardware, one at a time is too slow */
2191 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2192 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2193 cleaned_count = 0;
2194 }
Auke Kok9a799d72007-09-15 14:07:45 -07002195
Alexander Duyck18806c92012-07-20 08:08:44 +00002196 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002197 size = le16_to_cpu(rx_desc->wb.upper.length);
2198 if (!size)
Alexander Duyckf8003262012-03-03 02:35:52 +00002199 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002200
Alexander Duyck124b74c2014-12-11 15:02:28 -08002201 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002202 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002203 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002204 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002205 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002206
Alexander Duyck3fd218762017-01-17 08:36:45 -08002207 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
2208
Alexander Duyck18806c92012-07-20 08:08:44 +00002209 /* retrieve a buffer from the ring */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002210 if (skb)
2211 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
Alexander Duyck6f429222017-01-17 08:37:13 -08002212 else if (ring_uses_build_skb(rx_ring))
2213 skb = ixgbe_build_skb(rx_ring, rx_buffer,
2214 rx_desc, size);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002215 else
2216 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
2217 rx_desc, size);
Alexander Duyckf8003262012-03-03 02:35:52 +00002218
Alexander Duyck18806c92012-07-20 08:08:44 +00002219 /* exit if we failed to retrieve a buffer */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002220 if (!skb) {
2221 rx_ring->rx_stats.alloc_rx_buff_failed++;
2222 rx_buffer->pagecnt_bias++;
Alexander Duyck18806c92012-07-20 08:08:44 +00002223 break;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002224 }
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002225
Alexander Duyck3fd218762017-01-17 08:36:45 -08002226 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002227 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002228
Alexander Duyckf8003262012-03-03 02:35:52 +00002229 /* place incomplete frames back on ring for completion */
2230 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2231 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002232
Alexander Duyckf8003262012-03-03 02:35:52 +00002233 /* verify the packet layout is correct */
2234 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2235 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002236
2237 /* probably a little skewed due to removing CRC */
2238 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002239
Alexander Duyck8a0da212012-01-31 02:59:49 +00002240 /* populate checksum, timestamp, VLAN, and protocol */
2241 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2242
Yi Zou332d4a72009-05-13 13:11:53 +00002243#ifdef IXGBE_FCOE
2244 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002245 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002246 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002247 /* include DDPed FCoE data */
2248 if (ddp_bytes > 0) {
2249 if (!mss) {
2250 mss = rx_ring->netdev->mtu -
2251 sizeof(struct fcoe_hdr) -
2252 sizeof(struct fc_frame_header) -
2253 sizeof(struct fcoe_crc_eof);
2254 if (mss > 512)
2255 mss &= ~511;
2256 }
2257 total_rx_bytes += ddp_bytes;
2258 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2259 mss);
2260 }
David S. Miller823dcd22011-08-20 10:39:12 -07002261 if (!ddp_bytes) {
2262 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002263 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002264 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002265 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002266
Yi Zou332d4a72009-05-13 13:11:53 +00002267#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002268 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002269
Alexander Duyckf8003262012-03-03 02:35:52 +00002270 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002271 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002272 }
Auke Kok9a799d72007-09-15 14:07:45 -07002273
Alexander Duyckc267fc12010-11-16 19:27:00 -08002274 u64_stats_update_begin(&rx_ring->syncp);
2275 rx_ring->stats.packets += total_rx_packets;
2276 rx_ring->stats.bytes += total_rx_bytes;
2277 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002278 q_vector->rx.total_packets += total_rx_packets;
2279 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002280
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002281 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002282}
2283
Auke Kok9a799d72007-09-15 14:07:45 -07002284/**
2285 * ixgbe_configure_msix - Configure MSI-X hardware
2286 * @adapter: board private structure
2287 *
2288 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2289 * interrupts.
2290 **/
2291static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2292{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002293 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002294 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002295 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002296
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002297 /* Populate MSIX to EITR Select */
2298 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002299 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002300 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2301 }
2302
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002303 /*
2304 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002305 * corresponding register.
2306 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002307 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002308 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002309 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002310
Alexander Duycka5579282012-02-08 07:50:04 +00002311 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002312 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002313
Alexander Duycka5579282012-02-08 07:50:04 +00002314 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002315 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002316
Alexander Duyckfe49f042009-06-04 16:00:09 +00002317 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002318 }
2319
Alexander Duyckbd508172010-11-16 19:27:03 -08002320 switch (adapter->hw.mac.type) {
2321 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002322 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002323 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002324 break;
2325 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002326 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002327 case ixgbe_mac_X550:
2328 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002329 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002330 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002331 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002332 default:
2333 break;
2334 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002335 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002336
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002337 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002338 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002339 mask &= ~(IXGBE_EIMS_OTHER |
2340 IXGBE_EIMS_MAILBOX |
2341 IXGBE_EIMS_LSC);
2342
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002343 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002344}
2345
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002346enum latency_range {
2347 lowest_latency = 0,
2348 low_latency = 1,
2349 bulk_latency = 2,
2350 latency_invalid = 255
2351};
2352
2353/**
2354 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002355 * @q_vector: structure containing interrupt and ring information
2356 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002357 *
2358 * Stores a new ITR value based on packets and byte
2359 * counts during the last interrupt. The advantage of per interrupt
2360 * computation is faster updates and more accurate ITR for the current
2361 * traffic pattern. Constants in this function were computed
2362 * based on theoretical maximum wire speed and thresholds were set based
2363 * on testing data as well as attempting to minimize response time
2364 * while increasing bulk throughput.
2365 * this functionality is controlled by the InterruptThrottleRate module
2366 * parameter (see ixgbe_param.c)
2367 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002368static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2369 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002370{
Alexander Duyckbd198052011-06-11 01:45:08 +00002371 int bytes = ring_container->total_bytes;
2372 int packets = ring_container->total_packets;
2373 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002374 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002375 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002376
2377 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002378 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002379
2380 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002381 * 0-10MB/s lowest (100000 ints/s)
2382 * 10-20MB/s low (20000 ints/s)
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002383 * 20-1249MB/s bulk (12000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002384 */
2385 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002386 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002387 if (timepassed_us == 0)
2388 return;
2389
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002390 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2391
2392 switch (itr_setting) {
2393 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002394 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002395 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002396 break;
2397 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002398 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002399 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002400 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002401 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002402 break;
2403 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002404 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002405 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002406 break;
2407 }
2408
Alexander Duyckbd198052011-06-11 01:45:08 +00002409 /* clear work counters since we have the values we need */
2410 ring_container->total_bytes = 0;
2411 ring_container->total_packets = 0;
2412
2413 /* write updated itr to ring container */
2414 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002415}
2416
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002417/**
2418 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002419 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002420 *
2421 * This function is made to be called by ethtool and by the driver
2422 * when it needs to update EITR registers at runtime. Hardware
2423 * specific quirks/differences are taken care of here.
2424 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002425void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002426{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002427 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002428 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002429 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002430 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002431
Alexander Duyckbd508172010-11-16 19:27:03 -08002432 switch (adapter->hw.mac.type) {
2433 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002434 /* must write high and low 16 bits to reset counter */
2435 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002436 break;
2437 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002438 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002439 case ixgbe_mac_X550:
2440 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002441 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002442 /*
2443 * set the WDIS bit to not clear the timer bits and cause an
2444 * immediate assertion of the interrupt
2445 */
2446 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002447 break;
2448 default:
2449 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002450 }
2451 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2452}
2453
Alexander Duyckbd198052011-06-11 01:45:08 +00002454static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002455{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002456 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002457 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002458
Alexander Duyckbd198052011-06-11 01:45:08 +00002459 ixgbe_update_itr(q_vector, &q_vector->tx);
2460 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002461
Alexander Duyck08c88332011-06-11 01:45:03 +00002462 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002463
2464 switch (current_itr) {
2465 /* counts and packets in update_itr are dependent on these numbers */
2466 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002467 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002468 break;
2469 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002470 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002471 break;
2472 case bulk_latency:
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002473 new_itr = IXGBE_12K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002474 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002475 default:
2476 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002477 }
2478
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002479 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002480 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002481 new_itr = (10 * new_itr * q_vector->itr) /
2482 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002483
Alexander Duyckbd198052011-06-11 01:45:08 +00002484 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002485 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002486
2487 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002488 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002489}
2490
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002491/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002492 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002493 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002494 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002495static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002496{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002497 struct ixgbe_hw *hw = &adapter->hw;
2498 u32 eicr = adapter->interrupt_event;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002499 s32 rc;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002500
Alexander Duyckf0f97782011-04-22 04:08:09 +00002501 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002502 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002503
Alexander Duyckf0f97782011-04-22 04:08:09 +00002504 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2505 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2506 return;
2507
2508 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2509
Joe Perches7ca647b2010-09-07 21:35:40 +00002510 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002511 case IXGBE_DEV_ID_82599_T3_LOM:
2512 /*
2513 * Since the warning interrupt is for both ports
2514 * we don't have to check if:
2515 * - This interrupt wasn't for our port.
2516 * - We may have missed the interrupt so always have to
2517 * check if we got a LSC
2518 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002519 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002520 !(eicr & IXGBE_EICR_LSC))
2521 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002522
Alexander Duyckf0f97782011-04-22 04:08:09 +00002523 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002524 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002525 bool link_up = false;
2526
Josh Hay3d292262012-12-15 03:28:19 +00002527 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002528
Alexander Duyckf0f97782011-04-22 04:08:09 +00002529 if (link_up)
2530 return;
2531 }
2532
2533 /* Check if this is not due to overtemp */
2534 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2535 return;
2536
2537 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002538 case IXGBE_DEV_ID_X550EM_A_1G_T:
2539 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2540 rc = hw->phy.ops.check_overtemp(hw);
2541 if (rc != IXGBE_ERR_OVERTEMP)
2542 return;
2543 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002544 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002545 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2546 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002547 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002548 return;
2549 break;
2550 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002551 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002552
2553 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002554}
2555
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002556static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2557{
2558 struct ixgbe_hw *hw = &adapter->hw;
2559
2560 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002561 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002562 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002563 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002564 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002565 }
2566}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002567
Jacob Keller4f51bf72011-08-20 04:49:45 +00002568static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2569{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002570 struct ixgbe_hw *hw = &adapter->hw;
2571
Jacob Keller4f51bf72011-08-20 04:49:45 +00002572 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2573 return;
2574
2575 switch (adapter->hw.mac.type) {
2576 case ixgbe_mac_82599EB:
2577 /*
2578 * Need to check link state so complete overtemp check
2579 * on service task
2580 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002581 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2582 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002583 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2584 adapter->interrupt_event = eicr;
2585 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2586 ixgbe_service_event_schedule(adapter);
2587 return;
2588 }
2589 return;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002590 case ixgbe_mac_x550em_a:
2591 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2592 adapter->interrupt_event = eicr;
2593 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2594 ixgbe_service_event_schedule(adapter);
2595 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2596 IXGBE_EICR_GPI_SDP0_X550EM_a);
2597 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2598 IXGBE_EICR_GPI_SDP0_X550EM_a);
2599 }
2600 return;
2601 case ixgbe_mac_X550:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002602 case ixgbe_mac_X540:
2603 if (!(eicr & IXGBE_EICR_TS))
2604 return;
2605 break;
2606 default:
2607 return;
2608 }
2609
Don Skidmoref44e7512015-06-09 16:36:23 -07002610 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002611}
2612
Don Skidmore45788d22015-06-09 16:59:04 -07002613static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2614{
2615 switch (hw->mac.type) {
2616 case ixgbe_mac_82598EB:
2617 if (hw->phy.type == ixgbe_phy_nl)
2618 return true;
2619 return false;
2620 case ixgbe_mac_82599EB:
2621 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002622 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002623 switch (hw->mac.ops.get_media_type(hw)) {
2624 case ixgbe_media_type_fiber:
2625 case ixgbe_media_type_fiber_qsfp:
2626 return true;
2627 default:
2628 return false;
2629 }
2630 default:
2631 return false;
2632 }
2633}
2634
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002635static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2636{
2637 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002638 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002639
Don Skidmore4ccc6502015-09-02 13:47:54 -07002640 if (!ixgbe_is_sfp(hw))
2641 return;
2642
2643 /* Later MAC's use different SDP */
2644 if (hw->mac.type >= ixgbe_mac_X540)
2645 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2646
2647 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002648 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002649 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002650 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2651 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002652 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002653 ixgbe_service_event_schedule(adapter);
2654 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002655 }
2656
Don Skidmore4ccc6502015-09-02 13:47:54 -07002657 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2658 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002659 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002660 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002661 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2662 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2663 ixgbe_service_event_schedule(adapter);
2664 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002665 }
2666}
2667
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002668static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2669{
2670 struct ixgbe_hw *hw = &adapter->hw;
2671
2672 adapter->lsc_int++;
2673 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2674 adapter->link_check_timeout = jiffies;
2675 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2676 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002677 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002678 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002679 }
2680}
2681
Alexander Duyckfe49f042009-06-04 16:00:09 +00002682static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2683 u64 qmask)
2684{
2685 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002686 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002687
Alexander Duyckbd508172010-11-16 19:27:03 -08002688 switch (hw->mac.type) {
2689 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002690 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002691 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2692 break;
2693 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002694 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002695 case ixgbe_mac_X550:
2696 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002697 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002698 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002699 if (mask)
2700 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002701 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002702 if (mask)
2703 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2704 break;
2705 default:
2706 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002707 }
2708 /* skip the flush */
2709}
2710
2711static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002712 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002713{
2714 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002715 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002716
Alexander Duyckbd508172010-11-16 19:27:03 -08002717 switch (hw->mac.type) {
2718 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002719 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002720 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2721 break;
2722 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002723 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002724 case ixgbe_mac_X550:
2725 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002726 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002727 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002728 if (mask)
2729 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002730 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002731 if (mask)
2732 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2733 break;
2734 default:
2735 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002736 }
2737 /* skip the flush */
2738}
2739
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002740/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002741 * ixgbe_irq_enable - Enable default interrupt generation settings
2742 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002743 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002744static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2745 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002746{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002747 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002748 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002749
Alexander Duyck2c4af692011-07-15 07:29:55 +00002750 /* don't reenable LSC while waiting for link */
2751 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2752 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002753
Alexander Duyck2c4af692011-07-15 07:29:55 +00002754 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002755 switch (adapter->hw.mac.type) {
2756 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002757 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002758 break;
2759 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002760 case ixgbe_mac_X550:
2761 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002762 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002763 mask |= IXGBE_EIMS_TS;
2764 break;
2765 default:
2766 break;
2767 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002768 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002769 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002770 switch (adapter->hw.mac.type) {
2771 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002772 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2773 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002774 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00002775 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002776 case ixgbe_mac_X550:
2777 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002778 case ixgbe_mac_x550em_a:
2779 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07002780 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07002781 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07002782 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07002783 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
2784 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00002785 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002786 mask |= IXGBE_EIMS_MAILBOX;
2787 break;
2788 default:
2789 break;
2790 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002791
Alexander Duyck2c4af692011-07-15 07:29:55 +00002792 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2793 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2794 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002795
Alexander Duyck2c4af692011-07-15 07:29:55 +00002796 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2797 if (queues)
2798 ixgbe_irq_enable_queues(adapter, ~0);
2799 if (flush)
2800 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002801}
2802
Alexander Duyck2c4af692011-07-15 07:29:55 +00002803static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002804{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002805 struct ixgbe_adapter *adapter = data;
2806 struct ixgbe_hw *hw = &adapter->hw;
2807 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002808
Alexander Duyck2c4af692011-07-15 07:29:55 +00002809 /*
2810 * Workaround for Silicon errata. Use clear-by-write instead
2811 * of clear-by-read. Reading with EICS will return the
2812 * interrupt causes without clearing, which later be done
2813 * with the write to EICR.
2814 */
2815 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002816
2817 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08002818 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00002819 * the bits are high when ixgbe_msix_other is called. There is a race
2820 * condition otherwise which results in possible performance loss
2821 * especially if the ixgbe_msix_other interrupt is triggering
2822 * consistently (as it would when PPS is turned on for the X540 device)
2823 */
2824 eicr &= 0xFFFF0000;
2825
Alexander Duyck2c4af692011-07-15 07:29:55 +00002826 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002827
Alexander Duyck2c4af692011-07-15 07:29:55 +00002828 if (eicr & IXGBE_EICR_LSC)
2829 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002830
Alexander Duyck2c4af692011-07-15 07:29:55 +00002831 if (eicr & IXGBE_EICR_MAILBOX)
2832 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002833
Alexander Duyck2c4af692011-07-15 07:29:55 +00002834 switch (hw->mac.type) {
2835 case ixgbe_mac_82599EB:
2836 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002837 case ixgbe_mac_X550:
2838 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002839 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07002840 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
2841 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
2842 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
2843 ixgbe_service_event_schedule(adapter);
2844 IXGBE_WRITE_REG(hw, IXGBE_EICR,
2845 IXGBE_EICR_GPI_SDP0_X540);
2846 }
Don Skidmored773ce22014-02-25 17:58:53 -08002847 if (eicr & IXGBE_EICR_ECC) {
2848 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07002849 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08002850 ixgbe_service_event_schedule(adapter);
2851 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2852 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002853 /* Handle Flow Director Full threshold interrupt */
2854 if (eicr & IXGBE_EICR_FLOW_DIR) {
2855 int reinit_count = 0;
2856 int i;
2857 for (i = 0; i < adapter->num_tx_queues; i++) {
2858 struct ixgbe_ring *ring = adapter->tx_ring[i];
2859 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2860 &ring->state))
2861 reinit_count++;
2862 }
2863 if (reinit_count) {
2864 /* no more flow director interrupts until after init */
2865 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2866 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2867 ixgbe_service_event_schedule(adapter);
2868 }
2869 }
2870 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002871 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002872 break;
2873 default:
2874 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002875 }
2876
Alexander Duyck2c4af692011-07-15 07:29:55 +00002877 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002878
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002879 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07002880 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002881
Alexander Duyck2c4af692011-07-15 07:29:55 +00002882 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002883 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002884 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002885
Alexander Duyck2c4af692011-07-15 07:29:55 +00002886 return IRQ_HANDLED;
2887}
2888
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002889static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002890{
2891 struct ixgbe_q_vector *q_vector = data;
2892
Auke Kok9a799d72007-09-15 14:07:45 -07002893 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002894
2895 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07002896 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002897
2898 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002899}
2900
Auke Kok9a799d72007-09-15 14:07:45 -07002901/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002902 * ixgbe_poll - NAPI Rx polling callback
2903 * @napi: structure for representing this polling device
2904 * @budget: how many packets driver is allowed to clean
2905 *
2906 * This function is used for legacy and MSI, NAPI mode
2907 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002908int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002909{
2910 struct ixgbe_q_vector *q_vector =
2911 container_of(napi, struct ixgbe_q_vector, napi);
2912 struct ixgbe_adapter *adapter = q_vector->adapter;
2913 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002914 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00002915 bool clean_complete = true;
2916
2917#ifdef CONFIG_IXGBE_DCA
2918 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2919 ixgbe_update_dca(q_vector);
2920#endif
2921
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002922 ixgbe_for_each_ring(ring, q_vector->tx) {
2923 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
2924 clean_complete = false;
2925 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002926
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08002927 /* Exit if we are called by netpoll */
2928 if (budget <= 0)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002929 return budget;
2930
Alexander Duyckeb01b972012-02-08 07:51:27 +00002931 /* attempt to distribute budget to each queue fairly, but don't allow
2932 * the budget to go below 1 because we'll exit polling */
2933 if (q_vector->rx.count > 1)
2934 per_ring_budget = max(budget/q_vector->rx.count, 1);
2935 else
2936 per_ring_budget = budget;
2937
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002938 ixgbe_for_each_ring(ring, q_vector->rx) {
2939 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
2940 per_ring_budget);
2941
2942 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002943 if (cleaned >= per_ring_budget)
2944 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002945 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002946
2947 /* If all work not completed, return budget and keep polling */
2948 if (!clean_complete)
2949 return budget;
2950
2951 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002952 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002953 if (adapter->rx_itr_setting & 1)
2954 ixgbe_set_itr(q_vector);
2955 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002956 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00002957
Paolo Abeni4b732cd2016-06-15 15:37:59 +02002958 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002959}
2960
2961/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002962 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2963 * @adapter: board private structure
2964 *
2965 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2966 * interrupts from the kernel.
2967 **/
2968static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2969{
2970 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002971 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002972 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002973
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002974 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002975 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002976 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002977
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002978 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002979 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002980 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002981 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002982 } else if (q_vector->rx.ring) {
2983 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2984 "%s-%s-%d", netdev->name, "rx", ri++);
2985 } else if (q_vector->tx.ring) {
2986 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2987 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002988 } else {
2989 /* skip this unused q_vector */
2990 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002991 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002992 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2993 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002994 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002995 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002996 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002997 goto free_queue_irqs;
2998 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002999 /* If Flow Director is enabled, set interrupt affinity */
3000 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3001 /* assign the mask for this irq */
3002 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00003003 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00003004 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003005 }
3006
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003007 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00003008 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003009 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00003010 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003011 goto free_queue_irqs;
3012 }
3013
3014 return 0;
3015
3016free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00003017 while (vector) {
3018 vector--;
3019 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3020 NULL);
3021 free_irq(adapter->msix_entries[vector].vector,
3022 adapter->q_vector[vector]);
3023 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003024 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3025 pci_disable_msix(adapter->pdev);
3026 kfree(adapter->msix_entries);
3027 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003028 return err;
3029}
3030
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08003031/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003032 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07003033 * @irq: interrupt number
3034 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07003035 **/
3036static irqreturn_t ixgbe_intr(int irq, void *data)
3037{
Alexander Duycka65151ba22011-05-27 05:31:32 +00003038 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07003039 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003040 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003041 u32 eicr;
3042
Don Skidmore54037502009-02-21 15:42:56 -08003043 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00003044 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08003045 * before the read of EICR.
3046 */
3047 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3048
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003049 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003050 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003051 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003052 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003053 /*
3054 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003055 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003056 * have disabled interrupts due to EIAM
3057 * finish the workaround of silicon errata on 82598. Unmask
3058 * the interrupt that we masked before the EICR read.
3059 */
3060 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3061 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003062 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003063 }
Auke Kok9a799d72007-09-15 14:07:45 -07003064
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003065 if (eicr & IXGBE_EICR_LSC)
3066 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003067
Alexander Duyckbd508172010-11-16 19:27:03 -08003068 switch (hw->mac.type) {
3069 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003070 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003071 /* Fall through */
3072 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003073 case ixgbe_mac_X550:
3074 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003075 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003076 if (eicr & IXGBE_EICR_ECC) {
3077 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003078 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003079 ixgbe_service_event_schedule(adapter);
3080 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3081 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003082 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003083 break;
3084 default:
3085 break;
3086 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003087
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003088 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003089 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003090 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003091
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003092 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003093 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003094
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003095 /*
3096 * re-enable link(maybe) and non-queue interrupts, no flush.
3097 * ixgbe_poll will re-enable the queue interrupts
3098 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003099 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3100 ixgbe_irq_enable(adapter, false, false);
3101
Auke Kok9a799d72007-09-15 14:07:45 -07003102 return IRQ_HANDLED;
3103}
3104
3105/**
3106 * ixgbe_request_irq - initialize interrupts
3107 * @adapter: board private structure
3108 *
3109 * Attempts to configure interrupts using the best available
3110 * capabilities of the hardware and kernel.
3111 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003112static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003113{
3114 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003115 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003116
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003117 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003118 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003119 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003120 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003121 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003122 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003123 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003124 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003125
Alexander Duyckde88eee2012-02-08 07:49:59 +00003126 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003127 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003128
Auke Kok9a799d72007-09-15 14:07:45 -07003129 return err;
3130}
3131
3132static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3133{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003134 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003135
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003136 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003137 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003138 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003139 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003140
Mark Rustad1fa71252016-09-28 15:36:38 -07003141 if (!adapter->msix_entries)
3142 return;
3143
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003144 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3145 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3146 struct msix_entry *entry = &adapter->msix_entries[vector];
3147
3148 /* free only the irqs that were actually requested */
3149 if (!q_vector->rx.ring && !q_vector->tx.ring)
3150 continue;
3151
3152 /* clear the affinity_mask in the IRQ descriptor */
3153 irq_set_affinity_hint(entry->vector, NULL);
3154
3155 free_irq(entry->vector, q_vector);
3156 }
3157
Babu Moger90c6f872016-06-18 17:40:47 -07003158 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003159}
3160
3161/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003162 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3163 * @adapter: board private structure
3164 **/
3165static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3166{
Alexander Duyckbd508172010-11-16 19:27:03 -08003167 switch (adapter->hw.mac.type) {
3168 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003169 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003170 break;
3171 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003172 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003173 case ixgbe_mac_X550:
3174 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003175 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003176 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3177 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003178 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003179 break;
3180 default:
3181 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003182 }
3183 IXGBE_WRITE_FLUSH(&adapter->hw);
3184 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003185 int vector;
3186
3187 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3188 synchronize_irq(adapter->msix_entries[vector].vector);
3189
3190 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003191 } else {
3192 synchronize_irq(adapter->pdev->irq);
3193 }
3194}
3195
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003196/**
Auke Kok9a799d72007-09-15 14:07:45 -07003197 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3198 *
3199 **/
3200static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3201{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003202 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003203
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003204 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003205
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003206 ixgbe_set_ivar(adapter, 0, 0, 0);
3207 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003208
Emil Tantilov396e7992010-07-01 20:05:12 +00003209 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003210}
3211
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003212/**
3213 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3214 * @adapter: board private structure
3215 * @ring: structure containing ring specific data
3216 *
3217 * Configure the Tx descriptor ring after a reset.
3218 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003219void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3220 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003221{
3222 struct ixgbe_hw *hw = &adapter->hw;
3223 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003224 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003225 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003226 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003227
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003228 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003229 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003230 IXGBE_WRITE_FLUSH(hw);
3231
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003232 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003233 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003234 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3235 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3236 ring->count * sizeof(union ixgbe_adv_tx_desc));
3237 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3238 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003239 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003240
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003241 /*
3242 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003243 * higher than 1 when:
3244 * - ITR is 0 as it could cause false TX hangs
3245 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003246 *
3247 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3248 * to or less than the number of on chip descriptors, which is
3249 * currently 40.
3250 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003251 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003252 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003253 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003254 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003255
Alexander Duycke954b372012-02-08 07:49:38 +00003256 /*
3257 * Setting PTHRESH to 32 both improves performance
3258 * and avoids a TX hang with DFP enabled
3259 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003260 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003261 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003262
3263 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003264 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003265 ring->atr_sample_rate = adapter->atr_sample_rate;
3266 ring->atr_count = 0;
3267 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3268 } else {
3269 ring->atr_sample_rate = 0;
3270 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003271
Alexander Duyckfd786b72013-01-12 06:33:31 +00003272 /* initialize XPS */
3273 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3274 struct ixgbe_q_vector *q_vector = ring->q_vector;
3275
3276 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003277 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003278 &q_vector->affinity_mask,
3279 ring->queue_index);
3280 }
3281
John Fastabendc84d3242010-11-16 19:27:12 -08003282 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3283
Alexander Duyckffed21b2017-01-17 08:37:29 -08003284 /* reinitialize tx_buffer_info */
3285 memset(ring->tx_buffer_info, 0,
3286 sizeof(struct ixgbe_tx_buffer) * ring->count);
3287
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003288 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003289 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3290
3291 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3292 if (hw->mac.type == ixgbe_mac_82598EB &&
3293 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3294 return;
3295
3296 /* poll to verify queue is enabled */
3297 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003298 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003299 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3300 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3301 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003302 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003303}
3304
Alexander Duyck120ff942010-08-19 13:34:50 +00003305static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3306{
3307 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003308 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003309 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003310
3311 if (hw->mac.type == ixgbe_mac_82598EB)
3312 return;
3313
3314 /* disable the arbiter while setting MTQC */
3315 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3316 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3317 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3318
3319 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003320 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3321 mtqc = IXGBE_MTQC_VT_ENA;
3322 if (tcs > 4)
3323 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3324 else if (tcs > 1)
3325 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003326 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3327 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003328 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003329 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003330 mtqc |= IXGBE_MTQC_64VF;
3331 } else {
3332 if (tcs > 4)
3333 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3334 else if (tcs > 1)
3335 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3336 else
3337 mtqc = IXGBE_MTQC_64Q_1PB;
3338 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003339
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003340 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003341
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003342 /* Enable Security TX Buffer IFG for multiple pb */
3343 if (tcs) {
3344 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3345 sectx |= IXGBE_SECTX_DCB;
3346 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003347 }
3348
3349 /* re-enable the arbiter */
3350 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3351 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3352}
3353
Auke Kok9a799d72007-09-15 14:07:45 -07003354/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003355 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003356 * @adapter: board private structure
3357 *
3358 * Configure the Tx unit of the MAC after a reset.
3359 **/
3360static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3361{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003362 struct ixgbe_hw *hw = &adapter->hw;
3363 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003364 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003365
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003366 ixgbe_setup_mtqc(adapter);
3367
3368 if (hw->mac.type != ixgbe_mac_82598EB) {
3369 /* DMATXCTL.EN must be before Tx queues are enabled */
3370 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3371 dmatxctl |= IXGBE_DMATXCTL_TE;
3372 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3373 }
3374
Auke Kok9a799d72007-09-15 14:07:45 -07003375 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003376 for (i = 0; i < adapter->num_tx_queues; i++)
3377 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003378}
3379
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003380static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3381 struct ixgbe_ring *ring)
3382{
3383 struct ixgbe_hw *hw = &adapter->hw;
3384 u8 reg_idx = ring->reg_idx;
3385 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3386
3387 srrctl |= IXGBE_SRRCTL_DROP_EN;
3388
3389 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3390}
3391
3392static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3393 struct ixgbe_ring *ring)
3394{
3395 struct ixgbe_hw *hw = &adapter->hw;
3396 u8 reg_idx = ring->reg_idx;
3397 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3398
3399 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3400
3401 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3402}
3403
3404#ifdef CONFIG_IXGBE_DCB
3405void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3406#else
3407static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3408#endif
3409{
3410 int i;
3411 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3412
3413 if (adapter->ixgbe_ieee_pfc)
3414 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3415
3416 /*
3417 * We should set the drop enable bit if:
3418 * SR-IOV is enabled
3419 * or
3420 * Number of Rx queues > 1 and flow control is disabled
3421 *
3422 * This allows us to avoid head of line blocking for security
3423 * and performance reasons.
3424 */
3425 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3426 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3427 for (i = 0; i < adapter->num_rx_queues; i++)
3428 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3429 } else {
3430 for (i = 0; i < adapter->num_rx_queues; i++)
3431 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3432 }
3433}
3434
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003435#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003436
Yi Zoua6616b42009-08-06 13:05:23 +00003437static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003438 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003439{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003440 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003441 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003442 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003443
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003444 if (hw->mac.type == ixgbe_mac_82598EB) {
3445 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3446
3447 /*
3448 * if VMDq is not active we must program one srrctl register
3449 * per RSS queue since we have enabled RDRXCTL.MVMEN
3450 */
3451 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003452 }
3453
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003454 /* configure header buffer length, needed for RSC */
3455 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003456
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003457 /* configure the packet buffer length */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003458 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3459 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3460 else
3461 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003462
3463 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003464 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003465
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003466 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003467}
3468
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003469/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003470 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003471 * @adapter: device handle
3472 *
3473 * - 82598/82599/X540: 128
3474 * - X550(non-SRIOV mode): 512
3475 * - X550(SRIOV mode): 64
3476 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003477u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003478{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003479 if (adapter->hw.mac.type < ixgbe_mac_X550)
3480 return 128;
3481 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3482 return 64;
3483 else
3484 return 512;
3485}
3486
3487/**
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003488 * ixgbe_store_key - Write the RSS key to HW
3489 * @adapter: device handle
3490 *
3491 * Write the RSS key stored in adapter.rss_key to HW.
3492 */
3493void ixgbe_store_key(struct ixgbe_adapter *adapter)
3494{
3495 struct ixgbe_hw *hw = &adapter->hw;
3496 int i;
3497
3498 for (i = 0; i < 10; i++)
3499 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3500}
3501
3502/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003503 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003504 * @adapter: device handle
3505 *
3506 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3507 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003508void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003509{
3510 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003511 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003512 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003513 u32 indices_multi;
3514 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003515
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003516 /* Fill out the redirection table as follows:
3517 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3518 * indices.
3519 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3520 * - X550: 8 bit wide entries containing 6 bit RSS index
3521 */
3522 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3523 indices_multi = 0x11;
3524 else
3525 indices_multi = 0x1;
3526
3527 /* Write redirection table to HW */
3528 for (i = 0; i < reta_entries; i++) {
3529 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3530 if ((i & 3) == 3) {
3531 if (i < 128)
3532 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3533 else
3534 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3535 reta);
3536 reta = 0;
3537 }
3538 }
3539}
3540
3541/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003542 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003543 * @adapter: device handle
3544 *
3545 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3546 */
3547static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3548{
3549 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3550 struct ixgbe_hw *hw = &adapter->hw;
3551 u32 vfreta = 0;
3552 unsigned int pf_pool = adapter->num_vfs;
3553
3554 /* Write redirection table to HW */
3555 for (i = 0; i < reta_entries; i++) {
3556 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3557 if ((i & 3) == 3) {
3558 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3559 vfreta);
3560 vfreta = 0;
3561 }
3562 }
3563}
3564
3565static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3566{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003567 u32 i, j;
3568 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3569 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3570
Alexander Duycke24fcf22016-09-07 20:28:24 -07003571 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003572 * make full use of any rings they may have. We will use the
3573 * PSRTYPE register to control how many rings we use within the PF.
3574 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003575 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3576 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003577
Alexander Duyck05abb122010-08-19 13:35:41 +00003578 /* Fill out hash function seeds */
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003579 ixgbe_store_key(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003580
Alexander Duyck05abb122010-08-19 13:35:41 +00003581 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003582 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3583
Don Skidmore0f9b2322014-11-18 09:35:08 +00003584 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003585 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003586 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003587
3588 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003589 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003590
3591 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003592}
3593
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003594static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003595{
3596 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003597 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3598 unsigned int pf_pool = adapter->num_vfs;
3599 int i, j;
3600
3601 /* Fill out hash function seeds */
3602 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003603 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
3604 adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003605
3606 /* Fill out the redirection table */
3607 for (i = 0, j = 0; i < 64; i++, j++) {
3608 if (j == rss_i)
3609 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003610
3611 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003612 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003613
3614 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003615}
3616
3617static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3618{
3619 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003620 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003621 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003622
3623 /* Disable indicating checksum in descriptor, enables RSS hash */
3624 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3625 rxcsum |= IXGBE_RXCSUM_PCSD;
3626 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3627
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003628 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003629 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003630 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003631 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003632 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003633
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003634 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3635 if (tcs > 4)
3636 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3637 else if (tcs > 1)
3638 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003639 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3640 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003641 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3642 else
3643 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3644 } else {
3645 if (tcs > 4)
3646 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3647 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003648 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3649 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003650 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003651 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003652 }
3653
Alexander Duyck05abb122010-08-19 13:35:41 +00003654 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003655 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3656 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3657 IXGBE_MRQC_RSS_FIELD_IPV6 |
3658 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003659
Alexander Duyckef6afc02012-02-08 07:51:53 +00003660 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003661 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003662 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003663 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003664
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003665 netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003666 if ((hw->mac.type >= ixgbe_mac_X550) &&
3667 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3668 unsigned int pf_pool = adapter->num_vfs;
3669
3670 /* Enable VF RSS mode */
3671 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3672 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3673
3674 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003675 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003676 vfmrqc = IXGBE_MRQC_RSSEN;
3677 vfmrqc |= rss_field;
3678 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3679 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003680 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003681 mrqc |= rss_field;
3682 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3683 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003684}
3685
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003686/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003687 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3688 * @adapter: address of board private structure
3689 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003690 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003691static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003692 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003693{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003694 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003695 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003696 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003697
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003698 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003699 return;
3700
Alexander Duyck73670962010-08-19 13:38:34 +00003701 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003702 rscctrl |= IXGBE_RSCCTL_RSCEN;
3703 /*
3704 * we must limit the number of descriptors so that the
3705 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003706 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003707 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003708 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003709 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003710}
3711
Alexander Duyck9e10e042010-08-19 13:40:06 +00003712#define IXGBE_MAX_RX_DESC_POLL 10
3713static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3714 struct ixgbe_ring *ring)
3715{
3716 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003717 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3718 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003719 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003720
Mark Rustadb0483c82014-01-14 18:53:17 -08003721 if (ixgbe_removed(hw->hw_addr))
3722 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003723 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3724 if (hw->mac.type == ixgbe_mac_82598EB &&
3725 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3726 return;
3727
3728 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003729 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003730 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3731 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3732
3733 if (!wait_loop) {
3734 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3735 "the polling period\n", reg_idx);
3736 }
3737}
3738
Yi Zou2d39d572011-01-06 14:29:56 +00003739void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3740 struct ixgbe_ring *ring)
3741{
3742 struct ixgbe_hw *hw = &adapter->hw;
3743 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3744 u32 rxdctl;
3745 u8 reg_idx = ring->reg_idx;
3746
Mark Rustadb0483c82014-01-14 18:53:17 -08003747 if (ixgbe_removed(hw->hw_addr))
3748 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003749 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3750 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3751
3752 /* write value back with RXDCTL.ENABLE bit cleared */
3753 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3754
3755 if (hw->mac.type == ixgbe_mac_82598EB &&
3756 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3757 return;
3758
3759 /* the hardware may take up to 100us to really disable the rx queue */
3760 do {
3761 udelay(10);
3762 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3763 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3764
3765 if (!wait_loop) {
3766 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3767 "the polling period\n", reg_idx);
3768 }
3769}
3770
Alexander Duyck84418e32010-08-19 13:40:54 +00003771void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3772 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003773{
3774 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc3630cc2017-01-17 08:36:28 -08003775 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyckacd37172010-08-19 13:36:05 +00003776 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003777 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003778 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003779
Alexander Duyck9e10e042010-08-19 13:40:06 +00003780 /* disable queue to avoid issues while updating state */
3781 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003782 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003783
Alexander Duyckacd37172010-08-19 13:36:05 +00003784 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3785 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3786 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3787 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08003788 /* Force flushing of IXGBE_RDLEN to prevent MDD */
3789 IXGBE_WRITE_FLUSH(hw);
3790
Alexander Duyckacd37172010-08-19 13:36:05 +00003791 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3792 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003793 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003794
3795 ixgbe_configure_srrctl(adapter, ring);
3796 ixgbe_configure_rscctl(adapter, ring);
3797
3798 if (hw->mac.type == ixgbe_mac_82598EB) {
3799 /*
3800 * enable cache line friendly hardware writes:
3801 * PTHRESH=32 descriptors (half the internal cache),
3802 * this also removes ugly rx_no_buffer_count increment
3803 * HTHRESH=4 descriptors (to minimize latency on fetch)
3804 * WTHRESH=8 burst writeback up to two cache lines
3805 */
3806 rxdctl &= ~0x3FFFFF;
3807 rxdctl |= 0x080420;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003808#if (PAGE_SIZE < 8192)
3809 } else {
3810 rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
3811 IXGBE_RXDCTL_RLPML_EN);
3812
3813 /* Limit the maximum frame size so we don't overrun the skb */
3814 if (ring_uses_build_skb(ring) &&
3815 !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
Alexander Duyck541ea692017-03-02 15:01:05 -08003816 rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003817 IXGBE_RXDCTL_RLPML_EN;
3818#endif
Alexander Duyck9e10e042010-08-19 13:40:06 +00003819 }
3820
Alexander Duyckffed21b2017-01-17 08:37:29 -08003821 /* initialize rx_buffer_info */
3822 memset(ring->rx_buffer_info, 0,
3823 sizeof(struct ixgbe_rx_buffer) * ring->count);
3824
Alexander Duyckc3630cc2017-01-17 08:36:28 -08003825 /* initialize Rx descriptor 0 */
3826 rx_desc = IXGBE_RX_DESC(ring, 0);
3827 rx_desc->wb.upper.length = 0;
3828
Alexander Duyck9e10e042010-08-19 13:40:06 +00003829 /* enable receive descriptor ring */
3830 rxdctl |= IXGBE_RXDCTL_ENABLE;
3831 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3832
3833 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003834 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003835}
3836
Alexander Duyck48654522010-08-19 13:36:27 +00003837static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3838{
3839 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003840 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003841 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003842
3843 /* PSRTYPE must be initialized in non 82598 adapters */
3844 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003845 IXGBE_PSRTYPE_UDPHDR |
3846 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003847 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003848 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003849
3850 if (hw->mac.type == ixgbe_mac_82598EB)
3851 return;
3852
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003853 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003854 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003855 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003856 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003857
John Fastabend2a47fa42013-11-06 09:54:52 -08003858 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3859 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003860}
3861
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003862static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3863{
3864 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003865 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003866 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003867 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003868
3869 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3870 return;
3871
3872 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003873 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3874 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003875 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003876 vmdctl |= IXGBE_VT_CTL_REPLEN;
3877 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003878
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003879 vf_shift = VMDQ_P(0) % 32;
3880 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003881
3882 /* Enable only the PF's pool for Tx/Rx */
Emil Tantilov11f2b492016-05-04 15:01:27 -07003883 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00003884 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
Emil Tantilov11f2b492016-05-04 15:01:27 -07003885 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00003886 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07003887 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00003888 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003889
3890 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003891 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003892
Alexander Duyck16369562015-11-02 17:10:13 -08003893 /* clear VLAN promisc flag so VFTA will be updated if necessary */
3894 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
3895
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003896 /*
3897 * Set up VF register offsets for selected VT Mode,
3898 * i.e. 32 or 64 VFs for SR-IOV
3899 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003900 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3901 case IXGBE_82599_VMDQ_8Q_MASK:
3902 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3903 break;
3904 case IXGBE_82599_VMDQ_4Q_MASK:
3905 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3906 break;
3907 default:
3908 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3909 break;
3910 }
3911
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003912 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3913
Greg Rosede4c7f62011-09-29 05:57:33 +00003914 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07003915 /* configure spoof checking */
3916 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
3917 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03003918
3919 /* Enable/Disable RSS query feature */
3920 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
3921 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00003922 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003923}
3924
Alexander Duyck477de6e2010-08-19 13:38:11 +00003925static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003926{
Auke Kok9a799d72007-09-15 14:07:45 -07003927 struct ixgbe_hw *hw = &adapter->hw;
3928 struct net_device *netdev = adapter->netdev;
3929 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003930 struct ixgbe_ring *rx_ring;
3931 int i;
3932 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003933
Alexander Duyck477de6e2010-08-19 13:38:11 +00003934#ifdef IXGBE_FCOE
3935 /* adjust max frame to be able to do baby jumbo for FCoE */
3936 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3937 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3938 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3939
3940#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003941
3942 /* adjust max frame to be at least the size of a standard frame */
3943 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3944 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3945
Alexander Duyck477de6e2010-08-19 13:38:11 +00003946 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3947 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3948 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3949 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3950
3951 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003952 }
3953
Auke Kok9a799d72007-09-15 14:07:45 -07003954 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003955 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3956 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003957 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3958
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003959 /*
3960 * Setup the HW Rx Head and Tail Descriptor Pointers and
3961 * the Base and Length of the Rx Descriptor Ring
3962 */
Auke Kok9a799d72007-09-15 14:07:45 -07003963 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003964 rx_ring = adapter->rx_ring[i];
Alexander Duyck4f4542b2017-01-17 08:36:14 -08003965
3966 clear_ring_rsc_enabled(rx_ring);
3967 clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003968 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08003969
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003970 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3971 set_ring_rsc_enabled(rx_ring);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08003972
3973 if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
3974 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003975
Alexander Duyck6f429222017-01-17 08:37:13 -08003976 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003977 if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
3978 continue;
3979
3980 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
3981
3982#if (PAGE_SIZE < 8192)
3983 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3984 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
3985
Alexander Duyck541ea692017-03-02 15:01:05 -08003986 if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
3987 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003988 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
3989#endif
Alexander Duyck477de6e2010-08-19 13:38:11 +00003990 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003991}
3992
Alexander Duyck73670962010-08-19 13:38:34 +00003993static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3994{
3995 struct ixgbe_hw *hw = &adapter->hw;
3996 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3997
3998 switch (hw->mac.type) {
3999 case ixgbe_mac_82598EB:
4000 /*
4001 * For VMDq support of different descriptor types or
4002 * buffer sizes through the use of multiple SRRCTL
4003 * registers, RDRXCTL.MVMEN must be set to 1
4004 *
4005 * also, the manual doesn't mention it clearly but DCA hints
4006 * will only use queue 0's tags unless this bit is set. Side
4007 * effects of setting this bit are only that SRRCTL must be
4008 * fully programmed [0..15]
4009 */
4010 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
4011 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07004012 case ixgbe_mac_X550:
4013 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004014 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07004015 if (adapter->num_vfs)
4016 rdrxctl |= IXGBE_RDRXCTL_PSP;
4017 /* fall through for older HW */
Alexander Duyck73670962010-08-19 13:38:34 +00004018 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004019 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00004020 /* Disable RSC for ACK packets */
4021 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
4022 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
4023 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
4024 /* hardware requires some bits to be set by default */
4025 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
4026 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
4027 break;
4028 default:
4029 /* We should do nothing since we don't know this hardware */
4030 return;
4031 }
4032
4033 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
4034}
4035
Alexander Duyck477de6e2010-08-19 13:38:11 +00004036/**
4037 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4038 * @adapter: board private structure
4039 *
4040 * Configure the Rx unit of the MAC after a reset.
4041 **/
4042static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
4043{
4044 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004045 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004046 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004047
4048 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07004049 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004050
4051 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00004052 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004053
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004054 /* RSC Setup */
4055 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4056 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
4057 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
4058 rfctl |= IXGBE_RFCTL_RSC_DIS;
Emil Tantilova21d0822016-08-10 11:19:23 -07004059
4060 /* disable NFS filtering */
4061 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004062 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
4063
Alexander Duyck9e10e042010-08-19 13:40:06 +00004064 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004065 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004066
Alexander Duyck477de6e2010-08-19 13:38:11 +00004067 /* set_rx_buffer_len must be called before ring initialization */
4068 ixgbe_set_rx_buffer_len(adapter);
4069
4070 /*
4071 * Setup the HW Rx Head and Tail Descriptor Pointers and
4072 * the Base and Length of the Rx Descriptor Ring
4073 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00004074 for (i = 0; i < adapter->num_rx_queues; i++)
4075 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004076
Don Skidmore1f9ac572015-03-13 13:54:30 -07004077 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004078 /* disable drop enable for 82598 parts */
4079 if (hw->mac.type == ixgbe_mac_82598EB)
4080 rxctrl |= IXGBE_RXCTRL_DMBYPS;
4081
4082 /* enable all receives */
4083 rxctrl |= IXGBE_RXCTRL_RXEN;
4084 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004085}
4086
Patrick McHardy80d5c362013-04-19 02:04:28 +00004087static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
4088 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004089{
4090 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004091 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004092
4093 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004094 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4095 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
4096
Jesse Grossf62bbb52010-10-20 13:56:10 +00004097 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004098
4099 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004100}
4101
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004102static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
4103{
4104 u32 vlvf;
4105 int idx;
4106
4107 /* short cut the special case */
4108 if (vlan == 0)
4109 return 0;
4110
4111 /* Search for the vlan id in the VLVF entries */
4112 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
4113 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
4114 if ((vlvf & VLAN_VID_MASK) == vlan)
4115 break;
4116 }
4117
4118 return idx;
4119}
4120
4121void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
4122{
4123 struct ixgbe_hw *hw = &adapter->hw;
4124 u32 bits, word;
4125 int idx;
4126
4127 idx = ixgbe_find_vlvf_entry(hw, vid);
4128 if (!idx)
4129 return;
4130
4131 /* See if any other pools are set for this VLAN filter
4132 * entry other than the PF.
4133 */
4134 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004135 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004136 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4137
4138 /* Disable the filter so this falls into the default pool. */
4139 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4140 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4141 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4142 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4143 }
4144}
4145
Patrick McHardy80d5c362013-04-19 02:04:28 +00004146static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4147 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004148{
4149 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004150 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004151
Auke Kok9a799d72007-09-15 14:07:45 -07004152 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004153 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004154 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4155
Jesse Grossf62bbb52010-10-20 13:56:10 +00004156 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004157
4158 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004159}
4160
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004161/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004162 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4163 * @adapter: driver data
4164 */
4165static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4166{
4167 struct ixgbe_hw *hw = &adapter->hw;
4168 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004169 int i, j;
4170
4171 switch (hw->mac.type) {
4172 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004173 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4174 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004175 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4176 break;
4177 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004178 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004179 case ixgbe_mac_X550:
4180 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004181 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004182 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004183 struct ixgbe_ring *ring = adapter->rx_ring[i];
4184
4185 if (ring->l2_accel_priv)
4186 continue;
4187 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004188 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4189 vlnctrl &= ~IXGBE_RXDCTL_VME;
4190 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4191 }
4192 break;
4193 default:
4194 break;
4195 }
4196}
4197
4198/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004199 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004200 * @adapter: driver data
4201 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004202static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004203{
4204 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004205 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004206 int i, j;
4207
4208 switch (hw->mac.type) {
4209 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004210 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4211 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004212 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4213 break;
4214 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004215 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004216 case ixgbe_mac_X550:
4217 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004218 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004219 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004220 struct ixgbe_ring *ring = adapter->rx_ring[i];
4221
4222 if (ring->l2_accel_priv)
4223 continue;
4224 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004225 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4226 vlnctrl |= IXGBE_RXDCTL_VME;
4227 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4228 }
4229 break;
4230 default:
4231 break;
4232 }
4233}
4234
Alexander Duyck16369562015-11-02 17:10:13 -08004235static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4236{
4237 struct ixgbe_hw *hw = &adapter->hw;
4238 u32 vlnctrl, i;
4239
Alexander Duyckf60439b2016-08-11 14:51:56 -07004240 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4241
Emil Tantilov691e4122016-08-22 16:17:46 -07004242 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4243 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4244 vlnctrl |= IXGBE_VLNCTRL_VFE;
4245 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4246 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004247 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004248 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4249 return;
4250 }
4251
Emil Tantilov691e4122016-08-22 16:17:46 -07004252 /* Nothing to do for 82598 */
4253 if (hw->mac.type == ixgbe_mac_82598EB)
4254 return;
4255
Alexander Duyck16369562015-11-02 17:10:13 -08004256 /* We are already in VLAN promisc, nothing to do */
4257 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4258 return;
4259
4260 /* Set flag so we don't redo unnecessary work */
4261 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4262
4263 /* Add PF to all active pools */
4264 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4265 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4266 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4267
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004268 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004269 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4270 }
4271
4272 /* Set all bits in the VLAN filter table array */
4273 for (i = hw->mac.vft_size; i--;)
4274 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4275}
4276
4277#define VFTA_BLOCK_SIZE 8
4278static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4279{
4280 struct ixgbe_hw *hw = &adapter->hw;
4281 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4282 u32 vid_start = vfta_offset * 32;
4283 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4284 u32 i, vid, word, bits;
4285
4286 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4287 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4288
4289 /* pull VLAN ID from VLVF */
4290 vid = vlvf & VLAN_VID_MASK;
4291
4292 /* only concern outselves with a certain range */
4293 if (vid < vid_start || vid >= vid_end)
4294 continue;
4295
4296 if (vlvf) {
4297 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004298 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004299
4300 /* if PF is part of this then continue */
4301 if (test_bit(vid, adapter->active_vlans))
4302 continue;
4303 }
4304
4305 /* remove PF from the pool */
4306 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004307 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004308 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4309 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4310 }
4311
4312 /* extract values from active_vlans and write back to VFTA */
4313 for (i = VFTA_BLOCK_SIZE; i--;) {
4314 vid = (vfta_offset + i) * 32;
4315 word = vid / BITS_PER_LONG;
4316 bits = vid % BITS_PER_LONG;
4317
4318 vfta[i] |= adapter->active_vlans[word] >> bits;
4319
4320 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4321 }
4322}
4323
4324static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4325{
4326 struct ixgbe_hw *hw = &adapter->hw;
4327 u32 vlnctrl, i;
4328
Alexander Duyckf60439b2016-08-11 14:51:56 -07004329 /* Set VLAN filtering to enabled */
4330 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4331 vlnctrl |= IXGBE_VLNCTRL_VFE;
4332 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4333
Emil Tantilov691e4122016-08-22 16:17:46 -07004334 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4335 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004336 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004337
4338 /* We are not in VLAN promisc, nothing to do */
4339 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4340 return;
4341
4342 /* Set flag so we don't redo unnecessary work */
4343 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4344
4345 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4346 ixgbe_scrub_vfta(adapter, i);
4347}
4348
Auke Kok9a799d72007-09-15 14:07:45 -07004349static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4350{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004351 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004352
Patrick McHardy80d5c362013-04-19 02:04:28 +00004353 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004354
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004355 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004356 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004357}
4358
4359/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004360 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4361 * @netdev: network interface device structure
4362 *
4363 * Writes multicast address list to the MTA hash table.
4364 * Returns: -ENOMEM on failure
4365 * 0 on no addresses written
4366 * X on writing X addresses to MTA
4367 **/
4368static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4369{
4370 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4371 struct ixgbe_hw *hw = &adapter->hw;
4372
4373 if (!netif_running(netdev))
4374 return 0;
4375
4376 if (hw->mac.ops.update_mc_addr_list)
4377 hw->mac.ops.update_mc_addr_list(hw, netdev);
4378 else
4379 return -ENOMEM;
4380
4381#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004382 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004383#endif
4384
4385 return netdev_mc_count(netdev);
4386}
4387
Jacob Keller5d7daa32014-03-29 06:51:25 +00004388#ifdef CONFIG_PCI_IOV
4389void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4390{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004391 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004392 struct ixgbe_hw *hw = &adapter->hw;
4393 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004394
4395 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4396 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4397
4398 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4399 hw->mac.ops.set_rar(hw, i,
4400 mac_table->addr,
4401 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004402 IXGBE_RAH_AV);
4403 else
4404 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004405 }
4406}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004407
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004408#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004409static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4410{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004411 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004412 struct ixgbe_hw *hw = &adapter->hw;
4413 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004414
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004415 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4416 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4417 continue;
4418
4419 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4420
4421 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4422 hw->mac.ops.set_rar(hw, i,
4423 mac_table->addr,
4424 mac_table->pool,
4425 IXGBE_RAH_AV);
4426 else
4427 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004428 }
4429}
4430
4431static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4432{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004433 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004434 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004435 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004436
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004437 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4438 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4439 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004440 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004441
Jacob Keller5d7daa32014-03-29 06:51:25 +00004442 ixgbe_sync_mac_table(adapter);
4443}
4444
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004445static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004446{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004447 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004448 struct ixgbe_hw *hw = &adapter->hw;
4449 int i, count = 0;
4450
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004451 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4452 /* do not count default RAR as available */
4453 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4454 continue;
4455
4456 /* only count unused and addresses that belong to us */
4457 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4458 if (mac_table->pool != pool)
4459 continue;
4460 }
4461
4462 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004463 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004464
Jacob Keller5d7daa32014-03-29 06:51:25 +00004465 return count;
4466}
4467
4468/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004469static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004470{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004471 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004472 struct ixgbe_hw *hw = &adapter->hw;
4473
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004474 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4475 mac_table->pool = VMDQ_P(0);
4476
4477 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4478
4479 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004480 IXGBE_RAH_AV);
4481}
4482
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004483int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4484 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004485{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004486 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004487 struct ixgbe_hw *hw = &adapter->hw;
4488 int i;
4489
4490 if (is_zero_ether_addr(addr))
4491 return -EINVAL;
4492
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004493 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4494 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004495 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004496
4497 ether_addr_copy(mac_table->addr, addr);
4498 mac_table->pool = pool;
4499
4500 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4501 IXGBE_MAC_STATE_IN_USE;
4502
Jacob Keller5d7daa32014-03-29 06:51:25 +00004503 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004504
Jacob Keller5d7daa32014-03-29 06:51:25 +00004505 return i;
4506 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004507
Jacob Keller5d7daa32014-03-29 06:51:25 +00004508 return -ENOMEM;
4509}
4510
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004511int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4512 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004513{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004514 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004515 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004516 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004517
4518 if (is_zero_ether_addr(addr))
4519 return -EINVAL;
4520
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004521 /* search table for addr, if found clear IN_USE flag and sync */
4522 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4523 /* we can only delete an entry if it is in use */
4524 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4525 continue;
4526 /* we only care about entries that belong to the given pool */
4527 if (mac_table->pool != pool)
4528 continue;
4529 /* we only care about a specific MAC address */
4530 if (!ether_addr_equal(addr, mac_table->addr))
4531 continue;
4532
4533 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4534 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4535
4536 ixgbe_sync_mac_table(adapter);
4537
4538 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004539 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004540
Jacob Keller5d7daa32014-03-29 06:51:25 +00004541 return -ENOMEM;
4542}
Jacob Kellerb335e752014-03-25 07:45:27 +00004543/**
Alexander Duyck28500622010-06-15 09:25:48 +00004544 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4545 * @netdev: network interface device structure
4546 *
4547 * Writes unicast address list to the RAR table.
4548 * Returns: -ENOMEM on failure/insufficient address space
4549 * 0 on no addresses written
4550 * X on writing X addresses to the RAR table
4551 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004552static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004553{
4554 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004555 int count = 0;
4556
4557 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004558 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004559 return -ENOMEM;
4560
John Fastabend95447462012-05-31 12:42:26 +00004561 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004562 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004563 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004564 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4565 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004566 count++;
4567 }
4568 }
Alexander Duyck28500622010-06-15 09:25:48 +00004569 return count;
4570}
4571
Alexander Duyck0f079d22015-10-22 16:26:36 -07004572static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4573{
4574 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4575 int ret;
4576
4577 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4578
4579 return min_t(int, ret, 0);
4580}
4581
4582static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4583{
4584 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4585
4586 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4587
4588 return 0;
4589}
4590
Alexander Duyck28500622010-06-15 09:25:48 +00004591/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004592 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004593 * @netdev: network interface device structure
4594 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004595 * The set_rx_method entry point is called whenever the unicast/multicast
4596 * address list or the network interface flags are updated. This routine is
4597 * responsible for configuring the hardware for proper unicast, multicast and
4598 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004599 **/
Greg Rose7f870472010-01-09 02:25:29 +00004600void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004601{
4602 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4603 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004604 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004605 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004606 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004607
4608 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004609 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4610
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004611 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004612 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004613 fctrl |= IXGBE_FCTRL_BAM;
4614 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4615 fctrl |= IXGBE_FCTRL_PMCF;
4616
Alexander Duyck28500622010-06-15 09:25:48 +00004617 /* clear the bits we are changing the status of */
4618 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004619 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004620 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004621 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004622 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004623 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004624 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004625 if (netdev->flags & IFF_ALLMULTI) {
4626 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004627 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004628 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004629 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004630 }
4631
4632 /*
4633 * Write addresses to available RAR registers, if there is not
4634 * sufficient space to store all the addresses then enable
4635 * unicast promiscuous mode
4636 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004637 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004638 fctrl |= IXGBE_FCTRL_UPE;
4639 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004640 }
4641
Emil Tantilovcf789592013-10-26 08:13:20 +00004642 /* Write addresses to the MTA, if the attempt fails
4643 * then we should just turn on promiscuous mode so
4644 * that we can at least receive multicast traffic
4645 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004646 count = ixgbe_write_mc_addr_list(netdev);
4647 if (count < 0) {
4648 fctrl |= IXGBE_FCTRL_MPE;
4649 vmolr |= IXGBE_VMOLR_MPE;
4650 } else if (count) {
4651 vmolr |= IXGBE_VMOLR_ROMPE;
4652 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004653
4654 if (hw->mac.type != ixgbe_mac_82598EB) {
4655 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004656 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4657 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004658 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004659 }
4660
Ben Greear3f2d1c02012-03-08 08:28:41 +00004661 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004662 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004663 /* UPE and MPE will be handled by normal PROMISC logic
4664 * in e1000e_set_rx_mode */
4665 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4666 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4667 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4668
4669 fctrl &= ~(IXGBE_FCTRL_DPF);
4670 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4671 }
4672
Auke Kok9a799d72007-09-15 14:07:45 -07004673 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004674
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004675 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004676 ixgbe_vlan_strip_enable(adapter);
4677 else
4678 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004679
4680 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4681 ixgbe_vlan_promisc_disable(adapter);
4682 else
4683 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004684}
4685
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004686static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4687{
4688 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004689
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004690 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004691 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004692}
4693
4694static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4695{
4696 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004697
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004698 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004699 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004700}
4701
Emil Tantilova21d0822016-08-10 11:19:23 -07004702static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07004703{
Emil Tantilova21d0822016-08-10 11:19:23 -07004704 struct ixgbe_hw *hw = &adapter->hw;
4705 u32 vxlanctrl;
4706
4707 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
4708 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
4709 return;
4710
4711 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask;
4712 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
4713
4714 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07004715 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07004716
4717 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
4718 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07004719}
4720
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004721#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004722/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004723 * ixgbe_configure_dcb - Configure DCB hardware
4724 * @adapter: ixgbe adapter struct
4725 *
4726 * This is called by the driver on open to configure the DCB hardware.
4727 * This is also called by the gennetlink interface when reconfiguring
4728 * the DCB state.
4729 */
4730static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4731{
4732 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00004733 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004734
Alexander Duyck67ebd792010-08-19 13:34:04 +00004735 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4736 if (hw->mac.type == ixgbe_mac_82598EB)
4737 netif_set_gso_max_size(adapter->netdev, 65536);
4738 return;
4739 }
4740
4741 if (hw->mac.type == ixgbe_mac_82598EB)
4742 netif_set_gso_max_size(adapter->netdev, 32768);
4743
John Fastabendb1208182011-10-15 05:00:10 +00004744#ifdef IXGBE_FCOE
4745 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4746 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4747#endif
4748
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004749 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004750 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004751 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4752 DCB_TX_CONFIG);
4753 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4754 DCB_RX_CONFIG);
4755 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004756 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4757 ixgbe_dcb_hw_ets(&adapter->hw,
4758 adapter->ixgbe_ieee_ets,
4759 max_frame);
4760 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4761 adapter->ixgbe_ieee_pfc->pfc_en,
4762 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004763 }
John Fastabend8187cd42011-02-23 05:58:08 +00004764
4765 /* Enable RSS Hash per TC */
4766 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004767 u32 msb = 0;
4768 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004769
Alexander Duyckd411a932012-06-30 00:14:01 +00004770 while (rss_i) {
4771 msb++;
4772 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004773 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004774
Alexander Duyck4ae63732012-06-22 06:46:33 +00004775 /* write msb to all 8 TCs in one write */
4776 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004777 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004778}
John Fastabend9da712d2011-08-23 03:14:22 +00004779#endif
4780
4781/* Additional bittime to account for IXGBE framing */
4782#define IXGBE_ETH_FRAMING 20
4783
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004784/**
John Fastabend9da712d2011-08-23 03:14:22 +00004785 * ixgbe_hpbthresh - calculate high water mark for flow control
4786 *
4787 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004788 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004789 */
4790static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4791{
4792 struct ixgbe_hw *hw = &adapter->hw;
4793 struct net_device *dev = adapter->netdev;
4794 int link, tc, kb, marker;
4795 u32 dv_id, rx_pba;
4796
4797 /* Calculate max LAN frame size */
4798 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4799
4800#ifdef IXGBE_FCOE
4801 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004802 if ((dev->features & NETIF_F_FCOE_MTU) &&
4803 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4804 (pb == ixgbe_fcoe_get_tc(adapter)))
4805 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004806#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004807
John Fastabend9da712d2011-08-23 03:14:22 +00004808 /* Calculate delay value for device */
4809 switch (hw->mac.type) {
4810 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004811 case ixgbe_mac_X550:
4812 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004813 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004814 dv_id = IXGBE_DV_X540(link, tc);
4815 break;
4816 default:
4817 dv_id = IXGBE_DV(link, tc);
4818 break;
4819 }
4820
4821 /* Loopback switch introduces additional latency */
4822 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4823 dv_id += IXGBE_B2BT(tc);
4824
4825 /* Delay value is calculated in bit times convert to KB */
4826 kb = IXGBE_BT2KB(dv_id);
4827 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4828
4829 marker = rx_pba - kb;
4830
4831 /* It is possible that the packet buffer is not large enough
4832 * to provide required headroom. In this case throw an error
4833 * to user and a do the best we can.
4834 */
4835 if (marker < 0) {
4836 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4837 "headroom to support flow control."
4838 "Decrease MTU or number of traffic classes\n", pb);
4839 marker = tc + 1;
4840 }
4841
4842 return marker;
4843}
4844
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004845/**
John Fastabend9da712d2011-08-23 03:14:22 +00004846 * ixgbe_lpbthresh - calculate low water mark for for flow control
4847 *
4848 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004849 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004850 */
Jacob Kellere5776622014-04-05 02:35:52 +00004851static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00004852{
4853 struct ixgbe_hw *hw = &adapter->hw;
4854 struct net_device *dev = adapter->netdev;
4855 int tc;
4856 u32 dv_id;
4857
4858 /* Calculate max LAN frame size */
4859 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4860
Jacob Kellere5776622014-04-05 02:35:52 +00004861#ifdef IXGBE_FCOE
4862 /* FCoE traffic class uses FCOE jumbo frames */
4863 if ((dev->features & NETIF_F_FCOE_MTU) &&
4864 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4865 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4866 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4867#endif
4868
John Fastabend9da712d2011-08-23 03:14:22 +00004869 /* Calculate delay value for device */
4870 switch (hw->mac.type) {
4871 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004872 case ixgbe_mac_X550:
4873 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004874 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004875 dv_id = IXGBE_LOW_DV_X540(tc);
4876 break;
4877 default:
4878 dv_id = IXGBE_LOW_DV(tc);
4879 break;
4880 }
4881
4882 /* Delay value is calculated in bit times convert to KB */
4883 return IXGBE_BT2KB(dv_id);
4884}
4885
4886/*
4887 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4888 */
4889static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4890{
4891 struct ixgbe_hw *hw = &adapter->hw;
4892 int num_tc = netdev_get_num_tc(adapter->netdev);
4893 int i;
4894
4895 if (!num_tc)
4896 num_tc = 1;
4897
John Fastabend9da712d2011-08-23 03:14:22 +00004898 for (i = 0; i < num_tc; i++) {
4899 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00004900 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00004901
4902 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00004903 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4904 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004905 }
Jacob Kellere5776622014-04-05 02:35:52 +00004906
4907 for (; i < MAX_TRAFFIC_CLASS; i++)
4908 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004909}
John Fastabend80605c652011-05-02 12:34:10 +00004910
4911static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4912{
John Fastabend80605c652011-05-02 12:34:10 +00004913 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004914 int hdrm;
4915 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004916
4917 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4918 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004919 hdrm = 32 << adapter->fdir_pballoc;
4920 else
4921 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004922
Alexander Duyckf7e10272011-07-21 00:40:35 +00004923 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004924 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004925}
4926
Alexander Duycke4911d52011-05-11 07:18:52 +00004927static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4928{
4929 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004930 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004931 struct ixgbe_fdir_filter *filter;
4932
4933 spin_lock(&adapter->fdir_perfect_lock);
4934
4935 if (!hlist_empty(&adapter->fdir_filter_list))
4936 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4937
Sasha Levinb67bfe02013-02-27 17:06:00 -08004938 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004939 &adapter->fdir_filter_list, fdir_node) {
4940 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004941 &filter->filter,
4942 filter->sw_idx,
4943 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4944 IXGBE_FDIR_DROP_QUEUE :
4945 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004946 }
4947
4948 spin_unlock(&adapter->fdir_perfect_lock);
4949}
4950
John Fastabend2a47fa42013-11-06 09:54:52 -08004951static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4952 struct ixgbe_adapter *adapter)
4953{
4954 struct ixgbe_hw *hw = &adapter->hw;
4955 u32 vmolr;
4956
4957 /* No unicast promiscuous support for VMDQ devices. */
4958 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4959 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4960
4961 /* clear the affected bit */
4962 vmolr &= ~IXGBE_VMOLR_MPE;
4963
4964 if (dev->flags & IFF_ALLMULTI) {
4965 vmolr |= IXGBE_VMOLR_MPE;
4966 } else {
4967 vmolr |= IXGBE_VMOLR_ROMPE;
4968 hw->mac.ops.update_mc_addr_list(hw, dev);
4969 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00004970 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08004971 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4972}
4973
John Fastabend2a47fa42013-11-06 09:54:52 -08004974static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4975{
4976 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004977 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004978 struct ixgbe_hw *hw = &adapter->hw;
4979 u16 pool = vadapter->pool;
4980 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4981 IXGBE_PSRTYPE_UDPHDR |
4982 IXGBE_PSRTYPE_IPV4HDR |
4983 IXGBE_PSRTYPE_L2HDR |
4984 IXGBE_PSRTYPE_IPV6HDR;
4985
4986 if (hw->mac.type == ixgbe_mac_82598EB)
4987 return;
4988
4989 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004990 psrtype |= 2u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004991 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004992 psrtype |= 1u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004993
4994 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4995}
4996
4997/**
4998 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4999 * @rx_ring: ring to free buffers from
5000 **/
5001static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
5002{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005003 u16 i = rx_ring->next_to_clean;
5004 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08005005
5006 /* Free all the Rx ring sk_buffs */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005007 while (i != rx_ring->next_to_alloc) {
John Fastabend2a47fa42013-11-06 09:54:52 -08005008 if (rx_buffer->skb) {
5009 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00005010 if (IXGBE_CB(skb)->page_released)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005011 dma_unmap_page_attrs(rx_ring->dev,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005012 IXGBE_CB(skb)->dma,
5013 ixgbe_rx_pg_size(rx_ring),
5014 DMA_FROM_DEVICE,
5015 IXGBE_RX_DMA_ATTR);
John Fastabend2a47fa42013-11-06 09:54:52 -08005016 dev_kfree_skb(skb);
5017 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00005018
Alexander Duyckf3213d92017-01-17 08:35:54 -08005019 /* Invalidate cache lines that may have been written to by
5020 * device so that we avoid corrupting memory.
5021 */
5022 dma_sync_single_range_for_cpu(rx_ring->dev,
5023 rx_buffer->dma,
5024 rx_buffer->page_offset,
5025 ixgbe_rx_bufsz(rx_ring),
5026 DMA_FROM_DEVICE);
5027
5028 /* free resources associated with mapping */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005029 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005030 ixgbe_rx_pg_size(rx_ring),
5031 DMA_FROM_DEVICE,
5032 IXGBE_RX_DMA_ATTR);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08005033 __page_frag_cache_drain(rx_buffer->page,
5034 rx_buffer->pagecnt_bias);
Alexander Duyck18cb6522014-11-14 00:56:29 +00005035
Alexander Duyckffed21b2017-01-17 08:37:29 -08005036 i++;
5037 rx_buffer++;
5038 if (i == rx_ring->count) {
5039 i = 0;
5040 rx_buffer = rx_ring->rx_buffer_info;
5041 }
John Fastabend2a47fa42013-11-06 09:54:52 -08005042 }
5043
John Fastabend2a47fa42013-11-06 09:54:52 -08005044 rx_ring->next_to_alloc = 0;
5045 rx_ring->next_to_clean = 0;
5046 rx_ring->next_to_use = 0;
5047}
5048
5049static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
5050 struct ixgbe_ring *rx_ring)
5051{
5052 struct ixgbe_adapter *adapter = vadapter->real_adapter;
5053 int index = rx_ring->queue_index + vadapter->rx_base_queue;
5054
5055 /* shutdown specific queue receive and wait for dma to settle */
5056 ixgbe_disable_rx_queue(adapter, rx_ring);
5057 usleep_range(10000, 20000);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005058 ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
John Fastabend2a47fa42013-11-06 09:54:52 -08005059 ixgbe_clean_rx_ring(rx_ring);
5060 rx_ring->l2_accel_priv = NULL;
5061}
5062
John Fastabendae72c8d2013-11-09 07:11:26 +00005063static int ixgbe_fwd_ring_down(struct net_device *vdev,
5064 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08005065{
5066 struct ixgbe_adapter *adapter = accel->real_adapter;
5067 unsigned int rxbase = accel->rx_base_queue;
5068 unsigned int txbase = accel->tx_base_queue;
5069 int i;
5070
5071 netif_tx_stop_all_queues(vdev);
5072
5073 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5074 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5075 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
5076 }
5077
5078 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5079 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
5080 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
5081 }
5082
5083
5084 return 0;
5085}
5086
5087static int ixgbe_fwd_ring_up(struct net_device *vdev,
5088 struct ixgbe_fwd_adapter *accel)
5089{
5090 struct ixgbe_adapter *adapter = accel->real_adapter;
5091 unsigned int rxbase, txbase, queues;
5092 int i, baseq, err = 0;
5093
5094 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
5095 return 0;
5096
5097 baseq = accel->pool * adapter->num_rx_queues_per_pool;
5098 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
5099 accel->pool, adapter->num_rx_pools,
5100 baseq, baseq + adapter->num_rx_queues_per_pool,
5101 adapter->fwd_bitmask);
5102
5103 accel->netdev = vdev;
5104 accel->rx_base_queue = rxbase = baseq;
5105 accel->tx_base_queue = txbase = baseq;
5106
5107 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5108 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5109
5110 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5111 adapter->rx_ring[rxbase + i]->netdev = vdev;
5112 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
5113 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
5114 }
5115
5116 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5117 adapter->tx_ring[txbase + i]->netdev = vdev;
5118 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
5119 }
5120
5121 queues = min_t(unsigned int,
5122 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
5123 err = netif_set_real_num_tx_queues(vdev, queues);
5124 if (err)
5125 goto fwd_queue_err;
5126
John Fastabend2a47fa42013-11-06 09:54:52 -08005127 err = netif_set_real_num_rx_queues(vdev, queues);
5128 if (err)
5129 goto fwd_queue_err;
5130
5131 if (is_valid_ether_addr(vdev->dev_addr))
5132 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
5133
5134 ixgbe_fwd_psrtype(accel);
5135 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
5136 return err;
5137fwd_queue_err:
5138 ixgbe_fwd_ring_down(vdev, accel);
5139 return err;
5140}
5141
David Ahern1cd127f2016-10-17 19:15:48 -07005142static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
5143{
5144 if (netif_is_macvlan(upper)) {
5145 struct macvlan_dev *dfwd = netdev_priv(upper);
5146 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5147
5148 if (dfwd->fwd_priv)
5149 ixgbe_fwd_ring_up(upper, vadapter);
5150 }
5151
5152 return 0;
5153}
5154
John Fastabend2a47fa42013-11-06 09:54:52 -08005155static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5156{
David Ahern1cd127f2016-10-17 19:15:48 -07005157 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5158 ixgbe_upper_dev_walk, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005159}
5160
Auke Kok9a799d72007-09-15 14:07:45 -07005161static void ixgbe_configure(struct ixgbe_adapter *adapter)
5162{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005163 struct ixgbe_hw *hw = &adapter->hw;
5164
John Fastabend80605c652011-05-02 12:34:10 +00005165 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005166#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005167 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005168#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005169 /*
5170 * We must restore virtualization before VLANs or else
5171 * the VLVF registers will not be populated
5172 */
5173 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005174
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005175 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005176 ixgbe_restore_vlan(adapter);
5177
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005178 switch (hw->mac.type) {
5179 case ixgbe_mac_82599EB:
5180 case ixgbe_mac_X540:
5181 hw->mac.ops.disable_rx_buff(hw);
5182 break;
5183 default:
5184 break;
5185 }
5186
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005187 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005188 ixgbe_init_fdir_signature_82599(&adapter->hw,
5189 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005190 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5191 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5192 adapter->fdir_pballoc);
5193 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005194 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005195
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005196 switch (hw->mac.type) {
5197 case ixgbe_mac_82599EB:
5198 case ixgbe_mac_X540:
5199 hw->mac.ops.enable_rx_buff(hw);
5200 break;
5201 default:
5202 break;
5203 }
5204
Mark Rustad9de76052015-08-08 16:27:41 -07005205#ifdef CONFIG_IXGBE_DCA
5206 /* configure DCA */
5207 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5208 ixgbe_setup_dca(adapter);
5209#endif /* CONFIG_IXGBE_DCA */
5210
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005211#ifdef IXGBE_FCOE
5212 /* configure FCoE L2 filters, redirection table, and Rx control */
5213 ixgbe_configure_fcoe(adapter);
5214
5215#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005216 ixgbe_configure_tx(adapter);
5217 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005218 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005219}
5220
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005221/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005222 * ixgbe_sfp_link_config - set up SFP+ link
5223 * @adapter: pointer to private adapter struct
5224 **/
5225static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5226{
Alexander Duyck70864002011-04-27 09:13:56 +00005227 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005228 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005229 * is that an SFP was inserted/removed after the reset
5230 * but before SFP detection was enabled. As such the best
5231 * solution is to just start searching as soon as we start
5232 */
5233 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5234 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005235
Alexander Duyck70864002011-04-27 09:13:56 +00005236 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005237 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005238}
5239
5240/**
5241 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005242 * @hw: pointer to private hardware struct
5243 *
5244 * Returns 0 on success, negative on failure
5245 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005246static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005247{
Josh Hay3d292262012-12-15 03:28:19 +00005248 u32 speed;
5249 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005250 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005251
5252 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005253 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005254
5255 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005256 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005257
Josh Hay3d292262012-12-15 03:28:19 +00005258 speed = hw->phy.autoneg_advertised;
5259 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5260 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5261 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005262 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005263 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005264
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005265 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005266 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005267
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005268 return ret;
5269}
5270
Alexander Duycka34bcff2010-08-19 13:39:20 +00005271static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005272{
Auke Kok9a799d72007-09-15 14:07:45 -07005273 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005274 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005275
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005276 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005277 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5278 IXGBE_GPIE_OCD;
5279 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005280 /*
5281 * use EIAM to auto-mask when MSI-X interrupt is asserted
5282 * this saves a register write for every interrupt
5283 */
5284 switch (hw->mac.type) {
5285 case ixgbe_mac_82598EB:
5286 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5287 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005288 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005289 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005290 case ixgbe_mac_X550:
5291 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005292 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005293 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005294 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5295 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5296 break;
5297 }
5298 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005299 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5300 * specifically only auto mask tx and rx interrupts */
5301 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005302 }
5303
Alexander Duycka34bcff2010-08-19 13:39:20 +00005304 /* XXX: to interrupt immediately for EICS writes, enable this */
5305 /* gpie |= IXGBE_GPIE_EIMEN; */
5306
5307 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5308 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005309
5310 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5311 case IXGBE_82599_VMDQ_8Q_MASK:
5312 gpie |= IXGBE_GPIE_VTMODE_16;
5313 break;
5314 case IXGBE_82599_VMDQ_4Q_MASK:
5315 gpie |= IXGBE_GPIE_VTMODE_32;
5316 break;
5317 default:
5318 gpie |= IXGBE_GPIE_VTMODE_64;
5319 break;
5320 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005321 }
5322
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005323 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005324 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5325 switch (adapter->hw.mac.type) {
5326 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005327 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005328 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005329 default:
5330 break;
5331 }
5332 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005333
Alexander Duycka34bcff2010-08-19 13:39:20 +00005334 /* Enable fan failure interrupt */
5335 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005336 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005337
Don Skidmorea023bbd2015-06-24 16:38:53 -04005338 switch (hw->mac.type) {
5339 case ixgbe_mac_82599EB:
5340 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5341 break;
5342 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005343 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005344 gpie |= IXGBE_SDP0_GPIEN_X540;
5345 break;
5346 default:
5347 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005348 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005349
5350 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5351}
5352
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005353static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005354{
5355 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005356 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005357 u32 ctrl_ext;
5358
5359 ixgbe_get_hw_control(adapter);
5360 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005361
Auke Kok9a799d72007-09-15 14:07:45 -07005362 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5363 ixgbe_configure_msix(adapter);
5364 else
5365 ixgbe_configure_msi_and_legacy(adapter);
5366
Emil Tantilovec74a472012-09-20 03:33:56 +00005367 /* enable the optics for 82599 SFP+ fiber */
5368 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005369 hw->mac.ops.enable_tx_laser(hw);
5370
Don Skidmore961fac82015-06-09 16:09:47 -07005371 if (hw->phy.ops.set_phy_power)
5372 hw->phy.ops.set_phy_power(hw, true);
5373
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005374 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005375 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005376 ixgbe_napi_enable_all(adapter);
5377
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005378 if (ixgbe_is_sfp(hw)) {
5379 ixgbe_sfp_link_config(adapter);
5380 } else {
5381 err = ixgbe_non_sfp_link_config(hw);
5382 if (err)
5383 e_err(probe, "link_config FAILED %d\n", err);
5384 }
5385
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005386 /* clear any pending interrupts, may auto mask */
5387 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005388 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005389
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005390 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005391 * If this adapter has a fan, check to see if we had a failure
5392 * before we enabled the interrupt.
5393 */
5394 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5395 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5396 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005397 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005398 }
5399
Auke Kok9a799d72007-09-15 14:07:45 -07005400 /* bring the link up in the watchdog, this could race with our first
5401 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005402 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5403 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005404 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005405
5406 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5407 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5408 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5409 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005410}
5411
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005412void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5413{
5414 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005415 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005416 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005417
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005418 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005419 usleep_range(1000, 2000);
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005420 if (adapter->hw.phy.type == ixgbe_phy_fw)
5421 ixgbe_watchdog_link_is_down(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005422 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005423 /*
5424 * If SR-IOV enabled then wait a bit before bringing the adapter
5425 * back up to give the VFs time to respond to the reset. The
5426 * two second wait is based upon the watchdog timer cycle in
5427 * the VF driver.
5428 */
5429 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5430 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005431 ixgbe_up(adapter);
5432 clear_bit(__IXGBE_RESETTING, &adapter->state);
5433}
5434
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005435void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005436{
5437 /* hardware has been reset, we need to reload some things */
5438 ixgbe_configure(adapter);
5439
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005440 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005441}
5442
5443void ixgbe_reset(struct ixgbe_adapter *adapter)
5444{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005445 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005446 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005447 int err;
5448
Mark Rustadb0483c82014-01-14 18:53:17 -08005449 if (ixgbe_removed(hw->hw_addr))
5450 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005451 /* lock SFP init bit to prevent race conditions with the watchdog */
5452 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5453 usleep_range(1000, 2000);
5454
5455 /* clear all SFP and link config related flags while holding SFP_INIT */
5456 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5457 IXGBE_FLAG2_SFP_NEEDS_RESET);
5458 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5459
Don Skidmore8ca783a2009-05-26 20:40:47 -07005460 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005461 switch (err) {
5462 case 0:
5463 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005464 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005465 break;
5466 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005467 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005468 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005469 case IXGBE_ERR_EEPROM_VERSION:
5470 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005471 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005472 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005473 "your hardware. If you are experiencing problems "
5474 "please contact your Intel or hardware "
5475 "representative who provided you with this "
5476 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005477 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005478 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005479 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005480 }
Auke Kok9a799d72007-09-15 14:07:45 -07005481
Alexander Duyck70864002011-04-27 09:13:56 +00005482 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005483
5484 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005485 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005486 __dev_uc_unsync(netdev, NULL);
5487
5488 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005489 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005490
5491 /* update SAN MAC vmdq pool selection */
5492 if (hw->mac.san_mac_rar_index)
5493 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005494
Jacob Keller8fecf672013-06-21 08:14:32 +00005495 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005496 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005497
5498 if (hw->phy.ops.set_phy_power) {
5499 if (!netif_running(adapter->netdev) && !adapter->wol)
5500 hw->phy.ops.set_phy_power(hw, false);
5501 else
5502 hw->phy.ops.set_phy_power(hw, true);
5503 }
Auke Kok9a799d72007-09-15 14:07:45 -07005504}
5505
Auke Kok9a799d72007-09-15 14:07:45 -07005506/**
Auke Kok9a799d72007-09-15 14:07:45 -07005507 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005508 * @tx_ring: ring to be cleaned
5509 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005510static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005511{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005512 u16 i = tx_ring->next_to_clean;
5513 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07005514
Alexander Duyckffed21b2017-01-17 08:37:29 -08005515 while (i != tx_ring->next_to_use) {
5516 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -07005517
Alexander Duyckffed21b2017-01-17 08:37:29 -08005518 /* Free all the Tx ring sk_buffs */
5519 dev_kfree_skb_any(tx_buffer->skb);
5520
5521 /* unmap skb header data */
5522 dma_unmap_single(tx_ring->dev,
5523 dma_unmap_addr(tx_buffer, dma),
5524 dma_unmap_len(tx_buffer, len),
5525 DMA_TO_DEVICE);
5526
5527 /* check for eop_desc to determine the end of the packet */
5528 eop_desc = tx_buffer->next_to_watch;
5529 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5530
5531 /* unmap remaining buffers */
5532 while (tx_desc != eop_desc) {
5533 tx_buffer++;
5534 tx_desc++;
5535 i++;
5536 if (unlikely(i == tx_ring->count)) {
5537 i = 0;
5538 tx_buffer = tx_ring->tx_buffer_info;
5539 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5540 }
5541
5542 /* unmap any remaining paged data */
5543 if (dma_unmap_len(tx_buffer, len))
5544 dma_unmap_page(tx_ring->dev,
5545 dma_unmap_addr(tx_buffer, dma),
5546 dma_unmap_len(tx_buffer, len),
5547 DMA_TO_DEVICE);
5548 }
5549
5550 /* move us one more past the eop_desc for start of next pkt */
5551 tx_buffer++;
5552 i++;
5553 if (unlikely(i == tx_ring->count)) {
5554 i = 0;
5555 tx_buffer = tx_ring->tx_buffer_info;
5556 }
Auke Kok9a799d72007-09-15 14:07:45 -07005557 }
5558
Alexander Duyckffed21b2017-01-17 08:37:29 -08005559 /* reset BQL for queue */
John Fastabenddad8a3b2012-04-23 12:22:39 +00005560 netdev_tx_reset_queue(txring_txq(tx_ring));
5561
Alexander Duyckffed21b2017-01-17 08:37:29 -08005562 /* reset next_to_use and next_to_clean */
Auke Kok9a799d72007-09-15 14:07:45 -07005563 tx_ring->next_to_use = 0;
5564 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005565}
5566
5567/**
Auke Kok9a799d72007-09-15 14:07:45 -07005568 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5569 * @adapter: board private structure
5570 **/
5571static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5572{
5573 int i;
5574
5575 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005576 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005577}
5578
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005579/**
5580 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5581 * @adapter: board private structure
5582 **/
5583static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5584{
5585 int i;
5586
5587 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005588 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005589}
5590
Alexander Duycke4911d52011-05-11 07:18:52 +00005591static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5592{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005593 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005594 struct ixgbe_fdir_filter *filter;
5595
5596 spin_lock(&adapter->fdir_perfect_lock);
5597
Sasha Levinb67bfe02013-02-27 17:06:00 -08005598 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005599 &adapter->fdir_filter_list, fdir_node) {
5600 hlist_del(&filter->fdir_node);
5601 kfree(filter);
5602 }
5603 adapter->fdir_filter_count = 0;
5604
5605 spin_unlock(&adapter->fdir_perfect_lock);
5606}
5607
David Ahern1cd127f2016-10-17 19:15:48 -07005608static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
5609{
5610 if (netif_is_macvlan(upper)) {
5611 struct macvlan_dev *vlan = netdev_priv(upper);
5612
5613 if (vlan->fwd_priv) {
5614 netif_tx_stop_all_queues(upper);
5615 netif_carrier_off(upper);
5616 netif_tx_disable(upper);
5617 }
5618 }
5619
5620 return 0;
5621}
5622
Auke Kok9a799d72007-09-15 14:07:45 -07005623void ixgbe_down(struct ixgbe_adapter *adapter)
5624{
5625 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005626 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005627 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005628
5629 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005630 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5631 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005632
5633 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005634 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005635
Yi Zou2d39d572011-01-06 14:29:56 +00005636 /* disable all enabled rx queues */
5637 for (i = 0; i < adapter->num_rx_queues; i++)
5638 /* this call also flushes the previous write */
5639 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5640
Don Skidmore032b4322011-03-18 09:32:53 +00005641 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005642
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005643 netif_tx_stop_all_queues(netdev);
5644
Alexander Duyck70864002011-04-27 09:13:56 +00005645 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005646 netif_carrier_off(netdev);
5647 netif_tx_disable(netdev);
5648
John Fastabend2a47fa42013-11-06 09:54:52 -08005649 /* disable any upper devices */
David Ahern1cd127f2016-10-17 19:15:48 -07005650 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5651 ixgbe_disable_macvlan, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005652
John Fastabendc0dfb902010-04-27 02:13:39 +00005653 ixgbe_irq_disable(adapter);
5654
5655 ixgbe_napi_disable_all(adapter);
5656
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005657 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5658 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005659 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5660
5661 del_timer_sync(&adapter->service_timer);
5662
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005663 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005664 /* Clear EITR Select mapping */
5665 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5666
5667 /* Mark all the VFs as inactive */
5668 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005669 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005670
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005671 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005672 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005673
Auke Kok9a799d72007-09-15 14:07:45 -07005674 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005675 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005676 }
5677
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005678 /* disable transmits in the hardware now that interrupts are off */
5679 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005680 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005681 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005682 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005683
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005684 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005685 switch (hw->mac.type) {
5686 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005687 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005688 case ixgbe_mac_X550:
5689 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005690 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005691 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005692 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5693 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005694 break;
5695 default:
5696 break;
5697 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005698
Paul Larson6f4a0e42008-06-24 17:00:56 -07005699 if (!pci_channel_offline(adapter->pdev))
5700 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005701
Emil Tantilovec74a472012-09-20 03:33:56 +00005702 /* power down the optics for 82599 SFP+ fiber */
5703 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005704 hw->mac.ops.disable_tx_laser(hw);
5705
Auke Kok9a799d72007-09-15 14:07:45 -07005706 ixgbe_clean_all_tx_rings(adapter);
5707 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005708}
5709
Auke Kok9a799d72007-09-15 14:07:45 -07005710/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005711 * ixgbe_eee_capable - helper function to determine EEE support on X550
5712 * @adapter: board private structure
5713 */
5714static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
5715{
5716 struct ixgbe_hw *hw = &adapter->hw;
5717
5718 switch (hw->device_id) {
5719 case IXGBE_DEV_ID_X550EM_A_1G_T:
5720 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
5721 if (!hw->phy.eee_speeds_supported)
5722 break;
5723 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
5724 if (!hw->phy.eee_speeds_advertised)
5725 break;
5726 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
5727 break;
5728 default:
5729 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
5730 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
5731 break;
5732 }
5733}
5734
5735/**
Auke Kok9a799d72007-09-15 14:07:45 -07005736 * ixgbe_tx_timeout - Respond to a Tx Hang
5737 * @netdev: network interface device structure
5738 **/
5739static void ixgbe_tx_timeout(struct net_device *netdev)
5740{
5741 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5742
5743 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005744 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005745}
5746
Usha Ketineni88290092016-04-26 05:00:26 -07005747#ifdef CONFIG_IXGBE_DCB
5748static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
5749{
5750 struct ixgbe_hw *hw = &adapter->hw;
5751 struct tc_configuration *tc;
5752 int j;
5753
5754 switch (hw->mac.type) {
5755 case ixgbe_mac_82598EB:
5756 case ixgbe_mac_82599EB:
5757 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5758 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5759 break;
5760 case ixgbe_mac_X540:
5761 case ixgbe_mac_X550:
5762 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5763 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5764 break;
5765 case ixgbe_mac_X550EM_x:
5766 case ixgbe_mac_x550em_a:
5767 default:
5768 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
5769 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
5770 break;
5771 }
5772
5773 /* Configure DCB traffic classes */
5774 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5775 tc = &adapter->dcb_cfg.tc_config[j];
5776 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5777 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5778 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5779 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5780 tc->dcb_pfc = pfc_disabled;
5781 }
5782
5783 /* Initialize default user to priority mapping, UPx->TC0 */
5784 tc = &adapter->dcb_cfg.tc_config[0];
5785 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5786 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5787
5788 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5789 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5790 adapter->dcb_cfg.pfc_mode_enable = false;
5791 adapter->dcb_set_bitmap = 0x00;
5792 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
5793 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5794 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5795 sizeof(adapter->temp_dcb_cfg));
5796}
5797#endif
5798
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005799/**
Auke Kok9a799d72007-09-15 14:07:45 -07005800 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5801 * @adapter: board private structure to initialize
5802 *
5803 * ixgbe_sw_init initializes the Adapter private data structure.
5804 * Fields are initialized based on PCI device information and
5805 * OS network device settings (MTU size).
5806 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07005807static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
5808 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07005809{
5810 struct ixgbe_hw *hw = &adapter->hw;
5811 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005812 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005813 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005814 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005815
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005816 /* PCI config space info */
5817
5818 hw->vendor_id = pdev->vendor;
5819 hw->device_id = pdev->device;
5820 hw->revision_id = pdev->revision;
5821 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5822 hw->subsystem_device_id = pdev->subsystem_device;
5823
Emil Tantilov55570b62016-10-12 12:34:25 -07005824 /* get_invariants needs the device IDs */
5825 ii->get_invariants(hw);
5826
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005827 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00005828 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005829 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005830 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005831 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5832 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005833 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5834 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005835 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5836#ifdef CONFIG_IXGBE_DCA
5837 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5838#endif
Usha Ketineni88290092016-04-26 05:00:26 -07005839#ifdef CONFIG_IXGBE_DCB
5840 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
5841 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
5842#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005843#ifdef IXGBE_FCOE
5844 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5845 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5846#ifdef CONFIG_IXGBE_DCB
5847 /* Default traffic class to use for FCoE */
5848 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5849#endif /* CONFIG_IXGBE_DCB */
5850#endif /* IXGBE_FCOE */
5851
John Fastabendb82b17d2016-02-16 21:18:53 -08005852 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005853 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
5854 GFP_KERNEL);
5855 if (!adapter->jump_tables[0])
5856 return -ENOMEM;
5857 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
5858
5859 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
5860 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08005861
Jacob Keller5d7daa32014-03-29 06:51:25 +00005862 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5863 hw->mac.num_rar_entries,
5864 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08005865 if (!adapter->mac_table)
5866 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005867
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005868 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005869 switch (hw->mac.type) {
5870 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005871 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005872
Don Skidmorebf069c92009-05-07 10:39:54 +00005873 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5874 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005875
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005876 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005877 adapter->ring_feature[RING_F_FDIR].limit = 0;
5878 adapter->atr_sample_rate = 0;
5879 adapter->fdir_pballoc = 0;
5880#ifdef IXGBE_FCOE
5881 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5882 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5883#ifdef CONFIG_IXGBE_DCB
5884 adapter->fcoe.up = 0;
5885#endif /* IXGBE_DCB */
5886#endif /* IXGBE_FCOE */
5887 break;
5888 case ixgbe_mac_82599EB:
5889 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5890 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005891 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005892 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005893 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005894 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5895 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005896 break;
Mark Rustad49425df2016-04-01 12:18:09 -07005897 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07005898 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005899 switch (hw->device_id) {
5900 case IXGBE_DEV_ID_X550EM_A_1G_T:
5901 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
5902 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5903 break;
5904 default:
5905 break;
5906 }
Emil Tantilova21d0822016-08-10 11:19:23 -07005907 /* fall through */
5908 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07005909#ifdef CONFIG_IXGBE_DCB
5910 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
5911#endif
5912#ifdef IXGBE_FCOE
5913 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5914#ifdef CONFIG_IXGBE_DCB
5915 adapter->fcoe.up = 0;
5916#endif /* IXGBE_DCB */
5917#endif /* IXGBE_FCOE */
5918 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005919 case ixgbe_mac_X550:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005920 if (hw->mac.type == ixgbe_mac_X550)
5921 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005922#ifdef CONFIG_IXGBE_DCA
5923 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
5924#endif
Mark Rustad67359c32015-06-15 11:33:25 -07005925 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005926 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08005927 default:
5928 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005929 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005930
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005931#ifdef IXGBE_FCOE
5932 /* FCoE support exists, always init the FCoE lock */
5933 spin_lock_init(&adapter->fcoe.lock);
5934
5935#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005936 /* n-tuple support exists, always init our spinlock */
5937 spin_lock_init(&adapter->fdir_perfect_lock);
5938
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005939#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07005940 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005941#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005942
5943 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005944 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005945 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005946 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005947 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5948 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005949 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005950
Alexander Duyck99d74482012-05-09 08:09:25 +00005951#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005952 if (max_vfs > 0)
5953 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 +00005954
Jacob Keller170e8542013-11-09 04:52:32 -08005955 /* assign number of SR-IOV VFs */
5956 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005957 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Emil Tantilov5c11f002017-01-20 14:11:56 -08005958 max_vfs = 0;
Jacob Keller170e8542013-11-09 04:52:32 -08005959 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
Jacob Keller170e8542013-11-09 04:52:32 -08005960 }
5961 }
5962#endif /* CONFIG_PCI_IOV */
5963
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005964 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005965 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005966 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005967
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005968 /* set default ring sizes */
5969 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5970 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5971
Alexander Duyckbd198052011-06-11 01:45:08 +00005972 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005973 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005974
Auke Kok9a799d72007-09-15 14:07:45 -07005975 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005976 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005977 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005978 return -EIO;
5979 }
5980
John Fastabend2a47fa42013-11-06 09:54:52 -08005981 /* PF holds first pool slot */
5982 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005983 set_bit(__IXGBE_DOWN, &adapter->state);
5984
5985 return 0;
5986}
5987
5988/**
5989 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005990 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005991 *
5992 * Return 0 on success, negative on failure
5993 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005994int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005995{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005996 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005997 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005998 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005999 int size;
6000
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006001 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006002
6003 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006004 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006005
Alexander Duyckffed21b2017-01-17 08:37:29 -08006006 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006007 if (!tx_ring->tx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006008 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006009 if (!tx_ring->tx_buffer_info)
6010 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006011
John Stultz827da442013-10-07 15:51:58 -07006012 u64_stats_init(&tx_ring->syncp);
6013
Auke Kok9a799d72007-09-15 14:07:45 -07006014 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08006015 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006016 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006017
Mark Rustadca8dfe22014-07-24 06:19:24 +00006018 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006019 tx_ring->desc = dma_alloc_coherent(dev,
6020 tx_ring->size,
6021 &tx_ring->dma,
6022 GFP_KERNEL);
6023 set_dev_node(dev, orig_node);
6024 if (!tx_ring->desc)
6025 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6026 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006027 if (!tx_ring->desc)
6028 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006029
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006030 tx_ring->next_to_use = 0;
6031 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006032 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006033
6034err:
6035 vfree(tx_ring->tx_buffer_info);
6036 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006037 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006038 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006039}
6040
6041/**
Alexander Duyck69888672008-09-11 20:05:39 -07006042 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6043 * @adapter: board private structure
6044 *
6045 * If this function returns with an error, then it's possible one or
6046 * more of the rings is populated (while the rest are not). It is the
6047 * callers duty to clean those orphaned rings.
6048 *
6049 * Return 0 on success, negative on failure
6050 **/
6051static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6052{
6053 int i, err = 0;
6054
6055 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006056 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006057 if (!err)
6058 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006059
Emil Tantilov396e7992010-07-01 20:05:12 +00006060 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006061 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07006062 }
6063
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006064 return 0;
6065err_setup_tx:
6066 /* rewind the index freeing the rings as we go */
6067 while (i--)
6068 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006069 return err;
6070}
6071
6072/**
Auke Kok9a799d72007-09-15 14:07:45 -07006073 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006074 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006075 *
6076 * Returns 0 on success, negative on failure
6077 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006078int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006079{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006080 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006081 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006082 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006083 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07006084
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006085 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006086
6087 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006088 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006089
Alexander Duyckffed21b2017-01-17 08:37:29 -08006090 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006091 if (!rx_ring->rx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006092 rx_ring->rx_buffer_info = vmalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006093 if (!rx_ring->rx_buffer_info)
6094 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006095
John Stultz827da442013-10-07 15:51:58 -07006096 u64_stats_init(&rx_ring->syncp);
6097
Auke Kok9a799d72007-09-15 14:07:45 -07006098 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006099 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6100 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006101
Mark Rustadca8dfe22014-07-24 06:19:24 +00006102 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006103 rx_ring->desc = dma_alloc_coherent(dev,
6104 rx_ring->size,
6105 &rx_ring->dma,
6106 GFP_KERNEL);
6107 set_dev_node(dev, orig_node);
6108 if (!rx_ring->desc)
6109 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6110 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006111 if (!rx_ring->desc)
6112 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006113
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006114 rx_ring->next_to_clean = 0;
6115 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006116
6117 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006118err:
6119 vfree(rx_ring->rx_buffer_info);
6120 rx_ring->rx_buffer_info = NULL;
6121 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07006122 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006123}
6124
6125/**
Alexander Duyck69888672008-09-11 20:05:39 -07006126 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6127 * @adapter: board private structure
6128 *
6129 * If this function returns with an error, then it's possible one or
6130 * more of the rings is populated (while the rest are not). It is the
6131 * callers duty to clean those orphaned rings.
6132 *
6133 * Return 0 on success, negative on failure
6134 **/
Alexander Duyck69888672008-09-11 20:05:39 -07006135static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6136{
6137 int i, err = 0;
6138
6139 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006140 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006141 if (!err)
6142 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006143
Emil Tantilov396e7992010-07-01 20:05:12 +00006144 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006145 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07006146 }
6147
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006148#ifdef IXGBE_FCOE
6149 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6150 if (!err)
6151#endif
6152 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006153err_setup_rx:
6154 /* rewind the index freeing the rings as we go */
6155 while (i--)
6156 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006157 return err;
6158}
6159
6160/**
Auke Kok9a799d72007-09-15 14:07:45 -07006161 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07006162 * @tx_ring: Tx descriptor ring for a specific queue
6163 *
6164 * Free all transmit software resources
6165 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006166void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006167{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006168 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006169
6170 vfree(tx_ring->tx_buffer_info);
6171 tx_ring->tx_buffer_info = NULL;
6172
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006173 /* if not set, then don't free */
6174 if (!tx_ring->desc)
6175 return;
6176
6177 dma_free_coherent(tx_ring->dev, tx_ring->size,
6178 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006179
6180 tx_ring->desc = NULL;
6181}
6182
6183/**
6184 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6185 * @adapter: board private structure
6186 *
6187 * Free all transmit software resources
6188 **/
6189static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6190{
6191 int i;
6192
6193 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006194 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006195 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006196}
6197
6198/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006199 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006200 * @rx_ring: ring to clean the resources from
6201 *
6202 * Free all receive software resources
6203 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006204void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006205{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006206 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006207
6208 vfree(rx_ring->rx_buffer_info);
6209 rx_ring->rx_buffer_info = NULL;
6210
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006211 /* if not set, then don't free */
6212 if (!rx_ring->desc)
6213 return;
6214
6215 dma_free_coherent(rx_ring->dev, rx_ring->size,
6216 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006217
6218 rx_ring->desc = NULL;
6219}
6220
6221/**
6222 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6223 * @adapter: board private structure
6224 *
6225 * Free all receive software resources
6226 **/
6227static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6228{
6229 int i;
6230
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006231#ifdef IXGBE_FCOE
6232 ixgbe_free_fcoe_ddp_resources(adapter);
6233
6234#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006235 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006236 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006237 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006238}
6239
6240/**
Auke Kok9a799d72007-09-15 14:07:45 -07006241 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6242 * @netdev: network interface device structure
6243 * @new_mtu: new value for maximum frame size
6244 *
6245 * Returns 0 on success, negative on failure
6246 **/
6247static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6248{
6249 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck655309e2012-02-08 07:50:35 +00006250
6251 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006252 * For 82599EB we cannot allow legacy VFs to enable their receive
6253 * paths when MTU greater than 1500 is configured. So display a
6254 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006255 */
6256 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6257 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Jarod Wilson91c527a2016-10-17 15:54:05 -04006258 (new_mtu > ETH_DATA_LEN))
Alexander Duyck872844d2012-08-15 02:10:43 +00006259 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006260
Emil Tantilov396e7992010-07-01 20:05:12 +00006261 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006262
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006263 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006264 netdev->mtu = new_mtu;
6265
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006266 if (netif_running(netdev))
6267 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006268
6269 return 0;
6270}
6271
6272/**
6273 * ixgbe_open - Called when a network interface is made active
6274 * @netdev: network interface device structure
6275 *
6276 * Returns 0 on success, negative value on failure
6277 *
6278 * The open entry point is called when a network interface is made
6279 * active by the system (IFF_UP). At this point all resources needed
6280 * for transmit and receive operations are allocated, the interrupt
6281 * handler is registered with the OS, the watchdog timer is started,
6282 * and the stack is notified that the interface is ready.
6283 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006284int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006285{
6286 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006287 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006288 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006289
Auke Kok4bebfaa2008-02-11 09:26:01 -08006290 /* disallow open during test */
6291 if (test_bit(__IXGBE_TESTING, &adapter->state))
6292 return -EBUSY;
6293
Jesse Brandeburg54386462009-04-17 20:44:27 +00006294 netif_carrier_off(netdev);
6295
Auke Kok9a799d72007-09-15 14:07:45 -07006296 /* allocate transmit descriptors */
6297 err = ixgbe_setup_all_tx_resources(adapter);
6298 if (err)
6299 goto err_setup_tx;
6300
Auke Kok9a799d72007-09-15 14:07:45 -07006301 /* allocate receive descriptors */
6302 err = ixgbe_setup_all_rx_resources(adapter);
6303 if (err)
6304 goto err_setup_rx;
6305
6306 ixgbe_configure(adapter);
6307
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006308 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006309 if (err)
6310 goto err_req_irq;
6311
Alexander Duyckac802f52012-07-12 05:52:53 +00006312 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08006313 if (adapter->num_rx_pools > 1)
6314 queues = adapter->num_rx_queues_per_pool;
6315 else
6316 queues = adapter->num_tx_queues;
6317
6318 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006319 if (err)
6320 goto err_set_queues;
6321
John Fastabend2a47fa42013-11-06 09:54:52 -08006322 if (adapter->num_rx_pools > 1 &&
6323 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
6324 queues = IXGBE_MAX_L2A_QUEUES;
6325 else
6326 queues = adapter->num_rx_queues;
6327 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006328 if (err)
6329 goto err_set_queues;
6330
Jacob Keller1a71ab22012-08-25 03:54:19 +00006331 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006332
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006333 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006334
Emil Tantilova21d0822016-08-10 11:19:23 -07006335 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
Alexander Duyckb3a49552016-06-16 12:22:19 -07006336 udp_tunnel_get_rx_info(netdev);
Mark Rustad67359c32015-06-15 11:33:25 -07006337
Auke Kok9a799d72007-09-15 14:07:45 -07006338 return 0;
6339
Alexander Duyckac802f52012-07-12 05:52:53 +00006340err_set_queues:
6341 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006342err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006343 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006344 if (hw->phy.ops.set_phy_power && !adapter->wol)
6345 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006346err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006347 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006348err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006349 ixgbe_reset(adapter);
6350
6351 return err;
6352}
6353
Jacob Kellera0cccce2014-05-16 05:12:29 +00006354static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6355{
6356 ixgbe_ptp_suspend(adapter);
6357
Don Skidmore6ac74392015-06-17 17:34:31 -04006358 if (adapter->hw.phy.ops.enter_lplu) {
6359 adapter->hw.phy.reset_disable = true;
6360 ixgbe_down(adapter);
6361 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6362 adapter->hw.phy.reset_disable = false;
6363 } else {
6364 ixgbe_down(adapter);
6365 }
6366
Jacob Kellera0cccce2014-05-16 05:12:29 +00006367 ixgbe_free_irq(adapter);
6368
6369 ixgbe_free_all_tx_resources(adapter);
6370 ixgbe_free_all_rx_resources(adapter);
6371}
6372
Auke Kok9a799d72007-09-15 14:07:45 -07006373/**
6374 * ixgbe_close - Disables a network interface
6375 * @netdev: network interface device structure
6376 *
6377 * Returns 0, this is not allowed to fail
6378 *
6379 * The close entry point is called when an interface is de-activated
6380 * by the OS. The hardware is still under the drivers control, but
6381 * needs to be disabled. A global MAC reset is issued to stop the
6382 * hardware, and all transmit and receive resources are freed.
6383 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006384int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006385{
6386 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006387
Jacob Keller1a71ab22012-08-25 03:54:19 +00006388 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006389
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006390 if (netif_device_present(netdev))
6391 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006392
Alexander Duycke4911d52011-05-11 07:18:52 +00006393 ixgbe_fdir_filter_exit(adapter);
6394
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006395 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006396
6397 return 0;
6398}
6399
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006400#ifdef CONFIG_PM
6401static int ixgbe_resume(struct pci_dev *pdev)
6402{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006403 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6404 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006405 u32 err;
6406
Mark Rustad0391bbe2014-02-28 15:48:55 -08006407 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006408 pci_set_power_state(pdev, PCI_D0);
6409 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006410 /*
6411 * pci_restore_state clears dev->state_saved so call
6412 * pci_save_state to restore it.
6413 */
6414 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006415
6416 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006417 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006418 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006419 return err;
6420 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006421 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006422 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006423 pci_set_master(pdev);
6424
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006425 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006426
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006427 ixgbe_reset(adapter);
6428
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006429 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6430
Alexander Duyckac802f52012-07-12 05:52:53 +00006431 rtnl_lock();
6432 err = ixgbe_init_interrupt_scheme(adapter);
6433 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006434 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006435
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006436
6437 if (!err)
6438 netif_device_attach(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006439 rtnl_unlock();
6440
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006441 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006442}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006443#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006444
6445static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006446{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006447 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6448 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006449 struct ixgbe_hw *hw = &adapter->hw;
6450 u32 ctrl, fctrl;
6451 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006452#ifdef CONFIG_PM
6453 int retval = 0;
6454#endif
6455
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006456 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006457 netif_device_detach(netdev);
6458
Jacob Kellera0cccce2014-05-16 05:12:29 +00006459 if (netif_running(netdev))
6460 ixgbe_close_suspend(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006461
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006462 ixgbe_clear_interrupt_scheme(adapter);
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006463 rtnl_unlock();
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006464
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006465#ifdef CONFIG_PM
6466 retval = pci_save_state(pdev);
6467 if (retval)
6468 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006469
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006470#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006471 if (hw->mac.ops.stop_link_on_d3)
6472 hw->mac.ops.stop_link_on_d3(hw);
6473
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006474 if (wufc) {
6475 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006476
Emil Tantilovec74a472012-09-20 03:33:56 +00006477 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6478 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006479 hw->mac.ops.enable_tx_laser(hw);
6480
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006481 /* turn on all-multi mode if wake on multicast is enabled */
6482 if (wufc & IXGBE_WUFC_MC) {
6483 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6484 fctrl |= IXGBE_FCTRL_MPE;
6485 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
6486 }
6487
6488 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6489 ctrl |= IXGBE_CTRL_GIO_DIS;
6490 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6491
6492 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6493 } else {
6494 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6495 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6496 }
6497
Alexander Duyckbd508172010-11-16 19:27:03 -08006498 switch (hw->mac.type) {
6499 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006500 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006501 break;
6502 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006503 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006504 case ixgbe_mac_X550:
6505 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006506 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006507 pci_wake_from_d3(pdev, !!wufc);
6508 break;
6509 default:
6510 break;
6511 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006512
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006513 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006514 if (hw->phy.ops.set_phy_power && !*enable_wake)
6515 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006516
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006517 ixgbe_release_hw_control(adapter);
6518
Mark Rustad41c62842014-03-12 00:38:35 +00006519 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6520 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006521
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006522 return 0;
6523}
6524
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006525#ifdef CONFIG_PM
6526static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6527{
6528 int retval;
6529 bool wake;
6530
6531 retval = __ixgbe_shutdown(pdev, &wake);
6532 if (retval)
6533 return retval;
6534
6535 if (wake) {
6536 pci_prepare_to_sleep(pdev);
6537 } else {
6538 pci_wake_from_d3(pdev, false);
6539 pci_set_power_state(pdev, PCI_D3hot);
6540 }
6541
6542 return 0;
6543}
6544#endif /* CONFIG_PM */
6545
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006546static void ixgbe_shutdown(struct pci_dev *pdev)
6547{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006548 bool wake;
6549
6550 __ixgbe_shutdown(pdev, &wake);
6551
6552 if (system_state == SYSTEM_POWER_OFF) {
6553 pci_wake_from_d3(pdev, wake);
6554 pci_set_power_state(pdev, PCI_D3hot);
6555 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006556}
6557
6558/**
Auke Kok9a799d72007-09-15 14:07:45 -07006559 * ixgbe_update_stats - Update the board statistics counters.
6560 * @adapter: board private structure
6561 **/
6562void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6563{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006564 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006565 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006566 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006567 u64 total_mpc = 0;
6568 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006569 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6570 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006571 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006572
Don Skidmored08935c2010-06-11 13:20:29 +00006573 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6574 test_bit(__IXGBE_RESETTING, &adapter->state))
6575 return;
6576
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006577 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006578 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006579 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006580 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006581 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6582 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006583 }
6584 adapter->rsc_total_count = rsc_count;
6585 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006586 }
6587
Alexander Duyck5b7da512010-11-16 19:26:50 -08006588 for (i = 0; i < adapter->num_rx_queues; i++) {
6589 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6590 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
6591 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6592 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006593 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006594 bytes += rx_ring->stats.bytes;
6595 packets += rx_ring->stats.packets;
6596 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006597 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006598 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6599 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006600 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006601 netdev->stats.rx_bytes = bytes;
6602 netdev->stats.rx_packets = packets;
6603
6604 bytes = 0;
6605 packets = 0;
6606 /* gather some stats to the adapter struct that are per queue */
6607 for (i = 0; i < adapter->num_tx_queues; i++) {
6608 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6609 restart_queue += tx_ring->tx_stats.restart_queue;
6610 tx_busy += tx_ring->tx_stats.tx_busy;
6611 bytes += tx_ring->stats.bytes;
6612 packets += tx_ring->stats.packets;
6613 }
6614 adapter->restart_queue = restart_queue;
6615 adapter->tx_busy = tx_busy;
6616 netdev->stats.tx_bytes = bytes;
6617 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006618
Joe Perches7ca647b2010-09-07 21:35:40 +00006619 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006620
6621 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006622 for (i = 0; i < 8; i++) {
6623 /* for packet buffers not used, the register should read 0 */
6624 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6625 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006626 hwstats->mpc[i] += mpc;
6627 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006628 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6629 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006630 switch (hw->mac.type) {
6631 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006632 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6633 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6634 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006635 hwstats->pxonrxc[i] +=
6636 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006637 break;
6638 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006639 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006640 case ixgbe_mac_X550:
6641 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006642 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006643 hwstats->pxonrxc[i] +=
6644 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006645 break;
6646 default:
6647 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006648 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006649 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006650
6651 /*16 register reads */
6652 for (i = 0; i < 16; i++) {
6653 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6654 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6655 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006656 (hw->mac.type == ixgbe_mac_X540) ||
6657 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006658 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6659 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006660 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6661 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6662 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6663 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6664 }
6665 }
6666
Joe Perches7ca647b2010-09-07 21:35:40 +00006667 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006668 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006669 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006670
John Fastabendc84d3242010-11-16 19:27:12 -08006671 ixgbe_update_xoff_received(adapter);
6672
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006673 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006674 switch (hw->mac.type) {
6675 case ixgbe_mac_82598EB:
6676 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006677 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6678 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6679 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6680 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006681 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006682 case ixgbe_mac_X550:
6683 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006684 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006685 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006686 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6687 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6688 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6689 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6690 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006691 for (i = 0; i < 16; i++)
6692 adapter->hw_rx_no_dma_resources +=
6693 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006694 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006695 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006696 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006697 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006698 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006699 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006700 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006701 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6702 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006703#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006704 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6705 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6706 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6707 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6708 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6709 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006710 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006711 if (adapter->fcoe.ddp_pool) {
6712 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6713 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6714 unsigned int cpu;
6715 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006716 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006717 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6718 noddp += ddp_pool->noddp;
6719 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006720 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006721 hwstats->fcoe_noddp = noddp;
6722 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006723 }
Yi Zou6d455222009-05-13 13:12:16 +00006724#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006725 break;
6726 default:
6727 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006728 }
Auke Kok9a799d72007-09-15 14:07:45 -07006729 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006730 hwstats->bprc += bprc;
6731 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006732 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006733 hwstats->mprc -= bprc;
6734 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6735 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6736 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6737 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6738 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6739 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6740 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6741 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006742 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006743 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006744 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006745 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006746 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6747 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006748 /*
6749 * 82598 errata - tx of flow control packets is included in tx counters
6750 */
6751 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006752 hwstats->gptc -= xon_off_tot;
6753 hwstats->mptc -= xon_off_tot;
6754 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6755 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6756 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6757 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6758 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6759 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6760 hwstats->ptc64 -= xon_off_tot;
6761 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6762 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6763 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6764 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6765 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6766 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006767
6768 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006769 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006770
6771 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006772 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006773 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006774 netdev->stats.rx_length_errors = hwstats->rlec;
6775 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006776 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006777}
6778
6779/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006780 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006781 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006782 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006783static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006784{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006785 struct ixgbe_hw *hw = &adapter->hw;
6786 int i;
6787
Alexander Duyckd034acf2011-04-27 09:25:34 +00006788 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6789 return;
6790
6791 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6792
6793 /* if interface is down do nothing */
6794 if (test_bit(__IXGBE_DOWN, &adapter->state))
6795 return;
6796
6797 /* do nothing if we are not using signature filters */
6798 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6799 return;
6800
6801 adapter->fdir_overflow++;
6802
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006803 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6804 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006805 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00006806 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006807 /* re-enable flow director interrupts */
6808 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006809 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006810 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006811 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006812 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006813}
6814
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006815/**
6816 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006817 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006818 *
6819 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006820 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006821 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006822 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006823 */
6824static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6825{
Auke Kok9a799d72007-09-15 14:07:45 -07006826 struct ixgbe_hw *hw = &adapter->hw;
6827 u64 eics = 0;
6828 int i;
6829
Mark Rustad09f40ae2014-01-14 18:53:11 -08006830 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006831 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006832 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006833 test_bit(__IXGBE_RESETTING, &adapter->state))
6834 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006835
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006836 /* Force detection of hung controller */
6837 if (netif_carrier_ok(adapter->netdev)) {
6838 for (i = 0; i < adapter->num_tx_queues; i++)
6839 set_check_for_tx_hang(adapter->tx_ring[i]);
6840 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006841
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006842 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006843 /*
6844 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006845 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006846 * would set *both* EIMS and EICS for any bit in EIAM
6847 */
6848 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6849 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006850 } else {
6851 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006852 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006853 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006854 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07006855 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006856 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006857 }
6858
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006859 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006860 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00006861}
6862
6863/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006864 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006865 * @adapter: pointer to the device adapter structure
6866 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006867 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006868static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006869{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006870 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006871 u32 link_speed = adapter->link_speed;
6872 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006873 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006874
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006875 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6876 return;
6877
6878 if (hw->mac.ops.check_link) {
6879 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006880 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006881 /* always assume link is up, if no check link function */
6882 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6883 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006884 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006885
6886 if (adapter->ixgbe_ieee_pfc)
6887 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6888
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006889 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006890 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006891 ixgbe_set_rx_drop_en(adapter);
6892 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006893
6894 if (link_up ||
6895 time_after(jiffies, (adapter->link_check_timeout +
6896 IXGBE_TRY_LINK_TIMEOUT))) {
6897 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6898 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6899 IXGBE_WRITE_FLUSH(hw);
6900 }
6901
6902 adapter->link_up = link_up;
6903 adapter->link_speed = link_speed;
6904}
6905
Alexander Duyck107d3012012-10-02 00:17:03 +00006906static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6907{
6908#ifdef CONFIG_IXGBE_DCB
6909 struct net_device *netdev = adapter->netdev;
6910 struct dcb_app app = {
6911 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6912 .protocol = 0,
6913 };
6914 u8 up = 0;
6915
6916 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6917 up = dcb_ieee_getapp_mask(netdev, &app);
6918
6919 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6920#endif
6921}
6922
David Ahern1cd127f2016-10-17 19:15:48 -07006923static int ixgbe_enable_macvlan(struct net_device *upper, void *data)
6924{
6925 if (netif_is_macvlan(upper)) {
6926 struct macvlan_dev *vlan = netdev_priv(upper);
6927
6928 if (vlan->fwd_priv)
6929 netif_tx_wake_all_queues(upper);
6930 }
6931
6932 return 0;
6933}
6934
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006935/**
6936 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6937 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006938 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006939 **/
6940static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6941{
6942 struct net_device *netdev = adapter->netdev;
6943 struct ixgbe_hw *hw = &adapter->hw;
6944 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07006945 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006946 bool flow_rx, flow_tx;
6947
6948 /* only continue if link was previously down */
6949 if (netif_carrier_ok(netdev))
6950 return;
6951
6952 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6953
6954 switch (hw->mac.type) {
6955 case ixgbe_mac_82598EB: {
6956 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6957 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6958 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6959 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6960 }
6961 break;
6962 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006963 case ixgbe_mac_X550:
6964 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006965 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006966 case ixgbe_mac_82599EB: {
6967 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6968 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6969 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6970 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6971 }
6972 break;
6973 default:
6974 flow_tx = false;
6975 flow_rx = false;
6976 break;
6977 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006978
Jacob Keller6cb562d2012-12-05 07:24:41 +00006979 adapter->last_rx_ptp_check = jiffies;
6980
Jacob Keller8fecf672013-06-21 08:14:32 +00006981 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006982 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006983
Mark Rustad454adb02015-07-10 14:19:22 -07006984 switch (link_speed) {
6985 case IXGBE_LINK_SPEED_10GB_FULL:
6986 speed_str = "10 Gbps";
6987 break;
6988 case IXGBE_LINK_SPEED_2_5GB_FULL:
6989 speed_str = "2.5 Gbps";
6990 break;
6991 case IXGBE_LINK_SPEED_1GB_FULL:
6992 speed_str = "1 Gbps";
6993 break;
6994 case IXGBE_LINK_SPEED_100_FULL:
6995 speed_str = "100 Mbps";
6996 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006997 case IXGBE_LINK_SPEED_10_FULL:
6998 speed_str = "10 Mbps";
6999 break;
Mark Rustad454adb02015-07-10 14:19:22 -07007000 default:
7001 speed_str = "unknown speed";
7002 break;
7003 }
7004 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007005 ((flow_rx && flow_tx) ? "RX/TX" :
7006 (flow_rx ? "RX" :
7007 (flow_tx ? "TX" : "None"))));
7008
7009 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007010 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007011
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007012 /* enable transmits */
7013 netif_tx_wake_all_queues(adapter->netdev);
7014
7015 /* enable any upper devices */
7016 rtnl_lock();
David Ahern1cd127f2016-10-17 19:15:48 -07007017 netdev_walk_all_upper_dev_rcu(adapter->netdev,
7018 ixgbe_enable_macvlan, NULL);
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007019 rtnl_unlock();
7020
Alexander Duyck107d3012012-10-02 00:17:03 +00007021 /* update the default user priority for VFs */
7022 ixgbe_update_default_up(adapter);
7023
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007024 /* ping all the active vfs to let them know link has changed */
7025 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007026}
7027
7028/**
7029 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7030 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007031 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007032 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00007033static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007034{
7035 struct net_device *netdev = adapter->netdev;
7036 struct ixgbe_hw *hw = &adapter->hw;
7037
7038 adapter->link_up = false;
7039 adapter->link_speed = 0;
7040
7041 /* only continue if link was up previously */
7042 if (!netif_carrier_ok(netdev))
7043 return;
7044
7045 /* poll for SFP+ cable when link is down */
7046 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
7047 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
7048
Jacob Keller8fecf672013-06-21 08:14:32 +00007049 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007050 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007051
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007052 e_info(drv, "NIC Link is Down\n");
7053 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007054
7055 /* ping all the active vfs to let them know link has changed */
7056 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007057}
7058
Emil Tantilov07923c12014-08-12 07:12:08 +00007059static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
7060{
7061 int i;
7062
7063 for (i = 0; i < adapter->num_tx_queues; i++) {
7064 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
7065
7066 if (tx_ring->next_to_use != tx_ring->next_to_clean)
7067 return true;
7068 }
7069
7070 return false;
7071}
7072
7073static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
7074{
7075 struct ixgbe_hw *hw = &adapter->hw;
7076 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
7077 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
7078
7079 int i, j;
7080
7081 if (!adapter->num_vfs)
7082 return false;
7083
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007084 /* resetting the PF is only needed for MAC before X550 */
7085 if (hw->mac.type >= ixgbe_mac_X550)
7086 return false;
7087
Emil Tantilov07923c12014-08-12 07:12:08 +00007088 for (i = 0; i < adapter->num_vfs; i++) {
7089 for (j = 0; j < q_per_pool; j++) {
7090 u32 h, t;
7091
7092 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
7093 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
7094
7095 if (h != t)
7096 return true;
7097 }
7098 }
7099
7100 return false;
7101}
7102
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007103/**
7104 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007105 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007106 **/
7107static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
7108{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007109 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00007110 if (ixgbe_ring_tx_pending(adapter) ||
7111 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007112 /* We've lost link, so the controller stops DMA,
7113 * but we've got queued Tx work that's never going
7114 * to get done, so reset controller to flush Tx.
7115 * (Do the reset outside of interrupt context).
7116 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00007117 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007118 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007119 }
7120 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007121}
7122
Emil Tantilov9079e412014-11-19 03:18:19 +00007123#ifdef CONFIG_PCI_IOV
7124static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
7125 struct pci_dev *vfdev)
7126{
7127 if (!pci_wait_for_pending_transaction(vfdev))
7128 e_dev_warn("Issuing VFLR with pending transactions\n");
7129
7130 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
7131 pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
7132
7133 msleep(100);
7134}
7135
7136static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
7137{
7138 struct ixgbe_hw *hw = &adapter->hw;
7139 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07007140 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00007141 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00007142
7143 if (!(netif_carrier_ok(adapter->netdev)))
7144 return;
7145
7146 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
7147 if (gpc) /* If incrementing then no need for the check below */
7148 return;
7149 /* Check to see if a bad DMA write target from an errant or
7150 * malicious VF has caused a PCIe error. If so then we can
7151 * issue a VFLR to the offending VF(s) and then resume without
7152 * requesting a full slot reset.
7153 */
7154
7155 if (!pdev)
7156 return;
7157
Emil Tantilov9079e412014-11-19 03:18:19 +00007158 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07007159 for (vf = 0; vf < adapter->num_vfs; ++vf) {
7160 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
7161 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00007162
Mark Rustad988d1302015-10-30 15:29:34 -07007163 if (!vfdev)
7164 continue;
7165 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
7166 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
7167 status_reg & PCI_STATUS_REC_MASTER_ABORT)
7168 ixgbe_issue_vf_flr(adapter, vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00007169 }
7170}
7171
Greg Rosea985b6c32010-11-18 03:02:52 +00007172static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
7173{
7174 u32 ssvpc;
7175
Greg Rose0584d992012-08-08 00:00:58 +00007176 /* Do not perform spoof check for 82598 or if not in IOV mode */
7177 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7178 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00007179 return;
7180
7181 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
7182
7183 /*
7184 * ssvpc register is cleared on read, if zero then no
7185 * spoofed packets in the last interval.
7186 */
7187 if (!ssvpc)
7188 return;
7189
Emil Tantilovd6ea0752012-08-08 06:28:37 +00007190 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00007191}
Emil Tantilov9079e412014-11-19 03:18:19 +00007192#else
7193static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7194{
7195}
7196
7197static void
7198ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7199{
7200}
7201#endif /* CONFIG_PCI_IOV */
7202
Greg Rosea985b6c32010-11-18 03:02:52 +00007203
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007204/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007205 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007206 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007207 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007208static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007209{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007210 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007211 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007212 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007213 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007214 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007215
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007216 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007217
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007218 if (adapter->link_up)
7219 ixgbe_watchdog_link_is_up(adapter);
7220 else
7221 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007222
Emil Tantilov9079e412014-11-19 03:18:19 +00007223 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007224 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007225 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007226
7227 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007228}
7229
Alexander Duyck70864002011-04-27 09:13:56 +00007230/**
7231 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007232 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007233 **/
7234static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7235{
7236 struct ixgbe_hw *hw = &adapter->hw;
7237 s32 err;
7238
7239 /* not searching for SFP so there is nothing to do here */
7240 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7241 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7242 return;
7243
Mark Rustad58e7cd22015-08-08 16:18:48 -07007244 if (adapter->sfp_poll_time &&
7245 time_after(adapter->sfp_poll_time, jiffies))
7246 return; /* If not yet time to poll for SFP */
7247
Alexander Duyck70864002011-04-27 09:13:56 +00007248 /* someone else is in init, wait until next service event */
7249 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7250 return;
7251
Mark Rustad58e7cd22015-08-08 16:18:48 -07007252 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7253
Alexander Duyck70864002011-04-27 09:13:56 +00007254 err = hw->phy.ops.identify_sfp(hw);
7255 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7256 goto sfp_out;
7257
7258 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7259 /* If no cable is present, then we need to reset
7260 * the next time we find a good cable. */
7261 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7262 }
7263
7264 /* exit on error */
7265 if (err)
7266 goto sfp_out;
7267
7268 /* exit if reset not needed */
7269 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7270 goto sfp_out;
7271
7272 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7273
7274 /*
7275 * A module may be identified correctly, but the EEPROM may not have
7276 * support for that module. setup_sfp() will fail in that case, so
7277 * we should not allow that module to load.
7278 */
7279 if (hw->mac.type == ixgbe_mac_82598EB)
7280 err = hw->phy.ops.reset(hw);
7281 else
7282 err = hw->mac.ops.setup_sfp(hw);
7283
7284 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7285 goto sfp_out;
7286
7287 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7288 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7289
7290sfp_out:
7291 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7292
7293 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7294 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7295 e_dev_err("failed to initialize because an unsupported "
7296 "SFP+ module type was detected.\n");
7297 e_dev_err("Reload the driver after installing a "
7298 "supported module.\n");
7299 unregister_netdev(adapter->netdev);
7300 }
7301}
7302
7303/**
7304 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007305 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007306 **/
7307static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7308{
7309 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00007310 u32 speed;
7311 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007312
7313 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7314 return;
7315
7316 /* someone else is in init, wait until next service event */
7317 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7318 return;
7319
7320 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7321
Josh Hay3d292262012-12-15 03:28:19 +00007322 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00007323 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00007324 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007325
7326 /* setup the highest link when no autoneg */
7327 if (!autoneg) {
7328 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
7329 speed = IXGBE_LINK_SPEED_10GB_FULL;
7330 }
7331 }
7332
Alexander Duyck70864002011-04-27 09:13:56 +00007333 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007334 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007335
7336 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7337 adapter->link_check_timeout = jiffies;
7338 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7339}
7340
7341/**
7342 * ixgbe_service_timer - Timer Call-back
7343 * @data: pointer to adapter cast into an unsigned long
7344 **/
7345static void ixgbe_service_timer(unsigned long data)
7346{
7347 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
7348 unsigned long next_event_offset;
7349
7350 /* poll faster when waiting for link */
7351 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7352 next_event_offset = HZ / 10;
7353 else
7354 next_event_offset = HZ * 2;
7355
7356 /* Reset the timer */
7357 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7358
Emil Tantilov9079e412014-11-19 03:18:19 +00007359 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007360}
7361
Don Skidmore597f22d2015-06-09 16:52:02 -07007362static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7363{
7364 struct ixgbe_hw *hw = &adapter->hw;
7365 u32 status;
7366
7367 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7368 return;
7369
7370 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7371
7372 if (!hw->phy.ops.handle_lasi)
7373 return;
7374
7375 status = hw->phy.ops.handle_lasi(&adapter->hw);
7376 if (status != IXGBE_ERR_OVERTEMP)
7377 return;
7378
7379 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7380}
7381
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007382static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7383{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007384 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007385 return;
7386
Mark Rustad09f40ae2014-01-14 18:53:11 -08007387 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007388 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007389 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007390 test_bit(__IXGBE_RESETTING, &adapter->state))
7391 return;
7392
7393 ixgbe_dump(adapter);
7394 netdev_err(adapter->netdev, "Reset adapter\n");
7395 adapter->tx_timeout_count++;
7396
John Fastabend8f4c5c92014-01-16 02:30:05 -08007397 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007398 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007399 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007400}
7401
Alexander Duyck70864002011-04-27 09:13:56 +00007402/**
7403 * ixgbe_service_task - manages and runs subtasks
7404 * @work: pointer to work_struct containing our data
7405 **/
7406static void ixgbe_service_task(struct work_struct *work)
7407{
7408 struct ixgbe_adapter *adapter = container_of(work,
7409 struct ixgbe_adapter,
7410 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007411 if (ixgbe_removed(adapter->hw.hw_addr)) {
7412 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7413 rtnl_lock();
7414 ixgbe_down(adapter);
7415 rtnl_unlock();
7416 }
7417 ixgbe_service_event_complete(adapter);
7418 return;
7419 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007420 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007421 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007422 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007423 udp_tunnel_get_rx_info(adapter->netdev);
7424 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007425 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007426 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007427 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007428 ixgbe_sfp_detection_subtask(adapter);
7429 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007430 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007431 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007432 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007433 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007434
Jacob Keller8fecf672013-06-21 08:14:32 +00007435 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007436 ixgbe_ptp_overflow_check(adapter);
7437 ixgbe_ptp_rx_hang(adapter);
7438 }
Alexander Duyck70864002011-04-27 09:13:56 +00007439
7440 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007441}
7442
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007443static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7444 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007445 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007446{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007447 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007448 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007449 union {
7450 struct iphdr *v4;
7451 struct ipv6hdr *v6;
7452 unsigned char *hdr;
7453 } ip;
7454 union {
7455 struct tcphdr *tcp;
7456 unsigned char *hdr;
7457 } l4;
7458 u32 paylen, l4_offset;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007459 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007460
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007461 if (skb->ip_summed != CHECKSUM_PARTIAL)
7462 return 0;
7463
Alexander Duyck897ab152011-05-27 05:31:47 +00007464 if (!skb_is_gso(skb))
7465 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007466
Francois Romieu2049e1f2014-03-30 03:14:27 +00007467 err = skb_cow_head(skb, 0);
7468 if (err < 0)
7469 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007470
Alexander Duyckb83e3012016-04-14 17:19:31 -04007471 ip.hdr = skb_network_header(skb);
7472 l4.hdr = skb_checksum_start(skb);
7473
Alexander Duyck897ab152011-05-27 05:31:47 +00007474 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7475 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7476
Alexander Duyckb83e3012016-04-14 17:19:31 -04007477 /* initialize outer IP header fields */
7478 if (ip.v4->version == 4) {
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007479 unsigned char *csum_start = skb_checksum_start(skb);
7480 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
7481
Alexander Duyckb83e3012016-04-14 17:19:31 -04007482 /* IP header will have to cancel out any data that
7483 * is not a part of the outer IP header
7484 */
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007485 ip.v4->check = csum_fold(csum_partial(trans_start,
7486 csum_start - trans_start,
7487 0));
Alexander Duyck897ab152011-05-27 05:31:47 +00007488 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007489
7490 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007491 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7492 IXGBE_TX_FLAGS_CSUM |
7493 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007494 } else {
7495 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007496 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7497 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007498 }
7499
Alexander Duyckb83e3012016-04-14 17:19:31 -04007500 /* determine offset of inner transport header */
7501 l4_offset = l4.hdr - skb->data;
7502
7503 /* compute length of segmentation header */
7504 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7505
7506 /* remove payload length from inner checksum */
7507 paylen = skb->len - l4_offset;
7508 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007509
Alexander Duyck091a6242012-02-08 07:51:01 +00007510 /* update gso size and bytecount with header size */
7511 first->gso_segs = skb_shinfo(skb)->gso_segs;
7512 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7513
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007514 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007515 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007516 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007517
7518 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007519 vlan_macip_lens = l4.hdr - ip.hdr;
7520 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007521 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007522
7523 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007524 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007525
7526 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007527}
7528
Alexander Duyck49763de2016-01-13 07:31:11 -08007529static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7530{
7531 unsigned int offset = 0;
7532
7533 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7534
7535 return offset == skb_checksum_start_offset(skb);
7536}
7537
Alexander Duyck244e27a2012-02-08 07:51:11 +00007538static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7539 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007540{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007541 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007542 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007543 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007544
Alexander Duyck897ab152011-05-27 05:31:47 +00007545 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007546csum_failed:
7547 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7548 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007549 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007550 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007551 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007552
Alexander Duyck49763de2016-01-13 07:31:11 -08007553 switch (skb->csum_offset) {
7554 case offsetof(struct tcphdr, check):
7555 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7556 /* fall through */
7557 case offsetof(struct udphdr, check):
7558 break;
7559 case offsetof(struct sctphdr, checksum):
7560 /* validate that this is actually an SCTP request */
7561 if (((first->protocol == htons(ETH_P_IP)) &&
7562 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7563 ((first->protocol == htons(ETH_P_IPV6)) &&
7564 ixgbe_ipv6_csum_is_sctp(skb))) {
7565 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7566 break;
7567 }
7568 /* fall through */
7569 default:
7570 skb_checksum_help(skb);
7571 goto csum_failed;
7572 }
7573
7574 /* update TX checksum flag */
7575 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7576 vlan_macip_lens = skb_checksum_start_offset(skb) -
7577 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007578no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007579 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007580 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007581 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007582
Alexander Duyck49763de2016-01-13 07:31:11 -08007583 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007584}
7585
Alexander Duyck472148c2012-11-07 02:34:28 +00007586#define IXGBE_SET_FLAG(_input, _flag, _result) \
7587 ((_flag <= _result) ? \
7588 ((u32)(_input & _flag) * (_result / _flag)) : \
7589 ((u32)(_input & _flag) / (_flag / _result)))
7590
7591static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007592{
7593 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007594 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7595 IXGBE_ADVTXD_DCMD_DEXT |
7596 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007597
7598 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007599 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7600 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007601
Alexander Duyckd3d00232011-07-15 02:31:25 +00007602 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007603 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7604 IXGBE_ADVTXD_DCMD_TSE);
7605
7606 /* set timestamp bit if present */
7607 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7608 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007609
Alexander Duyck62748b72012-07-20 08:09:01 +00007610 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007611 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007612
Alexander Duyckd3d00232011-07-15 02:31:25 +00007613 return cmd_type;
7614}
7615
Alexander Duyck729739b2012-02-08 07:51:06 +00007616static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7617 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007618{
Alexander Duyck472148c2012-11-07 02:34:28 +00007619 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007620
7621 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007622 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7623 IXGBE_TX_FLAGS_CSUM,
7624 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007625
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007626 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007627 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7628 IXGBE_TX_FLAGS_IPV4,
7629 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007630
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007631 /*
7632 * Check Context must be set if Tx switch is enabled, which it
7633 * always is for case where virtual functions are running
7634 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007635 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7636 IXGBE_TX_FLAGS_CC,
7637 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007638
Alexander Duyck472148c2012-11-07 02:34:28 +00007639 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007640}
7641
Daniel Borkmann2367a172014-08-26 19:34:18 +02007642static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7643{
7644 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7645
7646 /* Herbert's original patch had:
7647 * smp_mb__after_netif_stop_queue();
7648 * but since that doesn't exist yet, just open code it.
7649 */
7650 smp_mb();
7651
7652 /* We need to check again in a case another CPU has just
7653 * made room available.
7654 */
7655 if (likely(ixgbe_desc_unused(tx_ring) < size))
7656 return -EBUSY;
7657
7658 /* A reprieve! - use start_queue because it doesn't call schedule */
7659 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7660 ++tx_ring->tx_stats.restart_queue;
7661 return 0;
7662}
7663
7664static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7665{
7666 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7667 return 0;
7668
7669 return __ixgbe_maybe_stop_tx(tx_ring, size);
7670}
7671
Alexander Duyckd3d00232011-07-15 02:31:25 +00007672#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7673 IXGBE_TXD_CMD_RS)
7674
7675static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007676 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007677 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007678{
Alexander Duyck729739b2012-02-08 07:51:06 +00007679 struct sk_buff *skb = first->skb;
7680 struct ixgbe_tx_buffer *tx_buffer;
7681 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007682 struct skb_frag_struct *frag;
7683 dma_addr_t dma;
7684 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007685 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007686 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007687 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007688
Alexander Duyck729739b2012-02-08 07:51:06 +00007689 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7690
Alexander Duyckec718252012-10-30 06:01:55 +00007691 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7692
7693 size = skb_headlen(skb);
7694 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007695
Alexander Duyckd3d00232011-07-15 02:31:25 +00007696#ifdef IXGBE_FCOE
7697 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007698 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007699 size -= sizeof(struct fcoe_crc_eof) - data_len;
7700 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007701 } else {
7702 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007703 }
Auke Kok9a799d72007-09-15 14:07:45 -07007704 }
7705
Alexander Duyckd3d00232011-07-15 02:31:25 +00007706#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007707 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007708
Alexander Duyckec718252012-10-30 06:01:55 +00007709 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007710
Alexander Duyckec718252012-10-30 06:01:55 +00007711 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7712 if (dma_mapping_error(tx_ring->dev, dma))
7713 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007714
Alexander Duyckec718252012-10-30 06:01:55 +00007715 /* record length, and DMA address */
7716 dma_unmap_len_set(tx_buffer, len, size);
7717 dma_unmap_addr_set(tx_buffer, dma, dma);
7718
7719 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7720
Alexander Duyck729739b2012-02-08 07:51:06 +00007721 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007722 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007723 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007724
Alexander Duyckd3d00232011-07-15 02:31:25 +00007725 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007726 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007727 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007728 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007729 i = 0;
7730 }
Alexander Duyckec718252012-10-30 06:01:55 +00007731 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007732
7733 dma += IXGBE_MAX_DATA_PER_TXD;
7734 size -= IXGBE_MAX_DATA_PER_TXD;
7735
7736 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007737 }
7738
Alexander Duyck729739b2012-02-08 07:51:06 +00007739 if (likely(!data_len))
7740 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007741
Alexander Duyck472148c2012-11-07 02:34:28 +00007742 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007743
Alexander Duyck729739b2012-02-08 07:51:06 +00007744 i++;
7745 tx_desc++;
7746 if (i == tx_ring->count) {
7747 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7748 i = 0;
7749 }
Alexander Duyckec718252012-10-30 06:01:55 +00007750 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007751
Alexander Duyckd3d00232011-07-15 02:31:25 +00007752#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007753 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007754#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007755 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007756#endif
7757 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007758
Alexander Duyck729739b2012-02-08 07:51:06 +00007759 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7760 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007761
Alexander Duyck729739b2012-02-08 07:51:06 +00007762 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007763 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007764
Alexander Duyck729739b2012-02-08 07:51:06 +00007765 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007766 cmd_type |= size | IXGBE_TXD_CMD;
7767 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007768
Alexander Duyck091a6242012-02-08 07:51:01 +00007769 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007770
Alexander Duyckd3d00232011-07-15 02:31:25 +00007771 /* set the timestamp */
7772 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007773
7774 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007775 * Force memory writes to complete before letting h/w know there
7776 * are new descriptors to fetch. (Only applicable for weak-ordered
7777 * memory model archs, such as IA-64).
7778 *
7779 * We also need this memory barrier to make certain all of the
7780 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007781 */
7782 wmb();
7783
Alexander Duyckd3d00232011-07-15 02:31:25 +00007784 /* set next_to_watch value indicating a packet is present */
7785 first->next_to_watch = tx_desc;
7786
Alexander Duyck729739b2012-02-08 07:51:06 +00007787 i++;
7788 if (i == tx_ring->count)
7789 i = 0;
7790
7791 tx_ring->next_to_use = i;
7792
Daniel Borkmann2367a172014-08-26 19:34:18 +02007793 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7794
7795 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00007796 writel(i, tx_ring->tail);
7797
7798 /* we need this if more than one processor can write to our tail
7799 * at a time, it synchronizes IO on IA64/Altix systems
7800 */
7801 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02007802 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02007803
Alexander Duyckd3d00232011-07-15 02:31:25 +00007804 return;
7805dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00007806 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckffed21b2017-01-17 08:37:29 -08007807 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckd3d00232011-07-15 02:31:25 +00007808
7809 /* clear dma mappings for failed tx_buffer_info map */
Alexander Duyckffed21b2017-01-17 08:37:29 -08007810 while (tx_buffer != first) {
7811 if (dma_unmap_len(tx_buffer, len))
7812 dma_unmap_page(tx_ring->dev,
7813 dma_unmap_addr(tx_buffer, dma),
7814 dma_unmap_len(tx_buffer, len),
7815 DMA_TO_DEVICE);
7816 dma_unmap_len_set(tx_buffer, len, 0);
7817
7818 if (i--)
7819 i += tx_ring->count;
Alexander Duyck729739b2012-02-08 07:51:06 +00007820 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckd3d00232011-07-15 02:31:25 +00007821 }
7822
Alexander Duyckffed21b2017-01-17 08:37:29 -08007823 if (dma_unmap_len(tx_buffer, len))
7824 dma_unmap_single(tx_ring->dev,
7825 dma_unmap_addr(tx_buffer, dma),
7826 dma_unmap_len(tx_buffer, len),
7827 DMA_TO_DEVICE);
7828 dma_unmap_len_set(tx_buffer, len, 0);
7829
7830 dev_kfree_skb_any(first->skb);
7831 first->skb = NULL;
7832
Alexander Duyckd3d00232011-07-15 02:31:25 +00007833 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07007834}
7835
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007836static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007837 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007838{
Alexander Duyck69830522011-01-06 14:29:58 +00007839 struct ixgbe_q_vector *q_vector = ring->q_vector;
7840 union ixgbe_atr_hash_dword input = { .dword = 0 };
7841 union ixgbe_atr_hash_dword common = { .dword = 0 };
7842 union {
7843 unsigned char *network;
7844 struct iphdr *ipv4;
7845 struct ipv6hdr *ipv6;
7846 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007847 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08007848 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07007849 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00007850 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08007851 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007852
Alexander Duyck69830522011-01-06 14:29:58 +00007853 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7854 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00007855 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007856
Alexander Duyck69830522011-01-06 14:29:58 +00007857 /* do nothing if sampling is disabled */
7858 if (!ring->atr_sample_rate)
7859 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007860
Alexander Duyck69830522011-01-06 14:29:58 +00007861 ring->atr_count++;
7862
Alexander Duycke2873d42016-01-25 19:39:40 -08007863 /* currently only IPv4/IPv6 with TCP is supported */
7864 if ((first->protocol != htons(ETH_P_IP)) &&
7865 (first->protocol != htons(ETH_P_IPV6)))
7866 return;
7867
Alexander Duyck69830522011-01-06 14:29:58 +00007868 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07007869 skb = first->skb;
7870 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007871 if (unlikely(hdr.network <= skb->data))
7872 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08007873 if (skb->encapsulation &&
7874 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07007875 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07007876 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00007877
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007878 if (unlikely(skb_tail_pointer(skb) < hdr.network +
7879 VXLAN_HEADROOM))
7880 return;
7881
Alexander Duyck9f12df92016-01-25 19:36:29 -08007882 /* verify the port is recognized as VXLAN */
7883 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08007884 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08007885 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07007886
7887 if (adapter->geneve_port &&
7888 udp_hdr(skb)->dest == adapter->geneve_port)
7889 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08007890 }
7891
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007892 /* Make sure we have at least [minimum IPv4 header + TCP]
7893 * or [IPv6 header] bytes
7894 */
7895 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
7896 return;
7897
Mark Rustade19dcde2015-12-09 14:55:37 -08007898 /* Currently only IPv4/IPv6 with TCP is supported */
7899 switch (hdr.ipv4->version) {
7900 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08007901 /* access ihl as u8 to avoid unaligned access on ia64 */
7902 hlen = (hdr.network[0] & 0x0F) << 2;
7903 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08007904 break;
7905 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08007906 hlen = hdr.network - skb->data;
7907 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
7908 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08007909 break;
7910 default:
7911 return;
Mark Rustad67359c32015-06-15 11:33:25 -07007912 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007913
Alexander Duycke2873d42016-01-25 19:39:40 -08007914 if (l4_proto != IPPROTO_TCP)
7915 return;
7916
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007917 if (unlikely(skb_tail_pointer(skb) < hdr.network +
7918 hlen + sizeof(struct tcphdr)))
7919 return;
7920
Alexander Duycke2873d42016-01-25 19:39:40 -08007921 th = (struct tcphdr *)(hdr.network + hlen);
7922
7923 /* skip this packet since the socket is closing */
7924 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00007925 return;
7926
7927 /* sample on all syn packets or once every atr sample count */
7928 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
7929 return;
7930
7931 /* reset sample count */
7932 ring->atr_count = 0;
7933
Alexander Duyck244e27a2012-02-08 07:51:11 +00007934 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00007935
7936 /*
7937 * src and dst are inverted, think how the receiver sees them
7938 *
7939 * The input is broken into two sections, a non-compressed section
7940 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7941 * is XORed together and stored in the compressed dword.
7942 */
7943 input.formatted.vlan_id = vlan_id;
7944
7945 /*
7946 * since src port and flex bytes occupy the same word XOR them together
7947 * and write the value to source port portion of compressed dword
7948 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007949 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00007950 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00007951 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00007952 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00007953 common.port.dst ^= th->source;
7954
Mark Rustade19dcde2015-12-09 14:55:37 -08007955 switch (hdr.ipv4->version) {
7956 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00007957 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7958 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08007959 break;
7960 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00007961 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7962 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7963 hdr.ipv6->saddr.s6_addr32[1] ^
7964 hdr.ipv6->saddr.s6_addr32[2] ^
7965 hdr.ipv6->saddr.s6_addr32[3] ^
7966 hdr.ipv6->daddr.s6_addr32[0] ^
7967 hdr.ipv6->daddr.s6_addr32[1] ^
7968 hdr.ipv6->daddr.s6_addr32[2] ^
7969 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08007970 break;
7971 default:
7972 break;
Alexander Duyck69830522011-01-06 14:29:58 +00007973 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007974
Alexander Duyck9f12df92016-01-25 19:36:29 -08007975 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07007976 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07007977
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007978 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007979 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7980 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007981}
7982
Jason Wangf663dd92014-01-10 16:18:26 +08007983static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01007984 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007985{
Jason Wangf663dd92014-01-10 16:18:26 +08007986 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7987#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00007988 struct ixgbe_adapter *adapter;
7989 struct ixgbe_ring_feature *f;
7990 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08007991#endif
7992
7993 if (fwd_adapter)
7994 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7995
7996#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00007997
Alexander Duyck97488bd2013-01-12 06:33:37 +00007998 /*
7999 * only execute the code below if protocol is FCoE
8000 * or FIP and we have FCoE enabled on the adapter
8001 */
8002 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00008003 case htons(ETH_P_FCOE):
8004 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00008005 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00008006
Alexander Duyck97488bd2013-01-12 06:33:37 +00008007 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8008 break;
8009 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01008010 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00008011 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008012
Alexander Duyck97488bd2013-01-12 06:33:37 +00008013 f = &adapter->ring_feature[RING_F_FCOE];
8014
8015 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8016 smp_processor_id();
8017
8018 while (txq >= f->indices)
8019 txq -= f->indices;
8020
8021 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08008022#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01008023 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08008024#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008025}
8026
Alexander Duyckfc77dc32010-11-16 19:26:51 -08008027netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00008028 struct ixgbe_adapter *adapter,
8029 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008030{
Alexander Duyckd3d00232011-07-15 02:31:25 +00008031 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00008032 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008033 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00008034 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00008035 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00008036 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00008037 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00008038
Alexander Duycka535c302011-05-27 05:31:52 +00008039 /*
8040 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00008041 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00008042 * + 2 desc gap to keep tail from touching head,
8043 * + 1 desc for context descriptor,
8044 * otherwise try next time
8045 */
Alexander Duycka535c302011-05-27 05:31:52 +00008046 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8047 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00008048
Alexander Duycka535c302011-05-27 05:31:52 +00008049 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8050 tx_ring->tx_stats.tx_busy++;
8051 return NETDEV_TX_BUSY;
8052 }
8053
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008054 /* record the location of the first descriptor for this packet */
8055 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8056 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00008057 first->bytecount = skb->len;
8058 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008059
Alexander Duyck66f32a82011-06-29 05:43:22 +00008060 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01008061 if (skb_vlan_tag_present(skb)) {
8062 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008063 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8064 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008065 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008066 struct vlan_hdr *vhdr, _vhdr;
8067 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8068 if (!vhdr)
8069 goto out_drop;
8070
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008071 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8072 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008073 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07008074 }
Toshiaki Makita02136682015-01-29 20:37:09 +09008075 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00008076
Mark Rustadd5234932014-08-09 07:02:09 +00008077 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
8078 adapter->ptp_clock &&
8079 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8080 &adapter->state)) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008081 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8082 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00008083
8084 /* schedule check for Tx timestamp */
8085 adapter->ptp_tx_skb = skb_get(skb);
8086 adapter->ptp_tx_start = jiffies;
8087 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008088 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008089
Jakub Kicinskiff29a862014-03-15 14:55:16 +00008090 skb_tx_timestamp(skb);
8091
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008092#ifdef CONFIG_PCI_IOV
8093 /*
8094 * Use the l2switch_enable flag - would be false if the DMA
8095 * Tx switch had been disabled.
8096 */
8097 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00008098 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008099
8100#endif
John Fastabend32701dc2011-09-27 03:51:56 +00008101 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00008102 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00008103 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8104 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008105 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00008106 tx_flags |= (skb->priority & 0x7) <<
8107 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008108 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8109 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00008110
8111 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00008112 goto out_drop;
8113 vhdr = (struct vlan_ethhdr *)skb->data;
8114 vhdr->h_vlan_TCI = htons(tx_flags >>
8115 IXGBE_TX_FLAGS_VLAN_SHIFT);
8116 } else {
8117 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8118 }
8119 }
Alexander Duycka535c302011-05-27 05:31:52 +00008120
Alexander Duyck244e27a2012-02-08 07:51:11 +00008121 /* record initial flags and protocol */
8122 first->tx_flags = tx_flags;
8123 first->protocol = protocol;
8124
Yi Zoueacd73f2009-05-13 13:11:06 +00008125#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00008126 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008127 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00008128 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00008129 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00008130 if (tso < 0)
8131 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07008132
Alexander Duyck66f32a82011-06-29 05:43:22 +00008133 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00008134 }
Auke Kok9a799d72007-09-15 14:07:45 -07008135
Auke Kok9a799d72007-09-15 14:07:45 -07008136#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008137 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008138 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07008139 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008140 else if (!tso)
8141 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008142
8143 /* add the ATR filter if ATR is on */
8144 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00008145 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008146
8147#ifdef IXGBE_FCOE
8148xmit_fcoe:
8149#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008150 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008151
Auke Kok9a799d72007-09-15 14:07:45 -07008152 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00008153
8154out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008155 dev_kfree_skb_any(first->skb);
8156 first->skb = NULL;
8157
Alexander Duyck897ab152011-05-27 05:31:47 +00008158 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07008159}
8160
John Fastabend2a47fa42013-11-06 09:54:52 -08008161static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8162 struct net_device *netdev,
8163 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008164{
8165 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008166 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07008167
Alexander Duycka50c29d2012-02-08 07:50:40 +00008168 /*
8169 * The minimum packet size for olinfo paylen is 17 so pad the skb
8170 * in order to meet this minimum size requirement.
8171 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08008172 if (skb_put_padto(skb, 17))
8173 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00008174
John Fastabend2a47fa42013-11-06 09:54:52 -08008175 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8176
Auke Kok9a799d72007-09-15 14:07:45 -07008177 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8178}
8179
John Fastabend2a47fa42013-11-06 09:54:52 -08008180static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8181 struct net_device *netdev)
8182{
8183 return __ixgbe_xmit_frame(skb, netdev, NULL);
8184}
8185
Auke Kok9a799d72007-09-15 14:07:45 -07008186/**
8187 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8188 * @netdev: network interface device structure
8189 * @p: pointer to an address structure
8190 *
8191 * Returns 0 on success, negative on failure
8192 **/
8193static int ixgbe_set_mac(struct net_device *netdev, void *p)
8194{
8195 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8196 struct ixgbe_hw *hw = &adapter->hw;
8197 struct sockaddr *addr = p;
8198
8199 if (!is_valid_ether_addr(addr->sa_data))
8200 return -EADDRNOTAVAIL;
8201
8202 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008203 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008204
Alexander Duyckc9f53e62015-10-22 16:26:30 -07008205 ixgbe_mac_set_default_filter(adapter);
8206
8207 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008208}
8209
Ben Hutchings6b73e102009-04-29 08:08:58 +00008210static int
8211ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8212{
8213 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8214 struct ixgbe_hw *hw = &adapter->hw;
8215 u16 value;
8216 int rc;
8217
8218 if (prtad != hw->phy.mdio.prtad)
8219 return -EINVAL;
8220 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8221 if (!rc)
8222 rc = value;
8223 return rc;
8224}
8225
8226static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8227 u16 addr, u16 value)
8228{
8229 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8230 struct ixgbe_hw *hw = &adapter->hw;
8231
8232 if (prtad != hw->phy.mdio.prtad)
8233 return -EINVAL;
8234 return hw->phy.ops.write_reg(hw, addr, devad, value);
8235}
8236
8237static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8238{
8239 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8240
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008241 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008242 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008243 return ixgbe_ptp_set_ts_config(adapter, req);
8244 case SIOCGHWTSTAMP:
8245 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008246 default:
8247 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8248 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008249}
8250
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008251/**
8252 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008253 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008254 * @netdev: network interface device structure
8255 *
8256 * Returns non-zero on failure
8257 **/
8258static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8259{
8260 int err = 0;
8261 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008262 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008263
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008264 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008265 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008266 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008267 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008268
8269 /* update SAN MAC vmdq pool selection */
8270 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008271 }
8272 return err;
8273}
8274
8275/**
8276 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008277 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008278 * @netdev: network interface device structure
8279 *
8280 * Returns non-zero on failure
8281 **/
8282static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8283{
8284 int err = 0;
8285 struct ixgbe_adapter *adapter = netdev_priv(dev);
8286 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8287
8288 if (is_valid_ether_addr(mac->san_addr)) {
8289 rtnl_lock();
8290 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8291 rtnl_unlock();
8292 }
8293 return err;
8294}
8295
Auke Kok9a799d72007-09-15 14:07:45 -07008296#ifdef CONFIG_NET_POLL_CONTROLLER
8297/*
8298 * Polling 'interrupt' - used by things like netconsole to send skbs
8299 * without having to re-enable interrupts. It's not called while
8300 * the interrupt routine is executing.
8301 */
8302static void ixgbe_netpoll(struct net_device *netdev)
8303{
8304 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008305 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008306
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008307 /* if interface is down do nothing */
8308 if (test_bit(__IXGBE_DOWN, &adapter->state))
8309 return;
8310
Alexander Duyck856f6062015-02-25 17:45:54 +00008311 /* loop through and schedule all active queues */
8312 for (i = 0; i < adapter->num_q_vectors; i++)
8313 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008314}
Auke Kok9a799d72007-09-15 14:07:45 -07008315
Alexander Duyck581330b2012-02-08 07:51:47 +00008316#endif
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008317
8318static void ixgbe_get_stats64(struct net_device *netdev,
8319 struct rtnl_link_stats64 *stats)
Eric Dumazetde1036b2010-10-20 23:00:04 +00008320{
8321 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8322 int i;
8323
Eric Dumazet1a515022010-11-16 19:26:42 -08008324 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008325 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08008326 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008327 u64 bytes, packets;
8328 unsigned int start;
8329
Eric Dumazet1a515022010-11-16 19:26:42 -08008330 if (ring) {
8331 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008332 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008333 packets = ring->stats.packets;
8334 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008335 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008336 stats->rx_packets += packets;
8337 stats->rx_bytes += bytes;
8338 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008339 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008340
8341 for (i = 0; i < adapter->num_tx_queues; i++) {
8342 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
8343 u64 bytes, packets;
8344 unsigned int start;
8345
8346 if (ring) {
8347 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008348 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008349 packets = ring->stats.packets;
8350 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008351 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008352 stats->tx_packets += packets;
8353 stats->tx_bytes += bytes;
8354 }
8355 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008356 rcu_read_unlock();
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008357
Eric Dumazetde1036b2010-10-20 23:00:04 +00008358 /* following stats updated by ixgbe_watchdog_task() */
8359 stats->multicast = netdev->stats.multicast;
8360 stats->rx_errors = netdev->stats.rx_errors;
8361 stats->rx_length_errors = netdev->stats.rx_length_errors;
8362 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8363 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
Eric Dumazetde1036b2010-10-20 23:00:04 +00008364}
8365
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008366#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008367/**
8368 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8369 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008370 * @tc: number of traffic classes currently enabled
8371 *
8372 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8373 * 802.1Q priority maps to a packet buffer that exists.
8374 */
8375static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8376{
8377 struct ixgbe_hw *hw = &adapter->hw;
8378 u32 reg, rsave;
8379 int i;
8380
8381 /* 82598 have a static priority to TC mapping that can not
8382 * be changed so no validation is needed.
8383 */
8384 if (hw->mac.type == ixgbe_mac_82598EB)
8385 return;
8386
8387 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8388 rsave = reg;
8389
8390 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8391 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8392
8393 /* If up2tc is out of bounds default to zero */
8394 if (up2tc > tc)
8395 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8396 }
8397
8398 if (reg != rsave)
8399 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8400
8401 return;
8402}
8403
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008404/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008405 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8406 * @adapter: Pointer to adapter struct
8407 *
8408 * Populate the netdev user priority to tc map
8409 */
8410static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8411{
8412 struct net_device *dev = adapter->netdev;
8413 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8414 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8415 u8 prio;
8416
8417 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8418 u8 tc = 0;
8419
8420 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8421 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8422 else if (ets)
8423 tc = ets->prio_tc[prio];
8424
8425 netdev_set_prio_tc_map(dev, prio, tc);
8426 }
8427}
8428
Alexander Duyckcca73c52013-01-12 06:33:44 +00008429#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008430/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008431 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008432 *
8433 * @netdev: net device to configure
8434 * @tc: number of traffic classes to enable
8435 */
8436int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8437{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008438 struct ixgbe_adapter *adapter = netdev_priv(dev);
8439 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08008440 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008441
John Fastabend8b1c0b22011-05-03 02:26:48 +00008442 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008443 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8444 return -EINVAL;
8445
8446 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008447 return -EINVAL;
8448
John Fastabend2a47fa42013-11-06 09:54:52 -08008449 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
8450 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
8451 return -EBUSY;
8452
John Fastabend8b1c0b22011-05-03 02:26:48 +00008453 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008454 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008455 * hardware is not flexible enough to do this dynamically.
8456 */
8457 if (netif_running(dev))
8458 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008459 else
8460 ixgbe_reset(adapter);
8461
John Fastabend8b1c0b22011-05-03 02:26:48 +00008462 ixgbe_clear_interrupt_scheme(adapter);
8463
Alexander Duyckcca73c52013-01-12 06:33:44 +00008464#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008465 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008466 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008467 ixgbe_set_prio_tc_map(adapter);
8468
John Fastabende7589ea2011-07-18 22:38:36 +00008469 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008470
Alexander Duyck943561d2012-05-09 22:14:44 -07008471 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8472 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008473 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008474 }
John Fastabende7589ea2011-07-18 22:38:36 +00008475 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008476 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008477
Alexander Duyck943561d2012-05-09 22:14:44 -07008478 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8479 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008480
8481 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008482
8483 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8484 adapter->dcb_cfg.pfc_mode_enable = false;
8485 }
8486
John Fastabend8b1c0b22011-05-03 02:26:48 +00008487 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008488
8489#endif /* CONFIG_IXGBE_DCB */
8490 ixgbe_init_interrupt_scheme(adapter);
8491
John Fastabend8b1c0b22011-05-03 02:26:48 +00008492 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008493 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008494
8495 return 0;
8496}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008497
John Fastabendb82b17d2016-02-16 21:18:53 -08008498static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8499 struct tc_cls_u32_offload *cls)
8500{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008501 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008502 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008503 u32 loc = cls->knode.handle & 0xfffff;
8504 int err = 0, i, j;
8505 struct ixgbe_jump_table *jump = NULL;
8506
8507 if (loc > IXGBE_MAX_HW_ENTRIES)
8508 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008509
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008510 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8511 return -EINVAL;
8512
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008513 /* Clear this filter in the link data it is associated with */
8514 if (uhtid != 0x800) {
8515 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008516 if (!jump)
8517 return -EINVAL;
8518 if (!test_bit(loc - 1, jump->child_loc_map))
8519 return -EINVAL;
8520 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008521 }
8522
8523 /* Check if the filter being deleted is a link */
8524 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8525 jump = adapter->jump_tables[i];
8526 if (jump && jump->link_hdl == hdl) {
8527 /* Delete filters in the hardware in the child hash
8528 * table associated with this link
8529 */
8530 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8531 if (!test_bit(j, jump->child_loc_map))
8532 continue;
8533 spin_lock(&adapter->fdir_perfect_lock);
8534 err = ixgbe_update_ethtool_fdir_entry(adapter,
8535 NULL,
8536 j + 1);
8537 spin_unlock(&adapter->fdir_perfect_lock);
8538 clear_bit(j, jump->child_loc_map);
8539 }
8540 /* Remove resources for this link */
8541 kfree(jump->input);
8542 kfree(jump->mask);
8543 kfree(jump);
8544 adapter->jump_tables[i] = NULL;
8545 return err;
8546 }
8547 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008548
John Fastabendb82b17d2016-02-16 21:18:53 -08008549 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008550 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008551 spin_unlock(&adapter->fdir_perfect_lock);
8552 return err;
8553}
8554
John Fastabenddb956ae2016-02-16 21:19:19 -08008555static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
8556 __be16 protocol,
8557 struct tc_cls_u32_offload *cls)
8558{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008559 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8560
8561 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8562 return -EINVAL;
8563
John Fastabenddb956ae2016-02-16 21:19:19 -08008564 /* This ixgbe devices do not support hash tables at the moment
8565 * so abort when given hash tables.
8566 */
8567 if (cls->hnode.divisor > 0)
8568 return -EINVAL;
8569
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008570 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008571 return 0;
8572}
8573
8574static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8575 struct tc_cls_u32_offload *cls)
8576{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008577 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8578
8579 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8580 return -EINVAL;
8581
8582 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008583 return 0;
8584}
8585
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008586#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07008587struct upper_walk_data {
8588 struct ixgbe_adapter *adapter;
8589 u64 action;
8590 int ifindex;
8591 u8 queue;
8592};
8593
8594static int get_macvlan_queue(struct net_device *upper, void *_data)
8595{
8596 if (netif_is_macvlan(upper)) {
8597 struct macvlan_dev *dfwd = netdev_priv(upper);
8598 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
8599 struct upper_walk_data *data = _data;
8600 struct ixgbe_adapter *adapter = data->adapter;
8601 int ifindex = data->ifindex;
8602
8603 if (vadapter && vadapter->netdev->ifindex == ifindex) {
8604 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
8605 data->action = data->queue;
8606 return 1;
8607 }
8608 }
8609
8610 return 0;
8611}
8612
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008613static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
8614 u8 *queue, u64 *action)
8615{
8616 unsigned int num_vfs = adapter->num_vfs, vf;
David Ahern1cd127f2016-10-17 19:15:48 -07008617 struct upper_walk_data data;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008618 struct net_device *upper;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008619
8620 /* redirect to a SRIOV VF */
8621 for (vf = 0; vf < num_vfs; ++vf) {
8622 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
8623 if (upper->ifindex == ifindex) {
8624 if (adapter->num_rx_pools > 1)
8625 *queue = vf * 2;
8626 else
8627 *queue = vf * adapter->num_rx_queues_per_pool;
8628
8629 *action = vf + 1;
8630 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
8631 return 0;
8632 }
8633 }
8634
8635 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07008636 data.adapter = adapter;
8637 data.ifindex = ifindex;
8638 data.action = 0;
8639 data.queue = 0;
8640 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
8641 get_macvlan_queue, &data)) {
8642 *action = data.action;
8643 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008644
David Ahern1cd127f2016-10-17 19:15:48 -07008645 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008646 }
8647
8648 return -EINVAL;
8649}
8650
8651static int parse_tc_actions(struct ixgbe_adapter *adapter,
8652 struct tcf_exts *exts, u64 *action, u8 *queue)
8653{
8654 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07008655 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008656 int err;
8657
8658 if (tc_no_actions(exts))
8659 return -EINVAL;
8660
WANG Cong22dc13c2016-08-13 22:35:00 -07008661 tcf_exts_to_list(exts, &actions);
8662 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008663
8664 /* Drop action */
8665 if (is_tcf_gact_shot(a)) {
8666 *action = IXGBE_FDIR_DROP_QUEUE;
8667 *queue = IXGBE_FDIR_DROP_QUEUE;
8668 return 0;
8669 }
8670
8671 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03008672 if (is_tcf_mirred_egress_redirect(a)) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008673 int ifindex = tcf_mirred_ifindex(a);
8674
8675 err = handle_redirect_action(adapter, ifindex, queue,
8676 action);
8677 if (err == 0)
8678 return err;
8679 }
8680 }
8681
8682 return -EINVAL;
8683}
8684#else
8685static int parse_tc_actions(struct ixgbe_adapter *adapter,
8686 struct tcf_exts *exts, u64 *action, u8 *queue)
8687{
8688 return -EINVAL;
8689}
8690#endif /* CONFIG_NET_CLS_ACT */
8691
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008692static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
8693 union ixgbe_atr_input *mask,
8694 struct tc_cls_u32_offload *cls,
8695 struct ixgbe_mat_field *field_ptr,
8696 struct ixgbe_nexthdr *nexthdr)
8697{
8698 int i, j, off;
8699 __be32 val, m;
8700 bool found_entry = false, found_jump_field = false;
8701
8702 for (i = 0; i < cls->knode.sel->nkeys; i++) {
8703 off = cls->knode.sel->keys[i].off;
8704 val = cls->knode.sel->keys[i].val;
8705 m = cls->knode.sel->keys[i].mask;
8706
8707 for (j = 0; field_ptr[j].val; j++) {
8708 if (field_ptr[j].off == off) {
8709 field_ptr[j].val(input, mask, val, m);
8710 input->filter.formatted.flow_type |=
8711 field_ptr[j].type;
8712 found_entry = true;
8713 break;
8714 }
8715 }
8716 if (nexthdr) {
8717 if (nexthdr->off == cls->knode.sel->keys[i].off &&
8718 nexthdr->val == cls->knode.sel->keys[i].val &&
8719 nexthdr->mask == cls->knode.sel->keys[i].mask)
8720 found_jump_field = true;
8721 else
8722 continue;
8723 }
8724 }
8725
8726 if (nexthdr && !found_jump_field)
8727 return -EINVAL;
8728
8729 if (!found_entry)
8730 return 0;
8731
8732 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
8733 IXGBE_ATR_L4TYPE_MASK;
8734
8735 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
8736 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
8737
8738 return 0;
8739}
8740
John Fastabendb82b17d2016-02-16 21:18:53 -08008741static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
8742 __be16 protocol,
8743 struct tc_cls_u32_offload *cls)
8744{
8745 u32 loc = cls->knode.handle & 0xfffff;
8746 struct ixgbe_hw *hw = &adapter->hw;
8747 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008748 struct ixgbe_fdir_filter *input = NULL;
8749 union ixgbe_atr_input *mask = NULL;
8750 struct ixgbe_jump_table *jump = NULL;
8751 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008752 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008753 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08008754
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008755 uhtid = TC_U32_USERHTID(cls->knode.handle);
8756 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08008757
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008758 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08008759 * L2 headers. The canonical method to match L2 frames is to use
8760 * negative values. However this is error prone at best but really
8761 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008762 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08008763 * headers when needed.
8764 */
8765 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008766 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008767
8768 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
8769 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008770 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008771 }
8772
8773 /* cls u32 is a graph starting at root node 0x800. The driver tracks
8774 * links and also the fields used to advance the parser across each
8775 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
8776 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
8777 * To add support for new nodes update ixgbe_model.h parse structures
8778 * this function _should_ be generic try not to hardcode values here.
8779 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008780 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008781 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08008782 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008783 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008784 return err;
8785 if (!adapter->jump_tables[uhtid])
8786 return err;
8787 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08008788 }
8789
8790 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008791 return err;
8792
8793 /* At this point we know the field_ptr is valid and need to either
8794 * build cls_u32 link or attach filter. Because adding a link to
8795 * a handle that does not exist is invalid and the same for adding
8796 * rules to handles that don't exist.
8797 */
8798
8799 if (link_uhtid) {
8800 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
8801
8802 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
8803 return err;
8804
8805 if (!test_bit(link_uhtid - 1, &adapter->tables))
8806 return err;
8807
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008808 /* Multiple filters as links to the same hash table are not
8809 * supported. To add a new filter with the same next header
8810 * but different match/jump conditions, create a new hash table
8811 * and link to it.
8812 */
8813 if (adapter->jump_tables[link_uhtid] &&
8814 (adapter->jump_tables[link_uhtid])->link_hdl) {
8815 e_err(drv, "Link filter exists for link: %x\n",
8816 link_uhtid);
8817 return err;
8818 }
8819
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008820 for (i = 0; nexthdr[i].jump; i++) {
8821 if (nexthdr[i].o != cls->knode.sel->offoff ||
8822 nexthdr[i].s != cls->knode.sel->offshift ||
8823 nexthdr[i].m != cls->knode.sel->offmask)
8824 return err;
8825
8826 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
8827 if (!jump)
8828 return -ENOMEM;
8829 input = kzalloc(sizeof(*input), GFP_KERNEL);
8830 if (!input) {
8831 err = -ENOMEM;
8832 goto free_jump;
8833 }
8834 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
8835 if (!mask) {
8836 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008837 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008838 }
8839 jump->input = input;
8840 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008841 jump->link_hdl = cls->knode.handle;
8842
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008843 err = ixgbe_clsu32_build_input(input, mask, cls,
8844 field_ptr, &nexthdr[i]);
8845 if (!err) {
8846 jump->mat = nexthdr[i].jump;
8847 adapter->jump_tables[link_uhtid] = jump;
8848 break;
8849 }
8850 }
8851 return 0;
8852 }
John Fastabendb82b17d2016-02-16 21:18:53 -08008853
8854 input = kzalloc(sizeof(*input), GFP_KERNEL);
8855 if (!input)
8856 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008857 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
8858 if (!mask) {
8859 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008860 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08008861 }
8862
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008863 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
8864 if ((adapter->jump_tables[uhtid])->input)
8865 memcpy(input, (adapter->jump_tables[uhtid])->input,
8866 sizeof(*input));
8867 if ((adapter->jump_tables[uhtid])->mask)
8868 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
8869 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008870
8871 /* Lookup in all child hash tables if this location is already
8872 * filled with a filter
8873 */
8874 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8875 struct ixgbe_jump_table *link = adapter->jump_tables[i];
8876
8877 if (link && (test_bit(loc - 1, link->child_loc_map))) {
8878 e_err(drv, "Filter exists in location: %x\n",
8879 loc);
8880 err = -EINVAL;
8881 goto err_out;
8882 }
8883 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008884 }
8885 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
8886 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08008887 goto err_out;
8888
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008889 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
8890 &queue);
8891 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08008892 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08008893
John Fastabendb82b17d2016-02-16 21:18:53 -08008894 input->sw_idx = loc;
8895
8896 spin_lock(&adapter->fdir_perfect_lock);
8897
8898 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008899 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
8900 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008901 if (err)
8902 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008903 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008904 err = -EINVAL;
8905 goto err_out_w_lock;
8906 }
8907
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008908 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008909 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
8910 input->sw_idx, queue);
8911 if (!err)
8912 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
8913 spin_unlock(&adapter->fdir_perfect_lock);
8914
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008915 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
8916 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008917
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008918 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008919 return err;
8920err_out_w_lock:
8921 spin_unlock(&adapter->fdir_perfect_lock);
8922err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008923 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008924free_input:
8925 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008926free_jump:
8927 kfree(jump);
8928 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008929}
8930
Emil Tantilov6e2a60b2016-02-17 15:55:06 -08008931static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
8932 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08008933{
John Fastabendb82b17d2016-02-16 21:18:53 -08008934 struct ixgbe_adapter *adapter = netdev_priv(dev);
8935
8936 if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
8937 tc->type == TC_SETUP_CLSU32) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008938 switch (tc->cls_u32->command) {
8939 case TC_CLSU32_NEW_KNODE:
8940 case TC_CLSU32_REPLACE_KNODE:
8941 return ixgbe_configure_clsu32(adapter,
8942 proto, tc->cls_u32);
8943 case TC_CLSU32_DELETE_KNODE:
8944 return ixgbe_delete_clsu32(adapter, tc->cls_u32);
John Fastabenddb956ae2016-02-16 21:19:19 -08008945 case TC_CLSU32_NEW_HNODE:
8946 case TC_CLSU32_REPLACE_HNODE:
8947 return ixgbe_configure_clsu32_add_hnode(adapter, proto,
8948 tc->cls_u32);
8949 case TC_CLSU32_DELETE_HNODE:
8950 return ixgbe_configure_clsu32_del_hnode(adapter,
8951 tc->cls_u32);
John Fastabendb82b17d2016-02-16 21:18:53 -08008952 default:
8953 return -EINVAL;
8954 }
8955 }
8956
John Fastabend5eb4dce2016-02-29 11:26:13 -08008957 if (tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08008958 return -EINVAL;
8959
Amritha Nambiar56f36ac2017-03-15 10:39:25 -07008960 tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
8961
8962 return ixgbe_setup_tc(dev, tc->mqprio->num_tc);
John Fastabende4c67342016-02-16 21:16:15 -08008963}
8964
Greg Roseda36b642012-12-11 08:26:43 +00008965#ifdef CONFIG_PCI_IOV
8966void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
8967{
8968 struct net_device *netdev = adapter->netdev;
8969
8970 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00008971 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00008972 rtnl_unlock();
8973}
8974
8975#endif
Don Skidmore082757a2011-07-21 05:55:00 +00008976void ixgbe_do_reset(struct net_device *netdev)
8977{
8978 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8979
8980 if (netif_running(netdev))
8981 ixgbe_reinit_locked(adapter);
8982 else
8983 ixgbe_reset(adapter);
8984}
8985
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008986static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008987 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008988{
8989 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8990
Don Skidmore082757a2011-07-21 05:55:00 +00008991 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00008992 if (!(features & NETIF_F_RXCSUM))
8993 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00008994
Alexander Duyck567d2de2012-02-11 07:18:57 +00008995 /* Turn off LRO if not RSC capable */
8996 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
8997 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008998
Alexander Duyck567d2de2012-02-11 07:18:57 +00008999 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00009000}
9001
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009002static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009003 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009004{
9005 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00009006 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00009007 bool need_reset = false;
9008
Don Skidmore082757a2011-07-21 05:55:00 +00009009 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009010 if (!(features & NETIF_F_LRO)) {
9011 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00009012 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00009013 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9014 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9015 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9016 if (adapter->rx_itr_setting == 1 ||
9017 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9018 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9019 need_reset = true;
9020 } else if ((changed ^ features) & NETIF_F_LRO) {
9021 e_info(probe, "rx-usecs set too low, "
9022 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00009023 }
9024 }
9025
9026 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08009027 * Check if Flow Director n-tuple support or hw_tc support was
9028 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00009029 */
John Fastabendb82b17d2016-02-16 21:18:53 -08009030 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00009031 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00009032 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9033 need_reset = true;
9034
Alexander Duyck567d2de2012-02-11 07:18:57 +00009035 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9036 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08009037 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00009038 /* turn off perfect filters, enable ATR and reset */
9039 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9040 need_reset = true;
9041
9042 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9043
9044 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08009045 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9046 /* We cannot enable ATR if we have 2 or more tcs */
9047 (netdev_get_num_tc(netdev) > 1) ||
9048 /* We cannot enable ATR if RSS is disabled */
9049 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9050 /* A sample rate of 0 indicates ATR disabled */
9051 (!adapter->atr_sample_rate))
9052 ; /* do nothing not supported */
9053 else /* otherwise supported and set the flag */
9054 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00009055 }
9056
Ben Greear3f2d1c02012-03-08 08:28:41 +00009057 if (changed & NETIF_F_RXALL)
9058 need_reset = true;
9059
Alexander Duyck567d2de2012-02-11 07:18:57 +00009060 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07009061
Mark Rustad67359c32015-06-15 11:33:25 -07009062 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07009063 if (features & NETIF_F_RXCSUM) {
9064 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9065 } else {
9066 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9067
9068 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9069 }
9070 }
9071
9072 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9073 if (features & NETIF_F_RXCSUM) {
9074 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9075 } else {
9076 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9077
9078 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9079 }
Mark Rustad67359c32015-06-15 11:33:25 -07009080 }
Mark Rustad67359c32015-06-15 11:33:25 -07009081
Don Skidmore082757a2011-07-21 05:55:00 +00009082 if (need_reset)
9083 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009084 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9085 NETIF_F_HW_VLAN_CTAG_FILTER))
9086 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00009087
9088 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00009089}
9090
Don Skidmore3f207802014-12-23 07:40:34 +00009091/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009092 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009093 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009094 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009095 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009096static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9097 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009098{
9099 struct ixgbe_adapter *adapter = netdev_priv(dev);
9100 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07009101 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07009102 u32 port_shift = 0;
9103 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07009104
Alexander Duyckb3a49552016-06-16 12:22:19 -07009105 if (ti->sa_family != AF_INET)
9106 return;
9107
Emil Tantilova21d0822016-08-10 11:19:23 -07009108 switch (ti->type) {
9109 case UDP_TUNNEL_TYPE_VXLAN:
9110 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9111 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009112
Emil Tantilova21d0822016-08-10 11:19:23 -07009113 if (adapter->vxlan_port == port)
9114 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009115
Emil Tantilova21d0822016-08-10 11:19:23 -07009116 if (adapter->vxlan_port) {
9117 netdev_info(dev,
9118 "VXLAN port %d set, not adding port %d\n",
9119 ntohs(adapter->vxlan_port),
9120 ntohs(port));
9121 return;
9122 }
9123
9124 adapter->vxlan_port = port;
9125 break;
9126 case UDP_TUNNEL_TYPE_GENEVE:
9127 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9128 return;
9129
9130 if (adapter->geneve_port == port)
9131 return;
9132
9133 if (adapter->geneve_port) {
9134 netdev_info(dev,
9135 "GENEVE port %d set, not adding port %d\n",
9136 ntohs(adapter->geneve_port),
9137 ntohs(port));
9138 return;
9139 }
9140
9141 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9142 adapter->geneve_port = port;
9143 break;
9144 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009145 return;
9146 }
9147
Emil Tantilova21d0822016-08-10 11:19:23 -07009148 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9149 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00009150}
9151
9152/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009153 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009154 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009155 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009156 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009157static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9158 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009159{
9160 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07009161 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00009162
Emil Tantilova21d0822016-08-10 11:19:23 -07009163 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9164 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07009165 return;
9166
9167 if (ti->sa_family != AF_INET)
9168 return;
9169
Emil Tantilova21d0822016-08-10 11:19:23 -07009170 switch (ti->type) {
9171 case UDP_TUNNEL_TYPE_VXLAN:
9172 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9173 return;
Mark Rustad67359c32015-06-15 11:33:25 -07009174
Emil Tantilova21d0822016-08-10 11:19:23 -07009175 if (adapter->vxlan_port != ti->port) {
9176 netdev_info(dev, "VXLAN port %d not found\n",
9177 ntohs(ti->port));
9178 return;
9179 }
9180
9181 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9182 break;
9183 case UDP_TUNNEL_TYPE_GENEVE:
9184 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9185 return;
9186
9187 if (adapter->geneve_port != ti->port) {
9188 netdev_info(dev, "GENEVE port %d not found\n",
9189 ntohs(ti->port));
9190 return;
9191 }
9192
9193 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9194 break;
9195 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009196 return;
9197 }
9198
Emil Tantilova21d0822016-08-10 11:19:23 -07009199 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9200 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00009201}
9202
stephen hemmingeredc7d572012-10-01 12:32:33 +00009203static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009204 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009205 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009206 u16 flags)
9207{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009208 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00009209 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009210 struct ixgbe_adapter *adapter = netdev_priv(dev);
9211 u16 pool = VMDQ_P(0);
9212
9213 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009214 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009215 }
9216
Jiri Pirkof6f64242014-11-28 14:34:15 +01009217 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009218}
9219
Don Skidmore219efe92015-04-09 22:03:22 -07009220/**
9221 * ixgbe_configure_bridge_mode - set various bridge modes
9222 * @adapter - the private structure
9223 * @mode - requested bridge mode
9224 *
9225 * Configure some settings require for various bridge modes.
9226 **/
9227static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9228 __u16 mode)
9229{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009230 struct ixgbe_hw *hw = &adapter->hw;
9231 unsigned int p, num_pools;
9232 u32 vmdctl;
9233
Don Skidmore219efe92015-04-09 22:03:22 -07009234 switch (mode) {
9235 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009236 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009237 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009238
9239 /* must enable Rx switching replication to allow multicast
9240 * packet reception on all VFs, and to enable source address
9241 * pruning.
9242 */
9243 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9244 vmdctl |= IXGBE_VT_CTL_REPLEN;
9245 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9246
9247 /* enable Rx source address pruning. Note, this requires
9248 * replication to be enabled or else it does nothing.
9249 */
9250 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9251 for (p = 0; p < num_pools; p++) {
9252 if (hw->mac.ops.set_source_address_pruning)
9253 hw->mac.ops.set_source_address_pruning(hw,
9254 true,
9255 p);
9256 }
Don Skidmore219efe92015-04-09 22:03:22 -07009257 break;
9258 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009259 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009260 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9261 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009262
9263 /* disable Rx switching replication unless we have SR-IOV
9264 * virtual functions
9265 */
9266 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9267 if (!adapter->num_vfs)
9268 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9269 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9270
9271 /* disable Rx source address pruning, since we don't expect to
9272 * be receiving external loopback of our transmitted frames.
9273 */
9274 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9275 for (p = 0; p < num_pools; p++) {
9276 if (hw->mac.ops.set_source_address_pruning)
9277 hw->mac.ops.set_source_address_pruning(hw,
9278 false,
9279 p);
9280 }
Don Skidmore219efe92015-04-09 22:03:22 -07009281 break;
9282 default:
9283 return -EINVAL;
9284 }
9285
9286 adapter->bridge_mode = mode;
9287
9288 e_info(drv, "enabling bridge mode: %s\n",
9289 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9290
9291 return 0;
9292}
9293
John Fastabend815cccb2012-10-24 08:13:09 +00009294static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009295 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009296{
9297 struct ixgbe_adapter *adapter = netdev_priv(dev);
9298 struct nlattr *attr, *br_spec;
9299 int rem;
9300
9301 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9302 return -EOPNOTSUPP;
9303
9304 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009305 if (!br_spec)
9306 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009307
9308 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009309 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009310 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009311
9312 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9313 continue;
9314
Thomas Grafb7c1a312014-11-26 13:42:17 +01009315 if (nla_len(attr) < sizeof(mode))
9316 return -EINVAL;
9317
John Fastabend815cccb2012-10-24 08:13:09 +00009318 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009319 status = ixgbe_configure_bridge_mode(adapter, mode);
9320 if (status)
9321 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009322
9323 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009324 }
9325
9326 return 0;
9327}
9328
9329static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009330 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009331 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009332{
9333 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009334
9335 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9336 return 0;
9337
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009338 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009339 adapter->bridge_mode, 0, 0, nlflags,
9340 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009341}
9342
John Fastabend2a47fa42013-11-06 09:54:52 -08009343static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9344{
9345 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
9346 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009347 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08009348 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009349 int pool, err;
9350
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009351 /* Hardware has a limited number of available pools. Each VF, and the
9352 * PF require a pool. Check to ensure we don't attempt to use more
9353 * then the available number of pools.
9354 */
9355 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9356 return ERR_PTR(-EINVAL);
9357
John Fastabend219354d2013-11-08 00:50:32 -08009358#ifdef CONFIG_RPS
9359 if (vdev->num_rx_queues != vdev->num_tx_queues) {
9360 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
9361 vdev->name);
9362 return ERR_PTR(-EINVAL);
9363 }
9364#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08009365 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08009366 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08009367 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
9368 netdev_info(pdev,
9369 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
9370 pdev->name);
9371 return ERR_PTR(-EINVAL);
9372 }
9373
9374 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
9375 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
9376 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
9377 return ERR_PTR(-EBUSY);
9378
Maninder Singhbc52f952015-06-19 09:37:55 +05309379 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08009380 if (!fwd_adapter)
9381 return ERR_PTR(-ENOMEM);
9382
9383 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
9384 adapter->num_rx_pools++;
9385 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08009386 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08009387
9388 /* Enable VMDq flag so device will be set in VM mode */
9389 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08009390 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08009391 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08009392
9393 /* Force reinit of ring allocation with VMDQ enabled */
9394 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9395 if (err)
9396 goto fwd_add_err;
9397 fwd_adapter->pool = pool;
9398 fwd_adapter->real_adapter = adapter;
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009399
9400 if (netif_running(pdev)) {
9401 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
9402 if (err)
9403 goto fwd_add_err;
9404 netif_tx_start_all_queues(vdev);
9405 }
9406
John Fastabend2a47fa42013-11-06 09:54:52 -08009407 return fwd_adapter;
9408fwd_add_err:
9409 /* unwind counter and free adapter struct */
9410 netdev_info(pdev,
9411 "%s: dfwd hardware acceleration failed\n", vdev->name);
9412 clear_bit(pool, &adapter->fwd_bitmask);
9413 adapter->num_rx_pools--;
9414 kfree(fwd_adapter);
9415 return ERR_PTR(err);
9416}
9417
9418static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9419{
9420 struct ixgbe_fwd_adapter *fwd_adapter = priv;
9421 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08009422 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009423
9424 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
9425 adapter->num_rx_pools--;
9426
John Fastabend51f37732013-11-08 00:51:10 -08009427 limit = find_last_bit(&adapter->fwd_bitmask, 32);
9428 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009429 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
9430 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9431 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
9432 fwd_adapter->pool, adapter->num_rx_pools,
9433 fwd_adapter->rx_base_queue,
9434 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
9435 adapter->fwd_bitmask);
9436 kfree(fwd_adapter);
9437}
9438
Alexander Duyckb83e3012016-04-14 17:19:31 -04009439#define IXGBE_MAX_MAC_HDR_LEN 127
9440#define IXGBE_MAX_NETWORK_HDR_LEN 511
9441
Mark Rustadf467bc02015-06-15 11:33:20 -07009442static netdev_features_t
9443ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9444 netdev_features_t features)
9445{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009446 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009447
Alexander Duyckb83e3012016-04-14 17:19:31 -04009448 /* Make certain the headers can be described by a context descriptor */
9449 mac_hdr_len = skb_network_header(skb) - skb->data;
9450 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9451 return features & ~(NETIF_F_HW_CSUM |
9452 NETIF_F_SCTP_CRC |
9453 NETIF_F_HW_VLAN_CTAG_TX |
9454 NETIF_F_TSO |
9455 NETIF_F_TSO6);
9456
9457 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9458 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9459 return features & ~(NETIF_F_HW_CSUM |
9460 NETIF_F_SCTP_CRC |
9461 NETIF_F_TSO |
9462 NETIF_F_TSO6);
9463
9464 /* We can only support IPV4 TSO in tunnels if we can mangle the
9465 * inner IP ID field, so strip TSO if MANGLEID is not supported.
9466 */
9467 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
9468 features &= ~NETIF_F_TSO;
Mark Rustadf467bc02015-06-15 11:33:20 -07009469
9470 return features;
9471}
9472
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009473static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00009474 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009475 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08009476 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07009477 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00009478 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009479 .ndo_validate_addr = eth_validate_addr,
9480 .ndo_set_mac_address = ixgbe_set_mac,
9481 .ndo_change_mtu = ixgbe_change_mtu,
9482 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00009483 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009484 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
9485 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00009486 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00009487 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
9488 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04009489 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00009490 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03009491 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +00009492 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +00009493 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00009494 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -08009495 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009496#ifdef CONFIG_NET_POLL_CONTROLLER
9497 .ndo_poll_controller = ixgbe_netpoll,
9498#endif
Yi Zou332d4a72009-05-13 13:11:53 +00009499#ifdef IXGBE_FCOE
9500 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00009501 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00009502 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00009503 .ndo_fcoe_enable = ixgbe_fcoe_enable,
9504 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00009505 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00009506 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00009507#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00009508 .ndo_set_features = ixgbe_set_features,
9509 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009510 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00009511 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
9512 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08009513 .ndo_dfwd_add_station = ixgbe_fwd_add,
9514 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -07009515 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
9516 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -07009517 .ndo_features_check = ixgbe_features_check,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009518};
9519
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009520/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00009521 * ixgbe_enumerate_functions - Get the number of ports this device has
9522 * @adapter: adapter structure
9523 *
9524 * This function enumerates the phsyical functions co-located on a single slot,
9525 * in order to determine how many ports a device has. This is most useful in
9526 * determining the required GT/s of PCIe bandwidth necessary for optimal
9527 * performance.
9528 **/
9529static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
9530{
Jacob Kellercaafb952014-07-19 07:17:17 +00009531 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009532 int physfns = 0;
9533
Jacob Kellerf1f96572013-08-31 02:45:38 +00009534 /* Some cards can not use the generic count PCIe functions method,
9535 * because they are behind a parent switch, so we hardcode these with
9536 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00009537 */
Jacob Keller88189702014-07-19 07:17:16 +00009538 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00009539 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00009540
9541 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
9542 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00009543 if (entry->is_virtfn)
9544 continue;
9545
9546 /* When the devices on the bus don't all match our device ID,
9547 * we can't reliably determine the correct number of
9548 * functions. This can occur if a function has been direct
9549 * attached to a virtual machine using VT-d, for example. In
9550 * this case, simply return -1 to indicate this.
9551 */
9552 if ((entry->vendor != pdev->vendor) ||
9553 (entry->device != pdev->device))
9554 return -1;
9555
9556 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009557 }
9558
9559 return physfns;
9560}
9561
9562/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00009563 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -07009564 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +00009565 * @device_id: the device ID
9566 * @subdev_id: the subsystem device ID
9567 *
9568 * This function is used by probe and ethtool to determine
9569 * which devices have WoL support
9570 *
9571 **/
Emil Tantilov740234f2016-04-21 11:37:12 -07009572bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
9573 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +00009574{
9575 struct ixgbe_hw *hw = &adapter->hw;
9576 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009577
Emil Tantilov740234f2016-04-21 11:37:12 -07009578 /* WOL not supported on 82598 */
9579 if (hw->mac.type == ixgbe_mac_82598EB)
9580 return false;
9581
9582 /* check eeprom to see if WOL is enabled for X540 and newer */
9583 if (hw->mac.type >= ixgbe_mac_X540) {
9584 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
9585 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
9586 (hw->bus.func == 0)))
9587 return true;
9588 }
9589
9590 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +00009591 switch (device_id) {
9592 case IXGBE_DEV_ID_82599_SFP:
9593 /* Only these subdevices could supports WOL */
9594 switch (subdevice_id) {
9595 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009596 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
9597 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
9598 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009599 /* only support first port */
9600 if (hw->bus.func != 0)
9601 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00009602 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009603 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00009604 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00009605 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009606 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
9607 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
9608 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -07009609 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009610 }
9611 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009612 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -07009613 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +00009614 switch (subdevice_id) {
9615 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -07009616 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009617 }
9618 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009619 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
9620 /* All except this subdevice support WOL */
9621 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -07009622 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009623 break;
9624 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -07009625 return true;
9626 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009627 break;
9628 }
9629
Emil Tantilov740234f2016-04-21 11:37:12 -07009630 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009631}
9632
9633/**
Auke Kok9a799d72007-09-15 14:07:45 -07009634 * ixgbe_probe - Device Initialization Routine
9635 * @pdev: PCI device information struct
9636 * @ent: entry in ixgbe_pci_tbl
9637 *
9638 * Returns 0 on success, negative on failure
9639 *
9640 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
9641 * The OS initialization, configuring of the adapter private structure,
9642 * and a hardware reset occur.
9643 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00009644static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07009645{
9646 struct net_device *netdev;
9647 struct ixgbe_adapter *adapter = NULL;
9648 struct ixgbe_hw *hw;
9649 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +00009650 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009651 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00009652 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009653 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +00009654#ifdef IXGBE_FCOE
9655 u16 device_caps;
9656#endif
Don Skidmore289700db2010-12-03 03:32:58 +00009657 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07009658
Andy Gospodarekbded64a2010-07-21 06:40:31 +00009659 /* Catch broken hardware that put the wrong VF device ID in
9660 * the PCIe SR-IOV capability.
9661 */
9662 if (pdev->is_virtfn) {
9663 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
9664 pci_name(pdev), pdev->vendor, pdev->device);
9665 return -EINVAL;
9666 }
9667
gouji-new9ce77662009-05-06 10:44:45 +00009668 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009669 if (err)
9670 return err;
9671
Russell Kingf5f2eda2013-06-10 12:47:42 +01009672 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07009673 pci_using_dac = 1;
9674 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009675 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07009676 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009677 dev_err(&pdev->dev,
9678 "No usable DMA configuration, aborting\n");
9679 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07009680 }
9681 pci_using_dac = 0;
9682 }
9683
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02009684 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07009685 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00009686 dev_err(&pdev->dev,
9687 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07009688 goto err_pci_reg;
9689 }
9690
Frans Pop19d5afd2009-10-02 10:04:12 -07009691 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009692
Auke Kok9a799d72007-09-15 14:07:45 -07009693 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07009694 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009695
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009696 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00009697#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009698 /* 8 TC w/ 4 queues per TC */
9699 indices = 4 * MAX_TRAFFIC_CLASS;
9700#else
9701 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00009702#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009703 }
John Fastabende901acd2011-04-26 07:26:08 +00009704
John Fastabendc85a2612010-02-25 23:15:21 +00009705 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07009706 if (!netdev) {
9707 err = -ENOMEM;
9708 goto err_alloc_etherdev;
9709 }
9710
Auke Kok9a799d72007-09-15 14:07:45 -07009711 SET_NETDEV_DEV(netdev, &pdev->dev);
9712
Auke Kok9a799d72007-09-15 14:07:45 -07009713 adapter = netdev_priv(netdev);
9714
9715 adapter->netdev = netdev;
9716 adapter->pdev = pdev;
9717 hw = &adapter->hw;
9718 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00009719 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07009720
Jeff Kirsher05857982008-09-11 19:57:00 -07009721 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00009722 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08009723 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07009724 if (!hw->hw_addr) {
9725 err = -EIO;
9726 goto err_ioremap;
9727 }
9728
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009729 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009730 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009731 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +00009732 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -07009733
Auke Kok9a799d72007-09-15 14:07:45 -07009734 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -08009735 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009736 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009737 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -07009738 if (ii->link_ops)
9739 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009740
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009741 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -08009742 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009743 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +00009744 if (ixgbe_removed(hw->hw_addr)) {
9745 err = -EIO;
9746 goto err_ioremap;
9747 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009748 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07009749 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009750 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
9751
9752 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -08009753 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009754 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00009755 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
9756 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
9757 hw->phy.mdio.mmds = 0;
9758 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9759 hw->phy.mdio.dev = netdev;
9760 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
9761 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009762
Auke Kok9a799d72007-09-15 14:07:45 -07009763 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -07009764 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -07009765 if (err)
9766 goto err_sw_init;
9767
Don Skidmoredbd15b82016-03-09 16:45:00 -05009768 /* Make sure the SWFW semaphore is in a valid state */
9769 if (hw->mac.ops.init_swfw_sync)
9770 hw->mac.ops.init_swfw_sync(hw);
9771
Don Skidmoree86bff02010-02-11 04:14:08 +00009772 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08009773 switch (adapter->hw.mac.type) {
9774 case ixgbe_mac_82599EB:
9775 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00009776 case ixgbe_mac_X550:
9777 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07009778 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +00009779 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08009780 break;
9781 default:
9782 break;
9783 }
Don Skidmoree86bff02010-02-11 04:14:08 +00009784
Don Skidmorebf069c92009-05-07 10:39:54 +00009785 /*
9786 * If there is a fan on this device and it has failed log the
9787 * failure.
9788 */
9789 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
9790 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
9791 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00009792 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00009793 }
9794
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00009795 if (allow_unsupported_sfp)
9796 hw->allow_unsupported_sfp = allow_unsupported_sfp;
9797
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009798 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009799 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009800 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009801 hw->phy.reset_if_overtemp = false;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08009802 ixgbe_set_eee_capable(adapter);
Mark Rustad29a8dca2015-08-08 16:17:46 -07009803 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07009804 err = 0;
9805 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00009806 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
9807 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009808 goto err_sw_init;
9809 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009810 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009811 goto err_sw_init;
9812 }
9813
Alexander Duyck99d74482012-05-09 08:09:25 +00009814#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00009815 /* SR-IOV not supported on the 82598 */
9816 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
9817 goto skip_sriov;
9818 /* Mailbox */
9819 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -08009820 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -08009821 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
Emil Tantilov5c11f002017-01-20 14:11:56 -08009822 ixgbe_enable_sriov(adapter, max_vfs);
Greg Rose60a1a682012-12-11 08:26:33 +00009823skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009824
Alexander Duyck99d74482012-05-09 08:09:25 +00009825#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00009826 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +00009827 NETIF_F_TSO |
9828 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00009829 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -08009830 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -04009831 NETIF_F_HW_CSUM;
9832
9833#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
9834 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -07009835 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -07009836 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -04009837 NETIF_F_GSO_UDP_TUNNEL | \
9838 NETIF_F_GSO_UDP_TUNNEL_CSUM)
9839
9840 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
9841 netdev->features |= NETIF_F_GSO_PARTIAL |
9842 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -07009843
Alexander Duyck49763de2016-01-13 07:31:11 -08009844 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -08009845 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00009846
Alexander Duyck49763de2016-01-13 07:31:11 -08009847 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -04009848 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -07009849 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -04009850 NETIF_F_HW_VLAN_CTAG_RX |
9851 NETIF_F_HW_VLAN_CTAG_TX |
9852 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -08009853 NETIF_F_HW_L2FW_DOFFLOAD;
9854
9855 if (hw->mac.type >= ixgbe_mac_82599EB)
9856 netdev->hw_features |= NETIF_F_NTUPLE |
9857 NETIF_F_HW_TC;
9858
Alexander Duyckb83e3012016-04-14 17:19:31 -04009859 if (pci_using_dac)
9860 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -07009861
Alexander Duyck5eee87c2016-05-11 13:23:34 -07009862 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
9863 netdev->hw_enc_features |= netdev->vlan_features;
9864 netdev->mpls_features |= NETIF_F_HW_CSUM;
9865
Alexander Duyckb83e3012016-04-14 17:19:31 -04009866 /* set this bit last since it cannot be part of vlan_features */
9867 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
9868 NETIF_F_HW_VLAN_CTAG_RX |
9869 NETIF_F_HW_VLAN_CTAG_TX;
9870
Jiri Pirko01789342011-08-16 06:29:00 +00009871 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00009872 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00009873
Jarod Wilson91c527a2016-10-17 15:54:05 -04009874 /* MTU range: 68 - 9710 */
9875 netdev->min_mtu = ETH_MIN_MTU;
9876 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
9877
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08009878#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07009879 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
Stephen Hemminger3f40c742016-11-21 09:52:40 -08009880 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -08009881#endif
9882
Yi Zoueacd73f2009-05-13 13:11:06 +00009883#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00009884 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009885 unsigned int fcoe_l;
9886
Yi Zoueacd73f2009-05-13 13:11:06 +00009887 if (hw->mac.ops.get_device_caps) {
9888 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00009889 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
9890 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00009891 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009892
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009893
9894 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
9895 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009896
Alexander Duycka58915c2012-05-25 06:38:18 +00009897 netdev->features |= NETIF_F_FSO |
9898 NETIF_F_FCOE_CRC;
9899
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009900 netdev->vlan_features |= NETIF_F_FSO |
9901 NETIF_F_FCOE_CRC |
9902 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00009903 }
Yi Zoueacd73f2009-05-13 13:11:06 +00009904#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07009905
Don Skidmore082757a2011-07-21 05:55:00 +00009906 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
9907 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00009908 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00009909 netdev->features |= NETIF_F_LRO;
9910
Auke Kok9a799d72007-09-15 14:07:45 -07009911 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009912 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009913 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009914 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009915 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009916 }
9917
Sowmini Varadhanc7374b52016-01-12 19:32:30 -08009918 eth_platform_get_mac_address(&adapter->pdev->dev,
9919 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +00009920
Auke Kok9a799d72007-09-15 14:07:45 -07009921 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07009922
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00009923 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009924 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009925 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009926 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009927 }
9928
Tushar Dave56768042016-01-07 14:17:03 -08009929 /* Set hw->mac.addr to permanent MAC address */
9930 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07009931 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +00009932
Alexander Duyck70864002011-04-27 09:13:56 +00009933 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00009934 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009935
Mark Rustad58cf6632014-03-12 00:38:40 +00009936 if (ixgbe_removed(hw->hw_addr)) {
9937 err = -EIO;
9938 goto err_sw_init;
9939 }
Alexander Duyck70864002011-04-27 09:13:56 +00009940 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +00009941 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00009942 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009943
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009944 err = ixgbe_init_interrupt_scheme(adapter);
9945 if (err)
9946 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009947
Jacob Keller8e2813f2012-04-21 06:05:40 +00009948 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009949 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009950 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009951 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00009952 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009953 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00009954 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009955
PJ Waskiewicze8e26352009-02-27 15:45:05 +00009956 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
9957
Emil Tantilov15e52092011-09-29 05:01:29 +00009958 /* save off EEPROM version number */
9959 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
9960 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
9961
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009962 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +00009963 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00009964 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -04009965 else
9966 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009967
Jacob Kellere027d1a2013-07-31 06:53:31 +00009968 /* calculate the expected PCIe bandwidth required for optimal
9969 * performance. Note that some older parts will never have enough
9970 * bandwidth due to being older generation PCIe parts. We clamp these
9971 * parts to ensure no warning is displayed if it can't be fixed.
9972 */
9973 switch (hw->mac.type) {
9974 case ixgbe_mac_82598EB:
9975 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
9976 break;
9977 default:
9978 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
9979 break;
Auke Kok0c254d82008-02-11 09:25:56 -08009980 }
Jacob Kellercaafb952014-07-19 07:17:17 +00009981
9982 /* don't check link if we failed to enumerate functions */
9983 if (expected_gts > 0)
9984 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08009985
Mark Rustad339de302014-06-06 01:57:06 +00009986 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009987 if (err)
Mark Rustad339de302014-06-06 01:57:06 +00009988 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009989 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
9990 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
9991 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +00009992 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +00009993 else
9994 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
9995 hw->mac.type, hw->phy.type, part_str);
9996
9997 e_dev_info("%pM\n", netdev->dev_addr);
9998
Auke Kok9a799d72007-09-15 14:07:45 -07009999 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010000 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010001 if (err == IXGBE_ERR_EEPROM_VERSION) {
10002 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +000010003 e_dev_warn("This device is a pre-production adapter/LOM. "
10004 "Please be aware there may be issues associated "
10005 "with your hardware. If you are experiencing "
10006 "problems please contact your Intel or hardware "
10007 "representative who provided you with this "
10008 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010009 }
Auke Kok9a799d72007-09-15 14:07:45 -070010010 strcpy(netdev->name, "eth%d");
10011 err = register_netdev(netdev);
10012 if (err)
10013 goto err_register;
10014
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010015 pci_set_drvdata(pdev, adapter);
10016
Emil Tantilovec74a472012-09-20 03:33:56 +000010017 /* power down the optics for 82599 SFP+ fiber */
10018 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +000010019 hw->mac.ops.disable_tx_laser(hw);
10020
Jesse Brandeburg54386462009-04-17 20:44:27 +000010021 /* carrier off reporting is important to ethtool even BEFORE open */
10022 netif_carrier_off(netdev);
10023
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010024#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +030010025 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010026 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010027 ixgbe_setup_dca(adapter);
10028 }
10029#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010030 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010031 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010032 for (i = 0; i < adapter->num_vfs; i++)
10033 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10034 }
10035
Jacob Keller2466dd92011-09-08 03:50:54 +000010036 /* firmware requires driver version to be 0xFFFFFFFF
10037 * since os does not support feature
10038 */
Emil Tantilov9612de92011-05-07 07:40:20 +000010039 if (hw->mac.ops.set_fw_drv_ver)
Tony Nguyencb8e0512016-10-26 16:25:18 -070010040 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10041 sizeof(ixgbe_driver_version) - 1,
10042 ixgbe_driver_version);
Emil Tantilov9612de92011-05-07 07:40:20 +000010043
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010044 /* add san mac addr to netdev */
10045 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010046
Neerav Parikhea818752012-01-04 20:23:40 +000010047 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010048
Don Skidmore12109822012-05-04 06:07:08 +000010049#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010050 if (ixgbe_sysfs_init(adapter))
10051 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +000010052#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010053
Catherine Sullivan00949162012-08-10 01:59:10 +000010054 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010055
Emil Tantilovd1a35ee2014-05-13 08:24:00 +000010056 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10057 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +000010058 hw->mac.ops.setup_link(hw,
10059 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10060 true);
10061
Auke Kok9a799d72007-09-15 14:07:45 -070010062 return 0;
10063
10064err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010065 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010066 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010067err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +000010068 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +000010069 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -080010070 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010071 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010072 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -070010073err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010074 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010075 free_netdev(netdev);
10076err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010077 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010078err_pci_reg:
10079err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010080 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010081 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010082 return err;
10083}
10084
10085/**
10086 * ixgbe_remove - Device Removal Routine
10087 * @pdev: PCI device information struct
10088 *
10089 * ixgbe_remove is called by the PCI subsystem to alert the driver
10090 * that it should release a PCI device. The could be caused by a
10091 * Hot-Plug event, or because the driver is going to be removed from
10092 * memory.
10093 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010094static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -070010095{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010096 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010097 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010098 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010099 int i;
Auke Kok9a799d72007-09-15 14:07:45 -070010100
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010101 /* if !adapter then we already cleaned up in probe */
10102 if (!adapter)
10103 return;
10104
10105 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +000010106 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010107
Mark Rustad09f40ae2014-01-14 18:53:11 -080010108 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010109 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -070010110
Jacob Keller3a6a4ed2012-05-01 05:24:58 +000010111
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010112#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010113 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10114 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10115 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -070010116 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10117 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010118 }
10119
10120#endif
Don Skidmore12109822012-05-04 06:07:08 +000010121#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010122 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +000010123#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010124
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010125 /* remove the added san mac */
10126 ixgbe_del_sanmac_netdev(netdev);
10127
Greg Roseda36b642012-12-11 08:26:43 +000010128#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -060010129 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +000010130#endif
Alex Williamson6b010e92015-07-29 14:38:21 -060010131 if (netdev->reg_state == NETREG_REGISTERED)
10132 unregister_netdev(netdev);
10133
Alexander Duyck7a921c92009-05-06 10:43:28 +000010134 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010135
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010136 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010137
Alexander Duyck2b1588c2012-03-17 02:39:16 +000010138#ifdef CONFIG_DCB
10139 kfree(adapter->ixgbe_ieee_pfc);
10140 kfree(adapter->ixgbe_ieee_ets);
10141
10142#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -080010143 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010144 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010145
Emil Tantilov849c4542010-06-03 16:53:41 +000010146 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010147
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010148 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
10149 if (adapter->jump_tables[i]) {
10150 kfree(adapter->jump_tables[i]->input);
10151 kfree(adapter->jump_tables[i]->mask);
10152 }
10153 kfree(adapter->jump_tables[i]);
10154 }
10155
Jacob Keller5d7daa32014-03-29 06:51:25 +000010156 kfree(adapter->mac_table);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010157 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010158 free_netdev(netdev);
10159
Frans Pop19d5afd2009-10-02 10:04:12 -070010160 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010161
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010162 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010163 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010164}
10165
10166/**
10167 * ixgbe_io_error_detected - called when PCI error is detected
10168 * @pdev: Pointer to PCI device
10169 * @state: The current pci connection state
10170 *
10171 * This function is called after a PCI bus error affecting
10172 * this device has been detected.
10173 */
10174static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +000010175 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -070010176{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010177 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10178 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010179
Greg Rose83c61fa2011-09-07 05:59:35 +000010180#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -080010181 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +000010182 struct pci_dev *bdev, *vfdev;
10183 u32 dw0, dw1, dw2, dw3;
10184 int vf, pos;
10185 u16 req_id, pf_func;
10186
10187 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
10188 adapter->num_vfs == 0)
10189 goto skip_bad_vf_detection;
10190
10191 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +080010192 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +000010193 bdev = bdev->bus->self;
10194
10195 if (!bdev)
10196 goto skip_bad_vf_detection;
10197
10198 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
10199 if (!pos)
10200 goto skip_bad_vf_detection;
10201
Mark Rustad14438462014-02-28 15:48:57 -080010202 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
10203 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
10204 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
10205 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
10206 if (ixgbe_removed(hw->hw_addr))
10207 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +000010208
10209 req_id = dw1 >> 16;
10210 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10211 if (!(req_id & 0x0080))
10212 goto skip_bad_vf_detection;
10213
10214 pf_func = req_id & 0x01;
10215 if ((pf_func & 1) == (pdev->devfn & 1)) {
10216 unsigned int device_id;
10217
10218 vf = (req_id & 0x7F) >> 1;
10219 e_dev_err("VF %d has caused a PCIe error\n", vf);
10220 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10221 "%8.8x\tdw3: %8.8x\n",
10222 dw0, dw1, dw2, dw3);
10223 switch (adapter->hw.mac.type) {
10224 case ixgbe_mac_82599EB:
10225 device_id = IXGBE_82599_VF_DEVICE_ID;
10226 break;
10227 case ixgbe_mac_X540:
10228 device_id = IXGBE_X540_VF_DEVICE_ID;
10229 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010230 case ixgbe_mac_X550:
10231 device_id = IXGBE_DEV_ID_X550_VF;
10232 break;
10233 case ixgbe_mac_X550EM_x:
10234 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10235 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010236 case ixgbe_mac_x550em_a:
10237 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10238 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010239 default:
10240 device_id = 0;
10241 break;
10242 }
10243
10244 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010245 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010246 while (vfdev) {
10247 if (vfdev->devfn == (req_id & 0xFF))
10248 break;
Jon Mason36e90312012-07-19 21:02:09 +000010249 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010250 device_id, vfdev);
10251 }
10252 /*
10253 * There's a slim chance the VF could have been hot plugged,
10254 * so if it is no longer present we don't need to issue the
10255 * VFLR. Just clean up the AER in that case.
10256 */
10257 if (vfdev) {
Emil Tantilov9079e412014-11-19 03:18:19 +000010258 ixgbe_issue_vf_flr(adapter, vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010259 /* Free device reference count */
10260 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010261 }
10262
10263 pci_cleanup_aer_uncorrect_error_status(pdev);
10264 }
10265
10266 /*
10267 * Even though the error may have occurred on the other port
10268 * we still need to increment the vf error reference count for
10269 * both ports because the I/O resume function will be called
10270 * for both of them.
10271 */
10272 adapter->vferr_refcount++;
10273
10274 return PCI_ERS_RESULT_RECOVERED;
10275
10276skip_bad_vf_detection:
10277#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010278 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10279 return PCI_ERS_RESULT_DISCONNECT;
10280
Mark Rustad41c62842014-03-12 00:38:35 +000010281 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010282 netif_device_detach(netdev);
10283
Mark Rustad41c62842014-03-12 00:38:35 +000010284 if (state == pci_channel_io_perm_failure) {
10285 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010286 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010287 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010288
Auke Kok9a799d72007-09-15 14:07:45 -070010289 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010290 ixgbe_close_suspend(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +000010291
10292 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10293 pci_disable_device(pdev);
10294 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010295
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010296 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010297 return PCI_ERS_RESULT_NEED_RESET;
10298}
10299
10300/**
10301 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10302 * @pdev: Pointer to PCI device
10303 *
10304 * Restart the card from scratch, as if from a cold-boot.
10305 */
10306static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10307{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010308 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010309 pci_ers_result_t result;
10310 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010311
gouji-new9ce77662009-05-06 10:44:45 +000010312 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010313 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010314 result = PCI_ERS_RESULT_DISCONNECT;
10315 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010316 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010317 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010318 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010319 pci_set_master(pdev);
10320 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010321 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010322
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010323 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010324
10325 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010326 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010327 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010328 }
Auke Kok9a799d72007-09-15 14:07:45 -070010329
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010330 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10331 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010332 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10333 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010334 /* non-fatal, continue */
10335 }
Auke Kok9a799d72007-09-15 14:07:45 -070010336
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010337 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010338}
10339
10340/**
10341 * ixgbe_io_resume - called when traffic can start flowing again.
10342 * @pdev: Pointer to PCI device
10343 *
10344 * This callback is called when the error recovery driver tells us that
10345 * its OK to resume normal operation.
10346 */
10347static void ixgbe_io_resume(struct pci_dev *pdev)
10348{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010349 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10350 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010351
Greg Rose83c61fa2011-09-07 05:59:35 +000010352#ifdef CONFIG_PCI_IOV
10353 if (adapter->vferr_refcount) {
10354 e_info(drv, "Resuming after VF err\n");
10355 adapter->vferr_refcount--;
10356 return;
10357 }
10358
10359#endif
Emil Tantilov126db132016-11-16 09:48:02 -080010360 rtnl_lock();
Alexander Duyckc7ccde02011-07-21 00:40:40 +000010361 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010362 ixgbe_open(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010363
10364 netif_device_attach(netdev);
Emil Tantilov126db132016-11-16 09:48:02 -080010365 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010366}
10367
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070010368static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070010369 .error_detected = ixgbe_io_error_detected,
10370 .slot_reset = ixgbe_io_slot_reset,
10371 .resume = ixgbe_io_resume,
10372};
10373
10374static struct pci_driver ixgbe_driver = {
10375 .name = ixgbe_driver_name,
10376 .id_table = ixgbe_pci_tbl,
10377 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010378 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070010379#ifdef CONFIG_PM
10380 .suspend = ixgbe_suspend,
10381 .resume = ixgbe_resume,
10382#endif
10383 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000010384 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070010385 .err_handler = &ixgbe_err_handler
10386};
10387
10388/**
10389 * ixgbe_init_module - Driver Registration Routine
10390 *
10391 * ixgbe_init_module is the first routine called when the driver is
10392 * loaded. All it does is register with the PCI subsystem.
10393 **/
10394static int __init ixgbe_init_module(void)
10395{
10396 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000010397 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000010398 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070010399
Mark Rustad780484d2015-10-21 17:21:10 -070010400 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
10401 if (!ixgbe_wq) {
10402 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
10403 return -ENOMEM;
10404 }
10405
Catherine Sullivan00949162012-08-10 01:59:10 +000010406 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000010407
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010408 ret = pci_register_driver(&ixgbe_driver);
10409 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000010410 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010411 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010412 return ret;
10413 }
10414
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010415#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010416 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010417#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010418
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010419 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070010420}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010421
Auke Kok9a799d72007-09-15 14:07:45 -070010422module_init(ixgbe_init_module);
10423
10424/**
10425 * ixgbe_exit_module - Driver Exit Cleanup Routine
10426 *
10427 * ixgbe_exit_module is called just before the driver is removed
10428 * from memory.
10429 **/
10430static void __exit ixgbe_exit_module(void)
10431{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010432#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010433 dca_unregister_notify(&dca_notifier);
10434#endif
Auke Kok9a799d72007-09-15 14:07:45 -070010435 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000010436
Catherine Sullivan00949162012-08-10 01:59:10 +000010437 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070010438 if (ixgbe_wq) {
10439 destroy_workqueue(ixgbe_wq);
10440 ixgbe_wq = NULL;
10441 }
Auke Kok9a799d72007-09-15 14:07:45 -070010442}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010443
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010444#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010445static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010446 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010447{
10448 int ret_val;
10449
10450 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010451 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010452
10453 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
10454}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010455
Alexander Duyckb4533682009-03-31 21:32:42 +000010456#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000010457
Auke Kok9a799d72007-09-15 14:07:45 -070010458module_exit(ixgbe_exit_module);
10459
10460/* ixgbe_main.c */