blob: 848dea922b2ac0e2a5c78d077edbc791ad445e21 [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},
134 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
Don Skidmorededa5622015-06-09 17:39:46 -0700135 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
Mark Rustad018d7142015-08-08 16:19:19 -0700136 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
Mark Rustadf572b2c2016-04-01 12:18:46 -0700137 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
138 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
Mark Rustad49425df2016-04-01 12:18:09 -0700139 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
Mark Rustad200157c2016-04-01 12:18:40 -0700140 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
141 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
Don Skidmore92ed8432016-08-17 20:34:40 -0400142 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
Mark Rustad2d40cd12016-04-01 12:18:35 -0700143 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800144 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw },
145 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw },
Auke Kok9a799d72007-09-15 14:07:45 -0700146 /* required last entry */
147 {0, }
148};
149MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
150
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400151#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800152static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000153 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800154static struct notifier_block dca_notifier = {
155 .notifier_call = ixgbe_notify_dca,
156 .next = NULL,
157 .priority = 0
158};
159#endif
160
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000161#ifdef CONFIG_PCI_IOV
162static unsigned int max_vfs;
163module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000164MODULE_PARM_DESC(max_vfs,
Jacob Keller170e8542013-11-09 04:52:32 -0800165 "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 +0000166#endif /* CONFIG_PCI_IOV */
167
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000168static unsigned int allow_unsupported_sfp;
169module_param(allow_unsupported_sfp, uint, 0);
170MODULE_PARM_DESC(allow_unsupported_sfp,
171 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
172
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000173#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
174static int debug = -1;
175module_param(debug, int, 0);
176MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
177
Auke Kok9a799d72007-09-15 14:07:45 -0700178MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
179MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
180MODULE_LICENSE("GPL");
181MODULE_VERSION(DRV_VERSION);
182
Mark Rustad780484d2015-10-21 17:21:10 -0700183static struct workqueue_struct *ixgbe_wq;
184
Mark Rustad14438462014-02-28 15:48:57 -0800185static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800186static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
Mark Rustad14438462014-02-28 15:48:57 -0800187
Jacob Kellerb8e82002013-04-09 07:20:09 +0000188static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
189 u32 reg, u16 *value)
190{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000191 struct pci_dev *parent_dev;
192 struct pci_bus *parent_bus;
193
194 parent_bus = adapter->pdev->bus->parent;
195 if (!parent_bus)
196 return -1;
197
198 parent_dev = parent_bus->self;
199 if (!parent_dev)
200 return -1;
201
Yijing Wangc0798ed2013-09-04 17:30:08 +0000202 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000203 return -1;
204
Yijing Wangc0798ed2013-09-04 17:30:08 +0000205 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800206 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
207 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
208 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000209 return 0;
210}
211
212static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
213{
214 struct ixgbe_hw *hw = &adapter->hw;
215 u16 link_status = 0;
216 int err;
217
218 hw->bus.type = ixgbe_bus_type_pci_express;
219
220 /* Get the negotiated link width and speed from PCI config space of the
221 * parent, as this device is behind a switch
222 */
223 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
224
225 /* assume caller will handle error case */
226 if (err)
227 return err;
228
229 hw->bus.width = ixgbe_convert_bus_width(link_status);
230 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
231
232 return 0;
233}
234
Jacob Kellere027d1a2013-07-31 06:53:31 +0000235/**
236 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
237 * @hw: hw specific details
238 *
239 * This function is used by probe to determine whether a device's PCI-Express
240 * bandwidth details should be gathered from the parent bus instead of from the
241 * device. Used to ensure that various locations all have the correct device ID
242 * checks.
243 */
244static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
245{
246 switch (hw->device_id) {
247 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000248 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000249 return true;
250 default:
251 return false;
252 }
253}
254
255static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
256 int expected_gts)
257{
Don Skidmoref9328bc2015-06-18 13:24:06 -0400258 struct ixgbe_hw *hw = &adapter->hw;
Jacob Kellere027d1a2013-07-31 06:53:31 +0000259 int max_gts = 0;
260 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
261 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
262 struct pci_dev *pdev;
263
Don Skidmoref9328bc2015-06-18 13:24:06 -0400264 /* Some devices are not connected over PCIe and thus do not negotiate
265 * speed. These devices do not have valid bus info, and thus any report
266 * we generate may not be correct.
267 */
268 if (hw->bus.type == ixgbe_bus_type_internal)
269 return;
270
Jacob Keller56d13922015-06-10 11:44:45 -0700271 /* determine whether to use the parent device */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000272 if (ixgbe_pcie_from_parent(&adapter->hw))
273 pdev = adapter->pdev->bus->parent->self;
274 else
275 pdev = adapter->pdev;
276
277 if (pcie_get_minimum_link(pdev, &speed, &width) ||
278 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
279 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
280 return;
281 }
282
283 switch (speed) {
284 case PCIE_SPEED_2_5GT:
285 /* 8b/10b encoding reduces max throughput by 20% */
286 max_gts = 2 * width;
287 break;
288 case PCIE_SPEED_5_0GT:
289 /* 8b/10b encoding reduces max throughput by 20% */
290 max_gts = 4 * width;
291 break;
292 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000293 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000294 max_gts = 8 * width;
295 break;
296 default:
297 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
298 return;
299 }
300
301 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
302 max_gts);
303 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
304 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
305 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
306 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
307 "Unknown"),
308 width,
309 (speed == PCIE_SPEED_2_5GT ? "20%" :
310 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000311 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000312 "Unknown"));
313
314 if (max_gts < expected_gts) {
315 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
316 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
317 expected_gts);
318 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
319 }
320}
321
Alexander Duyck70864002011-04-27 09:13:56 +0000322static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
323{
324 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800325 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000326 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
Mark Rustad780484d2015-10-21 17:21:10 -0700327 queue_work(ixgbe_wq, &adapter->service_task);
Alexander Duyck70864002011-04-27 09:13:56 +0000328}
329
Mark Rustad2a1a0912014-01-14 18:53:15 -0800330static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
331{
332 struct ixgbe_adapter *adapter = hw->back;
333
334 if (!hw->hw_addr)
335 return;
336 hw->hw_addr = NULL;
337 e_dev_err("Adapter removed\n");
Mark Rustad58cf6632014-03-12 00:38:40 +0000338 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
339 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800340}
341
Mark Rustadf8e24722014-03-18 07:03:40 +0000342static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800343{
344 u32 value;
345
346 /* The following check not only optimizes a bit by not
347 * performing a read on the status register when the
348 * register just read was a status register read that
349 * returned IXGBE_FAILED_READ_REG. It also blocks any
350 * potential recursion.
351 */
352 if (reg == IXGBE_STATUS) {
353 ixgbe_remove_adapter(hw);
354 return;
355 }
356 value = ixgbe_read_reg(hw, IXGBE_STATUS);
357 if (value == IXGBE_FAILED_READ_REG)
358 ixgbe_remove_adapter(hw);
359}
360
Mark Rustadf8e24722014-03-18 07:03:40 +0000361/**
362 * ixgbe_read_reg - Read from device register
363 * @hw: hw specific details
364 * @reg: offset of register to read
365 *
366 * Returns : value read or IXGBE_FAILED_READ_REG if removed
367 *
368 * This function is used to read device registers. It checks for device
369 * removal by confirming any read that returns all ones by checking the
370 * status register value for all ones. This function avoids reading from
371 * the hardware if a removal was previously detected in which case it
372 * returns IXGBE_FAILED_READ_REG (all ones).
373 */
374u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
375{
376 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
377 u32 value;
378
379 if (ixgbe_removed(reg_addr))
380 return IXGBE_FAILED_READ_REG;
Mark Rustad2f2219b2016-04-07 10:43:50 -0700381 if (unlikely(hw->phy.nw_mng_if_sel &
382 IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) {
383 struct ixgbe_adapter *adapter;
384 int i;
385
386 for (i = 0; i < 200; ++i) {
387 value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
388 if (likely(!value))
389 goto writes_completed;
390 if (value == IXGBE_FAILED_READ_REG) {
391 ixgbe_remove_adapter(hw);
392 return IXGBE_FAILED_READ_REG;
393 }
394 udelay(5);
395 }
396
397 adapter = hw->back;
398 e_warn(hw, "register writes incomplete %08x\n", value);
399 }
400
401writes_completed:
Mark Rustadf8e24722014-03-18 07:03:40 +0000402 value = readl(reg_addr + reg);
403 if (unlikely(value == IXGBE_FAILED_READ_REG))
404 ixgbe_check_remove(hw, reg);
405 return value;
406}
407
Mark Rustad14438462014-02-28 15:48:57 -0800408static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
409{
410 u16 value;
411
412 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
413 if (value == IXGBE_FAILED_READ_CFG_WORD) {
414 ixgbe_remove_adapter(hw);
415 return true;
416 }
417 return false;
418}
419
420u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
421{
422 struct ixgbe_adapter *adapter = hw->back;
423 u16 value;
424
425 if (ixgbe_removed(hw->hw_addr))
426 return IXGBE_FAILED_READ_CFG_WORD;
427 pci_read_config_word(adapter->pdev, reg, &value);
428 if (value == IXGBE_FAILED_READ_CFG_WORD &&
429 ixgbe_check_cfg_remove(hw, adapter->pdev))
430 return IXGBE_FAILED_READ_CFG_WORD;
431 return value;
432}
433
434#ifdef CONFIG_PCI_IOV
435static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
436{
437 struct ixgbe_adapter *adapter = hw->back;
438 u32 value;
439
440 if (ixgbe_removed(hw->hw_addr))
441 return IXGBE_FAILED_READ_CFG_DWORD;
442 pci_read_config_dword(adapter->pdev, reg, &value);
443 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
444 ixgbe_check_cfg_remove(hw, adapter->pdev))
445 return IXGBE_FAILED_READ_CFG_DWORD;
446 return value;
447}
448#endif /* CONFIG_PCI_IOV */
449
Jacob Kellered192312014-02-22 01:23:53 +0000450void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
451{
452 struct ixgbe_adapter *adapter = hw->back;
453
454 if (ixgbe_removed(hw->hw_addr))
455 return;
456 pci_write_config_word(adapter->pdev, reg, value);
457}
458
Alexander Duyck70864002011-04-27 09:13:56 +0000459static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
460{
461 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
462
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000463 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100464 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000465 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
466}
467
Taku Izumidcd79ae2010-04-27 14:39:53 +0000468struct ixgbe_reg_info {
469 u32 ofs;
470 char *name;
471};
472
473static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
474
475 /* General Registers */
476 {IXGBE_CTRL, "CTRL"},
477 {IXGBE_STATUS, "STATUS"},
478 {IXGBE_CTRL_EXT, "CTRL_EXT"},
479
480 /* Interrupt Registers */
481 {IXGBE_EICR, "EICR"},
482
483 /* RX Registers */
484 {IXGBE_SRRCTL(0), "SRRCTL"},
485 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
486 {IXGBE_RDLEN(0), "RDLEN"},
487 {IXGBE_RDH(0), "RDH"},
488 {IXGBE_RDT(0), "RDT"},
489 {IXGBE_RXDCTL(0), "RXDCTL"},
490 {IXGBE_RDBAL(0), "RDBAL"},
491 {IXGBE_RDBAH(0), "RDBAH"},
492
493 /* TX Registers */
494 {IXGBE_TDBAL(0), "TDBAL"},
495 {IXGBE_TDBAH(0), "TDBAH"},
496 {IXGBE_TDLEN(0), "TDLEN"},
497 {IXGBE_TDH(0), "TDH"},
498 {IXGBE_TDT(0), "TDT"},
499 {IXGBE_TXDCTL(0), "TXDCTL"},
500
501 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000502 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000503};
504
505
506/*
507 * ixgbe_regdump - register printout routine
508 */
509static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
510{
Joe Perches332f2352017-01-03 07:28:11 -0800511 int i;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000512 char rname[16];
513 u32 regs[64];
514
515 switch (reginfo->ofs) {
516 case IXGBE_SRRCTL(0):
517 for (i = 0; i < 64; i++)
518 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
519 break;
520 case IXGBE_DCA_RXCTRL(0):
521 for (i = 0; i < 64; i++)
522 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
523 break;
524 case IXGBE_RDLEN(0):
525 for (i = 0; i < 64; i++)
526 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
527 break;
528 case IXGBE_RDH(0):
529 for (i = 0; i < 64; i++)
530 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
531 break;
532 case IXGBE_RDT(0):
533 for (i = 0; i < 64; i++)
534 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
535 break;
536 case IXGBE_RXDCTL(0):
537 for (i = 0; i < 64; i++)
538 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
539 break;
540 case IXGBE_RDBAL(0):
541 for (i = 0; i < 64; i++)
542 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
543 break;
544 case IXGBE_RDBAH(0):
545 for (i = 0; i < 64; i++)
546 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
547 break;
548 case IXGBE_TDBAL(0):
549 for (i = 0; i < 64; i++)
550 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
551 break;
552 case IXGBE_TDBAH(0):
553 for (i = 0; i < 64; i++)
554 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
555 break;
556 case IXGBE_TDLEN(0):
557 for (i = 0; i < 64; i++)
558 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
559 break;
560 case IXGBE_TDH(0):
561 for (i = 0; i < 64; i++)
562 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
563 break;
564 case IXGBE_TDT(0):
565 for (i = 0; i < 64; i++)
566 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
567 break;
568 case IXGBE_TXDCTL(0):
569 for (i = 0; i < 64; i++)
570 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
571 break;
572 default:
Joe Perches332f2352017-01-03 07:28:11 -0800573 pr_info("%-15s %08x\n",
574 reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000575 return;
576 }
577
Joe Perches332f2352017-01-03 07:28:11 -0800578 i = 0;
579 while (i < 64) {
580 int j;
581 char buf[9 * 8 + 1];
582 char *p = buf;
583
584 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000585 for (j = 0; j < 8; j++)
Joe Perches332f2352017-01-03 07:28:11 -0800586 p += sprintf(p, " %08x", regs[i++]);
587 pr_err("%-15s%s\n", rname, buf);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000588 }
589
590}
591
592/*
593 * ixgbe_dump - Print registers, tx-rings and rx-rings
594 */
595static void ixgbe_dump(struct ixgbe_adapter *adapter)
596{
597 struct net_device *netdev = adapter->netdev;
598 struct ixgbe_hw *hw = &adapter->hw;
599 struct ixgbe_reg_info *reginfo;
600 int n = 0;
601 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000602 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000603 union ixgbe_adv_tx_desc *tx_desc;
604 struct my_u0 { u64 a; u64 b; } *u0;
605 struct ixgbe_ring *rx_ring;
606 union ixgbe_adv_rx_desc *rx_desc;
607 struct ixgbe_rx_buffer *rx_buffer_info;
608 u32 staterr;
609 int i = 0;
610
611 if (!netif_msg_hw(adapter))
612 return;
613
614 /* Print netdevice Info */
615 if (netdev) {
616 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000617 pr_info("Device Name state "
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100618 "trans_start\n");
619 pr_info("%-15s %016lX %016lX\n",
Joe Perchesc7689572010-09-07 21:35:17 +0000620 netdev->name,
621 netdev->state,
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100622 dev_trans_start(netdev));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000623 }
624
625 /* Print Registers */
626 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000627 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000628 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
629 reginfo->name; reginfo++) {
630 ixgbe_regdump(hw, reginfo);
631 }
632
633 /* Print TX Ring Summary */
634 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000635 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000636
637 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000638 pr_info(" %s %s %s %s\n",
639 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
640 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000641 for (n = 0; n < adapter->num_tx_queues; n++) {
642 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000643 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000644 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000645 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000646 (u64)dma_unmap_addr(tx_buffer, dma),
647 dma_unmap_len(tx_buffer, len),
648 tx_buffer->next_to_watch,
649 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000650 }
651
652 /* Print TX Rings */
653 if (!netif_msg_tx_done(adapter))
654 goto rx_ring_summary;
655
656 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
657
658 /* Transmit Descriptor Formats
659 *
Josh Hay39ac8682012-09-26 05:59:36 +0000660 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000661 * +--------------------------------------------------------------+
662 * 0 | Buffer Address [63:0] |
663 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000664 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000665 * +--------------------------------------------------------------+
666 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000667 *
668 * 82598 Advanced Transmit Descriptor (Write-Back Format)
669 * +--------------------------------------------------------------+
670 * 0 | RSV [63:0] |
671 * +--------------------------------------------------------------+
672 * 8 | RSV | STA | NXTSEQ |
673 * +--------------------------------------------------------------+
674 * 63 36 35 32 31 0
675 *
676 * 82599+ Advanced Transmit Descriptor
677 * +--------------------------------------------------------------+
678 * 0 | Buffer Address [63:0] |
679 * +--------------------------------------------------------------+
680 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
681 * +--------------------------------------------------------------+
682 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
683 *
684 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
685 * +--------------------------------------------------------------+
686 * 0 | RSV [63:0] |
687 * +--------------------------------------------------------------+
688 * 8 | RSV | STA | RSV |
689 * +--------------------------------------------------------------+
690 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000691 */
692
693 for (n = 0; n < adapter->num_tx_queues; n++) {
694 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000695 pr_info("------------------------------------\n");
696 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
697 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000698 pr_info("%s%s %s %s %s %s\n",
699 "T [desc] [address 63:0 ] ",
700 "[PlPOIdStDDt Ln] [bi->dma ] ",
701 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000702
703 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000704 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000705 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000706 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000707 if (dma_unmap_len(tx_buffer, len) > 0) {
Joe Perches332f2352017-01-03 07:28:11 -0800708 const char *ring_desc;
709
710 if (i == tx_ring->next_to_use &&
711 i == tx_ring->next_to_clean)
712 ring_desc = " NTC/U";
713 else if (i == tx_ring->next_to_use)
714 ring_desc = " NTU";
715 else if (i == tx_ring->next_to_clean)
716 ring_desc = " NTC";
717 else
718 ring_desc = "";
719 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
Josh Hay8ad88e32012-09-26 05:59:41 +0000720 i,
721 le64_to_cpu(u0->a),
722 le64_to_cpu(u0->b),
723 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000724 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000725 tx_buffer->next_to_watch,
726 (u64)tx_buffer->time_stamp,
Joe Perches332f2352017-01-03 07:28:11 -0800727 tx_buffer->skb,
728 ring_desc);
Josh Hay8ad88e32012-09-26 05:59:41 +0000729
730 if (netif_msg_pktdata(adapter) &&
731 tx_buffer->skb)
732 print_hex_dump(KERN_INFO, "",
733 DUMP_PREFIX_ADDRESS, 16, 1,
734 tx_buffer->skb->data,
735 dma_unmap_len(tx_buffer, len),
736 true);
737 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000738 }
739 }
740
741 /* Print RX Rings Summary */
742rx_ring_summary:
743 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000744 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000745 for (n = 0; n < adapter->num_rx_queues; n++) {
746 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000747 pr_info("%5d %5X %5X\n",
748 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000749 }
750
751 /* Print RX Rings */
752 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000753 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000754
755 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
756
Josh Hay39ac8682012-09-26 05:59:36 +0000757 /* Receive Descriptor Formats
758 *
759 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000760 * 63 1 0
761 * +-----------------------------------------------------+
762 * 0 | Packet Buffer Address [63:1] |A0/NSE|
763 * +----------------------------------------------+------+
764 * 8 | Header Buffer Address [63:1] | DD |
765 * +-----------------------------------------------------+
766 *
767 *
Josh Hay39ac8682012-09-26 05:59:36 +0000768 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000769 *
770 * 63 48 47 32 31 30 21 20 16 15 4 3 0
771 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000772 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
773 * | Packet | IP | | | | Type | Type |
774 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000775 * +------------------------------------------------------+
776 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
777 * +------------------------------------------------------+
778 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000779 *
780 * 82599+ Advanced Receive Descriptor (Read) Format
781 * 63 1 0
782 * +-----------------------------------------------------+
783 * 0 | Packet Buffer Address [63:1] |A0/NSE|
784 * +----------------------------------------------+------+
785 * 8 | Header Buffer Address [63:1] | DD |
786 * +-----------------------------------------------------+
787 *
788 *
789 * 82599+ Advanced Receive Descriptor (Write-Back) Format
790 *
791 * 63 48 47 32 31 30 21 20 17 16 4 3 0
792 * +------------------------------------------------------+
793 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
794 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
795 * |/ Flow Dir Flt ID | | | | | |
796 * +------------------------------------------------------+
797 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
798 * +------------------------------------------------------+
799 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000800 */
Josh Hay39ac8682012-09-26 05:59:36 +0000801
Taku Izumidcd79ae2010-04-27 14:39:53 +0000802 for (n = 0; n < adapter->num_rx_queues; n++) {
803 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000804 pr_info("------------------------------------\n");
805 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
806 pr_info("------------------------------------\n");
Joe Perches332f2352017-01-03 07:28:11 -0800807 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000808 "R [desc] [ PktBuf A0] ",
809 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800810 "<-- Adv Rx Read format");
811 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000812 "RWB[desc] [PcsmIpSHl PtRs] ",
813 "[vl er S cks ln] ---------------- [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800814 "<-- Adv Rx Write-Back format");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000815
816 for (i = 0; i < rx_ring->count; i++) {
Joe Perches332f2352017-01-03 07:28:11 -0800817 const char *ring_desc;
818
819 if (i == rx_ring->next_to_use)
820 ring_desc = " NTU";
821 else if (i == rx_ring->next_to_clean)
822 ring_desc = " NTC";
823 else
824 ring_desc = "";
825
Taku Izumidcd79ae2010-04-27 14:39:53 +0000826 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000827 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000828 u0 = (struct my_u0 *)rx_desc;
829 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
830 if (staterr & IXGBE_RXD_STAT_DD) {
831 /* Descriptor Done */
Joe Perches332f2352017-01-03 07:28:11 -0800832 pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
833 i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000834 le64_to_cpu(u0->a),
835 le64_to_cpu(u0->b),
Joe Perches332f2352017-01-03 07:28:11 -0800836 rx_buffer_info->skb,
837 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000838 } else {
Joe Perches332f2352017-01-03 07:28:11 -0800839 pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
840 i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000841 le64_to_cpu(u0->a),
842 le64_to_cpu(u0->b),
843 (u64)rx_buffer_info->dma,
Joe Perches332f2352017-01-03 07:28:11 -0800844 rx_buffer_info->skb,
845 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000846
Emil Tantilov9c50c032012-07-26 01:21:24 +0000847 if (netif_msg_pktdata(adapter) &&
848 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000849 print_hex_dump(KERN_INFO, "",
850 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000851 page_address(rx_buffer_info->page) +
852 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000853 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000854 }
855 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000856 }
857 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000858}
859
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800860static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
861{
862 u32 ctrl_ext;
863
864 /* Let firmware take over control of h/w */
865 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
866 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000867 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800868}
869
870static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
871{
872 u32 ctrl_ext;
873
874 /* Let firmware know the driver has taken over */
875 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
876 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000877 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800878}
Auke Kok9a799d72007-09-15 14:07:45 -0700879
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000880/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000881 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
882 * @adapter: pointer to adapter struct
883 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
884 * @queue: queue to map the corresponding interrupt to
885 * @msix_vector: the vector to map to the corresponding queue
886 *
887 */
888static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000889 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700890{
891 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000892 struct ixgbe_hw *hw = &adapter->hw;
893 switch (hw->mac.type) {
894 case ixgbe_mac_82598EB:
895 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
896 if (direction == -1)
897 direction = 0;
898 index = (((direction * 64) + queue) >> 2) & 0x1F;
899 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
900 ivar &= ~(0xFF << (8 * (queue & 0x3)));
901 ivar |= (msix_vector << (8 * (queue & 0x3)));
902 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
903 break;
904 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800905 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000906 case ixgbe_mac_X550:
907 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700908 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000909 if (direction == -1) {
910 /* other causes */
911 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
912 index = ((queue & 1) * 8);
913 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
914 ivar &= ~(0xFF << index);
915 ivar |= (msix_vector << index);
916 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
917 break;
918 } else {
919 /* tx or rx causes */
920 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
921 index = ((16 * (queue & 1)) + (8 * direction));
922 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
923 ivar &= ~(0xFF << index);
924 ivar |= (msix_vector << index);
925 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
926 break;
927 }
928 default:
929 break;
930 }
Auke Kok9a799d72007-09-15 14:07:45 -0700931}
932
Alexander Duyckfe49f042009-06-04 16:00:09 +0000933static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000934 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000935{
936 u32 mask;
937
Alexander Duyckbd508172010-11-16 19:27:03 -0800938 switch (adapter->hw.mac.type) {
939 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000940 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
941 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800942 break;
943 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800944 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000945 case ixgbe_mac_X550:
946 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700947 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000948 mask = (qmask & 0xFFFFFFFF);
949 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
950 mask = (qmask >> 32);
951 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800952 break;
953 default:
954 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000955 }
956}
957
Alexander Duyck943561d2012-05-09 22:14:44 -0700958static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
959{
960 struct ixgbe_hw *hw = &adapter->hw;
961 struct ixgbe_hw_stats *hwstats = &adapter->stats;
962 int i;
963 u32 data;
964
965 if ((hw->fc.current_mode != ixgbe_fc_full) &&
966 (hw->fc.current_mode != ixgbe_fc_rx_pause))
967 return;
968
969 switch (hw->mac.type) {
970 case ixgbe_mac_82598EB:
971 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
972 break;
973 default:
974 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
975 }
976 hwstats->lxoffrxc += data;
977
978 /* refill credits (no tx hang) if we received xoff */
979 if (!data)
980 return;
981
982 for (i = 0; i < adapter->num_tx_queues; i++)
983 clear_bit(__IXGBE_HANG_CHECK_ARMED,
984 &adapter->tx_ring[i]->state);
985}
986
John Fastabendc84d3242010-11-16 19:27:12 -0800987static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700988{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700989 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800990 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800991 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000992 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800993 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700994 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700995
Alexander Duyck943561d2012-05-09 22:14:44 -0700996 if (adapter->ixgbe_ieee_pfc)
997 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800998
Alexander Duyck943561d2012-05-09 22:14:44 -0700999 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
1000 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -08001001 return;
Alexander Duyck943561d2012-05-09 22:14:44 -07001002 }
John Fastabendc84d3242010-11-16 19:27:12 -08001003
1004 /* update stats for each tc, only valid with PFC enabled */
1005 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001006 u32 pxoffrxc;
1007
John Fastabendc84d3242010-11-16 19:27:12 -08001008 switch (hw->mac.type) {
1009 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001010 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001011 break;
1012 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001013 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001014 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001015 hwstats->pxoffrxc[i] += pxoffrxc;
1016 /* Get the TC for given UP */
1017 tc = netdev_get_prio_tc_map(adapter->netdev, i);
1018 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -07001019 }
1020
John Fastabendc84d3242010-11-16 19:27:12 -08001021 /* disarm tx queues that have received xoff frames */
1022 for (i = 0; i < adapter->num_tx_queues; i++) {
1023 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -08001024
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001025 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001026 if (xoff[tc])
1027 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1028 }
1029}
1030
1031static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1032{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001033 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001034}
1035
1036static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1037{
John Fastabend2a47fa42013-11-06 09:54:52 -08001038 struct ixgbe_adapter *adapter;
1039 struct ixgbe_hw *hw;
1040 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001041
John Fastabend2a47fa42013-11-06 09:54:52 -08001042 if (ring->l2_accel_priv)
1043 adapter = ring->l2_accel_priv->real_adapter;
1044 else
1045 adapter = netdev_priv(ring->netdev);
1046
1047 hw = &adapter->hw;
1048 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1049 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001050
1051 if (head != tail)
1052 return (head < tail) ?
1053 tail - head : (tail + ring->count - head);
1054
1055 return 0;
1056}
1057
1058static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1059{
1060 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1061 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1062 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001063
1064 clear_check_for_tx_hang(tx_ring);
1065
1066 /*
1067 * Check for a hung queue, but be thorough. This verifies
1068 * that a transmit has been completed since the previous
1069 * check AND there is at least one packet pending. The
1070 * ARMED bit is set to indicate a potential hang. The
1071 * bit is cleared if a pause frame is received to remove
1072 * false hang detection due to PFC or 802.3x frames. By
1073 * requiring this to fail twice we avoid races with
1074 * pfc clearing the ARMED bit and conditions where we
1075 * run the check_tx_hang logic with a transmit completion
1076 * pending but without time to complete it yet.
1077 */
Mark Rustade90dd262014-07-22 06:51:08 +00001078 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001079 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001080 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1081 &tx_ring->state);
1082 /* update completed stats and continue */
1083 tx_ring->tx_stats.tx_done_old = tx_done;
1084 /* reset the countdown */
1085 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001086
Mark Rustade90dd262014-07-22 06:51:08 +00001087 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001088}
1089
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001090/**
1091 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1092 * @adapter: driver private struct
1093 **/
1094static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1095{
1096
1097 /* Do the reset outside of interrupt context */
1098 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
Emil Tantilov57ca2a42016-07-29 14:46:31 -07001099 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Jacob Keller12ff3f32012-12-01 07:57:17 +00001100 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001101 ixgbe_service_event_schedule(adapter);
1102 }
1103}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001104
Auke Kok9a799d72007-09-15 14:07:45 -07001105/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001106 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1107 **/
1108static int ixgbe_tx_maxrate(struct net_device *netdev,
1109 int queue_index, u32 maxrate)
1110{
1111 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1112 struct ixgbe_hw *hw = &adapter->hw;
1113 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1114
1115 if (!maxrate)
1116 return 0;
1117
1118 /* Calculate the rate factor values to set */
1119 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1120 bcnrc_val /= maxrate;
1121
1122 /* clear everything but the rate factor */
1123 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1124 IXGBE_RTTBCNRC_RF_DEC_MASK;
1125
1126 /* enable the rate scheduler */
1127 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1128
1129 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1130 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1131
1132 return 0;
1133}
1134
1135/**
Auke Kok9a799d72007-09-15 14:07:45 -07001136 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001137 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001138 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001139 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001140 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001141static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001142 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001143{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001144 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001145 struct ixgbe_tx_buffer *tx_buffer;
1146 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001147 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001148 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001149 unsigned int i = tx_ring->next_to_clean;
1150
1151 if (test_bit(__IXGBE_DOWN, &adapter->state))
1152 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001153
Alexander Duyckd3d00232011-07-15 02:31:25 +00001154 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001155 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001156 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001157
Alexander Duyck729739b2012-02-08 07:51:06 +00001158 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001159 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001160
Alexander Duyckd3d00232011-07-15 02:31:25 +00001161 /* if next_to_watch is not set then there is no work pending */
1162 if (!eop_desc)
1163 break;
1164
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001165 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001166 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001167
Alexander Duyckd3d00232011-07-15 02:31:25 +00001168 /* if DD is not set pending work has not been completed */
1169 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1170 break;
1171
Alexander Duyckd3d00232011-07-15 02:31:25 +00001172 /* clear next_to_watch to prevent false hangs */
1173 tx_buffer->next_to_watch = NULL;
1174
Alexander Duyck091a6242012-02-08 07:51:01 +00001175 /* update the statistics for this packet */
1176 total_bytes += tx_buffer->bytecount;
1177 total_packets += tx_buffer->gso_segs;
1178
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001179 /* free the skb */
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001180 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001181
Alexander Duyck729739b2012-02-08 07:51:06 +00001182 /* unmap skb header data */
1183 dma_unmap_single(tx_ring->dev,
1184 dma_unmap_addr(tx_buffer, dma),
1185 dma_unmap_len(tx_buffer, len),
1186 DMA_TO_DEVICE);
1187
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001188 /* clear tx_buffer data */
Alexander Duyck729739b2012-02-08 07:51:06 +00001189 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001190
Alexander Duyck729739b2012-02-08 07:51:06 +00001191 /* unmap remaining buffers */
1192 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001193 tx_buffer++;
1194 tx_desc++;
1195 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001196 if (unlikely(!i)) {
1197 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001198 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001199 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001200 }
1201
Alexander Duyck729739b2012-02-08 07:51:06 +00001202 /* unmap any remaining paged data */
1203 if (dma_unmap_len(tx_buffer, len)) {
1204 dma_unmap_page(tx_ring->dev,
1205 dma_unmap_addr(tx_buffer, dma),
1206 dma_unmap_len(tx_buffer, len),
1207 DMA_TO_DEVICE);
1208 dma_unmap_len_set(tx_buffer, len, 0);
1209 }
1210 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001211
Alexander Duyck729739b2012-02-08 07:51:06 +00001212 /* move us one more past the eop_desc for start of next pkt */
1213 tx_buffer++;
1214 tx_desc++;
1215 i++;
1216 if (unlikely(!i)) {
1217 i -= tx_ring->count;
1218 tx_buffer = tx_ring->tx_buffer_info;
1219 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1220 }
1221
1222 /* issue prefetch for next Tx descriptor */
1223 prefetch(tx_desc);
1224
1225 /* update budget accounting */
1226 budget--;
1227 } while (likely(budget));
1228
1229 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001230 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001231 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001232 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001233 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001234 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001235 q_vector->tx.total_bytes += total_bytes;
1236 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001237
John Fastabendc84d3242010-11-16 19:27:12 -08001238 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001239 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001240 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001241 e_err(drv, "Detected Tx Unit Hang\n"
1242 " Tx Queue <%d>\n"
1243 " TDH, TDT <%x>, <%x>\n"
1244 " next_to_use <%x>\n"
1245 " next_to_clean <%x>\n"
1246 "tx_buffer_info[next_to_clean]\n"
1247 " time_stamp <%lx>\n"
1248 " jiffies <%lx>\n",
1249 tx_ring->queue_index,
1250 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1251 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001252 tx_ring->next_to_use, i,
1253 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001254
1255 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1256
1257 e_info(probe,
1258 "tx hang %d detected on queue %d, resetting adapter\n",
1259 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1260
1261 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001262 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001263
1264 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001265 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001266 }
Auke Kok9a799d72007-09-15 14:07:45 -07001267
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001268 netdev_tx_completed_queue(txring_txq(tx_ring),
1269 total_packets, total_bytes);
1270
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001271#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001272 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001273 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001274 /* Make sure that anybody stopping the queue after this
1275 * sees the new next_to_clean.
1276 */
1277 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001278 if (__netif_subqueue_stopped(tx_ring->netdev,
1279 tx_ring->queue_index)
1280 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1281 netif_wake_subqueue(tx_ring->netdev,
1282 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001283 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001284 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001285 }
Auke Kok9a799d72007-09-15 14:07:45 -07001286
Alexander Duyck59224552011-08-31 00:01:06 +00001287 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001288}
1289
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001290#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001291static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001292 struct ixgbe_ring *tx_ring,
1293 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001294{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001295 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001296 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001297 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001298
Mark Rustad9de76052015-08-08 16:27:41 -07001299 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1300 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1301
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001302 switch (hw->mac.type) {
1303 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001304 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001305 break;
1306 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001307 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001308 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1309 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1310 break;
1311 default:
1312 /* for unknown hardware do not write register */
1313 return;
1314 }
1315
1316 /*
1317 * We can enable relaxed ordering for reads, but not writes when
1318 * DCA is enabled. This is due to a known issue in some chipsets
1319 * which will cause the DCA tag to be cleared.
1320 */
1321 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1322 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1323 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1324
1325 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1326}
1327
1328static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1329 struct ixgbe_ring *rx_ring,
1330 int cpu)
1331{
1332 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001333 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001334 u8 reg_idx = rx_ring->reg_idx;
1335
Mark Rustad9de76052015-08-08 16:27:41 -07001336 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1337 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001338
1339 switch (hw->mac.type) {
1340 case ixgbe_mac_82599EB:
1341 case ixgbe_mac_X540:
1342 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001343 break;
1344 default:
1345 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001346 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001347
1348 /*
1349 * We can enable relaxed ordering for reads, but not writes when
1350 * DCA is enabled. This is due to a known issue in some chipsets
1351 * which will cause the DCA tag to be cleared.
1352 */
1353 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Mark Rustad9de76052015-08-08 16:27:41 -07001354 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001355 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1356
1357 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001358}
1359
1360static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1361{
1362 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001363 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001364 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001365
1366 if (q_vector->cpu == cpu)
1367 goto out_no_update;
1368
Alexander Duycka5579282012-02-08 07:50:04 +00001369 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001370 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001371
Alexander Duycka5579282012-02-08 07:50:04 +00001372 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001373 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001374
1375 q_vector->cpu = cpu;
1376out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001377 put_cpu();
1378}
1379
1380static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1381{
1382 int i;
1383
Alexander Duycke35ec122009-05-21 13:07:12 +00001384 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001385 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1386 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1387 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1388 else
1389 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1390 IXGBE_DCA_CTRL_DCA_DISABLE);
Alexander Duycke35ec122009-05-21 13:07:12 +00001391
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001392 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001393 adapter->q_vector[i]->cpu = -1;
1394 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001395 }
1396}
1397
1398static int __ixgbe_notify_dca(struct device *dev, void *data)
1399{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001400 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001401 unsigned long event = *(unsigned long *)data;
1402
Don Skidmore2a72c312011-07-20 02:27:05 +00001403 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001404 return 0;
1405
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001406 switch (event) {
1407 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001408 /* if we're already enabled, don't do it again */
1409 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1410 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001411 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001412 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001413 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1414 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001415 break;
1416 }
1417 /* Fall Through since DCA is disabled. */
1418 case DCA_PROVIDER_REMOVE:
1419 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1420 dca_remove_requester(dev);
1421 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001422 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1423 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001424 }
1425 break;
1426 }
1427
Denis V. Lunev652f0932008-03-27 14:39:17 +03001428 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001429}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001430
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001431#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b82015-04-29 10:57:39 +08001432
1433#define IXGBE_RSS_L4_TYPES_MASK \
1434 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1435 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1436 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1437 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1438
Alexander Duyck8a0da212012-01-31 02:59:49 +00001439static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1440 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001441 struct sk_buff *skb)
1442{
Fan Du7edda4b82015-04-29 10:57:39 +08001443 u16 rss_type;
1444
1445 if (!(ring->netdev->features & NETIF_F_RXHASH))
1446 return;
1447
1448 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1449 IXGBE_RXDADV_RSSTYPE_MASK;
1450
1451 if (!rss_type)
1452 return;
1453
1454 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1455 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1456 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001457}
1458
Alexander Duyckf8003262012-03-03 02:35:52 +00001459#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001460/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001461 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001462 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001463 * @rx_desc: advanced rx descriptor
1464 *
1465 * Returns : true if it is FCoE pkt
1466 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001467static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001468 union ixgbe_adv_rx_desc *rx_desc)
1469{
1470 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1471
Alexander Duyck57efd442012-06-25 21:54:46 +00001472 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001473 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1474 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1475 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1476}
1477
Alexander Duyckf8003262012-03-03 02:35:52 +00001478#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001479/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001480 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001481 * @ring: structure containing ring specific data
1482 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001483 * @skb: skb currently being received and modified
1484 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001485static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001486 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001487 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001488{
Don Skidmore3f207802014-12-23 07:40:34 +00001489 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore3f207802014-12-23 07:40:34 +00001490 bool encap_pkt = false;
1491
Alexander Duyck8a0da212012-01-31 02:59:49 +00001492 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001493
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001494 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001495 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001496 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001497
Emil Tantilova21d0822016-08-10 11:19:23 -07001498 /* check for VXLAN and Geneve packets */
1499 if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
Don Skidmore3f207802014-12-23 07:40:34 +00001500 encap_pkt = true;
1501 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001502 }
1503
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001504 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001505 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1506 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001507 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001508 return;
1509 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001510
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001511 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001512 return;
1513
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001514 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001515 /*
1516 * 82599 errata, UDP frames with a 0 checksum can be marked as
1517 * checksum errors.
1518 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001519 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1520 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001521 return;
1522
Alexander Duyck8a0da212012-01-31 02:59:49 +00001523 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001524 return;
1525 }
1526
Auke Kok9a799d72007-09-15 14:07:45 -07001527 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001528 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001529 if (encap_pkt) {
1530 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1531 return;
1532
1533 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
Mark Rustadd4692512015-12-04 11:26:43 -08001534 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001535 return;
1536 }
1537 /* If we checked the outer header let the stack know */
1538 skb->csum_level = 1;
1539 }
Auke Kok9a799d72007-09-15 14:07:45 -07001540}
1541
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001542static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
1543{
1544 return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
1545}
1546
Alexander Duyckf990b792012-01-31 02:59:34 +00001547static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1548 struct ixgbe_rx_buffer *bi)
1549{
1550 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001551 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001552
Alexander Duyckf8003262012-03-03 02:35:52 +00001553 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001554 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001555 return true;
1556
Alexander Duyckf8003262012-03-03 02:35:52 +00001557 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001558 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1559 if (unlikely(!page)) {
1560 rx_ring->rx_stats.alloc_rx_page_failed++;
1561 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001562 }
1563
Alexander Duyckf8003262012-03-03 02:35:52 +00001564 /* map page for use */
Alexander Duyckf3213d92017-01-17 08:35:54 -08001565 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
1566 ixgbe_rx_pg_size(rx_ring),
1567 DMA_FROM_DEVICE,
1568 IXGBE_RX_DMA_ATTR);
Alexander Duyckf990b792012-01-31 02:59:34 +00001569
Alexander Duyckf8003262012-03-03 02:35:52 +00001570 /*
1571 * if mapping failed free memory back to system since
1572 * there isn't much point in holding memory we can't use
1573 */
1574 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001575 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001576
Alexander Duyckf990b792012-01-31 02:59:34 +00001577 rx_ring->rx_stats.alloc_rx_page_failed++;
1578 return false;
1579 }
1580
Alexander Duyckf8003262012-03-03 02:35:52 +00001581 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001582 bi->page = page;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001583 bi->page_offset = ixgbe_rx_offset(rx_ring);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001584 bi->pagecnt_bias = 1;
Alexander Duyckf8003262012-03-03 02:35:52 +00001585
Alexander Duyckf990b792012-01-31 02:59:34 +00001586 return true;
1587}
1588
Auke Kok9a799d72007-09-15 14:07:45 -07001589/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001590 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001591 * @rx_ring: ring to place buffers on
1592 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001593 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001594void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001595{
Auke Kok9a799d72007-09-15 14:07:45 -07001596 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001597 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001598 u16 i = rx_ring->next_to_use;
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001599 u16 bufsz;
Auke Kok9a799d72007-09-15 14:07:45 -07001600
Alexander Duyckf8003262012-03-03 02:35:52 +00001601 /* nothing to do */
1602 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001603 return;
1604
Alexander Duycke4f74022012-01-31 02:59:44 +00001605 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001606 bi = &rx_ring->rx_buffer_info[i];
1607 i -= rx_ring->count;
1608
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001609 bufsz = ixgbe_rx_bufsz(rx_ring);
1610
Alexander Duyckf8003262012-03-03 02:35:52 +00001611 do {
1612 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001613 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001614
Alexander Duyckf3213d92017-01-17 08:35:54 -08001615 /* sync the buffer for use by the device */
1616 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001617 bi->page_offset, bufsz,
Alexander Duyckf3213d92017-01-17 08:35:54 -08001618 DMA_FROM_DEVICE);
1619
Alexander Duyckf8003262012-03-03 02:35:52 +00001620 /*
1621 * Refresh the desc even if buffer_addrs didn't change
1622 * because each write-back erases this info.
1623 */
1624 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001625
Alexander Duyckf990b792012-01-31 02:59:34 +00001626 rx_desc++;
1627 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001628 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001629 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001630 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001631 bi = rx_ring->rx_buffer_info;
1632 i -= rx_ring->count;
1633 }
1634
Alexander Duyckc3630cc2017-01-17 08:36:28 -08001635 /* clear the length for the next_to_use descriptor */
1636 rx_desc->wb.upper.length = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001637
1638 cleaned_count--;
1639 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001640
Alexander Duyckf990b792012-01-31 02:59:34 +00001641 i += rx_ring->count;
1642
Alexander Duyckad435ec2014-11-14 00:56:35 +00001643 if (rx_ring->next_to_use != i) {
1644 rx_ring->next_to_use = i;
1645
1646 /* update next to alloc since we have filled the ring */
1647 rx_ring->next_to_alloc = i;
1648
1649 /* Force memory writes to complete before letting h/w
1650 * know there are new descriptors to fetch. (Only
1651 * applicable for weak-ordered memory model archs,
1652 * such as IA-64).
1653 */
1654 wmb();
1655 writel(i, rx_ring->tail);
1656 }
Auke Kok9a799d72007-09-15 14:07:45 -07001657}
1658
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001659static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1660 struct sk_buff *skb)
1661{
Alexander Duyckf8003262012-03-03 02:35:52 +00001662 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001663
1664 /* set gso_size to avoid messing up TCP MSS */
1665 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1666 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001667 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001668}
1669
1670static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1671 struct sk_buff *skb)
1672{
1673 /* if append_cnt is 0 then frame is not RSC */
1674 if (!IXGBE_CB(skb)->append_cnt)
1675 return;
1676
1677 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1678 rx_ring->rx_stats.rsc_flush++;
1679
1680 ixgbe_set_rsc_gso_size(rx_ring, skb);
1681
1682 /* gso_size is computed using append_cnt so always clear it last */
1683 IXGBE_CB(skb)->append_cnt = 0;
1684}
1685
Alexander Duyck8a0da212012-01-31 02:59:49 +00001686/**
1687 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1688 * @rx_ring: rx descriptor ring packet is being transacted on
1689 * @rx_desc: pointer to the EOP Rx descriptor
1690 * @skb: pointer to current skb being populated
1691 *
1692 * This function checks the ring, descriptor, and packet information in
1693 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1694 * other fields within the skb.
1695 **/
1696static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1697 union ixgbe_adv_rx_desc *rx_desc,
1698 struct sk_buff *skb)
1699{
John Fastabend43e95f12012-05-15 06:12:17 +00001700 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001701 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001702
Alexander Duyck8a0da212012-01-31 02:59:49 +00001703 ixgbe_update_rsc_stats(rx_ring, skb);
1704
1705 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1706
1707 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1708
Mark Rustada9763f32015-10-27 09:58:07 -07001709 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1710 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001711
Patrick McHardyf6469682013-04-19 02:04:27 +00001712 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001713 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001714 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001715 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001716 }
1717
1718 skb_record_rx_queue(skb, rx_ring->queue_index);
1719
John Fastabend43e95f12012-05-15 06:12:17 +00001720 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001721}
1722
1723static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1724 struct sk_buff *skb)
1725{
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08001726 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001727}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001728
Alexander Duyckf8003262012-03-03 02:35:52 +00001729/**
1730 * ixgbe_is_non_eop - process handling of non-EOP buffers
1731 * @rx_ring: Rx ring being processed
1732 * @rx_desc: Rx descriptor for current buffer
1733 * @skb: Current socket buffer containing buffer in progress
1734 *
1735 * This function updates next to clean. If the buffer is an EOP buffer
1736 * this function exits returning false, otherwise it will place the
1737 * sk_buff in the next buffer to be chained and return true indicating
1738 * that this is in fact a non-EOP buffer.
1739 **/
1740static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1741 union ixgbe_adv_rx_desc *rx_desc,
1742 struct sk_buff *skb)
1743{
1744 u32 ntc = rx_ring->next_to_clean + 1;
1745
1746 /* fetch, update, and store next to clean */
1747 ntc = (ntc < rx_ring->count) ? ntc : 0;
1748 rx_ring->next_to_clean = ntc;
1749
1750 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1751
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001752 /* update RSC append count if present */
1753 if (ring_is_rsc_enabled(rx_ring)) {
1754 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1755 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1756
1757 if (unlikely(rsc_enabled)) {
1758 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1759
1760 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1761 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1762
1763 /* update ntc based on RSC value */
1764 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1765 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1766 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1767 }
1768 }
1769
1770 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001771 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1772 return false;
1773
Alexander Duyckf8003262012-03-03 02:35:52 +00001774 /* place skb in next buffer to be received */
1775 rx_ring->rx_buffer_info[ntc].skb = skb;
1776 rx_ring->rx_stats.non_eop_descs++;
1777
1778 return true;
1779}
1780
1781/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001782 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1783 * @rx_ring: rx descriptor ring packet is being transacted on
1784 * @skb: pointer to current skb being adjusted
1785 *
1786 * This function is an ixgbe specific version of __pskb_pull_tail. The
1787 * main difference between this version and the original function is that
1788 * this function can make several assumptions about the state of things
1789 * that allow for significant optimizations versus the standard function.
1790 * As a result we can do things like drop a frag and maintain an accurate
1791 * truesize for the skb.
1792 */
1793static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1794 struct sk_buff *skb)
1795{
1796 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1797 unsigned char *va;
1798 unsigned int pull_len;
1799
1800 /*
1801 * it is valid to use page_address instead of kmap since we are
1802 * working with pages allocated out of the lomem pool per
1803 * alloc_page(GFP_ATOMIC)
1804 */
1805 va = skb_frag_address(frag);
1806
1807 /*
1808 * we need the header to contain the greater of either ETH_HLEN or
1809 * 60 bytes if the skb->len is less than 60 for skb_pad.
1810 */
Alexander Duyck8496e3382014-09-05 19:22:18 -04001811 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001812
1813 /* align pull length to size of long to optimize memcpy performance */
1814 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1815
1816 /* update all of the pointers */
1817 skb_frag_size_sub(frag, pull_len);
1818 frag->page_offset += pull_len;
1819 skb->data_len -= pull_len;
1820 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001821}
1822
1823/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001824 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1825 * @rx_ring: rx descriptor ring packet is being transacted on
1826 * @skb: pointer to current skb being updated
1827 *
1828 * This function provides a basic DMA sync up for the first fragment of an
1829 * skb. The reason for doing this is that the first fragment cannot be
1830 * unmapped until we have reached the end of packet descriptor for a buffer
1831 * chain.
1832 */
1833static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1834 struct sk_buff *skb)
1835{
1836 /* if the page was released unmap it, else just sync our portion */
1837 if (unlikely(IXGBE_CB(skb)->page_released)) {
Alexander Duyckf3213d92017-01-17 08:35:54 -08001838 dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
1839 ixgbe_rx_pg_size(rx_ring),
1840 DMA_FROM_DEVICE,
1841 IXGBE_RX_DMA_ATTR);
Alexander Duyck42073d92012-07-20 08:08:28 +00001842 } else {
1843 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1844
1845 dma_sync_single_range_for_cpu(rx_ring->dev,
1846 IXGBE_CB(skb)->dma,
1847 frag->page_offset,
Alexander Duyckf215af82017-01-17 08:35:44 -08001848 skb_frag_size(frag),
Alexander Duyck42073d92012-07-20 08:08:28 +00001849 DMA_FROM_DEVICE);
1850 }
Alexander Duyck42073d92012-07-20 08:08:28 +00001851}
1852
1853/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001854 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1855 * @rx_ring: rx descriptor ring packet is being transacted on
1856 * @rx_desc: pointer to the EOP Rx descriptor
1857 * @skb: pointer to current skb being fixed
1858 *
1859 * Check for corrupted packet headers caused by senders on the local L2
1860 * embedded NIC switch not setting up their Tx Descriptors right. These
1861 * should be very rare.
1862 *
1863 * Also address the case where we are pulling data in on pages only
1864 * and as such no data is present in the skb header.
1865 *
1866 * In addition if skb is not at least 60 bytes we need to pad it so that
1867 * it is large enough to qualify as a valid Ethernet frame.
1868 *
1869 * Returns true if an error was encountered and skb was freed.
1870 **/
1871static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1872 union ixgbe_adv_rx_desc *rx_desc,
1873 struct sk_buff *skb)
1874{
Alexander Duyckf8003262012-03-03 02:35:52 +00001875 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001876
1877 /* verify that the packet does not have any known errors */
1878 if (unlikely(ixgbe_test_staterr(rx_desc,
1879 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1880 !(netdev->features & NETIF_F_RXALL))) {
1881 dev_kfree_skb_any(skb);
1882 return true;
1883 }
1884
Alexander Duyck19861ce2012-07-20 08:08:33 +00001885 /* place header in linear portion of buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08001886 if (!skb_headlen(skb))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001887 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001888
Alexander Duyck57efd442012-06-25 21:54:46 +00001889#ifdef IXGBE_FCOE
1890 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1891 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1892 return false;
1893
1894#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001895 /* if eth_skb_pad returns an error the skb was freed */
1896 if (eth_skb_pad(skb))
1897 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001898
1899 return false;
1900}
1901
1902/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001903 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1904 * @rx_ring: rx descriptor ring to store buffers on
1905 * @old_buff: donor buffer to have page reused
1906 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001907 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001908 **/
1909static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1910 struct ixgbe_rx_buffer *old_buff)
1911{
1912 struct ixgbe_rx_buffer *new_buff;
1913 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001914
1915 new_buff = &rx_ring->rx_buffer_info[nta];
1916
1917 /* update, and store next to alloc */
1918 nta++;
1919 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1920
Alexander Duyck3fd218762017-01-17 08:36:45 -08001921 /* Transfer page from old buffer to new buffer.
1922 * Move each member individually to avoid possible store
1923 * forwarding stalls and unnecessary copy of skb.
1924 */
1925 new_buff->dma = old_buff->dma;
1926 new_buff->page = old_buff->page;
1927 new_buff->page_offset = old_buff->page_offset;
1928 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
Alexander Duyckf8003262012-03-03 02:35:52 +00001929}
1930
Alexander Duyck18cb6522014-11-14 00:56:29 +00001931static inline bool ixgbe_page_is_reserved(struct page *page)
1932{
Michal Hocko2f064f32015-08-21 14:11:51 -07001933 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001934}
1935
Alexander Duyck3fd218762017-01-17 08:36:45 -08001936static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
Alexander Duyckf8003262012-03-03 02:35:52 +00001937{
Alexander Duyck3fd218762017-01-17 08:36:45 -08001938 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
1939 struct page *page = rx_buffer->page;
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001940
Alexander Duyck09816fb2012-07-20 08:08:23 +00001941 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001942 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001943 return false;
1944
1945#if (PAGE_SIZE < 8192)
1946 /* if we are only owner of page we can reuse it */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001947 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001948 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001949#else
Alexander Duyck3fd218762017-01-17 08:36:45 -08001950 /* The last offset is a bit aggressive in that we assume the
1951 * worst case of FCoE being enabled and using a 3K buffer.
1952 * However this should have minimal impact as the 1K extra is
1953 * still less than one buffer in size.
1954 */
1955#define IXGBE_LAST_OFFSET \
1956 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
1957 if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
Alexander Duyck09816fb2012-07-20 08:08:23 +00001958 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001959#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001960
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001961 /* If we have drained the page fragment pool we need to update
1962 * the pagecnt_bias and page count so that we fully restock the
1963 * number of references the driver holds.
Alexander Duyck18cb6522014-11-14 00:56:29 +00001964 */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001965 if (unlikely(!pagecnt_bias)) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001966 page_ref_add(page, USHRT_MAX);
1967 rx_buffer->pagecnt_bias = USHRT_MAX;
1968 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00001969
Alexander Duyck0549ae22012-07-20 08:08:18 +00001970 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001971}
1972
Alexander Duyckaf43da02017-01-17 08:35:34 -08001973/**
1974 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1975 * @rx_ring: rx descriptor ring to transact packets on
1976 * @rx_buffer: buffer containing page to add
1977 * @rx_desc: descriptor containing length of buffer written by hardware
1978 * @skb: sk_buff to place the data into
1979 *
1980 * This function will add the data contained in rx_buffer->page to the skb.
1981 * This is done either through a direct copy if the data in the buffer is
1982 * less than the skb header size, otherwise it will just attach the page as
1983 * a frag to the skb.
1984 *
1985 * The function will then update the page offset if necessary and return
1986 * true if the buffer can be reused by the adapter.
1987 **/
Alexander Duyck3fd218762017-01-17 08:36:45 -08001988static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckaf43da02017-01-17 08:35:34 -08001989 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck3fd218762017-01-17 08:36:45 -08001990 struct sk_buff *skb,
1991 unsigned int size)
Alexander Duyckaf43da02017-01-17 08:35:34 -08001992{
Alexander Duyckaf43da02017-01-17 08:35:34 -08001993#if (PAGE_SIZE < 8192)
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001994 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
Alexander Duyckaf43da02017-01-17 08:35:34 -08001995#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001996 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
1997 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
1998 SKB_DATA_ALIGN(size);
Alexander Duyckaf43da02017-01-17 08:35:34 -08001999#endif
Alexander Duyck3fd218762017-01-17 08:36:45 -08002000 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
Alexander Duyckaf43da02017-01-17 08:35:34 -08002001 rx_buffer->page_offset, size, truesize);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002002#if (PAGE_SIZE < 8192)
2003 rx_buffer->page_offset ^= truesize;
2004#else
2005 rx_buffer->page_offset += truesize;
2006#endif
Alexander Duyckaf43da02017-01-17 08:35:34 -08002007}
2008
Alexander Duyck3fd218762017-01-17 08:36:45 -08002009static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
2010 union ixgbe_adv_rx_desc *rx_desc,
2011 struct sk_buff **skb,
2012 const unsigned int size)
Alexander Duyck18806c92012-07-20 08:08:44 +00002013{
2014 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyck18806c92012-07-20 08:08:44 +00002015
2016 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
Alexander Duyck3fd218762017-01-17 08:36:45 -08002017 prefetchw(rx_buffer->page);
2018 *skb = rx_buffer->skb;
Alexander Duyck18806c92012-07-20 08:08:44 +00002019
Alexander Duyck3fd218762017-01-17 08:36:45 -08002020 /* Delay unmapping of the first packet. It carries the header
2021 * information, HW may still access the header after the writeback.
2022 * Only unmap it when EOP is reached
2023 */
2024 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
2025 if (!*skb)
2026 goto skip_sync;
Alexander Duyck18806c92012-07-20 08:08:44 +00002027 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002028 if (*skb)
2029 ixgbe_dma_sync_frag(rx_ring, *skb);
Alexander Duyck18806c92012-07-20 08:08:44 +00002030 }
2031
Alexander Duyck3fd218762017-01-17 08:36:45 -08002032 /* we are reusing so sync this buffer for CPU use */
2033 dma_sync_single_range_for_cpu(rx_ring->dev,
2034 rx_buffer->dma,
2035 rx_buffer->page_offset,
2036 size,
2037 DMA_FROM_DEVICE);
2038skip_sync:
2039 rx_buffer->pagecnt_bias--;
2040
2041 return rx_buffer;
2042}
2043
2044static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
2045 struct ixgbe_rx_buffer *rx_buffer,
2046 struct sk_buff *skb)
2047{
2048 if (ixgbe_can_reuse_rx_page(rx_buffer)) {
Alexander Duyck18806c92012-07-20 08:08:44 +00002049 /* hand second half of page back to the ring */
2050 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
Alexander Duyck18806c92012-07-20 08:08:44 +00002051 } else {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002052 if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
2053 /* the page has been released from the ring */
2054 IXGBE_CB(skb)->page_released = true;
2055 } else {
2056 /* we are not reusing the buffer so unmap it */
2057 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
2058 ixgbe_rx_pg_size(rx_ring),
2059 DMA_FROM_DEVICE,
2060 IXGBE_RX_DMA_ATTR);
2061 }
Alexander Duyck3fd218762017-01-17 08:36:45 -08002062 __page_frag_cache_drain(rx_buffer->page,
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002063 rx_buffer->pagecnt_bias);
Alexander Duyck18806c92012-07-20 08:08:44 +00002064 }
2065
Alexander Duyck3fd218762017-01-17 08:36:45 -08002066 /* clear contents of rx_buffer */
Alexander Duyck18806c92012-07-20 08:08:44 +00002067 rx_buffer->page = NULL;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002068 rx_buffer->skb = NULL;
2069}
2070
2071static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
2072 struct ixgbe_rx_buffer *rx_buffer,
2073 union ixgbe_adv_rx_desc *rx_desc,
2074 unsigned int size)
2075{
2076 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
2077#if (PAGE_SIZE < 8192)
2078 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2079#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08002080 unsigned int truesize = SKB_DATA_ALIGN(size);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002081#endif
2082 struct sk_buff *skb;
2083
2084 /* prefetch first cache line of first page */
2085 prefetch(va);
2086#if L1_CACHE_BYTES < 128
2087 prefetch(va + L1_CACHE_BYTES);
2088#endif
2089
2090 /* allocate a skb to store the frags */
2091 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
2092 if (unlikely(!skb))
2093 return NULL;
2094
2095 if (size > IXGBE_RX_HDR_SIZE) {
2096 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2097 IXGBE_CB(skb)->dma = rx_buffer->dma;
2098
2099 skb_add_rx_frag(skb, 0, rx_buffer->page,
2100 rx_buffer->page_offset,
2101 size, truesize);
2102#if (PAGE_SIZE < 8192)
2103 rx_buffer->page_offset ^= truesize;
2104#else
2105 rx_buffer->page_offset += truesize;
2106#endif
2107 } else {
2108 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
2109 rx_buffer->pagecnt_bias++;
2110 }
Alexander Duyck18806c92012-07-20 08:08:44 +00002111
2112 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002113}
2114
Alexander Duyck6f429222017-01-17 08:37:13 -08002115static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
2116 struct ixgbe_rx_buffer *rx_buffer,
2117 union ixgbe_adv_rx_desc *rx_desc,
2118 unsigned int size)
2119{
2120 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
2121#if (PAGE_SIZE < 8192)
2122 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2123#else
2124 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
2125 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size);
2126#endif
2127 struct sk_buff *skb;
2128
2129 /* prefetch first cache line of first page */
2130 prefetch(va);
2131#if L1_CACHE_BYTES < 128
2132 prefetch(va + L1_CACHE_BYTES);
2133#endif
2134
Alexander Duyck3a1eb6d2017-02-15 09:15:59 -08002135 /* build an skb around the page buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08002136 skb = build_skb(va - IXGBE_SKB_PAD, truesize);
2137 if (unlikely(!skb))
2138 return NULL;
2139
2140 /* update pointers within the skb to store the data */
2141 skb_reserve(skb, IXGBE_SKB_PAD);
2142 __skb_put(skb, size);
2143
2144 /* record DMA address if this is the start of a chain of buffers */
2145 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2146 IXGBE_CB(skb)->dma = rx_buffer->dma;
2147
2148 /* update buffer offset */
2149#if (PAGE_SIZE < 8192)
2150 rx_buffer->page_offset ^= truesize;
2151#else
2152 rx_buffer->page_offset += truesize;
2153#endif
2154
2155 return skb;
2156}
2157
Alexander Duyckf8003262012-03-03 02:35:52 +00002158/**
2159 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2160 * @q_vector: structure containing interrupt and ring information
2161 * @rx_ring: rx descriptor ring to transact packets on
2162 * @budget: Total limit on number of packets to process
2163 *
2164 * This function provides a "bounce buffer" approach to Rx interrupt
2165 * processing. The advantage to this is that on systems that have
2166 * expensive overhead for IOMMU access this provides a means of avoiding
2167 * it by maintaining the mapping of the page to the syste.
2168 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002169 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002170 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002171static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002172 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002173 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002174{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002175 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00002176#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00002177 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00002178 int ddp_bytes;
2179 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002180#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002181 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002182
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002183 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002184 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002185 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyckf8003262012-03-03 02:35:52 +00002186 struct sk_buff *skb;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002187 unsigned int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002188
Alexander Duyckf8003262012-03-03 02:35:52 +00002189 /* return some buffers to hardware, one at a time is too slow */
2190 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2191 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2192 cleaned_count = 0;
2193 }
Auke Kok9a799d72007-09-15 14:07:45 -07002194
Alexander Duyck18806c92012-07-20 08:08:44 +00002195 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002196 size = le16_to_cpu(rx_desc->wb.upper.length);
2197 if (!size)
Alexander Duyckf8003262012-03-03 02:35:52 +00002198 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002199
Alexander Duyck124b74c2014-12-11 15:02:28 -08002200 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002201 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002202 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002203 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002204 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002205
Alexander Duyck3fd218762017-01-17 08:36:45 -08002206 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
2207
Alexander Duyck18806c92012-07-20 08:08:44 +00002208 /* retrieve a buffer from the ring */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002209 if (skb)
2210 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
Alexander Duyck6f429222017-01-17 08:37:13 -08002211 else if (ring_uses_build_skb(rx_ring))
2212 skb = ixgbe_build_skb(rx_ring, rx_buffer,
2213 rx_desc, size);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002214 else
2215 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
2216 rx_desc, size);
Alexander Duyckf8003262012-03-03 02:35:52 +00002217
Alexander Duyck18806c92012-07-20 08:08:44 +00002218 /* exit if we failed to retrieve a buffer */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002219 if (!skb) {
2220 rx_ring->rx_stats.alloc_rx_buff_failed++;
2221 rx_buffer->pagecnt_bias++;
Alexander Duyck18806c92012-07-20 08:08:44 +00002222 break;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002223 }
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002224
Alexander Duyck3fd218762017-01-17 08:36:45 -08002225 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002226 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002227
Alexander Duyckf8003262012-03-03 02:35:52 +00002228 /* place incomplete frames back on ring for completion */
2229 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2230 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002231
Alexander Duyckf8003262012-03-03 02:35:52 +00002232 /* verify the packet layout is correct */
2233 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2234 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002235
2236 /* probably a little skewed due to removing CRC */
2237 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002238
Alexander Duyck8a0da212012-01-31 02:59:49 +00002239 /* populate checksum, timestamp, VLAN, and protocol */
2240 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2241
Yi Zou332d4a72009-05-13 13:11:53 +00002242#ifdef IXGBE_FCOE
2243 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002244 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002245 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002246 /* include DDPed FCoE data */
2247 if (ddp_bytes > 0) {
2248 if (!mss) {
2249 mss = rx_ring->netdev->mtu -
2250 sizeof(struct fcoe_hdr) -
2251 sizeof(struct fc_frame_header) -
2252 sizeof(struct fcoe_crc_eof);
2253 if (mss > 512)
2254 mss &= ~511;
2255 }
2256 total_rx_bytes += ddp_bytes;
2257 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2258 mss);
2259 }
David S. Miller823dcd22011-08-20 10:39:12 -07002260 if (!ddp_bytes) {
2261 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002262 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002263 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002264 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002265
Yi Zou332d4a72009-05-13 13:11:53 +00002266#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002267 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002268
Alexander Duyckf8003262012-03-03 02:35:52 +00002269 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002270 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002271 }
Auke Kok9a799d72007-09-15 14:07:45 -07002272
Alexander Duyckc267fc12010-11-16 19:27:00 -08002273 u64_stats_update_begin(&rx_ring->syncp);
2274 rx_ring->stats.packets += total_rx_packets;
2275 rx_ring->stats.bytes += total_rx_bytes;
2276 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002277 q_vector->rx.total_packets += total_rx_packets;
2278 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002279
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002280 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002281}
2282
Auke Kok9a799d72007-09-15 14:07:45 -07002283/**
2284 * ixgbe_configure_msix - Configure MSI-X hardware
2285 * @adapter: board private structure
2286 *
2287 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2288 * interrupts.
2289 **/
2290static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2291{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002292 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002293 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002294 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002295
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002296 /* Populate MSIX to EITR Select */
2297 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002298 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002299 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2300 }
2301
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002302 /*
2303 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002304 * corresponding register.
2305 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002306 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002307 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002308 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002309
Alexander Duycka5579282012-02-08 07:50:04 +00002310 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002311 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002312
Alexander Duycka5579282012-02-08 07:50:04 +00002313 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002314 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002315
Alexander Duyckfe49f042009-06-04 16:00:09 +00002316 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002317 }
2318
Alexander Duyckbd508172010-11-16 19:27:03 -08002319 switch (adapter->hw.mac.type) {
2320 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002321 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002322 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002323 break;
2324 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002325 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002326 case ixgbe_mac_X550:
2327 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002328 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002329 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002330 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002331 default:
2332 break;
2333 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002334 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002335
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002336 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002337 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002338 mask &= ~(IXGBE_EIMS_OTHER |
2339 IXGBE_EIMS_MAILBOX |
2340 IXGBE_EIMS_LSC);
2341
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002342 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002343}
2344
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002345enum latency_range {
2346 lowest_latency = 0,
2347 low_latency = 1,
2348 bulk_latency = 2,
2349 latency_invalid = 255
2350};
2351
2352/**
2353 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002354 * @q_vector: structure containing interrupt and ring information
2355 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002356 *
2357 * Stores a new ITR value based on packets and byte
2358 * counts during the last interrupt. The advantage of per interrupt
2359 * computation is faster updates and more accurate ITR for the current
2360 * traffic pattern. Constants in this function were computed
2361 * based on theoretical maximum wire speed and thresholds were set based
2362 * on testing data as well as attempting to minimize response time
2363 * while increasing bulk throughput.
2364 * this functionality is controlled by the InterruptThrottleRate module
2365 * parameter (see ixgbe_param.c)
2366 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002367static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2368 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002369{
Alexander Duyckbd198052011-06-11 01:45:08 +00002370 int bytes = ring_container->total_bytes;
2371 int packets = ring_container->total_packets;
2372 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002373 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002374 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002375
2376 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002377 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002378
2379 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002380 * 0-10MB/s lowest (100000 ints/s)
2381 * 10-20MB/s low (20000 ints/s)
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002382 * 20-1249MB/s bulk (12000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002383 */
2384 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002385 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002386 if (timepassed_us == 0)
2387 return;
2388
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002389 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2390
2391 switch (itr_setting) {
2392 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002393 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002394 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002395 break;
2396 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002397 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002398 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002399 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002400 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002401 break;
2402 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002403 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002404 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002405 break;
2406 }
2407
Alexander Duyckbd198052011-06-11 01:45:08 +00002408 /* clear work counters since we have the values we need */
2409 ring_container->total_bytes = 0;
2410 ring_container->total_packets = 0;
2411
2412 /* write updated itr to ring container */
2413 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002414}
2415
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002416/**
2417 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002418 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002419 *
2420 * This function is made to be called by ethtool and by the driver
2421 * when it needs to update EITR registers at runtime. Hardware
2422 * specific quirks/differences are taken care of here.
2423 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002424void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002425{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002426 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002427 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002428 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002429 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002430
Alexander Duyckbd508172010-11-16 19:27:03 -08002431 switch (adapter->hw.mac.type) {
2432 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002433 /* must write high and low 16 bits to reset counter */
2434 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002435 break;
2436 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002437 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002438 case ixgbe_mac_X550:
2439 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002440 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002441 /*
2442 * set the WDIS bit to not clear the timer bits and cause an
2443 * immediate assertion of the interrupt
2444 */
2445 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002446 break;
2447 default:
2448 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002449 }
2450 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2451}
2452
Alexander Duyckbd198052011-06-11 01:45:08 +00002453static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002454{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002455 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002456 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002457
Alexander Duyckbd198052011-06-11 01:45:08 +00002458 ixgbe_update_itr(q_vector, &q_vector->tx);
2459 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002460
Alexander Duyck08c88332011-06-11 01:45:03 +00002461 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002462
2463 switch (current_itr) {
2464 /* counts and packets in update_itr are dependent on these numbers */
2465 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002466 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002467 break;
2468 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002469 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002470 break;
2471 case bulk_latency:
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002472 new_itr = IXGBE_12K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002473 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002474 default:
2475 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002476 }
2477
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002478 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002479 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002480 new_itr = (10 * new_itr * q_vector->itr) /
2481 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002482
Alexander Duyckbd198052011-06-11 01:45:08 +00002483 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002484 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002485
2486 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002487 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002488}
2489
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002490/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002491 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002492 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002493 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002494static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002495{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002496 struct ixgbe_hw *hw = &adapter->hw;
2497 u32 eicr = adapter->interrupt_event;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002498 s32 rc;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002499
Alexander Duyckf0f97782011-04-22 04:08:09 +00002500 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002501 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002502
Alexander Duyckf0f97782011-04-22 04:08:09 +00002503 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2504 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2505 return;
2506
2507 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2508
Joe Perches7ca647b2010-09-07 21:35:40 +00002509 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002510 case IXGBE_DEV_ID_82599_T3_LOM:
2511 /*
2512 * Since the warning interrupt is for both ports
2513 * we don't have to check if:
2514 * - This interrupt wasn't for our port.
2515 * - We may have missed the interrupt so always have to
2516 * check if we got a LSC
2517 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002518 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002519 !(eicr & IXGBE_EICR_LSC))
2520 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002521
Alexander Duyckf0f97782011-04-22 04:08:09 +00002522 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002523 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002524 bool link_up = false;
2525
Josh Hay3d292262012-12-15 03:28:19 +00002526 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002527
Alexander Duyckf0f97782011-04-22 04:08:09 +00002528 if (link_up)
2529 return;
2530 }
2531
2532 /* Check if this is not due to overtemp */
2533 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2534 return;
2535
2536 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002537 case IXGBE_DEV_ID_X550EM_A_1G_T:
2538 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2539 rc = hw->phy.ops.check_overtemp(hw);
2540 if (rc != IXGBE_ERR_OVERTEMP)
2541 return;
2542 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002543 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002544 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2545 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002546 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002547 return;
2548 break;
2549 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002550 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002551
2552 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002553}
2554
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002555static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2556{
2557 struct ixgbe_hw *hw = &adapter->hw;
2558
2559 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002560 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002561 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002562 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002563 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002564 }
2565}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002566
Jacob Keller4f51bf72011-08-20 04:49:45 +00002567static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2568{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002569 struct ixgbe_hw *hw = &adapter->hw;
2570
Jacob Keller4f51bf72011-08-20 04:49:45 +00002571 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2572 return;
2573
2574 switch (adapter->hw.mac.type) {
2575 case ixgbe_mac_82599EB:
2576 /*
2577 * Need to check link state so complete overtemp check
2578 * on service task
2579 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002580 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2581 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002582 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2583 adapter->interrupt_event = eicr;
2584 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2585 ixgbe_service_event_schedule(adapter);
2586 return;
2587 }
2588 return;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002589 case ixgbe_mac_x550em_a:
2590 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2591 adapter->interrupt_event = eicr;
2592 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2593 ixgbe_service_event_schedule(adapter);
2594 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2595 IXGBE_EICR_GPI_SDP0_X550EM_a);
2596 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2597 IXGBE_EICR_GPI_SDP0_X550EM_a);
2598 }
2599 return;
2600 case ixgbe_mac_X550:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002601 case ixgbe_mac_X540:
2602 if (!(eicr & IXGBE_EICR_TS))
2603 return;
2604 break;
2605 default:
2606 return;
2607 }
2608
Don Skidmoref44e7512015-06-09 16:36:23 -07002609 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002610}
2611
Don Skidmore45788d22015-06-09 16:59:04 -07002612static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2613{
2614 switch (hw->mac.type) {
2615 case ixgbe_mac_82598EB:
2616 if (hw->phy.type == ixgbe_phy_nl)
2617 return true;
2618 return false;
2619 case ixgbe_mac_82599EB:
2620 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002621 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002622 switch (hw->mac.ops.get_media_type(hw)) {
2623 case ixgbe_media_type_fiber:
2624 case ixgbe_media_type_fiber_qsfp:
2625 return true;
2626 default:
2627 return false;
2628 }
2629 default:
2630 return false;
2631 }
2632}
2633
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002634static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2635{
2636 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002637 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002638
Don Skidmore4ccc6502015-09-02 13:47:54 -07002639 if (!ixgbe_is_sfp(hw))
2640 return;
2641
2642 /* Later MAC's use different SDP */
2643 if (hw->mac.type >= ixgbe_mac_X540)
2644 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2645
2646 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002647 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002648 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002649 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2650 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002651 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002652 ixgbe_service_event_schedule(adapter);
2653 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002654 }
2655
Don Skidmore4ccc6502015-09-02 13:47:54 -07002656 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2657 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002658 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002659 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002660 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2661 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2662 ixgbe_service_event_schedule(adapter);
2663 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002664 }
2665}
2666
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002667static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2668{
2669 struct ixgbe_hw *hw = &adapter->hw;
2670
2671 adapter->lsc_int++;
2672 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2673 adapter->link_check_timeout = jiffies;
2674 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2675 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002676 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002677 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002678 }
2679}
2680
Alexander Duyckfe49f042009-06-04 16:00:09 +00002681static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2682 u64 qmask)
2683{
2684 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002685 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002686
Alexander Duyckbd508172010-11-16 19:27:03 -08002687 switch (hw->mac.type) {
2688 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002689 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002690 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2691 break;
2692 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002693 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002694 case ixgbe_mac_X550:
2695 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002696 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002697 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002698 if (mask)
2699 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002700 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002701 if (mask)
2702 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2703 break;
2704 default:
2705 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002706 }
2707 /* skip the flush */
2708}
2709
2710static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002711 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002712{
2713 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002714 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002715
Alexander Duyckbd508172010-11-16 19:27:03 -08002716 switch (hw->mac.type) {
2717 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002718 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002719 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2720 break;
2721 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002722 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002723 case ixgbe_mac_X550:
2724 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002725 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002726 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002727 if (mask)
2728 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002729 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002730 if (mask)
2731 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2732 break;
2733 default:
2734 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002735 }
2736 /* skip the flush */
2737}
2738
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002739/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002740 * ixgbe_irq_enable - Enable default interrupt generation settings
2741 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002742 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002743static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2744 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002745{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002746 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002747 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002748
Alexander Duyck2c4af692011-07-15 07:29:55 +00002749 /* don't reenable LSC while waiting for link */
2750 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2751 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002752
Alexander Duyck2c4af692011-07-15 07:29:55 +00002753 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002754 switch (adapter->hw.mac.type) {
2755 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002756 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002757 break;
2758 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002759 case ixgbe_mac_X550:
2760 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002761 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002762 mask |= IXGBE_EIMS_TS;
2763 break;
2764 default:
2765 break;
2766 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002767 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002768 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002769 switch (adapter->hw.mac.type) {
2770 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002771 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2772 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002773 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00002774 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002775 case ixgbe_mac_X550:
2776 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002777 case ixgbe_mac_x550em_a:
2778 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07002779 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07002780 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07002781 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07002782 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
2783 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00002784 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002785 mask |= IXGBE_EIMS_MAILBOX;
2786 break;
2787 default:
2788 break;
2789 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002790
Alexander Duyck2c4af692011-07-15 07:29:55 +00002791 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2792 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2793 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002794
Alexander Duyck2c4af692011-07-15 07:29:55 +00002795 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2796 if (queues)
2797 ixgbe_irq_enable_queues(adapter, ~0);
2798 if (flush)
2799 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002800}
2801
Alexander Duyck2c4af692011-07-15 07:29:55 +00002802static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002803{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002804 struct ixgbe_adapter *adapter = data;
2805 struct ixgbe_hw *hw = &adapter->hw;
2806 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002807
Alexander Duyck2c4af692011-07-15 07:29:55 +00002808 /*
2809 * Workaround for Silicon errata. Use clear-by-write instead
2810 * of clear-by-read. Reading with EICS will return the
2811 * interrupt causes without clearing, which later be done
2812 * with the write to EICR.
2813 */
2814 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002815
2816 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08002817 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00002818 * the bits are high when ixgbe_msix_other is called. There is a race
2819 * condition otherwise which results in possible performance loss
2820 * especially if the ixgbe_msix_other interrupt is triggering
2821 * consistently (as it would when PPS is turned on for the X540 device)
2822 */
2823 eicr &= 0xFFFF0000;
2824
Alexander Duyck2c4af692011-07-15 07:29:55 +00002825 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002826
Alexander Duyck2c4af692011-07-15 07:29:55 +00002827 if (eicr & IXGBE_EICR_LSC)
2828 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002829
Alexander Duyck2c4af692011-07-15 07:29:55 +00002830 if (eicr & IXGBE_EICR_MAILBOX)
2831 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002832
Alexander Duyck2c4af692011-07-15 07:29:55 +00002833 switch (hw->mac.type) {
2834 case ixgbe_mac_82599EB:
2835 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002836 case ixgbe_mac_X550:
2837 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002838 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07002839 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
2840 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
2841 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
2842 ixgbe_service_event_schedule(adapter);
2843 IXGBE_WRITE_REG(hw, IXGBE_EICR,
2844 IXGBE_EICR_GPI_SDP0_X540);
2845 }
Don Skidmored773ce22014-02-25 17:58:53 -08002846 if (eicr & IXGBE_EICR_ECC) {
2847 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07002848 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08002849 ixgbe_service_event_schedule(adapter);
2850 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2851 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002852 /* Handle Flow Director Full threshold interrupt */
2853 if (eicr & IXGBE_EICR_FLOW_DIR) {
2854 int reinit_count = 0;
2855 int i;
2856 for (i = 0; i < adapter->num_tx_queues; i++) {
2857 struct ixgbe_ring *ring = adapter->tx_ring[i];
2858 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2859 &ring->state))
2860 reinit_count++;
2861 }
2862 if (reinit_count) {
2863 /* no more flow director interrupts until after init */
2864 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2865 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2866 ixgbe_service_event_schedule(adapter);
2867 }
2868 }
2869 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002870 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002871 break;
2872 default:
2873 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002874 }
2875
Alexander Duyck2c4af692011-07-15 07:29:55 +00002876 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002877
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002878 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07002879 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002880
Alexander Duyck2c4af692011-07-15 07:29:55 +00002881 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002882 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002883 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002884
Alexander Duyck2c4af692011-07-15 07:29:55 +00002885 return IRQ_HANDLED;
2886}
2887
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002888static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002889{
2890 struct ixgbe_q_vector *q_vector = data;
2891
Auke Kok9a799d72007-09-15 14:07:45 -07002892 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002893
2894 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07002895 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002896
2897 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002898}
2899
Auke Kok9a799d72007-09-15 14:07:45 -07002900/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002901 * ixgbe_poll - NAPI Rx polling callback
2902 * @napi: structure for representing this polling device
2903 * @budget: how many packets driver is allowed to clean
2904 *
2905 * This function is used for legacy and MSI, NAPI mode
2906 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002907int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002908{
2909 struct ixgbe_q_vector *q_vector =
2910 container_of(napi, struct ixgbe_q_vector, napi);
2911 struct ixgbe_adapter *adapter = q_vector->adapter;
2912 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002913 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00002914 bool clean_complete = true;
2915
2916#ifdef CONFIG_IXGBE_DCA
2917 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2918 ixgbe_update_dca(q_vector);
2919#endif
2920
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002921 ixgbe_for_each_ring(ring, q_vector->tx) {
2922 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
2923 clean_complete = false;
2924 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002925
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08002926 /* Exit if we are called by netpoll */
2927 if (budget <= 0)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002928 return budget;
2929
Alexander Duyckeb01b972012-02-08 07:51:27 +00002930 /* attempt to distribute budget to each queue fairly, but don't allow
2931 * the budget to go below 1 because we'll exit polling */
2932 if (q_vector->rx.count > 1)
2933 per_ring_budget = max(budget/q_vector->rx.count, 1);
2934 else
2935 per_ring_budget = budget;
2936
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002937 ixgbe_for_each_ring(ring, q_vector->rx) {
2938 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
2939 per_ring_budget);
2940
2941 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002942 if (cleaned >= per_ring_budget)
2943 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002944 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002945
2946 /* If all work not completed, return budget and keep polling */
2947 if (!clean_complete)
2948 return budget;
2949
2950 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002951 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002952 if (adapter->rx_itr_setting & 1)
2953 ixgbe_set_itr(q_vector);
2954 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002955 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00002956
Paolo Abeni4b732cd2016-06-15 15:37:59 +02002957 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002958}
2959
2960/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002961 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2962 * @adapter: board private structure
2963 *
2964 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2965 * interrupts from the kernel.
2966 **/
2967static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2968{
2969 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002970 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002971 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002972
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002973 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002974 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002975 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002976
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002977 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002978 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002979 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002980 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002981 } else if (q_vector->rx.ring) {
2982 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2983 "%s-%s-%d", netdev->name, "rx", ri++);
2984 } else if (q_vector->tx.ring) {
2985 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2986 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002987 } else {
2988 /* skip this unused q_vector */
2989 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002990 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002991 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2992 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002993 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002994 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002995 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002996 goto free_queue_irqs;
2997 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002998 /* If Flow Director is enabled, set interrupt affinity */
2999 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3000 /* assign the mask for this irq */
3001 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00003002 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00003003 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003004 }
3005
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003006 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00003007 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003008 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00003009 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003010 goto free_queue_irqs;
3011 }
3012
3013 return 0;
3014
3015free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00003016 while (vector) {
3017 vector--;
3018 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3019 NULL);
3020 free_irq(adapter->msix_entries[vector].vector,
3021 adapter->q_vector[vector]);
3022 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003023 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3024 pci_disable_msix(adapter->pdev);
3025 kfree(adapter->msix_entries);
3026 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003027 return err;
3028}
3029
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08003030/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003031 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07003032 * @irq: interrupt number
3033 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07003034 **/
3035static irqreturn_t ixgbe_intr(int irq, void *data)
3036{
Alexander Duycka65151ba22011-05-27 05:31:32 +00003037 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07003038 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003039 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003040 u32 eicr;
3041
Don Skidmore54037502009-02-21 15:42:56 -08003042 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00003043 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08003044 * before the read of EICR.
3045 */
3046 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3047
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003048 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003049 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003050 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003051 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003052 /*
3053 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003054 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003055 * have disabled interrupts due to EIAM
3056 * finish the workaround of silicon errata on 82598. Unmask
3057 * the interrupt that we masked before the EICR read.
3058 */
3059 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3060 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003061 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003062 }
Auke Kok9a799d72007-09-15 14:07:45 -07003063
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003064 if (eicr & IXGBE_EICR_LSC)
3065 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003066
Alexander Duyckbd508172010-11-16 19:27:03 -08003067 switch (hw->mac.type) {
3068 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003069 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003070 /* Fall through */
3071 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003072 case ixgbe_mac_X550:
3073 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003074 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003075 if (eicr & IXGBE_EICR_ECC) {
3076 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003077 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003078 ixgbe_service_event_schedule(adapter);
3079 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3080 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003081 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003082 break;
3083 default:
3084 break;
3085 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003086
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003087 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003088 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003089 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003090
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003091 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003092 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003093
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003094 /*
3095 * re-enable link(maybe) and non-queue interrupts, no flush.
3096 * ixgbe_poll will re-enable the queue interrupts
3097 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003098 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3099 ixgbe_irq_enable(adapter, false, false);
3100
Auke Kok9a799d72007-09-15 14:07:45 -07003101 return IRQ_HANDLED;
3102}
3103
3104/**
3105 * ixgbe_request_irq - initialize interrupts
3106 * @adapter: board private structure
3107 *
3108 * Attempts to configure interrupts using the best available
3109 * capabilities of the hardware and kernel.
3110 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003111static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003112{
3113 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003114 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003115
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003116 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003117 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003118 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003119 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003120 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003121 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003122 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003123 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003124
Alexander Duyckde88eee2012-02-08 07:49:59 +00003125 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003126 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003127
Auke Kok9a799d72007-09-15 14:07:45 -07003128 return err;
3129}
3130
3131static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3132{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003133 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003134
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003135 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003136 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003137 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003138 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003139
Mark Rustad1fa71252016-09-28 15:36:38 -07003140 if (!adapter->msix_entries)
3141 return;
3142
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003143 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3144 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3145 struct msix_entry *entry = &adapter->msix_entries[vector];
3146
3147 /* free only the irqs that were actually requested */
3148 if (!q_vector->rx.ring && !q_vector->tx.ring)
3149 continue;
3150
3151 /* clear the affinity_mask in the IRQ descriptor */
3152 irq_set_affinity_hint(entry->vector, NULL);
3153
3154 free_irq(entry->vector, q_vector);
3155 }
3156
Babu Moger90c6f872016-06-18 17:40:47 -07003157 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003158}
3159
3160/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003161 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3162 * @adapter: board private structure
3163 **/
3164static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3165{
Alexander Duyckbd508172010-11-16 19:27:03 -08003166 switch (adapter->hw.mac.type) {
3167 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003168 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003169 break;
3170 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003171 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003172 case ixgbe_mac_X550:
3173 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003174 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003175 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3176 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003177 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003178 break;
3179 default:
3180 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003181 }
3182 IXGBE_WRITE_FLUSH(&adapter->hw);
3183 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003184 int vector;
3185
3186 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3187 synchronize_irq(adapter->msix_entries[vector].vector);
3188
3189 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003190 } else {
3191 synchronize_irq(adapter->pdev->irq);
3192 }
3193}
3194
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003195/**
Auke Kok9a799d72007-09-15 14:07:45 -07003196 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3197 *
3198 **/
3199static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3200{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003201 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003202
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003203 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003204
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003205 ixgbe_set_ivar(adapter, 0, 0, 0);
3206 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003207
Emil Tantilov396e7992010-07-01 20:05:12 +00003208 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003209}
3210
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003211/**
3212 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3213 * @adapter: board private structure
3214 * @ring: structure containing ring specific data
3215 *
3216 * Configure the Tx descriptor ring after a reset.
3217 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003218void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3219 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003220{
3221 struct ixgbe_hw *hw = &adapter->hw;
3222 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003223 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003224 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003225 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003226
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003227 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003228 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003229 IXGBE_WRITE_FLUSH(hw);
3230
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003231 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003232 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003233 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3234 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3235 ring->count * sizeof(union ixgbe_adv_tx_desc));
3236 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3237 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003238 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003239
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003240 /*
3241 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003242 * higher than 1 when:
3243 * - ITR is 0 as it could cause false TX hangs
3244 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003245 *
3246 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3247 * to or less than the number of on chip descriptors, which is
3248 * currently 40.
3249 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003250 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003251 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003252 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003253 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003254
Alexander Duycke954b372012-02-08 07:49:38 +00003255 /*
3256 * Setting PTHRESH to 32 both improves performance
3257 * and avoids a TX hang with DFP enabled
3258 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003259 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003260 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003261
3262 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003263 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003264 ring->atr_sample_rate = adapter->atr_sample_rate;
3265 ring->atr_count = 0;
3266 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3267 } else {
3268 ring->atr_sample_rate = 0;
3269 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003270
Alexander Duyckfd786b72013-01-12 06:33:31 +00003271 /* initialize XPS */
3272 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3273 struct ixgbe_q_vector *q_vector = ring->q_vector;
3274
3275 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003276 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003277 &q_vector->affinity_mask,
3278 ring->queue_index);
3279 }
3280
John Fastabendc84d3242010-11-16 19:27:12 -08003281 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3282
Alexander Duyckffed21b2017-01-17 08:37:29 -08003283 /* reinitialize tx_buffer_info */
3284 memset(ring->tx_buffer_info, 0,
3285 sizeof(struct ixgbe_tx_buffer) * ring->count);
3286
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003287 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003288 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3289
3290 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3291 if (hw->mac.type == ixgbe_mac_82598EB &&
3292 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3293 return;
3294
3295 /* poll to verify queue is enabled */
3296 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003297 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003298 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3299 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3300 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003301 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003302}
3303
Alexander Duyck120ff942010-08-19 13:34:50 +00003304static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3305{
3306 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003307 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003308 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003309
3310 if (hw->mac.type == ixgbe_mac_82598EB)
3311 return;
3312
3313 /* disable the arbiter while setting MTQC */
3314 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3315 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3316 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3317
3318 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003319 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3320 mtqc = IXGBE_MTQC_VT_ENA;
3321 if (tcs > 4)
3322 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3323 else if (tcs > 1)
3324 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003325 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3326 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003327 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003328 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003329 mtqc |= IXGBE_MTQC_64VF;
3330 } else {
3331 if (tcs > 4)
3332 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3333 else if (tcs > 1)
3334 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3335 else
3336 mtqc = IXGBE_MTQC_64Q_1PB;
3337 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003338
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003339 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003340
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003341 /* Enable Security TX Buffer IFG for multiple pb */
3342 if (tcs) {
3343 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3344 sectx |= IXGBE_SECTX_DCB;
3345 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003346 }
3347
3348 /* re-enable the arbiter */
3349 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3350 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3351}
3352
Auke Kok9a799d72007-09-15 14:07:45 -07003353/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003354 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003355 * @adapter: board private structure
3356 *
3357 * Configure the Tx unit of the MAC after a reset.
3358 **/
3359static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3360{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003361 struct ixgbe_hw *hw = &adapter->hw;
3362 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003363 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003364
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003365 ixgbe_setup_mtqc(adapter);
3366
3367 if (hw->mac.type != ixgbe_mac_82598EB) {
3368 /* DMATXCTL.EN must be before Tx queues are enabled */
3369 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3370 dmatxctl |= IXGBE_DMATXCTL_TE;
3371 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3372 }
3373
Auke Kok9a799d72007-09-15 14:07:45 -07003374 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003375 for (i = 0; i < adapter->num_tx_queues; i++)
3376 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003377}
3378
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003379static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3380 struct ixgbe_ring *ring)
3381{
3382 struct ixgbe_hw *hw = &adapter->hw;
3383 u8 reg_idx = ring->reg_idx;
3384 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3385
3386 srrctl |= IXGBE_SRRCTL_DROP_EN;
3387
3388 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3389}
3390
3391static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3392 struct ixgbe_ring *ring)
3393{
3394 struct ixgbe_hw *hw = &adapter->hw;
3395 u8 reg_idx = ring->reg_idx;
3396 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3397
3398 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3399
3400 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3401}
3402
3403#ifdef CONFIG_IXGBE_DCB
3404void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3405#else
3406static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3407#endif
3408{
3409 int i;
3410 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3411
3412 if (adapter->ixgbe_ieee_pfc)
3413 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3414
3415 /*
3416 * We should set the drop enable bit if:
3417 * SR-IOV is enabled
3418 * or
3419 * Number of Rx queues > 1 and flow control is disabled
3420 *
3421 * This allows us to avoid head of line blocking for security
3422 * and performance reasons.
3423 */
3424 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3425 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3426 for (i = 0; i < adapter->num_rx_queues; i++)
3427 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3428 } else {
3429 for (i = 0; i < adapter->num_rx_queues; i++)
3430 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3431 }
3432}
3433
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003434#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003435
Yi Zoua6616b42009-08-06 13:05:23 +00003436static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003437 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003438{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003439 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003440 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003441 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003442
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003443 if (hw->mac.type == ixgbe_mac_82598EB) {
3444 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3445
3446 /*
3447 * if VMDq is not active we must program one srrctl register
3448 * per RSS queue since we have enabled RDRXCTL.MVMEN
3449 */
3450 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003451 }
3452
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003453 /* configure header buffer length, needed for RSC */
3454 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003455
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003456 /* configure the packet buffer length */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003457 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3458 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3459 else
3460 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003461
3462 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003463 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003464
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003465 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003466}
3467
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003468/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003469 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003470 * @adapter: device handle
3471 *
3472 * - 82598/82599/X540: 128
3473 * - X550(non-SRIOV mode): 512
3474 * - X550(SRIOV mode): 64
3475 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003476u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003477{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003478 if (adapter->hw.mac.type < ixgbe_mac_X550)
3479 return 128;
3480 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3481 return 64;
3482 else
3483 return 512;
3484}
3485
3486/**
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003487 * ixgbe_store_key - Write the RSS key to HW
3488 * @adapter: device handle
3489 *
3490 * Write the RSS key stored in adapter.rss_key to HW.
3491 */
3492void ixgbe_store_key(struct ixgbe_adapter *adapter)
3493{
3494 struct ixgbe_hw *hw = &adapter->hw;
3495 int i;
3496
3497 for (i = 0; i < 10; i++)
3498 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3499}
3500
3501/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003502 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003503 * @adapter: device handle
3504 *
3505 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3506 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003507void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003508{
3509 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003510 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003511 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003512 u32 indices_multi;
3513 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003514
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003515 /* Fill out the redirection table as follows:
3516 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3517 * indices.
3518 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3519 * - X550: 8 bit wide entries containing 6 bit RSS index
3520 */
3521 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3522 indices_multi = 0x11;
3523 else
3524 indices_multi = 0x1;
3525
3526 /* Write redirection table to HW */
3527 for (i = 0; i < reta_entries; i++) {
3528 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3529 if ((i & 3) == 3) {
3530 if (i < 128)
3531 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3532 else
3533 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3534 reta);
3535 reta = 0;
3536 }
3537 }
3538}
3539
3540/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003541 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003542 * @adapter: device handle
3543 *
3544 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3545 */
3546static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3547{
3548 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3549 struct ixgbe_hw *hw = &adapter->hw;
3550 u32 vfreta = 0;
3551 unsigned int pf_pool = adapter->num_vfs;
3552
3553 /* Write redirection table to HW */
3554 for (i = 0; i < reta_entries; i++) {
3555 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3556 if ((i & 3) == 3) {
3557 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3558 vfreta);
3559 vfreta = 0;
3560 }
3561 }
3562}
3563
3564static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3565{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003566 u32 i, j;
3567 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3568 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3569
Alexander Duycke24fcf22016-09-07 20:28:24 -07003570 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003571 * make full use of any rings they may have. We will use the
3572 * PSRTYPE register to control how many rings we use within the PF.
3573 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003574 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3575 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003576
Alexander Duyck05abb122010-08-19 13:35:41 +00003577 /* Fill out hash function seeds */
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003578 ixgbe_store_key(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003579
Alexander Duyck05abb122010-08-19 13:35:41 +00003580 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003581 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3582
Don Skidmore0f9b2322014-11-18 09:35:08 +00003583 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003584 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003585 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003586
3587 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003588 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003589
3590 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003591}
3592
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003593static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003594{
3595 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003596 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3597 unsigned int pf_pool = adapter->num_vfs;
3598 int i, j;
3599
3600 /* Fill out hash function seeds */
3601 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003602 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
3603 adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003604
3605 /* Fill out the redirection table */
3606 for (i = 0, j = 0; i < 64; i++, j++) {
3607 if (j == rss_i)
3608 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003609
3610 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003611 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003612
3613 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003614}
3615
3616static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3617{
3618 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003619 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003620 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003621
3622 /* Disable indicating checksum in descriptor, enables RSS hash */
3623 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3624 rxcsum |= IXGBE_RXCSUM_PCSD;
3625 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3626
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003627 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003628 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003629 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003630 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003631 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003632
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003633 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3634 if (tcs > 4)
3635 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3636 else if (tcs > 1)
3637 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003638 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3639 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003640 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3641 else
3642 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3643 } else {
3644 if (tcs > 4)
3645 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3646 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003647 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3648 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003649 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003650 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003651 }
3652
Alexander Duyck05abb122010-08-19 13:35:41 +00003653 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003654 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3655 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3656 IXGBE_MRQC_RSS_FIELD_IPV6 |
3657 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003658
Alexander Duyckef6afc02012-02-08 07:51:53 +00003659 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003660 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003661 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003662 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003663
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003664 netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003665 if ((hw->mac.type >= ixgbe_mac_X550) &&
3666 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3667 unsigned int pf_pool = adapter->num_vfs;
3668
3669 /* Enable VF RSS mode */
3670 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3671 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3672
3673 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003674 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003675 vfmrqc = IXGBE_MRQC_RSSEN;
3676 vfmrqc |= rss_field;
3677 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3678 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003679 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003680 mrqc |= rss_field;
3681 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3682 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003683}
3684
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003685/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003686 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3687 * @adapter: address of board private structure
3688 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003689 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003690static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003691 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003692{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003693 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003694 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003695 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003696
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003697 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003698 return;
3699
Alexander Duyck73670962010-08-19 13:38:34 +00003700 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003701 rscctrl |= IXGBE_RSCCTL_RSCEN;
3702 /*
3703 * we must limit the number of descriptors so that the
3704 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003705 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003706 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003707 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003708 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003709}
3710
Alexander Duyck9e10e042010-08-19 13:40:06 +00003711#define IXGBE_MAX_RX_DESC_POLL 10
3712static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3713 struct ixgbe_ring *ring)
3714{
3715 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003716 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3717 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003718 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003719
Mark Rustadb0483c82014-01-14 18:53:17 -08003720 if (ixgbe_removed(hw->hw_addr))
3721 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003722 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3723 if (hw->mac.type == ixgbe_mac_82598EB &&
3724 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3725 return;
3726
3727 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003728 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003729 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3730 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3731
3732 if (!wait_loop) {
3733 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3734 "the polling period\n", reg_idx);
3735 }
3736}
3737
Yi Zou2d39d572011-01-06 14:29:56 +00003738void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3739 struct ixgbe_ring *ring)
3740{
3741 struct ixgbe_hw *hw = &adapter->hw;
3742 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3743 u32 rxdctl;
3744 u8 reg_idx = ring->reg_idx;
3745
Mark Rustadb0483c82014-01-14 18:53:17 -08003746 if (ixgbe_removed(hw->hw_addr))
3747 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003748 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3749 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3750
3751 /* write value back with RXDCTL.ENABLE bit cleared */
3752 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3753
3754 if (hw->mac.type == ixgbe_mac_82598EB &&
3755 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3756 return;
3757
3758 /* the hardware may take up to 100us to really disable the rx queue */
3759 do {
3760 udelay(10);
3761 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3762 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3763
3764 if (!wait_loop) {
3765 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3766 "the polling period\n", reg_idx);
3767 }
3768}
3769
Alexander Duyck84418e32010-08-19 13:40:54 +00003770void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3771 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003772{
3773 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc3630cc2017-01-17 08:36:28 -08003774 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyckacd37172010-08-19 13:36:05 +00003775 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003776 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003777 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003778
Alexander Duyck9e10e042010-08-19 13:40:06 +00003779 /* disable queue to avoid issues while updating state */
3780 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003781 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003782
Alexander Duyckacd37172010-08-19 13:36:05 +00003783 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3784 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3785 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3786 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08003787 /* Force flushing of IXGBE_RDLEN to prevent MDD */
3788 IXGBE_WRITE_FLUSH(hw);
3789
Alexander Duyckacd37172010-08-19 13:36:05 +00003790 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3791 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003792 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003793
3794 ixgbe_configure_srrctl(adapter, ring);
3795 ixgbe_configure_rscctl(adapter, ring);
3796
3797 if (hw->mac.type == ixgbe_mac_82598EB) {
3798 /*
3799 * enable cache line friendly hardware writes:
3800 * PTHRESH=32 descriptors (half the internal cache),
3801 * this also removes ugly rx_no_buffer_count increment
3802 * HTHRESH=4 descriptors (to minimize latency on fetch)
3803 * WTHRESH=8 burst writeback up to two cache lines
3804 */
3805 rxdctl &= ~0x3FFFFF;
3806 rxdctl |= 0x080420;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003807#if (PAGE_SIZE < 8192)
3808 } else {
3809 rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
3810 IXGBE_RXDCTL_RLPML_EN);
3811
3812 /* Limit the maximum frame size so we don't overrun the skb */
3813 if (ring_uses_build_skb(ring) &&
3814 !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
3815 rxdctl |= IXGBE_MAX_FRAME_BUILD_SKB |
3816 IXGBE_RXDCTL_RLPML_EN;
3817#endif
Alexander Duyck9e10e042010-08-19 13:40:06 +00003818 }
3819
Alexander Duyckffed21b2017-01-17 08:37:29 -08003820 /* initialize rx_buffer_info */
3821 memset(ring->rx_buffer_info, 0,
3822 sizeof(struct ixgbe_rx_buffer) * ring->count);
3823
Alexander Duyckc3630cc2017-01-17 08:36:28 -08003824 /* initialize Rx descriptor 0 */
3825 rx_desc = IXGBE_RX_DESC(ring, 0);
3826 rx_desc->wb.upper.length = 0;
3827
Alexander Duyck9e10e042010-08-19 13:40:06 +00003828 /* enable receive descriptor ring */
3829 rxdctl |= IXGBE_RXDCTL_ENABLE;
3830 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3831
3832 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003833 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003834}
3835
Alexander Duyck48654522010-08-19 13:36:27 +00003836static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3837{
3838 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003839 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003840 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003841
3842 /* PSRTYPE must be initialized in non 82598 adapters */
3843 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003844 IXGBE_PSRTYPE_UDPHDR |
3845 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003846 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003847 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003848
3849 if (hw->mac.type == ixgbe_mac_82598EB)
3850 return;
3851
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003852 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003853 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003854 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003855 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003856
John Fastabend2a47fa42013-11-06 09:54:52 -08003857 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3858 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003859}
3860
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003861static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3862{
3863 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003864 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003865 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003866 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003867
3868 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3869 return;
3870
3871 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003872 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3873 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003874 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003875 vmdctl |= IXGBE_VT_CTL_REPLEN;
3876 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003877
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003878 vf_shift = VMDQ_P(0) % 32;
3879 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003880
3881 /* Enable only the PF's pool for Tx/Rx */
Emil Tantilov11f2b492016-05-04 15:01:27 -07003882 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00003883 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
Emil Tantilov11f2b492016-05-04 15:01:27 -07003884 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00003885 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07003886 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00003887 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003888
3889 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003890 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003891
Alexander Duyck16369562015-11-02 17:10:13 -08003892 /* clear VLAN promisc flag so VFTA will be updated if necessary */
3893 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
3894
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003895 /*
3896 * Set up VF register offsets for selected VT Mode,
3897 * i.e. 32 or 64 VFs for SR-IOV
3898 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003899 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3900 case IXGBE_82599_VMDQ_8Q_MASK:
3901 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3902 break;
3903 case IXGBE_82599_VMDQ_4Q_MASK:
3904 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3905 break;
3906 default:
3907 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3908 break;
3909 }
3910
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003911 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3912
Greg Rosede4c7f62011-09-29 05:57:33 +00003913 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07003914 /* configure spoof checking */
3915 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
3916 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03003917
3918 /* Enable/Disable RSS query feature */
3919 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
3920 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00003921 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003922}
3923
Alexander Duyck477de6e2010-08-19 13:38:11 +00003924static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003925{
Auke Kok9a799d72007-09-15 14:07:45 -07003926 struct ixgbe_hw *hw = &adapter->hw;
3927 struct net_device *netdev = adapter->netdev;
3928 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003929 struct ixgbe_ring *rx_ring;
3930 int i;
3931 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003932
Alexander Duyck477de6e2010-08-19 13:38:11 +00003933#ifdef IXGBE_FCOE
3934 /* adjust max frame to be able to do baby jumbo for FCoE */
3935 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3936 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3937 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3938
3939#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003940
3941 /* adjust max frame to be at least the size of a standard frame */
3942 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3943 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3944
Alexander Duyck477de6e2010-08-19 13:38:11 +00003945 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3946 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3947 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3948 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3949
3950 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003951 }
3952
Auke Kok9a799d72007-09-15 14:07:45 -07003953 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003954 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3955 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003956 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3957
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003958 /*
3959 * Setup the HW Rx Head and Tail Descriptor Pointers and
3960 * the Base and Length of the Rx Descriptor Ring
3961 */
Auke Kok9a799d72007-09-15 14:07:45 -07003962 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003963 rx_ring = adapter->rx_ring[i];
Alexander Duyck4f4542b2017-01-17 08:36:14 -08003964
3965 clear_ring_rsc_enabled(rx_ring);
3966 clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003967 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08003968
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003969 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3970 set_ring_rsc_enabled(rx_ring);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08003971
3972 if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
3973 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003974
Alexander Duyck6f429222017-01-17 08:37:13 -08003975 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003976 if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
3977 continue;
3978
3979 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
3980
3981#if (PAGE_SIZE < 8192)
3982 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3983 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
3984
Alexander Duyckc74042f2017-02-03 09:19:40 -08003985 if ((max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
3986 (max_frame > IXGBE_MAX_FRAME_BUILD_SKB))
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003987 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
3988#endif
Alexander Duyck477de6e2010-08-19 13:38:11 +00003989 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003990}
3991
Alexander Duyck73670962010-08-19 13:38:34 +00003992static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3993{
3994 struct ixgbe_hw *hw = &adapter->hw;
3995 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3996
3997 switch (hw->mac.type) {
3998 case ixgbe_mac_82598EB:
3999 /*
4000 * For VMDq support of different descriptor types or
4001 * buffer sizes through the use of multiple SRRCTL
4002 * registers, RDRXCTL.MVMEN must be set to 1
4003 *
4004 * also, the manual doesn't mention it clearly but DCA hints
4005 * will only use queue 0's tags unless this bit is set. Side
4006 * effects of setting this bit are only that SRRCTL must be
4007 * fully programmed [0..15]
4008 */
4009 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
4010 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07004011 case ixgbe_mac_X550:
4012 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004013 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07004014 if (adapter->num_vfs)
4015 rdrxctl |= IXGBE_RDRXCTL_PSP;
4016 /* fall through for older HW */
Alexander Duyck73670962010-08-19 13:38:34 +00004017 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004018 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00004019 /* Disable RSC for ACK packets */
4020 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
4021 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
4022 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
4023 /* hardware requires some bits to be set by default */
4024 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
4025 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
4026 break;
4027 default:
4028 /* We should do nothing since we don't know this hardware */
4029 return;
4030 }
4031
4032 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
4033}
4034
Alexander Duyck477de6e2010-08-19 13:38:11 +00004035/**
4036 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4037 * @adapter: board private structure
4038 *
4039 * Configure the Rx unit of the MAC after a reset.
4040 **/
4041static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
4042{
4043 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004044 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004045 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004046
4047 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07004048 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004049
4050 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00004051 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004052
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004053 /* RSC Setup */
4054 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4055 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
4056 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
4057 rfctl |= IXGBE_RFCTL_RSC_DIS;
Emil Tantilova21d0822016-08-10 11:19:23 -07004058
4059 /* disable NFS filtering */
4060 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004061 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
4062
Alexander Duyck9e10e042010-08-19 13:40:06 +00004063 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004064 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004065
Alexander Duyck477de6e2010-08-19 13:38:11 +00004066 /* set_rx_buffer_len must be called before ring initialization */
4067 ixgbe_set_rx_buffer_len(adapter);
4068
4069 /*
4070 * Setup the HW Rx Head and Tail Descriptor Pointers and
4071 * the Base and Length of the Rx Descriptor Ring
4072 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00004073 for (i = 0; i < adapter->num_rx_queues; i++)
4074 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004075
Don Skidmore1f9ac572015-03-13 13:54:30 -07004076 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004077 /* disable drop enable for 82598 parts */
4078 if (hw->mac.type == ixgbe_mac_82598EB)
4079 rxctrl |= IXGBE_RXCTRL_DMBYPS;
4080
4081 /* enable all receives */
4082 rxctrl |= IXGBE_RXCTRL_RXEN;
4083 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004084}
4085
Patrick McHardy80d5c362013-04-19 02:04:28 +00004086static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
4087 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004088{
4089 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004090 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004091
4092 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004093 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4094 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
4095
Jesse Grossf62bbb52010-10-20 13:56:10 +00004096 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004097
4098 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004099}
4100
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004101static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
4102{
4103 u32 vlvf;
4104 int idx;
4105
4106 /* short cut the special case */
4107 if (vlan == 0)
4108 return 0;
4109
4110 /* Search for the vlan id in the VLVF entries */
4111 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
4112 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
4113 if ((vlvf & VLAN_VID_MASK) == vlan)
4114 break;
4115 }
4116
4117 return idx;
4118}
4119
4120void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
4121{
4122 struct ixgbe_hw *hw = &adapter->hw;
4123 u32 bits, word;
4124 int idx;
4125
4126 idx = ixgbe_find_vlvf_entry(hw, vid);
4127 if (!idx)
4128 return;
4129
4130 /* See if any other pools are set for this VLAN filter
4131 * entry other than the PF.
4132 */
4133 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004134 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004135 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4136
4137 /* Disable the filter so this falls into the default pool. */
4138 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4139 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4140 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4141 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4142 }
4143}
4144
Patrick McHardy80d5c362013-04-19 02:04:28 +00004145static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4146 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004147{
4148 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004149 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004150
Auke Kok9a799d72007-09-15 14:07:45 -07004151 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004152 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004153 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4154
Jesse Grossf62bbb52010-10-20 13:56:10 +00004155 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004156
4157 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004158}
4159
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004160/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004161 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4162 * @adapter: driver data
4163 */
4164static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4165{
4166 struct ixgbe_hw *hw = &adapter->hw;
4167 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004168 int i, j;
4169
4170 switch (hw->mac.type) {
4171 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004172 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4173 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004174 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4175 break;
4176 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004177 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004178 case ixgbe_mac_X550:
4179 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004180 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004181 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004182 struct ixgbe_ring *ring = adapter->rx_ring[i];
4183
4184 if (ring->l2_accel_priv)
4185 continue;
4186 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004187 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4188 vlnctrl &= ~IXGBE_RXDCTL_VME;
4189 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4190 }
4191 break;
4192 default:
4193 break;
4194 }
4195}
4196
4197/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004198 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004199 * @adapter: driver data
4200 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004201static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004202{
4203 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004204 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004205 int i, j;
4206
4207 switch (hw->mac.type) {
4208 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004209 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4210 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004211 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4212 break;
4213 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004214 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004215 case ixgbe_mac_X550:
4216 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004217 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004218 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004219 struct ixgbe_ring *ring = adapter->rx_ring[i];
4220
4221 if (ring->l2_accel_priv)
4222 continue;
4223 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004224 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4225 vlnctrl |= IXGBE_RXDCTL_VME;
4226 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4227 }
4228 break;
4229 default:
4230 break;
4231 }
4232}
4233
Alexander Duyck16369562015-11-02 17:10:13 -08004234static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4235{
4236 struct ixgbe_hw *hw = &adapter->hw;
4237 u32 vlnctrl, i;
4238
Alexander Duyckf60439b2016-08-11 14:51:56 -07004239 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4240
Emil Tantilov691e4122016-08-22 16:17:46 -07004241 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4242 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4243 vlnctrl |= IXGBE_VLNCTRL_VFE;
4244 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4245 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004246 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004247 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4248 return;
4249 }
4250
Emil Tantilov691e4122016-08-22 16:17:46 -07004251 /* Nothing to do for 82598 */
4252 if (hw->mac.type == ixgbe_mac_82598EB)
4253 return;
4254
Alexander Duyck16369562015-11-02 17:10:13 -08004255 /* We are already in VLAN promisc, nothing to do */
4256 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4257 return;
4258
4259 /* Set flag so we don't redo unnecessary work */
4260 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4261
4262 /* Add PF to all active pools */
4263 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4264 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4265 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4266
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004267 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004268 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4269 }
4270
4271 /* Set all bits in the VLAN filter table array */
4272 for (i = hw->mac.vft_size; i--;)
4273 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4274}
4275
4276#define VFTA_BLOCK_SIZE 8
4277static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4278{
4279 struct ixgbe_hw *hw = &adapter->hw;
4280 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4281 u32 vid_start = vfta_offset * 32;
4282 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4283 u32 i, vid, word, bits;
4284
4285 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4286 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4287
4288 /* pull VLAN ID from VLVF */
4289 vid = vlvf & VLAN_VID_MASK;
4290
4291 /* only concern outselves with a certain range */
4292 if (vid < vid_start || vid >= vid_end)
4293 continue;
4294
4295 if (vlvf) {
4296 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004297 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004298
4299 /* if PF is part of this then continue */
4300 if (test_bit(vid, adapter->active_vlans))
4301 continue;
4302 }
4303
4304 /* remove PF from the pool */
4305 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004306 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004307 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4308 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4309 }
4310
4311 /* extract values from active_vlans and write back to VFTA */
4312 for (i = VFTA_BLOCK_SIZE; i--;) {
4313 vid = (vfta_offset + i) * 32;
4314 word = vid / BITS_PER_LONG;
4315 bits = vid % BITS_PER_LONG;
4316
4317 vfta[i] |= adapter->active_vlans[word] >> bits;
4318
4319 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4320 }
4321}
4322
4323static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4324{
4325 struct ixgbe_hw *hw = &adapter->hw;
4326 u32 vlnctrl, i;
4327
Alexander Duyckf60439b2016-08-11 14:51:56 -07004328 /* Set VLAN filtering to enabled */
4329 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4330 vlnctrl |= IXGBE_VLNCTRL_VFE;
4331 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4332
Emil Tantilov691e4122016-08-22 16:17:46 -07004333 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4334 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004335 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004336
4337 /* We are not in VLAN promisc, nothing to do */
4338 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4339 return;
4340
4341 /* Set flag so we don't redo unnecessary work */
4342 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4343
4344 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4345 ixgbe_scrub_vfta(adapter, i);
4346}
4347
Auke Kok9a799d72007-09-15 14:07:45 -07004348static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4349{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004350 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004351
Patrick McHardy80d5c362013-04-19 02:04:28 +00004352 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004353
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004354 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004355 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004356}
4357
4358/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004359 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4360 * @netdev: network interface device structure
4361 *
4362 * Writes multicast address list to the MTA hash table.
4363 * Returns: -ENOMEM on failure
4364 * 0 on no addresses written
4365 * X on writing X addresses to MTA
4366 **/
4367static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4368{
4369 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4370 struct ixgbe_hw *hw = &adapter->hw;
4371
4372 if (!netif_running(netdev))
4373 return 0;
4374
4375 if (hw->mac.ops.update_mc_addr_list)
4376 hw->mac.ops.update_mc_addr_list(hw, netdev);
4377 else
4378 return -ENOMEM;
4379
4380#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004381 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004382#endif
4383
4384 return netdev_mc_count(netdev);
4385}
4386
Jacob Keller5d7daa32014-03-29 06:51:25 +00004387#ifdef CONFIG_PCI_IOV
4388void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4389{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004390 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004391 struct ixgbe_hw *hw = &adapter->hw;
4392 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004393
4394 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4395 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4396
4397 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4398 hw->mac.ops.set_rar(hw, i,
4399 mac_table->addr,
4400 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004401 IXGBE_RAH_AV);
4402 else
4403 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004404 }
4405}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004406
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004407#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004408static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4409{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004410 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004411 struct ixgbe_hw *hw = &adapter->hw;
4412 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004413
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004414 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4415 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4416 continue;
4417
4418 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4419
4420 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4421 hw->mac.ops.set_rar(hw, i,
4422 mac_table->addr,
4423 mac_table->pool,
4424 IXGBE_RAH_AV);
4425 else
4426 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004427 }
4428}
4429
4430static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4431{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004432 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004433 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004434 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004435
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004436 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4437 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4438 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004439 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004440
Jacob Keller5d7daa32014-03-29 06:51:25 +00004441 ixgbe_sync_mac_table(adapter);
4442}
4443
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004444static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004445{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004446 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004447 struct ixgbe_hw *hw = &adapter->hw;
4448 int i, count = 0;
4449
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004450 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4451 /* do not count default RAR as available */
4452 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4453 continue;
4454
4455 /* only count unused and addresses that belong to us */
4456 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4457 if (mac_table->pool != pool)
4458 continue;
4459 }
4460
4461 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004462 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004463
Jacob Keller5d7daa32014-03-29 06:51:25 +00004464 return count;
4465}
4466
4467/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004468static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004469{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004470 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004471 struct ixgbe_hw *hw = &adapter->hw;
4472
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004473 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4474 mac_table->pool = VMDQ_P(0);
4475
4476 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4477
4478 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004479 IXGBE_RAH_AV);
4480}
4481
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004482int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4483 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004484{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004485 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004486 struct ixgbe_hw *hw = &adapter->hw;
4487 int i;
4488
4489 if (is_zero_ether_addr(addr))
4490 return -EINVAL;
4491
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004492 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4493 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004494 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004495
4496 ether_addr_copy(mac_table->addr, addr);
4497 mac_table->pool = pool;
4498
4499 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4500 IXGBE_MAC_STATE_IN_USE;
4501
Jacob Keller5d7daa32014-03-29 06:51:25 +00004502 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004503
Jacob Keller5d7daa32014-03-29 06:51:25 +00004504 return i;
4505 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004506
Jacob Keller5d7daa32014-03-29 06:51:25 +00004507 return -ENOMEM;
4508}
4509
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004510int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4511 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004512{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004513 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004514 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004515 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004516
4517 if (is_zero_ether_addr(addr))
4518 return -EINVAL;
4519
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004520 /* search table for addr, if found clear IN_USE flag and sync */
4521 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4522 /* we can only delete an entry if it is in use */
4523 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4524 continue;
4525 /* we only care about entries that belong to the given pool */
4526 if (mac_table->pool != pool)
4527 continue;
4528 /* we only care about a specific MAC address */
4529 if (!ether_addr_equal(addr, mac_table->addr))
4530 continue;
4531
4532 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4533 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4534
4535 ixgbe_sync_mac_table(adapter);
4536
4537 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004538 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004539
Jacob Keller5d7daa32014-03-29 06:51:25 +00004540 return -ENOMEM;
4541}
Jacob Kellerb335e752014-03-25 07:45:27 +00004542/**
Alexander Duyck28500622010-06-15 09:25:48 +00004543 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4544 * @netdev: network interface device structure
4545 *
4546 * Writes unicast address list to the RAR table.
4547 * Returns: -ENOMEM on failure/insufficient address space
4548 * 0 on no addresses written
4549 * X on writing X addresses to the RAR table
4550 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004551static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004552{
4553 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004554 int count = 0;
4555
4556 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004557 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004558 return -ENOMEM;
4559
John Fastabend95447462012-05-31 12:42:26 +00004560 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004561 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004562 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004563 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4564 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004565 count++;
4566 }
4567 }
Alexander Duyck28500622010-06-15 09:25:48 +00004568 return count;
4569}
4570
Alexander Duyck0f079d22015-10-22 16:26:36 -07004571static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4572{
4573 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4574 int ret;
4575
4576 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4577
4578 return min_t(int, ret, 0);
4579}
4580
4581static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4582{
4583 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4584
4585 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4586
4587 return 0;
4588}
4589
Alexander Duyck28500622010-06-15 09:25:48 +00004590/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004591 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004592 * @netdev: network interface device structure
4593 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004594 * The set_rx_method entry point is called whenever the unicast/multicast
4595 * address list or the network interface flags are updated. This routine is
4596 * responsible for configuring the hardware for proper unicast, multicast and
4597 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004598 **/
Greg Rose7f870472010-01-09 02:25:29 +00004599void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004600{
4601 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4602 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004603 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004604 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004605 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004606
4607 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004608 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4609
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004610 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004611 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004612 fctrl |= IXGBE_FCTRL_BAM;
4613 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4614 fctrl |= IXGBE_FCTRL_PMCF;
4615
Alexander Duyck28500622010-06-15 09:25:48 +00004616 /* clear the bits we are changing the status of */
4617 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004618 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004619 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004620 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004621 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004622 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004623 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004624 if (netdev->flags & IFF_ALLMULTI) {
4625 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004626 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004627 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004628 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004629 }
4630
4631 /*
4632 * Write addresses to available RAR registers, if there is not
4633 * sufficient space to store all the addresses then enable
4634 * unicast promiscuous mode
4635 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004636 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004637 fctrl |= IXGBE_FCTRL_UPE;
4638 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004639 }
4640
Emil Tantilovcf789592013-10-26 08:13:20 +00004641 /* Write addresses to the MTA, if the attempt fails
4642 * then we should just turn on promiscuous mode so
4643 * that we can at least receive multicast traffic
4644 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004645 count = ixgbe_write_mc_addr_list(netdev);
4646 if (count < 0) {
4647 fctrl |= IXGBE_FCTRL_MPE;
4648 vmolr |= IXGBE_VMOLR_MPE;
4649 } else if (count) {
4650 vmolr |= IXGBE_VMOLR_ROMPE;
4651 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004652
4653 if (hw->mac.type != ixgbe_mac_82598EB) {
4654 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004655 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4656 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004657 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004658 }
4659
Ben Greear3f2d1c02012-03-08 08:28:41 +00004660 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004661 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004662 /* UPE and MPE will be handled by normal PROMISC logic
4663 * in e1000e_set_rx_mode */
4664 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4665 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4666 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4667
4668 fctrl &= ~(IXGBE_FCTRL_DPF);
4669 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4670 }
4671
Auke Kok9a799d72007-09-15 14:07:45 -07004672 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004673
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004674 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004675 ixgbe_vlan_strip_enable(adapter);
4676 else
4677 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004678
4679 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4680 ixgbe_vlan_promisc_disable(adapter);
4681 else
4682 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004683}
4684
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004685static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4686{
4687 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004688
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004689 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004690 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004691}
4692
4693static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4694{
4695 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004696
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004697 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004698 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004699}
4700
Emil Tantilova21d0822016-08-10 11:19:23 -07004701static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07004702{
Emil Tantilova21d0822016-08-10 11:19:23 -07004703 struct ixgbe_hw *hw = &adapter->hw;
4704 u32 vxlanctrl;
4705
4706 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
4707 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
4708 return;
4709
4710 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask;
4711 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
4712
4713 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07004714 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07004715
4716 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
4717 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07004718}
4719
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004720#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004721/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004722 * ixgbe_configure_dcb - Configure DCB hardware
4723 * @adapter: ixgbe adapter struct
4724 *
4725 * This is called by the driver on open to configure the DCB hardware.
4726 * This is also called by the gennetlink interface when reconfiguring
4727 * the DCB state.
4728 */
4729static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4730{
4731 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00004732 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004733
Alexander Duyck67ebd792010-08-19 13:34:04 +00004734 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4735 if (hw->mac.type == ixgbe_mac_82598EB)
4736 netif_set_gso_max_size(adapter->netdev, 65536);
4737 return;
4738 }
4739
4740 if (hw->mac.type == ixgbe_mac_82598EB)
4741 netif_set_gso_max_size(adapter->netdev, 32768);
4742
John Fastabendb1208182011-10-15 05:00:10 +00004743#ifdef IXGBE_FCOE
4744 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4745 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4746#endif
4747
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004748 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004749 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004750 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4751 DCB_TX_CONFIG);
4752 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4753 DCB_RX_CONFIG);
4754 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004755 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4756 ixgbe_dcb_hw_ets(&adapter->hw,
4757 adapter->ixgbe_ieee_ets,
4758 max_frame);
4759 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4760 adapter->ixgbe_ieee_pfc->pfc_en,
4761 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004762 }
John Fastabend8187cd42011-02-23 05:58:08 +00004763
4764 /* Enable RSS Hash per TC */
4765 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004766 u32 msb = 0;
4767 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004768
Alexander Duyckd411a932012-06-30 00:14:01 +00004769 while (rss_i) {
4770 msb++;
4771 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004772 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004773
Alexander Duyck4ae63732012-06-22 06:46:33 +00004774 /* write msb to all 8 TCs in one write */
4775 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004776 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004777}
John Fastabend9da712d2011-08-23 03:14:22 +00004778#endif
4779
4780/* Additional bittime to account for IXGBE framing */
4781#define IXGBE_ETH_FRAMING 20
4782
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004783/**
John Fastabend9da712d2011-08-23 03:14:22 +00004784 * ixgbe_hpbthresh - calculate high water mark for flow control
4785 *
4786 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004787 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004788 */
4789static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4790{
4791 struct ixgbe_hw *hw = &adapter->hw;
4792 struct net_device *dev = adapter->netdev;
4793 int link, tc, kb, marker;
4794 u32 dv_id, rx_pba;
4795
4796 /* Calculate max LAN frame size */
4797 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4798
4799#ifdef IXGBE_FCOE
4800 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004801 if ((dev->features & NETIF_F_FCOE_MTU) &&
4802 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4803 (pb == ixgbe_fcoe_get_tc(adapter)))
4804 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004805#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004806
John Fastabend9da712d2011-08-23 03:14:22 +00004807 /* Calculate delay value for device */
4808 switch (hw->mac.type) {
4809 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004810 case ixgbe_mac_X550:
4811 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004812 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004813 dv_id = IXGBE_DV_X540(link, tc);
4814 break;
4815 default:
4816 dv_id = IXGBE_DV(link, tc);
4817 break;
4818 }
4819
4820 /* Loopback switch introduces additional latency */
4821 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4822 dv_id += IXGBE_B2BT(tc);
4823
4824 /* Delay value is calculated in bit times convert to KB */
4825 kb = IXGBE_BT2KB(dv_id);
4826 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4827
4828 marker = rx_pba - kb;
4829
4830 /* It is possible that the packet buffer is not large enough
4831 * to provide required headroom. In this case throw an error
4832 * to user and a do the best we can.
4833 */
4834 if (marker < 0) {
4835 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4836 "headroom to support flow control."
4837 "Decrease MTU or number of traffic classes\n", pb);
4838 marker = tc + 1;
4839 }
4840
4841 return marker;
4842}
4843
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004844/**
John Fastabend9da712d2011-08-23 03:14:22 +00004845 * ixgbe_lpbthresh - calculate low water mark for for flow control
4846 *
4847 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004848 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004849 */
Jacob Kellere5776622014-04-05 02:35:52 +00004850static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00004851{
4852 struct ixgbe_hw *hw = &adapter->hw;
4853 struct net_device *dev = adapter->netdev;
4854 int tc;
4855 u32 dv_id;
4856
4857 /* Calculate max LAN frame size */
4858 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4859
Jacob Kellere5776622014-04-05 02:35:52 +00004860#ifdef IXGBE_FCOE
4861 /* FCoE traffic class uses FCOE jumbo frames */
4862 if ((dev->features & NETIF_F_FCOE_MTU) &&
4863 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4864 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4865 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4866#endif
4867
John Fastabend9da712d2011-08-23 03:14:22 +00004868 /* Calculate delay value for device */
4869 switch (hw->mac.type) {
4870 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004871 case ixgbe_mac_X550:
4872 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004873 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004874 dv_id = IXGBE_LOW_DV_X540(tc);
4875 break;
4876 default:
4877 dv_id = IXGBE_LOW_DV(tc);
4878 break;
4879 }
4880
4881 /* Delay value is calculated in bit times convert to KB */
4882 return IXGBE_BT2KB(dv_id);
4883}
4884
4885/*
4886 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4887 */
4888static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4889{
4890 struct ixgbe_hw *hw = &adapter->hw;
4891 int num_tc = netdev_get_num_tc(adapter->netdev);
4892 int i;
4893
4894 if (!num_tc)
4895 num_tc = 1;
4896
John Fastabend9da712d2011-08-23 03:14:22 +00004897 for (i = 0; i < num_tc; i++) {
4898 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00004899 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00004900
4901 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00004902 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4903 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004904 }
Jacob Kellere5776622014-04-05 02:35:52 +00004905
4906 for (; i < MAX_TRAFFIC_CLASS; i++)
4907 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004908}
John Fastabend80605c652011-05-02 12:34:10 +00004909
4910static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4911{
John Fastabend80605c652011-05-02 12:34:10 +00004912 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004913 int hdrm;
4914 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004915
4916 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4917 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004918 hdrm = 32 << adapter->fdir_pballoc;
4919 else
4920 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004921
Alexander Duyckf7e10272011-07-21 00:40:35 +00004922 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004923 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004924}
4925
Alexander Duycke4911d52011-05-11 07:18:52 +00004926static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4927{
4928 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004929 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004930 struct ixgbe_fdir_filter *filter;
4931
4932 spin_lock(&adapter->fdir_perfect_lock);
4933
4934 if (!hlist_empty(&adapter->fdir_filter_list))
4935 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4936
Sasha Levinb67bfe02013-02-27 17:06:00 -08004937 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004938 &adapter->fdir_filter_list, fdir_node) {
4939 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004940 &filter->filter,
4941 filter->sw_idx,
4942 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4943 IXGBE_FDIR_DROP_QUEUE :
4944 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004945 }
4946
4947 spin_unlock(&adapter->fdir_perfect_lock);
4948}
4949
John Fastabend2a47fa42013-11-06 09:54:52 -08004950static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4951 struct ixgbe_adapter *adapter)
4952{
4953 struct ixgbe_hw *hw = &adapter->hw;
4954 u32 vmolr;
4955
4956 /* No unicast promiscuous support for VMDQ devices. */
4957 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4958 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4959
4960 /* clear the affected bit */
4961 vmolr &= ~IXGBE_VMOLR_MPE;
4962
4963 if (dev->flags & IFF_ALLMULTI) {
4964 vmolr |= IXGBE_VMOLR_MPE;
4965 } else {
4966 vmolr |= IXGBE_VMOLR_ROMPE;
4967 hw->mac.ops.update_mc_addr_list(hw, dev);
4968 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00004969 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08004970 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4971}
4972
John Fastabend2a47fa42013-11-06 09:54:52 -08004973static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4974{
4975 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004976 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004977 struct ixgbe_hw *hw = &adapter->hw;
4978 u16 pool = vadapter->pool;
4979 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4980 IXGBE_PSRTYPE_UDPHDR |
4981 IXGBE_PSRTYPE_IPV4HDR |
4982 IXGBE_PSRTYPE_L2HDR |
4983 IXGBE_PSRTYPE_IPV6HDR;
4984
4985 if (hw->mac.type == ixgbe_mac_82598EB)
4986 return;
4987
4988 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004989 psrtype |= 2u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004990 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004991 psrtype |= 1u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004992
4993 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4994}
4995
4996/**
4997 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4998 * @rx_ring: ring to free buffers from
4999 **/
5000static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
5001{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005002 u16 i = rx_ring->next_to_clean;
5003 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08005004
5005 /* Free all the Rx ring sk_buffs */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005006 while (i != rx_ring->next_to_alloc) {
John Fastabend2a47fa42013-11-06 09:54:52 -08005007 if (rx_buffer->skb) {
5008 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00005009 if (IXGBE_CB(skb)->page_released)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005010 dma_unmap_page_attrs(rx_ring->dev,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005011 IXGBE_CB(skb)->dma,
5012 ixgbe_rx_pg_size(rx_ring),
5013 DMA_FROM_DEVICE,
5014 IXGBE_RX_DMA_ATTR);
John Fastabend2a47fa42013-11-06 09:54:52 -08005015 dev_kfree_skb(skb);
5016 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00005017
Alexander Duyckf3213d92017-01-17 08:35:54 -08005018 /* Invalidate cache lines that may have been written to by
5019 * device so that we avoid corrupting memory.
5020 */
5021 dma_sync_single_range_for_cpu(rx_ring->dev,
5022 rx_buffer->dma,
5023 rx_buffer->page_offset,
5024 ixgbe_rx_bufsz(rx_ring),
5025 DMA_FROM_DEVICE);
5026
5027 /* free resources associated with mapping */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005028 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005029 ixgbe_rx_pg_size(rx_ring),
5030 DMA_FROM_DEVICE,
5031 IXGBE_RX_DMA_ATTR);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08005032 __page_frag_cache_drain(rx_buffer->page,
5033 rx_buffer->pagecnt_bias);
Alexander Duyck18cb6522014-11-14 00:56:29 +00005034
Alexander Duyckffed21b2017-01-17 08:37:29 -08005035 i++;
5036 rx_buffer++;
5037 if (i == rx_ring->count) {
5038 i = 0;
5039 rx_buffer = rx_ring->rx_buffer_info;
5040 }
John Fastabend2a47fa42013-11-06 09:54:52 -08005041 }
5042
John Fastabend2a47fa42013-11-06 09:54:52 -08005043 rx_ring->next_to_alloc = 0;
5044 rx_ring->next_to_clean = 0;
5045 rx_ring->next_to_use = 0;
5046}
5047
5048static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
5049 struct ixgbe_ring *rx_ring)
5050{
5051 struct ixgbe_adapter *adapter = vadapter->real_adapter;
5052 int index = rx_ring->queue_index + vadapter->rx_base_queue;
5053
5054 /* shutdown specific queue receive and wait for dma to settle */
5055 ixgbe_disable_rx_queue(adapter, rx_ring);
5056 usleep_range(10000, 20000);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005057 ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
John Fastabend2a47fa42013-11-06 09:54:52 -08005058 ixgbe_clean_rx_ring(rx_ring);
5059 rx_ring->l2_accel_priv = NULL;
5060}
5061
John Fastabendae72c8d2013-11-09 07:11:26 +00005062static int ixgbe_fwd_ring_down(struct net_device *vdev,
5063 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08005064{
5065 struct ixgbe_adapter *adapter = accel->real_adapter;
5066 unsigned int rxbase = accel->rx_base_queue;
5067 unsigned int txbase = accel->tx_base_queue;
5068 int i;
5069
5070 netif_tx_stop_all_queues(vdev);
5071
5072 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5073 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5074 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
5075 }
5076
5077 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5078 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
5079 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
5080 }
5081
5082
5083 return 0;
5084}
5085
5086static int ixgbe_fwd_ring_up(struct net_device *vdev,
5087 struct ixgbe_fwd_adapter *accel)
5088{
5089 struct ixgbe_adapter *adapter = accel->real_adapter;
5090 unsigned int rxbase, txbase, queues;
5091 int i, baseq, err = 0;
5092
5093 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
5094 return 0;
5095
5096 baseq = accel->pool * adapter->num_rx_queues_per_pool;
5097 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
5098 accel->pool, adapter->num_rx_pools,
5099 baseq, baseq + adapter->num_rx_queues_per_pool,
5100 adapter->fwd_bitmask);
5101
5102 accel->netdev = vdev;
5103 accel->rx_base_queue = rxbase = baseq;
5104 accel->tx_base_queue = txbase = baseq;
5105
5106 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5107 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5108
5109 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5110 adapter->rx_ring[rxbase + i]->netdev = vdev;
5111 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
5112 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
5113 }
5114
5115 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5116 adapter->tx_ring[txbase + i]->netdev = vdev;
5117 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
5118 }
5119
5120 queues = min_t(unsigned int,
5121 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
5122 err = netif_set_real_num_tx_queues(vdev, queues);
5123 if (err)
5124 goto fwd_queue_err;
5125
John Fastabend2a47fa42013-11-06 09:54:52 -08005126 err = netif_set_real_num_rx_queues(vdev, queues);
5127 if (err)
5128 goto fwd_queue_err;
5129
5130 if (is_valid_ether_addr(vdev->dev_addr))
5131 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
5132
5133 ixgbe_fwd_psrtype(accel);
5134 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
5135 return err;
5136fwd_queue_err:
5137 ixgbe_fwd_ring_down(vdev, accel);
5138 return err;
5139}
5140
David Ahern1cd127f2016-10-17 19:15:48 -07005141static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
5142{
5143 if (netif_is_macvlan(upper)) {
5144 struct macvlan_dev *dfwd = netdev_priv(upper);
5145 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5146
5147 if (dfwd->fwd_priv)
5148 ixgbe_fwd_ring_up(upper, vadapter);
5149 }
5150
5151 return 0;
5152}
5153
John Fastabend2a47fa42013-11-06 09:54:52 -08005154static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5155{
David Ahern1cd127f2016-10-17 19:15:48 -07005156 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5157 ixgbe_upper_dev_walk, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005158}
5159
Auke Kok9a799d72007-09-15 14:07:45 -07005160static void ixgbe_configure(struct ixgbe_adapter *adapter)
5161{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005162 struct ixgbe_hw *hw = &adapter->hw;
5163
John Fastabend80605c652011-05-02 12:34:10 +00005164 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005165#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005166 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005167#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005168 /*
5169 * We must restore virtualization before VLANs or else
5170 * the VLVF registers will not be populated
5171 */
5172 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005173
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005174 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005175 ixgbe_restore_vlan(adapter);
5176
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005177 switch (hw->mac.type) {
5178 case ixgbe_mac_82599EB:
5179 case ixgbe_mac_X540:
5180 hw->mac.ops.disable_rx_buff(hw);
5181 break;
5182 default:
5183 break;
5184 }
5185
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005186 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005187 ixgbe_init_fdir_signature_82599(&adapter->hw,
5188 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005189 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5190 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5191 adapter->fdir_pballoc);
5192 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005193 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005194
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005195 switch (hw->mac.type) {
5196 case ixgbe_mac_82599EB:
5197 case ixgbe_mac_X540:
5198 hw->mac.ops.enable_rx_buff(hw);
5199 break;
5200 default:
5201 break;
5202 }
5203
Mark Rustad9de76052015-08-08 16:27:41 -07005204#ifdef CONFIG_IXGBE_DCA
5205 /* configure DCA */
5206 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5207 ixgbe_setup_dca(adapter);
5208#endif /* CONFIG_IXGBE_DCA */
5209
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005210#ifdef IXGBE_FCOE
5211 /* configure FCoE L2 filters, redirection table, and Rx control */
5212 ixgbe_configure_fcoe(adapter);
5213
5214#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005215 ixgbe_configure_tx(adapter);
5216 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005217 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005218}
5219
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005220/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005221 * ixgbe_sfp_link_config - set up SFP+ link
5222 * @adapter: pointer to private adapter struct
5223 **/
5224static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5225{
Alexander Duyck70864002011-04-27 09:13:56 +00005226 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005227 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005228 * is that an SFP was inserted/removed after the reset
5229 * but before SFP detection was enabled. As such the best
5230 * solution is to just start searching as soon as we start
5231 */
5232 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5233 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005234
Alexander Duyck70864002011-04-27 09:13:56 +00005235 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005236 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005237}
5238
5239/**
5240 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005241 * @hw: pointer to private hardware struct
5242 *
5243 * Returns 0 on success, negative on failure
5244 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005245static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005246{
Josh Hay3d292262012-12-15 03:28:19 +00005247 u32 speed;
5248 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005249 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005250
5251 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005252 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005253
5254 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005255 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005256
Josh Hay3d292262012-12-15 03:28:19 +00005257 speed = hw->phy.autoneg_advertised;
5258 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5259 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5260 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005261 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005262 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005263
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005264 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005265 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005266
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005267 return ret;
5268}
5269
Alexander Duycka34bcff2010-08-19 13:39:20 +00005270static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005271{
Auke Kok9a799d72007-09-15 14:07:45 -07005272 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005273 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005274
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005275 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005276 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5277 IXGBE_GPIE_OCD;
5278 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005279 /*
5280 * use EIAM to auto-mask when MSI-X interrupt is asserted
5281 * this saves a register write for every interrupt
5282 */
5283 switch (hw->mac.type) {
5284 case ixgbe_mac_82598EB:
5285 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5286 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005287 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005288 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005289 case ixgbe_mac_X550:
5290 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005291 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005292 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005293 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5294 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5295 break;
5296 }
5297 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005298 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5299 * specifically only auto mask tx and rx interrupts */
5300 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005301 }
5302
Alexander Duycka34bcff2010-08-19 13:39:20 +00005303 /* XXX: to interrupt immediately for EICS writes, enable this */
5304 /* gpie |= IXGBE_GPIE_EIMEN; */
5305
5306 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5307 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005308
5309 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5310 case IXGBE_82599_VMDQ_8Q_MASK:
5311 gpie |= IXGBE_GPIE_VTMODE_16;
5312 break;
5313 case IXGBE_82599_VMDQ_4Q_MASK:
5314 gpie |= IXGBE_GPIE_VTMODE_32;
5315 break;
5316 default:
5317 gpie |= IXGBE_GPIE_VTMODE_64;
5318 break;
5319 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005320 }
5321
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005322 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005323 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5324 switch (adapter->hw.mac.type) {
5325 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005326 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005327 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005328 default:
5329 break;
5330 }
5331 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005332
Alexander Duycka34bcff2010-08-19 13:39:20 +00005333 /* Enable fan failure interrupt */
5334 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005335 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005336
Don Skidmorea023bbd2015-06-24 16:38:53 -04005337 switch (hw->mac.type) {
5338 case ixgbe_mac_82599EB:
5339 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5340 break;
5341 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005342 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005343 gpie |= IXGBE_SDP0_GPIEN_X540;
5344 break;
5345 default:
5346 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005347 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005348
5349 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5350}
5351
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005352static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005353{
5354 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005355 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005356 u32 ctrl_ext;
5357
5358 ixgbe_get_hw_control(adapter);
5359 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005360
Auke Kok9a799d72007-09-15 14:07:45 -07005361 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5362 ixgbe_configure_msix(adapter);
5363 else
5364 ixgbe_configure_msi_and_legacy(adapter);
5365
Emil Tantilovec74a472012-09-20 03:33:56 +00005366 /* enable the optics for 82599 SFP+ fiber */
5367 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005368 hw->mac.ops.enable_tx_laser(hw);
5369
Don Skidmore961fac82015-06-09 16:09:47 -07005370 if (hw->phy.ops.set_phy_power)
5371 hw->phy.ops.set_phy_power(hw, true);
5372
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005373 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005374 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005375 ixgbe_napi_enable_all(adapter);
5376
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005377 if (ixgbe_is_sfp(hw)) {
5378 ixgbe_sfp_link_config(adapter);
5379 } else {
5380 err = ixgbe_non_sfp_link_config(hw);
5381 if (err)
5382 e_err(probe, "link_config FAILED %d\n", err);
5383 }
5384
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005385 /* clear any pending interrupts, may auto mask */
5386 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005387 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005388
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005389 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005390 * If this adapter has a fan, check to see if we had a failure
5391 * before we enabled the interrupt.
5392 */
5393 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5394 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5395 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005396 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005397 }
5398
Auke Kok9a799d72007-09-15 14:07:45 -07005399 /* bring the link up in the watchdog, this could race with our first
5400 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005401 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5402 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005403 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005404
5405 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5406 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5407 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5408 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005409}
5410
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005411void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5412{
5413 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005414 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005415 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005416
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005417 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005418 usleep_range(1000, 2000);
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005419 if (adapter->hw.phy.type == ixgbe_phy_fw)
5420 ixgbe_watchdog_link_is_down(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005421 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005422 /*
5423 * If SR-IOV enabled then wait a bit before bringing the adapter
5424 * back up to give the VFs time to respond to the reset. The
5425 * two second wait is based upon the watchdog timer cycle in
5426 * the VF driver.
5427 */
5428 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5429 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005430 ixgbe_up(adapter);
5431 clear_bit(__IXGBE_RESETTING, &adapter->state);
5432}
5433
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005434void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005435{
5436 /* hardware has been reset, we need to reload some things */
5437 ixgbe_configure(adapter);
5438
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005439 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005440}
5441
5442void ixgbe_reset(struct ixgbe_adapter *adapter)
5443{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005444 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005445 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005446 int err;
5447
Mark Rustadb0483c82014-01-14 18:53:17 -08005448 if (ixgbe_removed(hw->hw_addr))
5449 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005450 /* lock SFP init bit to prevent race conditions with the watchdog */
5451 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5452 usleep_range(1000, 2000);
5453
5454 /* clear all SFP and link config related flags while holding SFP_INIT */
5455 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5456 IXGBE_FLAG2_SFP_NEEDS_RESET);
5457 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5458
Don Skidmore8ca783a2009-05-26 20:40:47 -07005459 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005460 switch (err) {
5461 case 0:
5462 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005463 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005464 break;
5465 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005466 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005467 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005468 case IXGBE_ERR_EEPROM_VERSION:
5469 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005470 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005471 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005472 "your hardware. If you are experiencing problems "
5473 "please contact your Intel or hardware "
5474 "representative who provided you with this "
5475 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005476 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005477 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005478 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005479 }
Auke Kok9a799d72007-09-15 14:07:45 -07005480
Alexander Duyck70864002011-04-27 09:13:56 +00005481 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005482
5483 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005484 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005485 __dev_uc_unsync(netdev, NULL);
5486
5487 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005488 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005489
5490 /* update SAN MAC vmdq pool selection */
5491 if (hw->mac.san_mac_rar_index)
5492 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005493
Jacob Keller8fecf672013-06-21 08:14:32 +00005494 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005495 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005496
5497 if (hw->phy.ops.set_phy_power) {
5498 if (!netif_running(adapter->netdev) && !adapter->wol)
5499 hw->phy.ops.set_phy_power(hw, false);
5500 else
5501 hw->phy.ops.set_phy_power(hw, true);
5502 }
Auke Kok9a799d72007-09-15 14:07:45 -07005503}
5504
Auke Kok9a799d72007-09-15 14:07:45 -07005505/**
Auke Kok9a799d72007-09-15 14:07:45 -07005506 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005507 * @tx_ring: ring to be cleaned
5508 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005509static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005510{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005511 u16 i = tx_ring->next_to_clean;
5512 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07005513
Alexander Duyckffed21b2017-01-17 08:37:29 -08005514 while (i != tx_ring->next_to_use) {
5515 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -07005516
Alexander Duyckffed21b2017-01-17 08:37:29 -08005517 /* Free all the Tx ring sk_buffs */
5518 dev_kfree_skb_any(tx_buffer->skb);
5519
5520 /* unmap skb header data */
5521 dma_unmap_single(tx_ring->dev,
5522 dma_unmap_addr(tx_buffer, dma),
5523 dma_unmap_len(tx_buffer, len),
5524 DMA_TO_DEVICE);
5525
5526 /* check for eop_desc to determine the end of the packet */
5527 eop_desc = tx_buffer->next_to_watch;
5528 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5529
5530 /* unmap remaining buffers */
5531 while (tx_desc != eop_desc) {
5532 tx_buffer++;
5533 tx_desc++;
5534 i++;
5535 if (unlikely(i == tx_ring->count)) {
5536 i = 0;
5537 tx_buffer = tx_ring->tx_buffer_info;
5538 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5539 }
5540
5541 /* unmap any remaining paged data */
5542 if (dma_unmap_len(tx_buffer, len))
5543 dma_unmap_page(tx_ring->dev,
5544 dma_unmap_addr(tx_buffer, dma),
5545 dma_unmap_len(tx_buffer, len),
5546 DMA_TO_DEVICE);
5547 }
5548
5549 /* move us one more past the eop_desc for start of next pkt */
5550 tx_buffer++;
5551 i++;
5552 if (unlikely(i == tx_ring->count)) {
5553 i = 0;
5554 tx_buffer = tx_ring->tx_buffer_info;
5555 }
Auke Kok9a799d72007-09-15 14:07:45 -07005556 }
5557
Alexander Duyckffed21b2017-01-17 08:37:29 -08005558 /* reset BQL for queue */
John Fastabenddad8a3b2012-04-23 12:22:39 +00005559 netdev_tx_reset_queue(txring_txq(tx_ring));
5560
Alexander Duyckffed21b2017-01-17 08:37:29 -08005561 /* reset next_to_use and next_to_clean */
Auke Kok9a799d72007-09-15 14:07:45 -07005562 tx_ring->next_to_use = 0;
5563 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005564}
5565
5566/**
Auke Kok9a799d72007-09-15 14:07:45 -07005567 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5568 * @adapter: board private structure
5569 **/
5570static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5571{
5572 int i;
5573
5574 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005575 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005576}
5577
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005578/**
5579 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5580 * @adapter: board private structure
5581 **/
5582static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5583{
5584 int i;
5585
5586 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005587 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005588}
5589
Alexander Duycke4911d52011-05-11 07:18:52 +00005590static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5591{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005592 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005593 struct ixgbe_fdir_filter *filter;
5594
5595 spin_lock(&adapter->fdir_perfect_lock);
5596
Sasha Levinb67bfe02013-02-27 17:06:00 -08005597 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005598 &adapter->fdir_filter_list, fdir_node) {
5599 hlist_del(&filter->fdir_node);
5600 kfree(filter);
5601 }
5602 adapter->fdir_filter_count = 0;
5603
5604 spin_unlock(&adapter->fdir_perfect_lock);
5605}
5606
David Ahern1cd127f2016-10-17 19:15:48 -07005607static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
5608{
5609 if (netif_is_macvlan(upper)) {
5610 struct macvlan_dev *vlan = netdev_priv(upper);
5611
5612 if (vlan->fwd_priv) {
5613 netif_tx_stop_all_queues(upper);
5614 netif_carrier_off(upper);
5615 netif_tx_disable(upper);
5616 }
5617 }
5618
5619 return 0;
5620}
5621
Auke Kok9a799d72007-09-15 14:07:45 -07005622void ixgbe_down(struct ixgbe_adapter *adapter)
5623{
5624 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005625 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005626 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005627
5628 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005629 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5630 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005631
5632 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005633 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005634
Yi Zou2d39d572011-01-06 14:29:56 +00005635 /* disable all enabled rx queues */
5636 for (i = 0; i < adapter->num_rx_queues; i++)
5637 /* this call also flushes the previous write */
5638 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5639
Don Skidmore032b4322011-03-18 09:32:53 +00005640 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005641
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005642 netif_tx_stop_all_queues(netdev);
5643
Alexander Duyck70864002011-04-27 09:13:56 +00005644 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005645 netif_carrier_off(netdev);
5646 netif_tx_disable(netdev);
5647
John Fastabend2a47fa42013-11-06 09:54:52 -08005648 /* disable any upper devices */
David Ahern1cd127f2016-10-17 19:15:48 -07005649 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5650 ixgbe_disable_macvlan, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005651
John Fastabendc0dfb902010-04-27 02:13:39 +00005652 ixgbe_irq_disable(adapter);
5653
5654 ixgbe_napi_disable_all(adapter);
5655
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005656 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5657 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005658 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5659
5660 del_timer_sync(&adapter->service_timer);
5661
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005662 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005663 /* Clear EITR Select mapping */
5664 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5665
5666 /* Mark all the VFs as inactive */
5667 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005668 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005669
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005670 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005671 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005672
Auke Kok9a799d72007-09-15 14:07:45 -07005673 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005674 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005675 }
5676
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005677 /* disable transmits in the hardware now that interrupts are off */
5678 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005679 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005680 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005681 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005682
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005683 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005684 switch (hw->mac.type) {
5685 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005686 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005687 case ixgbe_mac_X550:
5688 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005689 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005690 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005691 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5692 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005693 break;
5694 default:
5695 break;
5696 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005697
Paul Larson6f4a0e42008-06-24 17:00:56 -07005698 if (!pci_channel_offline(adapter->pdev))
5699 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005700
Emil Tantilovec74a472012-09-20 03:33:56 +00005701 /* power down the optics for 82599 SFP+ fiber */
5702 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005703 hw->mac.ops.disable_tx_laser(hw);
5704
Auke Kok9a799d72007-09-15 14:07:45 -07005705 ixgbe_clean_all_tx_rings(adapter);
5706 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005707}
5708
Auke Kok9a799d72007-09-15 14:07:45 -07005709/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005710 * ixgbe_eee_capable - helper function to determine EEE support on X550
5711 * @adapter: board private structure
5712 */
5713static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
5714{
5715 struct ixgbe_hw *hw = &adapter->hw;
5716
5717 switch (hw->device_id) {
5718 case IXGBE_DEV_ID_X550EM_A_1G_T:
5719 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
5720 if (!hw->phy.eee_speeds_supported)
5721 break;
5722 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
5723 if (!hw->phy.eee_speeds_advertised)
5724 break;
5725 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
5726 break;
5727 default:
5728 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
5729 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
5730 break;
5731 }
5732}
5733
5734/**
Auke Kok9a799d72007-09-15 14:07:45 -07005735 * ixgbe_tx_timeout - Respond to a Tx Hang
5736 * @netdev: network interface device structure
5737 **/
5738static void ixgbe_tx_timeout(struct net_device *netdev)
5739{
5740 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5741
5742 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005743 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005744}
5745
Usha Ketineni88290092016-04-26 05:00:26 -07005746#ifdef CONFIG_IXGBE_DCB
5747static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
5748{
5749 struct ixgbe_hw *hw = &adapter->hw;
5750 struct tc_configuration *tc;
5751 int j;
5752
5753 switch (hw->mac.type) {
5754 case ixgbe_mac_82598EB:
5755 case ixgbe_mac_82599EB:
5756 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5757 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5758 break;
5759 case ixgbe_mac_X540:
5760 case ixgbe_mac_X550:
5761 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5762 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5763 break;
5764 case ixgbe_mac_X550EM_x:
5765 case ixgbe_mac_x550em_a:
5766 default:
5767 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
5768 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
5769 break;
5770 }
5771
5772 /* Configure DCB traffic classes */
5773 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5774 tc = &adapter->dcb_cfg.tc_config[j];
5775 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5776 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5777 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5778 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5779 tc->dcb_pfc = pfc_disabled;
5780 }
5781
5782 /* Initialize default user to priority mapping, UPx->TC0 */
5783 tc = &adapter->dcb_cfg.tc_config[0];
5784 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5785 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5786
5787 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5788 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5789 adapter->dcb_cfg.pfc_mode_enable = false;
5790 adapter->dcb_set_bitmap = 0x00;
5791 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
5792 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5793 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5794 sizeof(adapter->temp_dcb_cfg));
5795}
5796#endif
5797
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005798/**
Auke Kok9a799d72007-09-15 14:07:45 -07005799 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5800 * @adapter: board private structure to initialize
5801 *
5802 * ixgbe_sw_init initializes the Adapter private data structure.
5803 * Fields are initialized based on PCI device information and
5804 * OS network device settings (MTU size).
5805 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07005806static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
5807 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07005808{
5809 struct ixgbe_hw *hw = &adapter->hw;
5810 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005811 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005812 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005813 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005814
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005815 /* PCI config space info */
5816
5817 hw->vendor_id = pdev->vendor;
5818 hw->device_id = pdev->device;
5819 hw->revision_id = pdev->revision;
5820 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5821 hw->subsystem_device_id = pdev->subsystem_device;
5822
Emil Tantilov55570b62016-10-12 12:34:25 -07005823 /* get_invariants needs the device IDs */
5824 ii->get_invariants(hw);
5825
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005826 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00005827 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005828 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005829 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005830 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5831 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005832 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5833 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005834 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5835#ifdef CONFIG_IXGBE_DCA
5836 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5837#endif
Usha Ketineni88290092016-04-26 05:00:26 -07005838#ifdef CONFIG_IXGBE_DCB
5839 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
5840 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
5841#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005842#ifdef IXGBE_FCOE
5843 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5844 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5845#ifdef CONFIG_IXGBE_DCB
5846 /* Default traffic class to use for FCoE */
5847 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5848#endif /* CONFIG_IXGBE_DCB */
5849#endif /* IXGBE_FCOE */
5850
John Fastabendb82b17d2016-02-16 21:18:53 -08005851 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005852 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
5853 GFP_KERNEL);
5854 if (!adapter->jump_tables[0])
5855 return -ENOMEM;
5856 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
5857
5858 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
5859 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08005860
Jacob Keller5d7daa32014-03-29 06:51:25 +00005861 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5862 hw->mac.num_rar_entries,
5863 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08005864 if (!adapter->mac_table)
5865 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005866
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005867 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005868 switch (hw->mac.type) {
5869 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005870 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005871
Don Skidmorebf069c92009-05-07 10:39:54 +00005872 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5873 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005874
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005875 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005876 adapter->ring_feature[RING_F_FDIR].limit = 0;
5877 adapter->atr_sample_rate = 0;
5878 adapter->fdir_pballoc = 0;
5879#ifdef IXGBE_FCOE
5880 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5881 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5882#ifdef CONFIG_IXGBE_DCB
5883 adapter->fcoe.up = 0;
5884#endif /* IXGBE_DCB */
5885#endif /* IXGBE_FCOE */
5886 break;
5887 case ixgbe_mac_82599EB:
5888 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5889 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005890 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005891 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005892 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005893 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5894 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005895 break;
Mark Rustad49425df2016-04-01 12:18:09 -07005896 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07005897 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005898 switch (hw->device_id) {
5899 case IXGBE_DEV_ID_X550EM_A_1G_T:
5900 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
5901 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5902 break;
5903 default:
5904 break;
5905 }
Emil Tantilova21d0822016-08-10 11:19:23 -07005906 /* fall through */
5907 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07005908#ifdef CONFIG_IXGBE_DCB
5909 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
5910#endif
5911#ifdef IXGBE_FCOE
5912 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5913#ifdef CONFIG_IXGBE_DCB
5914 adapter->fcoe.up = 0;
5915#endif /* IXGBE_DCB */
5916#endif /* IXGBE_FCOE */
5917 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005918 case ixgbe_mac_X550:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005919 if (hw->mac.type == ixgbe_mac_X550)
5920 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005921#ifdef CONFIG_IXGBE_DCA
5922 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
5923#endif
Mark Rustad67359c32015-06-15 11:33:25 -07005924 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005925 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08005926 default:
5927 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005928 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005929
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005930#ifdef IXGBE_FCOE
5931 /* FCoE support exists, always init the FCoE lock */
5932 spin_lock_init(&adapter->fcoe.lock);
5933
5934#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005935 /* n-tuple support exists, always init our spinlock */
5936 spin_lock_init(&adapter->fdir_perfect_lock);
5937
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005938#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07005939 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005940#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005941
5942 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005943 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005944 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005945 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005946 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5947 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005948 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005949
Alexander Duyck99d74482012-05-09 08:09:25 +00005950#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005951 if (max_vfs > 0)
5952 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 +00005953
Jacob Keller170e8542013-11-09 04:52:32 -08005954 /* assign number of SR-IOV VFs */
5955 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005956 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Jacob Keller170e8542013-11-09 04:52:32 -08005957 adapter->num_vfs = 0;
5958 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5959 } else {
5960 adapter->num_vfs = max_vfs;
5961 }
5962 }
5963#endif /* CONFIG_PCI_IOV */
5964
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005965 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005966 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005967 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005968
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005969 /* set default ring sizes */
5970 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5971 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5972
Alexander Duyckbd198052011-06-11 01:45:08 +00005973 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005974 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005975
Auke Kok9a799d72007-09-15 14:07:45 -07005976 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005977 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005978 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005979 return -EIO;
5980 }
5981
John Fastabend2a47fa42013-11-06 09:54:52 -08005982 /* PF holds first pool slot */
5983 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005984 set_bit(__IXGBE_DOWN, &adapter->state);
5985
5986 return 0;
5987}
5988
5989/**
5990 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005991 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005992 *
5993 * Return 0 on success, negative on failure
5994 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005995int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005996{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005997 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005998 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005999 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07006000 int size;
6001
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006002 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006003
6004 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006005 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006006
Alexander Duyckffed21b2017-01-17 08:37:29 -08006007 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006008 if (!tx_ring->tx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006009 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006010 if (!tx_ring->tx_buffer_info)
6011 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006012
John Stultz827da442013-10-07 15:51:58 -07006013 u64_stats_init(&tx_ring->syncp);
6014
Auke Kok9a799d72007-09-15 14:07:45 -07006015 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08006016 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006017 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006018
Mark Rustadca8dfe22014-07-24 06:19:24 +00006019 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006020 tx_ring->desc = dma_alloc_coherent(dev,
6021 tx_ring->size,
6022 &tx_ring->dma,
6023 GFP_KERNEL);
6024 set_dev_node(dev, orig_node);
6025 if (!tx_ring->desc)
6026 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6027 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006028 if (!tx_ring->desc)
6029 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006030
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006031 tx_ring->next_to_use = 0;
6032 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006033 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006034
6035err:
6036 vfree(tx_ring->tx_buffer_info);
6037 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006038 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006039 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006040}
6041
6042/**
Alexander Duyck69888672008-09-11 20:05:39 -07006043 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6044 * @adapter: board private structure
6045 *
6046 * If this function returns with an error, then it's possible one or
6047 * more of the rings is populated (while the rest are not). It is the
6048 * callers duty to clean those orphaned rings.
6049 *
6050 * Return 0 on success, negative on failure
6051 **/
6052static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6053{
6054 int i, err = 0;
6055
6056 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006057 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006058 if (!err)
6059 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006060
Emil Tantilov396e7992010-07-01 20:05:12 +00006061 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006062 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07006063 }
6064
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006065 return 0;
6066err_setup_tx:
6067 /* rewind the index freeing the rings as we go */
6068 while (i--)
6069 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006070 return err;
6071}
6072
6073/**
Auke Kok9a799d72007-09-15 14:07:45 -07006074 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006075 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006076 *
6077 * Returns 0 on success, negative on failure
6078 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006079int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006080{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006081 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006082 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006083 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006084 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07006085
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006086 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006087
6088 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006089 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006090
Alexander Duyckffed21b2017-01-17 08:37:29 -08006091 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006092 if (!rx_ring->rx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006093 rx_ring->rx_buffer_info = vmalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006094 if (!rx_ring->rx_buffer_info)
6095 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006096
John Stultz827da442013-10-07 15:51:58 -07006097 u64_stats_init(&rx_ring->syncp);
6098
Auke Kok9a799d72007-09-15 14:07:45 -07006099 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006100 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6101 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006102
Mark Rustadca8dfe22014-07-24 06:19:24 +00006103 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006104 rx_ring->desc = dma_alloc_coherent(dev,
6105 rx_ring->size,
6106 &rx_ring->dma,
6107 GFP_KERNEL);
6108 set_dev_node(dev, orig_node);
6109 if (!rx_ring->desc)
6110 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6111 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006112 if (!rx_ring->desc)
6113 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006114
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006115 rx_ring->next_to_clean = 0;
6116 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006117
6118 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006119err:
6120 vfree(rx_ring->rx_buffer_info);
6121 rx_ring->rx_buffer_info = NULL;
6122 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07006123 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006124}
6125
6126/**
Alexander Duyck69888672008-09-11 20:05:39 -07006127 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6128 * @adapter: board private structure
6129 *
6130 * If this function returns with an error, then it's possible one or
6131 * more of the rings is populated (while the rest are not). It is the
6132 * callers duty to clean those orphaned rings.
6133 *
6134 * Return 0 on success, negative on failure
6135 **/
Alexander Duyck69888672008-09-11 20:05:39 -07006136static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6137{
6138 int i, err = 0;
6139
6140 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006141 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006142 if (!err)
6143 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006144
Emil Tantilov396e7992010-07-01 20:05:12 +00006145 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006146 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07006147 }
6148
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006149#ifdef IXGBE_FCOE
6150 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6151 if (!err)
6152#endif
6153 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006154err_setup_rx:
6155 /* rewind the index freeing the rings as we go */
6156 while (i--)
6157 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006158 return err;
6159}
6160
6161/**
Auke Kok9a799d72007-09-15 14:07:45 -07006162 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07006163 * @tx_ring: Tx descriptor ring for a specific queue
6164 *
6165 * Free all transmit software resources
6166 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006167void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006168{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006169 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006170
6171 vfree(tx_ring->tx_buffer_info);
6172 tx_ring->tx_buffer_info = NULL;
6173
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006174 /* if not set, then don't free */
6175 if (!tx_ring->desc)
6176 return;
6177
6178 dma_free_coherent(tx_ring->dev, tx_ring->size,
6179 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006180
6181 tx_ring->desc = NULL;
6182}
6183
6184/**
6185 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6186 * @adapter: board private structure
6187 *
6188 * Free all transmit software resources
6189 **/
6190static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6191{
6192 int i;
6193
6194 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006195 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006196 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006197}
6198
6199/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006200 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006201 * @rx_ring: ring to clean the resources from
6202 *
6203 * Free all receive software resources
6204 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006205void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006206{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006207 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006208
6209 vfree(rx_ring->rx_buffer_info);
6210 rx_ring->rx_buffer_info = NULL;
6211
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006212 /* if not set, then don't free */
6213 if (!rx_ring->desc)
6214 return;
6215
6216 dma_free_coherent(rx_ring->dev, rx_ring->size,
6217 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006218
6219 rx_ring->desc = NULL;
6220}
6221
6222/**
6223 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6224 * @adapter: board private structure
6225 *
6226 * Free all receive software resources
6227 **/
6228static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6229{
6230 int i;
6231
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006232#ifdef IXGBE_FCOE
6233 ixgbe_free_fcoe_ddp_resources(adapter);
6234
6235#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006236 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006237 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006238 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006239}
6240
6241/**
Auke Kok9a799d72007-09-15 14:07:45 -07006242 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6243 * @netdev: network interface device structure
6244 * @new_mtu: new value for maximum frame size
6245 *
6246 * Returns 0 on success, negative on failure
6247 **/
6248static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6249{
6250 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck655309e2012-02-08 07:50:35 +00006251
6252 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006253 * For 82599EB we cannot allow legacy VFs to enable their receive
6254 * paths when MTU greater than 1500 is configured. So display a
6255 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006256 */
6257 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6258 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Jarod Wilson91c527a2016-10-17 15:54:05 -04006259 (new_mtu > ETH_DATA_LEN))
Alexander Duyck872844d2012-08-15 02:10:43 +00006260 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006261
Emil Tantilov396e7992010-07-01 20:05:12 +00006262 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006263
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006264 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006265 netdev->mtu = new_mtu;
6266
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006267 if (netif_running(netdev))
6268 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006269
6270 return 0;
6271}
6272
6273/**
6274 * ixgbe_open - Called when a network interface is made active
6275 * @netdev: network interface device structure
6276 *
6277 * Returns 0 on success, negative value on failure
6278 *
6279 * The open entry point is called when a network interface is made
6280 * active by the system (IFF_UP). At this point all resources needed
6281 * for transmit and receive operations are allocated, the interrupt
6282 * handler is registered with the OS, the watchdog timer is started,
6283 * and the stack is notified that the interface is ready.
6284 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006285int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006286{
6287 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006288 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006289 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006290
Auke Kok4bebfaa2008-02-11 09:26:01 -08006291 /* disallow open during test */
6292 if (test_bit(__IXGBE_TESTING, &adapter->state))
6293 return -EBUSY;
6294
Jesse Brandeburg54386462009-04-17 20:44:27 +00006295 netif_carrier_off(netdev);
6296
Auke Kok9a799d72007-09-15 14:07:45 -07006297 /* allocate transmit descriptors */
6298 err = ixgbe_setup_all_tx_resources(adapter);
6299 if (err)
6300 goto err_setup_tx;
6301
Auke Kok9a799d72007-09-15 14:07:45 -07006302 /* allocate receive descriptors */
6303 err = ixgbe_setup_all_rx_resources(adapter);
6304 if (err)
6305 goto err_setup_rx;
6306
6307 ixgbe_configure(adapter);
6308
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006309 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006310 if (err)
6311 goto err_req_irq;
6312
Alexander Duyckac802f52012-07-12 05:52:53 +00006313 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08006314 if (adapter->num_rx_pools > 1)
6315 queues = adapter->num_rx_queues_per_pool;
6316 else
6317 queues = adapter->num_tx_queues;
6318
6319 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006320 if (err)
6321 goto err_set_queues;
6322
John Fastabend2a47fa42013-11-06 09:54:52 -08006323 if (adapter->num_rx_pools > 1 &&
6324 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
6325 queues = IXGBE_MAX_L2A_QUEUES;
6326 else
6327 queues = adapter->num_rx_queues;
6328 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006329 if (err)
6330 goto err_set_queues;
6331
Jacob Keller1a71ab22012-08-25 03:54:19 +00006332 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006333
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006334 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006335
Emil Tantilova21d0822016-08-10 11:19:23 -07006336 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
Alexander Duyckb3a49552016-06-16 12:22:19 -07006337 udp_tunnel_get_rx_info(netdev);
Mark Rustad67359c32015-06-15 11:33:25 -07006338
Auke Kok9a799d72007-09-15 14:07:45 -07006339 return 0;
6340
Alexander Duyckac802f52012-07-12 05:52:53 +00006341err_set_queues:
6342 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006343err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006344 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006345 if (hw->phy.ops.set_phy_power && !adapter->wol)
6346 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006347err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006348 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006349err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006350 ixgbe_reset(adapter);
6351
6352 return err;
6353}
6354
Jacob Kellera0cccce2014-05-16 05:12:29 +00006355static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6356{
6357 ixgbe_ptp_suspend(adapter);
6358
Don Skidmore6ac74392015-06-17 17:34:31 -04006359 if (adapter->hw.phy.ops.enter_lplu) {
6360 adapter->hw.phy.reset_disable = true;
6361 ixgbe_down(adapter);
6362 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6363 adapter->hw.phy.reset_disable = false;
6364 } else {
6365 ixgbe_down(adapter);
6366 }
6367
Jacob Kellera0cccce2014-05-16 05:12:29 +00006368 ixgbe_free_irq(adapter);
6369
6370 ixgbe_free_all_tx_resources(adapter);
6371 ixgbe_free_all_rx_resources(adapter);
6372}
6373
Auke Kok9a799d72007-09-15 14:07:45 -07006374/**
6375 * ixgbe_close - Disables a network interface
6376 * @netdev: network interface device structure
6377 *
6378 * Returns 0, this is not allowed to fail
6379 *
6380 * The close entry point is called when an interface is de-activated
6381 * by the OS. The hardware is still under the drivers control, but
6382 * needs to be disabled. A global MAC reset is issued to stop the
6383 * hardware, and all transmit and receive resources are freed.
6384 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006385int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006386{
6387 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006388
Jacob Keller1a71ab22012-08-25 03:54:19 +00006389 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006390
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006391 if (netif_device_present(netdev))
6392 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006393
Alexander Duycke4911d52011-05-11 07:18:52 +00006394 ixgbe_fdir_filter_exit(adapter);
6395
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006396 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006397
6398 return 0;
6399}
6400
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006401#ifdef CONFIG_PM
6402static int ixgbe_resume(struct pci_dev *pdev)
6403{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006404 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6405 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006406 u32 err;
6407
Mark Rustad0391bbe2014-02-28 15:48:55 -08006408 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006409 pci_set_power_state(pdev, PCI_D0);
6410 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006411 /*
6412 * pci_restore_state clears dev->state_saved so call
6413 * pci_save_state to restore it.
6414 */
6415 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006416
6417 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006418 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006419 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006420 return err;
6421 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006422 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006423 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006424 pci_set_master(pdev);
6425
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006426 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006427
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006428 ixgbe_reset(adapter);
6429
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006430 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6431
Alexander Duyckac802f52012-07-12 05:52:53 +00006432 rtnl_lock();
6433 err = ixgbe_init_interrupt_scheme(adapter);
6434 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006435 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006436
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006437
6438 if (!err)
6439 netif_device_attach(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006440 rtnl_unlock();
6441
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006442 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006443}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006444#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006445
6446static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006447{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006448 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6449 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006450 struct ixgbe_hw *hw = &adapter->hw;
6451 u32 ctrl, fctrl;
6452 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006453#ifdef CONFIG_PM
6454 int retval = 0;
6455#endif
6456
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006457 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006458 netif_device_detach(netdev);
6459
Jacob Kellera0cccce2014-05-16 05:12:29 +00006460 if (netif_running(netdev))
6461 ixgbe_close_suspend(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006462
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006463 ixgbe_clear_interrupt_scheme(adapter);
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006464 rtnl_unlock();
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006465
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006466#ifdef CONFIG_PM
6467 retval = pci_save_state(pdev);
6468 if (retval)
6469 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006470
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006471#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006472 if (hw->mac.ops.stop_link_on_d3)
6473 hw->mac.ops.stop_link_on_d3(hw);
6474
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006475 if (wufc) {
6476 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006477
Emil Tantilovec74a472012-09-20 03:33:56 +00006478 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6479 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006480 hw->mac.ops.enable_tx_laser(hw);
6481
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006482 /* turn on all-multi mode if wake on multicast is enabled */
6483 if (wufc & IXGBE_WUFC_MC) {
6484 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6485 fctrl |= IXGBE_FCTRL_MPE;
6486 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
6487 }
6488
6489 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6490 ctrl |= IXGBE_CTRL_GIO_DIS;
6491 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6492
6493 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6494 } else {
6495 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6496 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6497 }
6498
Alexander Duyckbd508172010-11-16 19:27:03 -08006499 switch (hw->mac.type) {
6500 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006501 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006502 break;
6503 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006504 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006505 case ixgbe_mac_X550:
6506 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006507 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006508 pci_wake_from_d3(pdev, !!wufc);
6509 break;
6510 default:
6511 break;
6512 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006513
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006514 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006515 if (hw->phy.ops.set_phy_power && !*enable_wake)
6516 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006517
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006518 ixgbe_release_hw_control(adapter);
6519
Mark Rustad41c62842014-03-12 00:38:35 +00006520 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6521 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006522
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006523 return 0;
6524}
6525
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006526#ifdef CONFIG_PM
6527static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6528{
6529 int retval;
6530 bool wake;
6531
6532 retval = __ixgbe_shutdown(pdev, &wake);
6533 if (retval)
6534 return retval;
6535
6536 if (wake) {
6537 pci_prepare_to_sleep(pdev);
6538 } else {
6539 pci_wake_from_d3(pdev, false);
6540 pci_set_power_state(pdev, PCI_D3hot);
6541 }
6542
6543 return 0;
6544}
6545#endif /* CONFIG_PM */
6546
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006547static void ixgbe_shutdown(struct pci_dev *pdev)
6548{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006549 bool wake;
6550
6551 __ixgbe_shutdown(pdev, &wake);
6552
6553 if (system_state == SYSTEM_POWER_OFF) {
6554 pci_wake_from_d3(pdev, wake);
6555 pci_set_power_state(pdev, PCI_D3hot);
6556 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006557}
6558
6559/**
Auke Kok9a799d72007-09-15 14:07:45 -07006560 * ixgbe_update_stats - Update the board statistics counters.
6561 * @adapter: board private structure
6562 **/
6563void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6564{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006565 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006566 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006567 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006568 u64 total_mpc = 0;
6569 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006570 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6571 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006572 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006573
Don Skidmored08935c2010-06-11 13:20:29 +00006574 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6575 test_bit(__IXGBE_RESETTING, &adapter->state))
6576 return;
6577
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006578 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006579 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006580 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006581 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006582 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6583 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006584 }
6585 adapter->rsc_total_count = rsc_count;
6586 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006587 }
6588
Alexander Duyck5b7da512010-11-16 19:26:50 -08006589 for (i = 0; i < adapter->num_rx_queues; i++) {
6590 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6591 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
6592 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6593 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006594 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006595 bytes += rx_ring->stats.bytes;
6596 packets += rx_ring->stats.packets;
6597 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006598 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006599 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6600 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006601 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006602 netdev->stats.rx_bytes = bytes;
6603 netdev->stats.rx_packets = packets;
6604
6605 bytes = 0;
6606 packets = 0;
6607 /* gather some stats to the adapter struct that are per queue */
6608 for (i = 0; i < adapter->num_tx_queues; i++) {
6609 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6610 restart_queue += tx_ring->tx_stats.restart_queue;
6611 tx_busy += tx_ring->tx_stats.tx_busy;
6612 bytes += tx_ring->stats.bytes;
6613 packets += tx_ring->stats.packets;
6614 }
6615 adapter->restart_queue = restart_queue;
6616 adapter->tx_busy = tx_busy;
6617 netdev->stats.tx_bytes = bytes;
6618 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006619
Joe Perches7ca647b2010-09-07 21:35:40 +00006620 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006621
6622 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006623 for (i = 0; i < 8; i++) {
6624 /* for packet buffers not used, the register should read 0 */
6625 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6626 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006627 hwstats->mpc[i] += mpc;
6628 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006629 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6630 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006631 switch (hw->mac.type) {
6632 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006633 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6634 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6635 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006636 hwstats->pxonrxc[i] +=
6637 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006638 break;
6639 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006640 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006641 case ixgbe_mac_X550:
6642 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006643 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006644 hwstats->pxonrxc[i] +=
6645 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006646 break;
6647 default:
6648 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006649 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006650 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006651
6652 /*16 register reads */
6653 for (i = 0; i < 16; i++) {
6654 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6655 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6656 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006657 (hw->mac.type == ixgbe_mac_X540) ||
6658 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006659 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6660 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006661 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6662 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6663 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6664 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6665 }
6666 }
6667
Joe Perches7ca647b2010-09-07 21:35:40 +00006668 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006669 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006670 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006671
John Fastabendc84d3242010-11-16 19:27:12 -08006672 ixgbe_update_xoff_received(adapter);
6673
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006674 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006675 switch (hw->mac.type) {
6676 case ixgbe_mac_82598EB:
6677 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006678 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6679 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6680 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6681 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006682 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006683 case ixgbe_mac_X550:
6684 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006685 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006686 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006687 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6688 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6689 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6690 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6691 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006692 for (i = 0; i < 16; i++)
6693 adapter->hw_rx_no_dma_resources +=
6694 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006695 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006696 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006697 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006698 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006699 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006700 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006701 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006702 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6703 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006704#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006705 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6706 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6707 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6708 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6709 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6710 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006711 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006712 if (adapter->fcoe.ddp_pool) {
6713 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6714 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6715 unsigned int cpu;
6716 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006717 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006718 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6719 noddp += ddp_pool->noddp;
6720 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006721 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006722 hwstats->fcoe_noddp = noddp;
6723 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006724 }
Yi Zou6d455222009-05-13 13:12:16 +00006725#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006726 break;
6727 default:
6728 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006729 }
Auke Kok9a799d72007-09-15 14:07:45 -07006730 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006731 hwstats->bprc += bprc;
6732 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006733 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006734 hwstats->mprc -= bprc;
6735 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6736 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6737 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6738 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6739 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6740 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6741 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6742 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006743 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006744 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006745 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006746 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006747 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6748 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006749 /*
6750 * 82598 errata - tx of flow control packets is included in tx counters
6751 */
6752 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006753 hwstats->gptc -= xon_off_tot;
6754 hwstats->mptc -= xon_off_tot;
6755 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6756 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6757 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6758 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6759 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6760 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6761 hwstats->ptc64 -= xon_off_tot;
6762 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6763 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6764 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6765 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6766 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6767 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006768
6769 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006770 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006771
6772 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006773 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006774 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006775 netdev->stats.rx_length_errors = hwstats->rlec;
6776 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006777 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006778}
6779
6780/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006781 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006782 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006783 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006784static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006785{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006786 struct ixgbe_hw *hw = &adapter->hw;
6787 int i;
6788
Alexander Duyckd034acf2011-04-27 09:25:34 +00006789 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6790 return;
6791
6792 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6793
6794 /* if interface is down do nothing */
6795 if (test_bit(__IXGBE_DOWN, &adapter->state))
6796 return;
6797
6798 /* do nothing if we are not using signature filters */
6799 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6800 return;
6801
6802 adapter->fdir_overflow++;
6803
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006804 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6805 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006806 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00006807 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006808 /* re-enable flow director interrupts */
6809 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006810 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006811 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006812 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006813 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006814}
6815
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006816/**
6817 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006818 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006819 *
6820 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006821 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006822 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006823 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006824 */
6825static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6826{
Auke Kok9a799d72007-09-15 14:07:45 -07006827 struct ixgbe_hw *hw = &adapter->hw;
6828 u64 eics = 0;
6829 int i;
6830
Mark Rustad09f40ae2014-01-14 18:53:11 -08006831 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006832 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006833 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006834 test_bit(__IXGBE_RESETTING, &adapter->state))
6835 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006836
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006837 /* Force detection of hung controller */
6838 if (netif_carrier_ok(adapter->netdev)) {
6839 for (i = 0; i < adapter->num_tx_queues; i++)
6840 set_check_for_tx_hang(adapter->tx_ring[i]);
6841 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006842
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006843 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006844 /*
6845 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006846 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006847 * would set *both* EIMS and EICS for any bit in EIAM
6848 */
6849 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6850 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006851 } else {
6852 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006853 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006854 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006855 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07006856 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006857 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006858 }
6859
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006860 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006861 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00006862}
6863
6864/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006865 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006866 * @adapter: pointer to the device adapter structure
6867 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006868 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006869static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006870{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006871 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006872 u32 link_speed = adapter->link_speed;
6873 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006874 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006875
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006876 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6877 return;
6878
6879 if (hw->mac.ops.check_link) {
6880 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006881 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006882 /* always assume link is up, if no check link function */
6883 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6884 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006885 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006886
6887 if (adapter->ixgbe_ieee_pfc)
6888 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6889
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006890 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006891 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006892 ixgbe_set_rx_drop_en(adapter);
6893 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006894
6895 if (link_up ||
6896 time_after(jiffies, (adapter->link_check_timeout +
6897 IXGBE_TRY_LINK_TIMEOUT))) {
6898 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6899 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6900 IXGBE_WRITE_FLUSH(hw);
6901 }
6902
6903 adapter->link_up = link_up;
6904 adapter->link_speed = link_speed;
6905}
6906
Alexander Duyck107d3012012-10-02 00:17:03 +00006907static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6908{
6909#ifdef CONFIG_IXGBE_DCB
6910 struct net_device *netdev = adapter->netdev;
6911 struct dcb_app app = {
6912 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6913 .protocol = 0,
6914 };
6915 u8 up = 0;
6916
6917 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6918 up = dcb_ieee_getapp_mask(netdev, &app);
6919
6920 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6921#endif
6922}
6923
David Ahern1cd127f2016-10-17 19:15:48 -07006924static int ixgbe_enable_macvlan(struct net_device *upper, void *data)
6925{
6926 if (netif_is_macvlan(upper)) {
6927 struct macvlan_dev *vlan = netdev_priv(upper);
6928
6929 if (vlan->fwd_priv)
6930 netif_tx_wake_all_queues(upper);
6931 }
6932
6933 return 0;
6934}
6935
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006936/**
6937 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6938 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006939 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006940 **/
6941static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6942{
6943 struct net_device *netdev = adapter->netdev;
6944 struct ixgbe_hw *hw = &adapter->hw;
6945 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07006946 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006947 bool flow_rx, flow_tx;
6948
6949 /* only continue if link was previously down */
6950 if (netif_carrier_ok(netdev))
6951 return;
6952
6953 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6954
6955 switch (hw->mac.type) {
6956 case ixgbe_mac_82598EB: {
6957 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6958 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6959 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6960 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6961 }
6962 break;
6963 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006964 case ixgbe_mac_X550:
6965 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006966 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006967 case ixgbe_mac_82599EB: {
6968 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6969 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6970 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6971 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6972 }
6973 break;
6974 default:
6975 flow_tx = false;
6976 flow_rx = false;
6977 break;
6978 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006979
Jacob Keller6cb562d2012-12-05 07:24:41 +00006980 adapter->last_rx_ptp_check = jiffies;
6981
Jacob Keller8fecf672013-06-21 08:14:32 +00006982 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006983 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006984
Mark Rustad454adb02015-07-10 14:19:22 -07006985 switch (link_speed) {
6986 case IXGBE_LINK_SPEED_10GB_FULL:
6987 speed_str = "10 Gbps";
6988 break;
6989 case IXGBE_LINK_SPEED_2_5GB_FULL:
6990 speed_str = "2.5 Gbps";
6991 break;
6992 case IXGBE_LINK_SPEED_1GB_FULL:
6993 speed_str = "1 Gbps";
6994 break;
6995 case IXGBE_LINK_SPEED_100_FULL:
6996 speed_str = "100 Mbps";
6997 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006998 case IXGBE_LINK_SPEED_10_FULL:
6999 speed_str = "10 Mbps";
7000 break;
Mark Rustad454adb02015-07-10 14:19:22 -07007001 default:
7002 speed_str = "unknown speed";
7003 break;
7004 }
7005 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007006 ((flow_rx && flow_tx) ? "RX/TX" :
7007 (flow_rx ? "RX" :
7008 (flow_tx ? "TX" : "None"))));
7009
7010 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007011 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007012
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007013 /* enable transmits */
7014 netif_tx_wake_all_queues(adapter->netdev);
7015
7016 /* enable any upper devices */
7017 rtnl_lock();
David Ahern1cd127f2016-10-17 19:15:48 -07007018 netdev_walk_all_upper_dev_rcu(adapter->netdev,
7019 ixgbe_enable_macvlan, NULL);
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007020 rtnl_unlock();
7021
Alexander Duyck107d3012012-10-02 00:17:03 +00007022 /* update the default user priority for VFs */
7023 ixgbe_update_default_up(adapter);
7024
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007025 /* ping all the active vfs to let them know link has changed */
7026 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007027}
7028
7029/**
7030 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7031 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007032 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007033 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00007034static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007035{
7036 struct net_device *netdev = adapter->netdev;
7037 struct ixgbe_hw *hw = &adapter->hw;
7038
7039 adapter->link_up = false;
7040 adapter->link_speed = 0;
7041
7042 /* only continue if link was up previously */
7043 if (!netif_carrier_ok(netdev))
7044 return;
7045
7046 /* poll for SFP+ cable when link is down */
7047 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
7048 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
7049
Jacob Keller8fecf672013-06-21 08:14:32 +00007050 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007051 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007052
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007053 e_info(drv, "NIC Link is Down\n");
7054 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007055
7056 /* ping all the active vfs to let them know link has changed */
7057 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007058}
7059
Emil Tantilov07923c12014-08-12 07:12:08 +00007060static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
7061{
7062 int i;
7063
7064 for (i = 0; i < adapter->num_tx_queues; i++) {
7065 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
7066
7067 if (tx_ring->next_to_use != tx_ring->next_to_clean)
7068 return true;
7069 }
7070
7071 return false;
7072}
7073
7074static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
7075{
7076 struct ixgbe_hw *hw = &adapter->hw;
7077 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
7078 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
7079
7080 int i, j;
7081
7082 if (!adapter->num_vfs)
7083 return false;
7084
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007085 /* resetting the PF is only needed for MAC before X550 */
7086 if (hw->mac.type >= ixgbe_mac_X550)
7087 return false;
7088
Emil Tantilov07923c12014-08-12 07:12:08 +00007089 for (i = 0; i < adapter->num_vfs; i++) {
7090 for (j = 0; j < q_per_pool; j++) {
7091 u32 h, t;
7092
7093 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
7094 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
7095
7096 if (h != t)
7097 return true;
7098 }
7099 }
7100
7101 return false;
7102}
7103
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007104/**
7105 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007106 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007107 **/
7108static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
7109{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007110 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00007111 if (ixgbe_ring_tx_pending(adapter) ||
7112 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007113 /* We've lost link, so the controller stops DMA,
7114 * but we've got queued Tx work that's never going
7115 * to get done, so reset controller to flush Tx.
7116 * (Do the reset outside of interrupt context).
7117 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00007118 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007119 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007120 }
7121 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007122}
7123
Emil Tantilov9079e412014-11-19 03:18:19 +00007124#ifdef CONFIG_PCI_IOV
7125static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
7126 struct pci_dev *vfdev)
7127{
7128 if (!pci_wait_for_pending_transaction(vfdev))
7129 e_dev_warn("Issuing VFLR with pending transactions\n");
7130
7131 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
7132 pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
7133
7134 msleep(100);
7135}
7136
7137static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
7138{
7139 struct ixgbe_hw *hw = &adapter->hw;
7140 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07007141 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00007142 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00007143
7144 if (!(netif_carrier_ok(adapter->netdev)))
7145 return;
7146
7147 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
7148 if (gpc) /* If incrementing then no need for the check below */
7149 return;
7150 /* Check to see if a bad DMA write target from an errant or
7151 * malicious VF has caused a PCIe error. If so then we can
7152 * issue a VFLR to the offending VF(s) and then resume without
7153 * requesting a full slot reset.
7154 */
7155
7156 if (!pdev)
7157 return;
7158
Emil Tantilov9079e412014-11-19 03:18:19 +00007159 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07007160 for (vf = 0; vf < adapter->num_vfs; ++vf) {
7161 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
7162 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00007163
Mark Rustad988d1302015-10-30 15:29:34 -07007164 if (!vfdev)
7165 continue;
7166 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
7167 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
7168 status_reg & PCI_STATUS_REC_MASTER_ABORT)
7169 ixgbe_issue_vf_flr(adapter, vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00007170 }
7171}
7172
Greg Rosea985b6c32010-11-18 03:02:52 +00007173static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
7174{
7175 u32 ssvpc;
7176
Greg Rose0584d992012-08-08 00:00:58 +00007177 /* Do not perform spoof check for 82598 or if not in IOV mode */
7178 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7179 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00007180 return;
7181
7182 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
7183
7184 /*
7185 * ssvpc register is cleared on read, if zero then no
7186 * spoofed packets in the last interval.
7187 */
7188 if (!ssvpc)
7189 return;
7190
Emil Tantilovd6ea0752012-08-08 06:28:37 +00007191 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00007192}
Emil Tantilov9079e412014-11-19 03:18:19 +00007193#else
7194static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7195{
7196}
7197
7198static void
7199ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7200{
7201}
7202#endif /* CONFIG_PCI_IOV */
7203
Greg Rosea985b6c32010-11-18 03:02:52 +00007204
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007205/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007206 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007207 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007208 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007209static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007210{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007211 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007212 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007213 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007214 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007215 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007216
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007217 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007218
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007219 if (adapter->link_up)
7220 ixgbe_watchdog_link_is_up(adapter);
7221 else
7222 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007223
Emil Tantilov9079e412014-11-19 03:18:19 +00007224 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007225 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007226 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007227
7228 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007229}
7230
Alexander Duyck70864002011-04-27 09:13:56 +00007231/**
7232 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007233 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007234 **/
7235static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7236{
7237 struct ixgbe_hw *hw = &adapter->hw;
7238 s32 err;
7239
7240 /* not searching for SFP so there is nothing to do here */
7241 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7242 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7243 return;
7244
Mark Rustad58e7cd22015-08-08 16:18:48 -07007245 if (adapter->sfp_poll_time &&
7246 time_after(adapter->sfp_poll_time, jiffies))
7247 return; /* If not yet time to poll for SFP */
7248
Alexander Duyck70864002011-04-27 09:13:56 +00007249 /* someone else is in init, wait until next service event */
7250 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7251 return;
7252
Mark Rustad58e7cd22015-08-08 16:18:48 -07007253 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7254
Alexander Duyck70864002011-04-27 09:13:56 +00007255 err = hw->phy.ops.identify_sfp(hw);
7256 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7257 goto sfp_out;
7258
7259 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7260 /* If no cable is present, then we need to reset
7261 * the next time we find a good cable. */
7262 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7263 }
7264
7265 /* exit on error */
7266 if (err)
7267 goto sfp_out;
7268
7269 /* exit if reset not needed */
7270 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7271 goto sfp_out;
7272
7273 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7274
7275 /*
7276 * A module may be identified correctly, but the EEPROM may not have
7277 * support for that module. setup_sfp() will fail in that case, so
7278 * we should not allow that module to load.
7279 */
7280 if (hw->mac.type == ixgbe_mac_82598EB)
7281 err = hw->phy.ops.reset(hw);
7282 else
7283 err = hw->mac.ops.setup_sfp(hw);
7284
7285 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7286 goto sfp_out;
7287
7288 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7289 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7290
7291sfp_out:
7292 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7293
7294 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7295 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7296 e_dev_err("failed to initialize because an unsupported "
7297 "SFP+ module type was detected.\n");
7298 e_dev_err("Reload the driver after installing a "
7299 "supported module.\n");
7300 unregister_netdev(adapter->netdev);
7301 }
7302}
7303
7304/**
7305 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007306 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007307 **/
7308static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7309{
7310 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00007311 u32 speed;
7312 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007313
7314 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7315 return;
7316
7317 /* someone else is in init, wait until next service event */
7318 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7319 return;
7320
7321 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7322
Josh Hay3d292262012-12-15 03:28:19 +00007323 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00007324 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00007325 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007326
7327 /* setup the highest link when no autoneg */
7328 if (!autoneg) {
7329 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
7330 speed = IXGBE_LINK_SPEED_10GB_FULL;
7331 }
7332 }
7333
Alexander Duyck70864002011-04-27 09:13:56 +00007334 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007335 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007336
7337 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7338 adapter->link_check_timeout = jiffies;
7339 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7340}
7341
7342/**
7343 * ixgbe_service_timer - Timer Call-back
7344 * @data: pointer to adapter cast into an unsigned long
7345 **/
7346static void ixgbe_service_timer(unsigned long data)
7347{
7348 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
7349 unsigned long next_event_offset;
7350
7351 /* poll faster when waiting for link */
7352 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7353 next_event_offset = HZ / 10;
7354 else
7355 next_event_offset = HZ * 2;
7356
7357 /* Reset the timer */
7358 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7359
Emil Tantilov9079e412014-11-19 03:18:19 +00007360 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007361}
7362
Don Skidmore597f22d2015-06-09 16:52:02 -07007363static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7364{
7365 struct ixgbe_hw *hw = &adapter->hw;
7366 u32 status;
7367
7368 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7369 return;
7370
7371 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7372
7373 if (!hw->phy.ops.handle_lasi)
7374 return;
7375
7376 status = hw->phy.ops.handle_lasi(&adapter->hw);
7377 if (status != IXGBE_ERR_OVERTEMP)
7378 return;
7379
7380 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7381}
7382
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007383static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7384{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007385 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007386 return;
7387
Mark Rustad09f40ae2014-01-14 18:53:11 -08007388 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007389 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007390 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007391 test_bit(__IXGBE_RESETTING, &adapter->state))
7392 return;
7393
7394 ixgbe_dump(adapter);
7395 netdev_err(adapter->netdev, "Reset adapter\n");
7396 adapter->tx_timeout_count++;
7397
John Fastabend8f4c5c92014-01-16 02:30:05 -08007398 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007399 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007400 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007401}
7402
Alexander Duyck70864002011-04-27 09:13:56 +00007403/**
7404 * ixgbe_service_task - manages and runs subtasks
7405 * @work: pointer to work_struct containing our data
7406 **/
7407static void ixgbe_service_task(struct work_struct *work)
7408{
7409 struct ixgbe_adapter *adapter = container_of(work,
7410 struct ixgbe_adapter,
7411 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007412 if (ixgbe_removed(adapter->hw.hw_addr)) {
7413 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7414 rtnl_lock();
7415 ixgbe_down(adapter);
7416 rtnl_unlock();
7417 }
7418 ixgbe_service_event_complete(adapter);
7419 return;
7420 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007421 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007422 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007423 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007424 udp_tunnel_get_rx_info(adapter->netdev);
7425 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007426 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007427 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007428 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007429 ixgbe_sfp_detection_subtask(adapter);
7430 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007431 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007432 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007433 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007434 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007435
Jacob Keller8fecf672013-06-21 08:14:32 +00007436 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007437 ixgbe_ptp_overflow_check(adapter);
7438 ixgbe_ptp_rx_hang(adapter);
7439 }
Alexander Duyck70864002011-04-27 09:13:56 +00007440
7441 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007442}
7443
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007444static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7445 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007446 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007447{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007448 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007449 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007450 union {
7451 struct iphdr *v4;
7452 struct ipv6hdr *v6;
7453 unsigned char *hdr;
7454 } ip;
7455 union {
7456 struct tcphdr *tcp;
7457 unsigned char *hdr;
7458 } l4;
7459 u32 paylen, l4_offset;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007460 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007461
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007462 if (skb->ip_summed != CHECKSUM_PARTIAL)
7463 return 0;
7464
Alexander Duyck897ab152011-05-27 05:31:47 +00007465 if (!skb_is_gso(skb))
7466 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007467
Francois Romieu2049e1f2014-03-30 03:14:27 +00007468 err = skb_cow_head(skb, 0);
7469 if (err < 0)
7470 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007471
Alexander Duyckb83e3012016-04-14 17:19:31 -04007472 ip.hdr = skb_network_header(skb);
7473 l4.hdr = skb_checksum_start(skb);
7474
Alexander Duyck897ab152011-05-27 05:31:47 +00007475 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7476 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7477
Alexander Duyckb83e3012016-04-14 17:19:31 -04007478 /* initialize outer IP header fields */
7479 if (ip.v4->version == 4) {
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007480 unsigned char *csum_start = skb_checksum_start(skb);
7481 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
7482
Alexander Duyckb83e3012016-04-14 17:19:31 -04007483 /* IP header will have to cancel out any data that
7484 * is not a part of the outer IP header
7485 */
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007486 ip.v4->check = csum_fold(csum_partial(trans_start,
7487 csum_start - trans_start,
7488 0));
Alexander Duyck897ab152011-05-27 05:31:47 +00007489 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007490
7491 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007492 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7493 IXGBE_TX_FLAGS_CSUM |
7494 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007495 } else {
7496 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007497 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7498 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007499 }
7500
Alexander Duyckb83e3012016-04-14 17:19:31 -04007501 /* determine offset of inner transport header */
7502 l4_offset = l4.hdr - skb->data;
7503
7504 /* compute length of segmentation header */
7505 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7506
7507 /* remove payload length from inner checksum */
7508 paylen = skb->len - l4_offset;
7509 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007510
Alexander Duyck091a6242012-02-08 07:51:01 +00007511 /* update gso size and bytecount with header size */
7512 first->gso_segs = skb_shinfo(skb)->gso_segs;
7513 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7514
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007515 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007516 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007517 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007518
7519 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007520 vlan_macip_lens = l4.hdr - ip.hdr;
7521 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007522 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007523
7524 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007525 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007526
7527 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007528}
7529
Alexander Duyck49763de2016-01-13 07:31:11 -08007530static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7531{
7532 unsigned int offset = 0;
7533
7534 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7535
7536 return offset == skb_checksum_start_offset(skb);
7537}
7538
Alexander Duyck244e27a2012-02-08 07:51:11 +00007539static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7540 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007541{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007542 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007543 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007544 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007545
Alexander Duyck897ab152011-05-27 05:31:47 +00007546 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007547csum_failed:
7548 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7549 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007550 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007551 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007552 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007553
Alexander Duyck49763de2016-01-13 07:31:11 -08007554 switch (skb->csum_offset) {
7555 case offsetof(struct tcphdr, check):
7556 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7557 /* fall through */
7558 case offsetof(struct udphdr, check):
7559 break;
7560 case offsetof(struct sctphdr, checksum):
7561 /* validate that this is actually an SCTP request */
7562 if (((first->protocol == htons(ETH_P_IP)) &&
7563 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7564 ((first->protocol == htons(ETH_P_IPV6)) &&
7565 ixgbe_ipv6_csum_is_sctp(skb))) {
7566 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7567 break;
7568 }
7569 /* fall through */
7570 default:
7571 skb_checksum_help(skb);
7572 goto csum_failed;
7573 }
7574
7575 /* update TX checksum flag */
7576 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7577 vlan_macip_lens = skb_checksum_start_offset(skb) -
7578 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007579no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007580 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007581 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007582 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007583
Alexander Duyck49763de2016-01-13 07:31:11 -08007584 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007585}
7586
Alexander Duyck472148c2012-11-07 02:34:28 +00007587#define IXGBE_SET_FLAG(_input, _flag, _result) \
7588 ((_flag <= _result) ? \
7589 ((u32)(_input & _flag) * (_result / _flag)) : \
7590 ((u32)(_input & _flag) / (_flag / _result)))
7591
7592static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007593{
7594 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007595 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7596 IXGBE_ADVTXD_DCMD_DEXT |
7597 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007598
7599 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007600 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7601 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007602
Alexander Duyckd3d00232011-07-15 02:31:25 +00007603 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007604 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7605 IXGBE_ADVTXD_DCMD_TSE);
7606
7607 /* set timestamp bit if present */
7608 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7609 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007610
Alexander Duyck62748b72012-07-20 08:09:01 +00007611 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007612 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007613
Alexander Duyckd3d00232011-07-15 02:31:25 +00007614 return cmd_type;
7615}
7616
Alexander Duyck729739b2012-02-08 07:51:06 +00007617static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7618 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007619{
Alexander Duyck472148c2012-11-07 02:34:28 +00007620 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007621
7622 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007623 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7624 IXGBE_TX_FLAGS_CSUM,
7625 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007626
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007627 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007628 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7629 IXGBE_TX_FLAGS_IPV4,
7630 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007631
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007632 /*
7633 * Check Context must be set if Tx switch is enabled, which it
7634 * always is for case where virtual functions are running
7635 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007636 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7637 IXGBE_TX_FLAGS_CC,
7638 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007639
Alexander Duyck472148c2012-11-07 02:34:28 +00007640 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007641}
7642
Daniel Borkmann2367a172014-08-26 19:34:18 +02007643static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7644{
7645 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7646
7647 /* Herbert's original patch had:
7648 * smp_mb__after_netif_stop_queue();
7649 * but since that doesn't exist yet, just open code it.
7650 */
7651 smp_mb();
7652
7653 /* We need to check again in a case another CPU has just
7654 * made room available.
7655 */
7656 if (likely(ixgbe_desc_unused(tx_ring) < size))
7657 return -EBUSY;
7658
7659 /* A reprieve! - use start_queue because it doesn't call schedule */
7660 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7661 ++tx_ring->tx_stats.restart_queue;
7662 return 0;
7663}
7664
7665static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7666{
7667 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7668 return 0;
7669
7670 return __ixgbe_maybe_stop_tx(tx_ring, size);
7671}
7672
Alexander Duyckd3d00232011-07-15 02:31:25 +00007673#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7674 IXGBE_TXD_CMD_RS)
7675
7676static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007677 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007678 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007679{
Alexander Duyck729739b2012-02-08 07:51:06 +00007680 struct sk_buff *skb = first->skb;
7681 struct ixgbe_tx_buffer *tx_buffer;
7682 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007683 struct skb_frag_struct *frag;
7684 dma_addr_t dma;
7685 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007686 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007687 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007688 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007689
Alexander Duyck729739b2012-02-08 07:51:06 +00007690 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7691
Alexander Duyckec718252012-10-30 06:01:55 +00007692 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7693
7694 size = skb_headlen(skb);
7695 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007696
Alexander Duyckd3d00232011-07-15 02:31:25 +00007697#ifdef IXGBE_FCOE
7698 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007699 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007700 size -= sizeof(struct fcoe_crc_eof) - data_len;
7701 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007702 } else {
7703 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007704 }
Auke Kok9a799d72007-09-15 14:07:45 -07007705 }
7706
Alexander Duyckd3d00232011-07-15 02:31:25 +00007707#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007708 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007709
Alexander Duyckec718252012-10-30 06:01:55 +00007710 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007711
Alexander Duyckec718252012-10-30 06:01:55 +00007712 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7713 if (dma_mapping_error(tx_ring->dev, dma))
7714 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007715
Alexander Duyckec718252012-10-30 06:01:55 +00007716 /* record length, and DMA address */
7717 dma_unmap_len_set(tx_buffer, len, size);
7718 dma_unmap_addr_set(tx_buffer, dma, dma);
7719
7720 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7721
Alexander Duyck729739b2012-02-08 07:51:06 +00007722 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007723 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007724 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007725
Alexander Duyckd3d00232011-07-15 02:31:25 +00007726 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007727 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007728 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007729 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007730 i = 0;
7731 }
Alexander Duyckec718252012-10-30 06:01:55 +00007732 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007733
7734 dma += IXGBE_MAX_DATA_PER_TXD;
7735 size -= IXGBE_MAX_DATA_PER_TXD;
7736
7737 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007738 }
7739
Alexander Duyck729739b2012-02-08 07:51:06 +00007740 if (likely(!data_len))
7741 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007742
Alexander Duyck472148c2012-11-07 02:34:28 +00007743 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007744
Alexander Duyck729739b2012-02-08 07:51:06 +00007745 i++;
7746 tx_desc++;
7747 if (i == tx_ring->count) {
7748 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7749 i = 0;
7750 }
Alexander Duyckec718252012-10-30 06:01:55 +00007751 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007752
Alexander Duyckd3d00232011-07-15 02:31:25 +00007753#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007754 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007755#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007756 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007757#endif
7758 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007759
Alexander Duyck729739b2012-02-08 07:51:06 +00007760 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7761 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007762
Alexander Duyck729739b2012-02-08 07:51:06 +00007763 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007764 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007765
Alexander Duyck729739b2012-02-08 07:51:06 +00007766 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007767 cmd_type |= size | IXGBE_TXD_CMD;
7768 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007769
Alexander Duyck091a6242012-02-08 07:51:01 +00007770 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007771
Alexander Duyckd3d00232011-07-15 02:31:25 +00007772 /* set the timestamp */
7773 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007774
7775 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007776 * Force memory writes to complete before letting h/w know there
7777 * are new descriptors to fetch. (Only applicable for weak-ordered
7778 * memory model archs, such as IA-64).
7779 *
7780 * We also need this memory barrier to make certain all of the
7781 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007782 */
7783 wmb();
7784
Alexander Duyckd3d00232011-07-15 02:31:25 +00007785 /* set next_to_watch value indicating a packet is present */
7786 first->next_to_watch = tx_desc;
7787
Alexander Duyck729739b2012-02-08 07:51:06 +00007788 i++;
7789 if (i == tx_ring->count)
7790 i = 0;
7791
7792 tx_ring->next_to_use = i;
7793
Daniel Borkmann2367a172014-08-26 19:34:18 +02007794 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7795
7796 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00007797 writel(i, tx_ring->tail);
7798
7799 /* we need this if more than one processor can write to our tail
7800 * at a time, it synchronizes IO on IA64/Altix systems
7801 */
7802 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02007803 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02007804
Alexander Duyckd3d00232011-07-15 02:31:25 +00007805 return;
7806dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00007807 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckffed21b2017-01-17 08:37:29 -08007808 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckd3d00232011-07-15 02:31:25 +00007809
7810 /* clear dma mappings for failed tx_buffer_info map */
Alexander Duyckffed21b2017-01-17 08:37:29 -08007811 while (tx_buffer != first) {
7812 if (dma_unmap_len(tx_buffer, len))
7813 dma_unmap_page(tx_ring->dev,
7814 dma_unmap_addr(tx_buffer, dma),
7815 dma_unmap_len(tx_buffer, len),
7816 DMA_TO_DEVICE);
7817 dma_unmap_len_set(tx_buffer, len, 0);
7818
7819 if (i--)
7820 i += tx_ring->count;
Alexander Duyck729739b2012-02-08 07:51:06 +00007821 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckd3d00232011-07-15 02:31:25 +00007822 }
7823
Alexander Duyckffed21b2017-01-17 08:37:29 -08007824 if (dma_unmap_len(tx_buffer, len))
7825 dma_unmap_single(tx_ring->dev,
7826 dma_unmap_addr(tx_buffer, dma),
7827 dma_unmap_len(tx_buffer, len),
7828 DMA_TO_DEVICE);
7829 dma_unmap_len_set(tx_buffer, len, 0);
7830
7831 dev_kfree_skb_any(first->skb);
7832 first->skb = NULL;
7833
Alexander Duyckd3d00232011-07-15 02:31:25 +00007834 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07007835}
7836
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007837static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007838 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007839{
Alexander Duyck69830522011-01-06 14:29:58 +00007840 struct ixgbe_q_vector *q_vector = ring->q_vector;
7841 union ixgbe_atr_hash_dword input = { .dword = 0 };
7842 union ixgbe_atr_hash_dword common = { .dword = 0 };
7843 union {
7844 unsigned char *network;
7845 struct iphdr *ipv4;
7846 struct ipv6hdr *ipv6;
7847 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007848 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08007849 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07007850 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00007851 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08007852 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007853
Alexander Duyck69830522011-01-06 14:29:58 +00007854 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7855 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00007856 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007857
Alexander Duyck69830522011-01-06 14:29:58 +00007858 /* do nothing if sampling is disabled */
7859 if (!ring->atr_sample_rate)
7860 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007861
Alexander Duyck69830522011-01-06 14:29:58 +00007862 ring->atr_count++;
7863
Alexander Duycke2873d42016-01-25 19:39:40 -08007864 /* currently only IPv4/IPv6 with TCP is supported */
7865 if ((first->protocol != htons(ETH_P_IP)) &&
7866 (first->protocol != htons(ETH_P_IPV6)))
7867 return;
7868
Alexander Duyck69830522011-01-06 14:29:58 +00007869 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07007870 skb = first->skb;
7871 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007872 if (unlikely(hdr.network <= skb->data))
7873 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08007874 if (skb->encapsulation &&
7875 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07007876 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07007877 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00007878
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007879 if (unlikely(skb_tail_pointer(skb) < hdr.network +
7880 VXLAN_HEADROOM))
7881 return;
7882
Alexander Duyck9f12df92016-01-25 19:36:29 -08007883 /* verify the port is recognized as VXLAN */
7884 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08007885 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08007886 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07007887
7888 if (adapter->geneve_port &&
7889 udp_hdr(skb)->dest == adapter->geneve_port)
7890 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08007891 }
7892
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007893 /* Make sure we have at least [minimum IPv4 header + TCP]
7894 * or [IPv6 header] bytes
7895 */
7896 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
7897 return;
7898
Mark Rustade19dcde2015-12-09 14:55:37 -08007899 /* Currently only IPv4/IPv6 with TCP is supported */
7900 switch (hdr.ipv4->version) {
7901 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08007902 /* access ihl as u8 to avoid unaligned access on ia64 */
7903 hlen = (hdr.network[0] & 0x0F) << 2;
7904 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08007905 break;
7906 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08007907 hlen = hdr.network - skb->data;
7908 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
7909 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08007910 break;
7911 default:
7912 return;
Mark Rustad67359c32015-06-15 11:33:25 -07007913 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007914
Alexander Duycke2873d42016-01-25 19:39:40 -08007915 if (l4_proto != IPPROTO_TCP)
7916 return;
7917
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007918 if (unlikely(skb_tail_pointer(skb) < hdr.network +
7919 hlen + sizeof(struct tcphdr)))
7920 return;
7921
Alexander Duycke2873d42016-01-25 19:39:40 -08007922 th = (struct tcphdr *)(hdr.network + hlen);
7923
7924 /* skip this packet since the socket is closing */
7925 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00007926 return;
7927
7928 /* sample on all syn packets or once every atr sample count */
7929 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
7930 return;
7931
7932 /* reset sample count */
7933 ring->atr_count = 0;
7934
Alexander Duyck244e27a2012-02-08 07:51:11 +00007935 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00007936
7937 /*
7938 * src and dst are inverted, think how the receiver sees them
7939 *
7940 * The input is broken into two sections, a non-compressed section
7941 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7942 * is XORed together and stored in the compressed dword.
7943 */
7944 input.formatted.vlan_id = vlan_id;
7945
7946 /*
7947 * since src port and flex bytes occupy the same word XOR them together
7948 * and write the value to source port portion of compressed dword
7949 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007950 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00007951 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00007952 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00007953 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00007954 common.port.dst ^= th->source;
7955
Mark Rustade19dcde2015-12-09 14:55:37 -08007956 switch (hdr.ipv4->version) {
7957 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00007958 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7959 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08007960 break;
7961 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00007962 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7963 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7964 hdr.ipv6->saddr.s6_addr32[1] ^
7965 hdr.ipv6->saddr.s6_addr32[2] ^
7966 hdr.ipv6->saddr.s6_addr32[3] ^
7967 hdr.ipv6->daddr.s6_addr32[0] ^
7968 hdr.ipv6->daddr.s6_addr32[1] ^
7969 hdr.ipv6->daddr.s6_addr32[2] ^
7970 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08007971 break;
7972 default:
7973 break;
Alexander Duyck69830522011-01-06 14:29:58 +00007974 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007975
Alexander Duyck9f12df92016-01-25 19:36:29 -08007976 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07007977 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07007978
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007979 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007980 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7981 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007982}
7983
Jason Wangf663dd92014-01-10 16:18:26 +08007984static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01007985 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007986{
Jason Wangf663dd92014-01-10 16:18:26 +08007987 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7988#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00007989 struct ixgbe_adapter *adapter;
7990 struct ixgbe_ring_feature *f;
7991 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08007992#endif
7993
7994 if (fwd_adapter)
7995 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7996
7997#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00007998
Alexander Duyck97488bd2013-01-12 06:33:37 +00007999 /*
8000 * only execute the code below if protocol is FCoE
8001 * or FIP and we have FCoE enabled on the adapter
8002 */
8003 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00008004 case htons(ETH_P_FCOE):
8005 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00008006 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00008007
Alexander Duyck97488bd2013-01-12 06:33:37 +00008008 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8009 break;
8010 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01008011 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00008012 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008013
Alexander Duyck97488bd2013-01-12 06:33:37 +00008014 f = &adapter->ring_feature[RING_F_FCOE];
8015
8016 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8017 smp_processor_id();
8018
8019 while (txq >= f->indices)
8020 txq -= f->indices;
8021
8022 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08008023#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01008024 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08008025#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008026}
8027
Alexander Duyckfc77dc32010-11-16 19:26:51 -08008028netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00008029 struct ixgbe_adapter *adapter,
8030 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008031{
Alexander Duyckd3d00232011-07-15 02:31:25 +00008032 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00008033 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008034 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00008035 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00008036 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00008037 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00008038 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00008039
Alexander Duycka535c302011-05-27 05:31:52 +00008040 /*
8041 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00008042 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00008043 * + 2 desc gap to keep tail from touching head,
8044 * + 1 desc for context descriptor,
8045 * otherwise try next time
8046 */
Alexander Duycka535c302011-05-27 05:31:52 +00008047 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8048 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00008049
Alexander Duycka535c302011-05-27 05:31:52 +00008050 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8051 tx_ring->tx_stats.tx_busy++;
8052 return NETDEV_TX_BUSY;
8053 }
8054
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008055 /* record the location of the first descriptor for this packet */
8056 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8057 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00008058 first->bytecount = skb->len;
8059 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008060
Alexander Duyck66f32a82011-06-29 05:43:22 +00008061 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01008062 if (skb_vlan_tag_present(skb)) {
8063 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008064 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8065 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008066 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008067 struct vlan_hdr *vhdr, _vhdr;
8068 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8069 if (!vhdr)
8070 goto out_drop;
8071
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008072 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8073 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008074 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07008075 }
Toshiaki Makita02136682015-01-29 20:37:09 +09008076 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00008077
Mark Rustadd5234932014-08-09 07:02:09 +00008078 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
8079 adapter->ptp_clock &&
8080 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8081 &adapter->state)) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008082 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8083 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00008084
8085 /* schedule check for Tx timestamp */
8086 adapter->ptp_tx_skb = skb_get(skb);
8087 adapter->ptp_tx_start = jiffies;
8088 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008089 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008090
Jakub Kicinskiff29a862014-03-15 14:55:16 +00008091 skb_tx_timestamp(skb);
8092
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008093#ifdef CONFIG_PCI_IOV
8094 /*
8095 * Use the l2switch_enable flag - would be false if the DMA
8096 * Tx switch had been disabled.
8097 */
8098 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00008099 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008100
8101#endif
John Fastabend32701dc2011-09-27 03:51:56 +00008102 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00008103 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00008104 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8105 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008106 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00008107 tx_flags |= (skb->priority & 0x7) <<
8108 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008109 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8110 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00008111
8112 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00008113 goto out_drop;
8114 vhdr = (struct vlan_ethhdr *)skb->data;
8115 vhdr->h_vlan_TCI = htons(tx_flags >>
8116 IXGBE_TX_FLAGS_VLAN_SHIFT);
8117 } else {
8118 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8119 }
8120 }
Alexander Duycka535c302011-05-27 05:31:52 +00008121
Alexander Duyck244e27a2012-02-08 07:51:11 +00008122 /* record initial flags and protocol */
8123 first->tx_flags = tx_flags;
8124 first->protocol = protocol;
8125
Yi Zoueacd73f2009-05-13 13:11:06 +00008126#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00008127 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008128 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00008129 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00008130 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00008131 if (tso < 0)
8132 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07008133
Alexander Duyck66f32a82011-06-29 05:43:22 +00008134 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00008135 }
Auke Kok9a799d72007-09-15 14:07:45 -07008136
Auke Kok9a799d72007-09-15 14:07:45 -07008137#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008138 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008139 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07008140 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008141 else if (!tso)
8142 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008143
8144 /* add the ATR filter if ATR is on */
8145 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00008146 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008147
8148#ifdef IXGBE_FCOE
8149xmit_fcoe:
8150#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008151 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008152
Auke Kok9a799d72007-09-15 14:07:45 -07008153 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00008154
8155out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008156 dev_kfree_skb_any(first->skb);
8157 first->skb = NULL;
8158
Alexander Duyck897ab152011-05-27 05:31:47 +00008159 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07008160}
8161
John Fastabend2a47fa42013-11-06 09:54:52 -08008162static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8163 struct net_device *netdev,
8164 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008165{
8166 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008167 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07008168
Alexander Duycka50c29d2012-02-08 07:50:40 +00008169 /*
8170 * The minimum packet size for olinfo paylen is 17 so pad the skb
8171 * in order to meet this minimum size requirement.
8172 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08008173 if (skb_put_padto(skb, 17))
8174 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00008175
John Fastabend2a47fa42013-11-06 09:54:52 -08008176 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8177
Auke Kok9a799d72007-09-15 14:07:45 -07008178 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8179}
8180
John Fastabend2a47fa42013-11-06 09:54:52 -08008181static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8182 struct net_device *netdev)
8183{
8184 return __ixgbe_xmit_frame(skb, netdev, NULL);
8185}
8186
Auke Kok9a799d72007-09-15 14:07:45 -07008187/**
8188 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8189 * @netdev: network interface device structure
8190 * @p: pointer to an address structure
8191 *
8192 * Returns 0 on success, negative on failure
8193 **/
8194static int ixgbe_set_mac(struct net_device *netdev, void *p)
8195{
8196 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8197 struct ixgbe_hw *hw = &adapter->hw;
8198 struct sockaddr *addr = p;
8199
8200 if (!is_valid_ether_addr(addr->sa_data))
8201 return -EADDRNOTAVAIL;
8202
8203 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008204 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008205
Alexander Duyckc9f53e62015-10-22 16:26:30 -07008206 ixgbe_mac_set_default_filter(adapter);
8207
8208 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008209}
8210
Ben Hutchings6b73e102009-04-29 08:08:58 +00008211static int
8212ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8213{
8214 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8215 struct ixgbe_hw *hw = &adapter->hw;
8216 u16 value;
8217 int rc;
8218
8219 if (prtad != hw->phy.mdio.prtad)
8220 return -EINVAL;
8221 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8222 if (!rc)
8223 rc = value;
8224 return rc;
8225}
8226
8227static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8228 u16 addr, u16 value)
8229{
8230 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8231 struct ixgbe_hw *hw = &adapter->hw;
8232
8233 if (prtad != hw->phy.mdio.prtad)
8234 return -EINVAL;
8235 return hw->phy.ops.write_reg(hw, addr, devad, value);
8236}
8237
8238static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8239{
8240 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8241
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008242 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008243 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008244 return ixgbe_ptp_set_ts_config(adapter, req);
8245 case SIOCGHWTSTAMP:
8246 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008247 default:
8248 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8249 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008250}
8251
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008252/**
8253 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008254 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008255 * @netdev: network interface device structure
8256 *
8257 * Returns non-zero on failure
8258 **/
8259static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8260{
8261 int err = 0;
8262 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008263 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008264
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008265 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008266 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008267 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008268 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008269
8270 /* update SAN MAC vmdq pool selection */
8271 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008272 }
8273 return err;
8274}
8275
8276/**
8277 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008278 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008279 * @netdev: network interface device structure
8280 *
8281 * Returns non-zero on failure
8282 **/
8283static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8284{
8285 int err = 0;
8286 struct ixgbe_adapter *adapter = netdev_priv(dev);
8287 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8288
8289 if (is_valid_ether_addr(mac->san_addr)) {
8290 rtnl_lock();
8291 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8292 rtnl_unlock();
8293 }
8294 return err;
8295}
8296
Auke Kok9a799d72007-09-15 14:07:45 -07008297#ifdef CONFIG_NET_POLL_CONTROLLER
8298/*
8299 * Polling 'interrupt' - used by things like netconsole to send skbs
8300 * without having to re-enable interrupts. It's not called while
8301 * the interrupt routine is executing.
8302 */
8303static void ixgbe_netpoll(struct net_device *netdev)
8304{
8305 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008306 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008307
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008308 /* if interface is down do nothing */
8309 if (test_bit(__IXGBE_DOWN, &adapter->state))
8310 return;
8311
Alexander Duyck856f6062015-02-25 17:45:54 +00008312 /* loop through and schedule all active queues */
8313 for (i = 0; i < adapter->num_q_vectors; i++)
8314 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008315}
Auke Kok9a799d72007-09-15 14:07:45 -07008316
Alexander Duyck581330b2012-02-08 07:51:47 +00008317#endif
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008318
8319static void ixgbe_get_stats64(struct net_device *netdev,
8320 struct rtnl_link_stats64 *stats)
Eric Dumazetde1036b2010-10-20 23:00:04 +00008321{
8322 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8323 int i;
8324
Eric Dumazet1a515022010-11-16 19:26:42 -08008325 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008326 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08008327 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008328 u64 bytes, packets;
8329 unsigned int start;
8330
Eric Dumazet1a515022010-11-16 19:26:42 -08008331 if (ring) {
8332 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008333 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008334 packets = ring->stats.packets;
8335 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008336 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008337 stats->rx_packets += packets;
8338 stats->rx_bytes += bytes;
8339 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008340 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008341
8342 for (i = 0; i < adapter->num_tx_queues; i++) {
8343 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
8344 u64 bytes, packets;
8345 unsigned int start;
8346
8347 if (ring) {
8348 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008349 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008350 packets = ring->stats.packets;
8351 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008352 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008353 stats->tx_packets += packets;
8354 stats->tx_bytes += bytes;
8355 }
8356 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008357 rcu_read_unlock();
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008358
Eric Dumazetde1036b2010-10-20 23:00:04 +00008359 /* following stats updated by ixgbe_watchdog_task() */
8360 stats->multicast = netdev->stats.multicast;
8361 stats->rx_errors = netdev->stats.rx_errors;
8362 stats->rx_length_errors = netdev->stats.rx_length_errors;
8363 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8364 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
Eric Dumazetde1036b2010-10-20 23:00:04 +00008365}
8366
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008367#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008368/**
8369 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8370 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008371 * @tc: number of traffic classes currently enabled
8372 *
8373 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8374 * 802.1Q priority maps to a packet buffer that exists.
8375 */
8376static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8377{
8378 struct ixgbe_hw *hw = &adapter->hw;
8379 u32 reg, rsave;
8380 int i;
8381
8382 /* 82598 have a static priority to TC mapping that can not
8383 * be changed so no validation is needed.
8384 */
8385 if (hw->mac.type == ixgbe_mac_82598EB)
8386 return;
8387
8388 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8389 rsave = reg;
8390
8391 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8392 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8393
8394 /* If up2tc is out of bounds default to zero */
8395 if (up2tc > tc)
8396 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8397 }
8398
8399 if (reg != rsave)
8400 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8401
8402 return;
8403}
8404
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008405/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008406 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8407 * @adapter: Pointer to adapter struct
8408 *
8409 * Populate the netdev user priority to tc map
8410 */
8411static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8412{
8413 struct net_device *dev = adapter->netdev;
8414 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8415 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8416 u8 prio;
8417
8418 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8419 u8 tc = 0;
8420
8421 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8422 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8423 else if (ets)
8424 tc = ets->prio_tc[prio];
8425
8426 netdev_set_prio_tc_map(dev, prio, tc);
8427 }
8428}
8429
Alexander Duyckcca73c52013-01-12 06:33:44 +00008430#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008431/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008432 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008433 *
8434 * @netdev: net device to configure
8435 * @tc: number of traffic classes to enable
8436 */
8437int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8438{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008439 struct ixgbe_adapter *adapter = netdev_priv(dev);
8440 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08008441 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008442
John Fastabend8b1c0b22011-05-03 02:26:48 +00008443 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008444 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8445 return -EINVAL;
8446
8447 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008448 return -EINVAL;
8449
John Fastabend2a47fa42013-11-06 09:54:52 -08008450 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
8451 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
8452 return -EBUSY;
8453
John Fastabend8b1c0b22011-05-03 02:26:48 +00008454 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008455 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008456 * hardware is not flexible enough to do this dynamically.
8457 */
8458 if (netif_running(dev))
8459 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008460 else
8461 ixgbe_reset(adapter);
8462
John Fastabend8b1c0b22011-05-03 02:26:48 +00008463 ixgbe_clear_interrupt_scheme(adapter);
8464
Alexander Duyckcca73c52013-01-12 06:33:44 +00008465#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008466 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008467 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008468 ixgbe_set_prio_tc_map(adapter);
8469
John Fastabende7589ea2011-07-18 22:38:36 +00008470 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008471
Alexander Duyck943561d2012-05-09 22:14:44 -07008472 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8473 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008474 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008475 }
John Fastabende7589ea2011-07-18 22:38:36 +00008476 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008477 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008478
Alexander Duyck943561d2012-05-09 22:14:44 -07008479 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8480 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008481
8482 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008483
8484 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8485 adapter->dcb_cfg.pfc_mode_enable = false;
8486 }
8487
John Fastabend8b1c0b22011-05-03 02:26:48 +00008488 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008489
8490#endif /* CONFIG_IXGBE_DCB */
8491 ixgbe_init_interrupt_scheme(adapter);
8492
John Fastabend8b1c0b22011-05-03 02:26:48 +00008493 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008494 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008495
8496 return 0;
8497}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008498
John Fastabendb82b17d2016-02-16 21:18:53 -08008499static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8500 struct tc_cls_u32_offload *cls)
8501{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008502 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008503 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008504 u32 loc = cls->knode.handle & 0xfffff;
8505 int err = 0, i, j;
8506 struct ixgbe_jump_table *jump = NULL;
8507
8508 if (loc > IXGBE_MAX_HW_ENTRIES)
8509 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008510
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008511 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8512 return -EINVAL;
8513
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008514 /* Clear this filter in the link data it is associated with */
8515 if (uhtid != 0x800) {
8516 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008517 if (!jump)
8518 return -EINVAL;
8519 if (!test_bit(loc - 1, jump->child_loc_map))
8520 return -EINVAL;
8521 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008522 }
8523
8524 /* Check if the filter being deleted is a link */
8525 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8526 jump = adapter->jump_tables[i];
8527 if (jump && jump->link_hdl == hdl) {
8528 /* Delete filters in the hardware in the child hash
8529 * table associated with this link
8530 */
8531 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8532 if (!test_bit(j, jump->child_loc_map))
8533 continue;
8534 spin_lock(&adapter->fdir_perfect_lock);
8535 err = ixgbe_update_ethtool_fdir_entry(adapter,
8536 NULL,
8537 j + 1);
8538 spin_unlock(&adapter->fdir_perfect_lock);
8539 clear_bit(j, jump->child_loc_map);
8540 }
8541 /* Remove resources for this link */
8542 kfree(jump->input);
8543 kfree(jump->mask);
8544 kfree(jump);
8545 adapter->jump_tables[i] = NULL;
8546 return err;
8547 }
8548 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008549
John Fastabendb82b17d2016-02-16 21:18:53 -08008550 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008551 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008552 spin_unlock(&adapter->fdir_perfect_lock);
8553 return err;
8554}
8555
John Fastabenddb956ae2016-02-16 21:19:19 -08008556static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
8557 __be16 protocol,
8558 struct tc_cls_u32_offload *cls)
8559{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008560 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8561
8562 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8563 return -EINVAL;
8564
John Fastabenddb956ae2016-02-16 21:19:19 -08008565 /* This ixgbe devices do not support hash tables at the moment
8566 * so abort when given hash tables.
8567 */
8568 if (cls->hnode.divisor > 0)
8569 return -EINVAL;
8570
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008571 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008572 return 0;
8573}
8574
8575static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8576 struct tc_cls_u32_offload *cls)
8577{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008578 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8579
8580 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8581 return -EINVAL;
8582
8583 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008584 return 0;
8585}
8586
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008587#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07008588struct upper_walk_data {
8589 struct ixgbe_adapter *adapter;
8590 u64 action;
8591 int ifindex;
8592 u8 queue;
8593};
8594
8595static int get_macvlan_queue(struct net_device *upper, void *_data)
8596{
8597 if (netif_is_macvlan(upper)) {
8598 struct macvlan_dev *dfwd = netdev_priv(upper);
8599 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
8600 struct upper_walk_data *data = _data;
8601 struct ixgbe_adapter *adapter = data->adapter;
8602 int ifindex = data->ifindex;
8603
8604 if (vadapter && vadapter->netdev->ifindex == ifindex) {
8605 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
8606 data->action = data->queue;
8607 return 1;
8608 }
8609 }
8610
8611 return 0;
8612}
8613
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008614static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
8615 u8 *queue, u64 *action)
8616{
8617 unsigned int num_vfs = adapter->num_vfs, vf;
David Ahern1cd127f2016-10-17 19:15:48 -07008618 struct upper_walk_data data;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008619 struct net_device *upper;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008620
8621 /* redirect to a SRIOV VF */
8622 for (vf = 0; vf < num_vfs; ++vf) {
8623 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
8624 if (upper->ifindex == ifindex) {
8625 if (adapter->num_rx_pools > 1)
8626 *queue = vf * 2;
8627 else
8628 *queue = vf * adapter->num_rx_queues_per_pool;
8629
8630 *action = vf + 1;
8631 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
8632 return 0;
8633 }
8634 }
8635
8636 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07008637 data.adapter = adapter;
8638 data.ifindex = ifindex;
8639 data.action = 0;
8640 data.queue = 0;
8641 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
8642 get_macvlan_queue, &data)) {
8643 *action = data.action;
8644 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008645
David Ahern1cd127f2016-10-17 19:15:48 -07008646 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008647 }
8648
8649 return -EINVAL;
8650}
8651
8652static int parse_tc_actions(struct ixgbe_adapter *adapter,
8653 struct tcf_exts *exts, u64 *action, u8 *queue)
8654{
8655 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07008656 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008657 int err;
8658
8659 if (tc_no_actions(exts))
8660 return -EINVAL;
8661
WANG Cong22dc13c2016-08-13 22:35:00 -07008662 tcf_exts_to_list(exts, &actions);
8663 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008664
8665 /* Drop action */
8666 if (is_tcf_gact_shot(a)) {
8667 *action = IXGBE_FDIR_DROP_QUEUE;
8668 *queue = IXGBE_FDIR_DROP_QUEUE;
8669 return 0;
8670 }
8671
8672 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03008673 if (is_tcf_mirred_egress_redirect(a)) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008674 int ifindex = tcf_mirred_ifindex(a);
8675
8676 err = handle_redirect_action(adapter, ifindex, queue,
8677 action);
8678 if (err == 0)
8679 return err;
8680 }
8681 }
8682
8683 return -EINVAL;
8684}
8685#else
8686static int parse_tc_actions(struct ixgbe_adapter *adapter,
8687 struct tcf_exts *exts, u64 *action, u8 *queue)
8688{
8689 return -EINVAL;
8690}
8691#endif /* CONFIG_NET_CLS_ACT */
8692
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008693static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
8694 union ixgbe_atr_input *mask,
8695 struct tc_cls_u32_offload *cls,
8696 struct ixgbe_mat_field *field_ptr,
8697 struct ixgbe_nexthdr *nexthdr)
8698{
8699 int i, j, off;
8700 __be32 val, m;
8701 bool found_entry = false, found_jump_field = false;
8702
8703 for (i = 0; i < cls->knode.sel->nkeys; i++) {
8704 off = cls->knode.sel->keys[i].off;
8705 val = cls->knode.sel->keys[i].val;
8706 m = cls->knode.sel->keys[i].mask;
8707
8708 for (j = 0; field_ptr[j].val; j++) {
8709 if (field_ptr[j].off == off) {
8710 field_ptr[j].val(input, mask, val, m);
8711 input->filter.formatted.flow_type |=
8712 field_ptr[j].type;
8713 found_entry = true;
8714 break;
8715 }
8716 }
8717 if (nexthdr) {
8718 if (nexthdr->off == cls->knode.sel->keys[i].off &&
8719 nexthdr->val == cls->knode.sel->keys[i].val &&
8720 nexthdr->mask == cls->knode.sel->keys[i].mask)
8721 found_jump_field = true;
8722 else
8723 continue;
8724 }
8725 }
8726
8727 if (nexthdr && !found_jump_field)
8728 return -EINVAL;
8729
8730 if (!found_entry)
8731 return 0;
8732
8733 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
8734 IXGBE_ATR_L4TYPE_MASK;
8735
8736 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
8737 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
8738
8739 return 0;
8740}
8741
John Fastabendb82b17d2016-02-16 21:18:53 -08008742static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
8743 __be16 protocol,
8744 struct tc_cls_u32_offload *cls)
8745{
8746 u32 loc = cls->knode.handle & 0xfffff;
8747 struct ixgbe_hw *hw = &adapter->hw;
8748 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008749 struct ixgbe_fdir_filter *input = NULL;
8750 union ixgbe_atr_input *mask = NULL;
8751 struct ixgbe_jump_table *jump = NULL;
8752 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008753 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008754 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08008755
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008756 uhtid = TC_U32_USERHTID(cls->knode.handle);
8757 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08008758
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008759 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08008760 * L2 headers. The canonical method to match L2 frames is to use
8761 * negative values. However this is error prone at best but really
8762 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008763 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08008764 * headers when needed.
8765 */
8766 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008767 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008768
8769 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
8770 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008771 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008772 }
8773
8774 /* cls u32 is a graph starting at root node 0x800. The driver tracks
8775 * links and also the fields used to advance the parser across each
8776 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
8777 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
8778 * To add support for new nodes update ixgbe_model.h parse structures
8779 * this function _should_ be generic try not to hardcode values here.
8780 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008781 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008782 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08008783 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008784 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008785 return err;
8786 if (!adapter->jump_tables[uhtid])
8787 return err;
8788 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08008789 }
8790
8791 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008792 return err;
8793
8794 /* At this point we know the field_ptr is valid and need to either
8795 * build cls_u32 link or attach filter. Because adding a link to
8796 * a handle that does not exist is invalid and the same for adding
8797 * rules to handles that don't exist.
8798 */
8799
8800 if (link_uhtid) {
8801 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
8802
8803 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
8804 return err;
8805
8806 if (!test_bit(link_uhtid - 1, &adapter->tables))
8807 return err;
8808
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008809 /* Multiple filters as links to the same hash table are not
8810 * supported. To add a new filter with the same next header
8811 * but different match/jump conditions, create a new hash table
8812 * and link to it.
8813 */
8814 if (adapter->jump_tables[link_uhtid] &&
8815 (adapter->jump_tables[link_uhtid])->link_hdl) {
8816 e_err(drv, "Link filter exists for link: %x\n",
8817 link_uhtid);
8818 return err;
8819 }
8820
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008821 for (i = 0; nexthdr[i].jump; i++) {
8822 if (nexthdr[i].o != cls->knode.sel->offoff ||
8823 nexthdr[i].s != cls->knode.sel->offshift ||
8824 nexthdr[i].m != cls->knode.sel->offmask)
8825 return err;
8826
8827 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
8828 if (!jump)
8829 return -ENOMEM;
8830 input = kzalloc(sizeof(*input), GFP_KERNEL);
8831 if (!input) {
8832 err = -ENOMEM;
8833 goto free_jump;
8834 }
8835 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
8836 if (!mask) {
8837 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008838 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008839 }
8840 jump->input = input;
8841 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008842 jump->link_hdl = cls->knode.handle;
8843
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008844 err = ixgbe_clsu32_build_input(input, mask, cls,
8845 field_ptr, &nexthdr[i]);
8846 if (!err) {
8847 jump->mat = nexthdr[i].jump;
8848 adapter->jump_tables[link_uhtid] = jump;
8849 break;
8850 }
8851 }
8852 return 0;
8853 }
John Fastabendb82b17d2016-02-16 21:18:53 -08008854
8855 input = kzalloc(sizeof(*input), GFP_KERNEL);
8856 if (!input)
8857 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008858 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
8859 if (!mask) {
8860 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008861 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08008862 }
8863
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008864 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
8865 if ((adapter->jump_tables[uhtid])->input)
8866 memcpy(input, (adapter->jump_tables[uhtid])->input,
8867 sizeof(*input));
8868 if ((adapter->jump_tables[uhtid])->mask)
8869 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
8870 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008871
8872 /* Lookup in all child hash tables if this location is already
8873 * filled with a filter
8874 */
8875 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8876 struct ixgbe_jump_table *link = adapter->jump_tables[i];
8877
8878 if (link && (test_bit(loc - 1, link->child_loc_map))) {
8879 e_err(drv, "Filter exists in location: %x\n",
8880 loc);
8881 err = -EINVAL;
8882 goto err_out;
8883 }
8884 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008885 }
8886 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
8887 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08008888 goto err_out;
8889
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008890 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
8891 &queue);
8892 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08008893 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08008894
John Fastabendb82b17d2016-02-16 21:18:53 -08008895 input->sw_idx = loc;
8896
8897 spin_lock(&adapter->fdir_perfect_lock);
8898
8899 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008900 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
8901 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008902 if (err)
8903 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008904 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008905 err = -EINVAL;
8906 goto err_out_w_lock;
8907 }
8908
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008909 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008910 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
8911 input->sw_idx, queue);
8912 if (!err)
8913 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
8914 spin_unlock(&adapter->fdir_perfect_lock);
8915
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008916 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
8917 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008918
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008919 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008920 return err;
8921err_out_w_lock:
8922 spin_unlock(&adapter->fdir_perfect_lock);
8923err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008924 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008925free_input:
8926 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008927free_jump:
8928 kfree(jump);
8929 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008930}
8931
Emil Tantilov6e2a60b2016-02-17 15:55:06 -08008932static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
8933 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08008934{
John Fastabendb82b17d2016-02-16 21:18:53 -08008935 struct ixgbe_adapter *adapter = netdev_priv(dev);
8936
8937 if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
8938 tc->type == TC_SETUP_CLSU32) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008939 switch (tc->cls_u32->command) {
8940 case TC_CLSU32_NEW_KNODE:
8941 case TC_CLSU32_REPLACE_KNODE:
8942 return ixgbe_configure_clsu32(adapter,
8943 proto, tc->cls_u32);
8944 case TC_CLSU32_DELETE_KNODE:
8945 return ixgbe_delete_clsu32(adapter, tc->cls_u32);
John Fastabenddb956ae2016-02-16 21:19:19 -08008946 case TC_CLSU32_NEW_HNODE:
8947 case TC_CLSU32_REPLACE_HNODE:
8948 return ixgbe_configure_clsu32_add_hnode(adapter, proto,
8949 tc->cls_u32);
8950 case TC_CLSU32_DELETE_HNODE:
8951 return ixgbe_configure_clsu32_del_hnode(adapter,
8952 tc->cls_u32);
John Fastabendb82b17d2016-02-16 21:18:53 -08008953 default:
8954 return -EINVAL;
8955 }
8956 }
8957
John Fastabend5eb4dce2016-02-29 11:26:13 -08008958 if (tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08008959 return -EINVAL;
8960
Amritha Nambiar56f36ac2017-03-15 10:39:25 -07008961 tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
8962
8963 return ixgbe_setup_tc(dev, tc->mqprio->num_tc);
John Fastabende4c67342016-02-16 21:16:15 -08008964}
8965
Greg Roseda36b642012-12-11 08:26:43 +00008966#ifdef CONFIG_PCI_IOV
8967void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
8968{
8969 struct net_device *netdev = adapter->netdev;
8970
8971 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00008972 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00008973 rtnl_unlock();
8974}
8975
8976#endif
Don Skidmore082757a2011-07-21 05:55:00 +00008977void ixgbe_do_reset(struct net_device *netdev)
8978{
8979 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8980
8981 if (netif_running(netdev))
8982 ixgbe_reinit_locked(adapter);
8983 else
8984 ixgbe_reset(adapter);
8985}
8986
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008987static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008988 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008989{
8990 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8991
Don Skidmore082757a2011-07-21 05:55:00 +00008992 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00008993 if (!(features & NETIF_F_RXCSUM))
8994 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00008995
Alexander Duyck567d2de2012-02-11 07:18:57 +00008996 /* Turn off LRO if not RSC capable */
8997 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
8998 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008999
Alexander Duyck567d2de2012-02-11 07:18:57 +00009000 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00009001}
9002
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009003static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009004 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009005{
9006 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00009007 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00009008 bool need_reset = false;
9009
Don Skidmore082757a2011-07-21 05:55:00 +00009010 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009011 if (!(features & NETIF_F_LRO)) {
9012 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00009013 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00009014 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9015 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9016 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9017 if (adapter->rx_itr_setting == 1 ||
9018 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9019 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9020 need_reset = true;
9021 } else if ((changed ^ features) & NETIF_F_LRO) {
9022 e_info(probe, "rx-usecs set too low, "
9023 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00009024 }
9025 }
9026
9027 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08009028 * Check if Flow Director n-tuple support or hw_tc support was
9029 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00009030 */
John Fastabendb82b17d2016-02-16 21:18:53 -08009031 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00009032 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00009033 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9034 need_reset = true;
9035
Alexander Duyck567d2de2012-02-11 07:18:57 +00009036 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9037 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08009038 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00009039 /* turn off perfect filters, enable ATR and reset */
9040 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9041 need_reset = true;
9042
9043 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9044
9045 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08009046 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9047 /* We cannot enable ATR if we have 2 or more tcs */
9048 (netdev_get_num_tc(netdev) > 1) ||
9049 /* We cannot enable ATR if RSS is disabled */
9050 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9051 /* A sample rate of 0 indicates ATR disabled */
9052 (!adapter->atr_sample_rate))
9053 ; /* do nothing not supported */
9054 else /* otherwise supported and set the flag */
9055 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00009056 }
9057
Ben Greear3f2d1c02012-03-08 08:28:41 +00009058 if (changed & NETIF_F_RXALL)
9059 need_reset = true;
9060
Alexander Duyck567d2de2012-02-11 07:18:57 +00009061 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07009062
Mark Rustad67359c32015-06-15 11:33:25 -07009063 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07009064 if (features & NETIF_F_RXCSUM) {
9065 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9066 } else {
9067 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9068
9069 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9070 }
9071 }
9072
9073 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9074 if (features & NETIF_F_RXCSUM) {
9075 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9076 } else {
9077 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9078
9079 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9080 }
Mark Rustad67359c32015-06-15 11:33:25 -07009081 }
Mark Rustad67359c32015-06-15 11:33:25 -07009082
Don Skidmore082757a2011-07-21 05:55:00 +00009083 if (need_reset)
9084 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009085 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9086 NETIF_F_HW_VLAN_CTAG_FILTER))
9087 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00009088
9089 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00009090}
9091
Don Skidmore3f207802014-12-23 07:40:34 +00009092/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009093 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009094 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009095 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009096 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009097static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9098 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009099{
9100 struct ixgbe_adapter *adapter = netdev_priv(dev);
9101 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07009102 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07009103 u32 port_shift = 0;
9104 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07009105
Alexander Duyckb3a49552016-06-16 12:22:19 -07009106 if (ti->sa_family != AF_INET)
9107 return;
9108
Emil Tantilova21d0822016-08-10 11:19:23 -07009109 switch (ti->type) {
9110 case UDP_TUNNEL_TYPE_VXLAN:
9111 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9112 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009113
Emil Tantilova21d0822016-08-10 11:19:23 -07009114 if (adapter->vxlan_port == port)
9115 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009116
Emil Tantilova21d0822016-08-10 11:19:23 -07009117 if (adapter->vxlan_port) {
9118 netdev_info(dev,
9119 "VXLAN port %d set, not adding port %d\n",
9120 ntohs(adapter->vxlan_port),
9121 ntohs(port));
9122 return;
9123 }
9124
9125 adapter->vxlan_port = port;
9126 break;
9127 case UDP_TUNNEL_TYPE_GENEVE:
9128 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9129 return;
9130
9131 if (adapter->geneve_port == port)
9132 return;
9133
9134 if (adapter->geneve_port) {
9135 netdev_info(dev,
9136 "GENEVE port %d set, not adding port %d\n",
9137 ntohs(adapter->geneve_port),
9138 ntohs(port));
9139 return;
9140 }
9141
9142 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9143 adapter->geneve_port = port;
9144 break;
9145 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009146 return;
9147 }
9148
Emil Tantilova21d0822016-08-10 11:19:23 -07009149 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9150 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00009151}
9152
9153/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009154 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009155 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009156 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009157 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009158static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9159 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009160{
9161 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07009162 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00009163
Emil Tantilova21d0822016-08-10 11:19:23 -07009164 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9165 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07009166 return;
9167
9168 if (ti->sa_family != AF_INET)
9169 return;
9170
Emil Tantilova21d0822016-08-10 11:19:23 -07009171 switch (ti->type) {
9172 case UDP_TUNNEL_TYPE_VXLAN:
9173 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9174 return;
Mark Rustad67359c32015-06-15 11:33:25 -07009175
Emil Tantilova21d0822016-08-10 11:19:23 -07009176 if (adapter->vxlan_port != ti->port) {
9177 netdev_info(dev, "VXLAN port %d not found\n",
9178 ntohs(ti->port));
9179 return;
9180 }
9181
9182 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9183 break;
9184 case UDP_TUNNEL_TYPE_GENEVE:
9185 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9186 return;
9187
9188 if (adapter->geneve_port != ti->port) {
9189 netdev_info(dev, "GENEVE port %d not found\n",
9190 ntohs(ti->port));
9191 return;
9192 }
9193
9194 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9195 break;
9196 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009197 return;
9198 }
9199
Emil Tantilova21d0822016-08-10 11:19:23 -07009200 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9201 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00009202}
9203
stephen hemmingeredc7d572012-10-01 12:32:33 +00009204static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009205 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009206 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009207 u16 flags)
9208{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009209 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00009210 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009211 struct ixgbe_adapter *adapter = netdev_priv(dev);
9212 u16 pool = VMDQ_P(0);
9213
9214 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009215 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009216 }
9217
Jiri Pirkof6f64242014-11-28 14:34:15 +01009218 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009219}
9220
Don Skidmore219efe92015-04-09 22:03:22 -07009221/**
9222 * ixgbe_configure_bridge_mode - set various bridge modes
9223 * @adapter - the private structure
9224 * @mode - requested bridge mode
9225 *
9226 * Configure some settings require for various bridge modes.
9227 **/
9228static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9229 __u16 mode)
9230{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009231 struct ixgbe_hw *hw = &adapter->hw;
9232 unsigned int p, num_pools;
9233 u32 vmdctl;
9234
Don Skidmore219efe92015-04-09 22:03:22 -07009235 switch (mode) {
9236 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009237 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009238 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009239
9240 /* must enable Rx switching replication to allow multicast
9241 * packet reception on all VFs, and to enable source address
9242 * pruning.
9243 */
9244 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9245 vmdctl |= IXGBE_VT_CTL_REPLEN;
9246 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9247
9248 /* enable Rx source address pruning. Note, this requires
9249 * replication to be enabled or else it does nothing.
9250 */
9251 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9252 for (p = 0; p < num_pools; p++) {
9253 if (hw->mac.ops.set_source_address_pruning)
9254 hw->mac.ops.set_source_address_pruning(hw,
9255 true,
9256 p);
9257 }
Don Skidmore219efe92015-04-09 22:03:22 -07009258 break;
9259 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009260 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009261 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9262 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009263
9264 /* disable Rx switching replication unless we have SR-IOV
9265 * virtual functions
9266 */
9267 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9268 if (!adapter->num_vfs)
9269 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9270 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9271
9272 /* disable Rx source address pruning, since we don't expect to
9273 * be receiving external loopback of our transmitted frames.
9274 */
9275 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9276 for (p = 0; p < num_pools; p++) {
9277 if (hw->mac.ops.set_source_address_pruning)
9278 hw->mac.ops.set_source_address_pruning(hw,
9279 false,
9280 p);
9281 }
Don Skidmore219efe92015-04-09 22:03:22 -07009282 break;
9283 default:
9284 return -EINVAL;
9285 }
9286
9287 adapter->bridge_mode = mode;
9288
9289 e_info(drv, "enabling bridge mode: %s\n",
9290 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9291
9292 return 0;
9293}
9294
John Fastabend815cccb2012-10-24 08:13:09 +00009295static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009296 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009297{
9298 struct ixgbe_adapter *adapter = netdev_priv(dev);
9299 struct nlattr *attr, *br_spec;
9300 int rem;
9301
9302 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9303 return -EOPNOTSUPP;
9304
9305 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009306 if (!br_spec)
9307 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009308
9309 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009310 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009311 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009312
9313 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9314 continue;
9315
Thomas Grafb7c1a312014-11-26 13:42:17 +01009316 if (nla_len(attr) < sizeof(mode))
9317 return -EINVAL;
9318
John Fastabend815cccb2012-10-24 08:13:09 +00009319 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009320 status = ixgbe_configure_bridge_mode(adapter, mode);
9321 if (status)
9322 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009323
9324 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009325 }
9326
9327 return 0;
9328}
9329
9330static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009331 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009332 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009333{
9334 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009335
9336 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9337 return 0;
9338
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009339 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009340 adapter->bridge_mode, 0, 0, nlflags,
9341 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009342}
9343
John Fastabend2a47fa42013-11-06 09:54:52 -08009344static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9345{
9346 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
9347 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009348 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08009349 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009350 int pool, err;
9351
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009352 /* Hardware has a limited number of available pools. Each VF, and the
9353 * PF require a pool. Check to ensure we don't attempt to use more
9354 * then the available number of pools.
9355 */
9356 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9357 return ERR_PTR(-EINVAL);
9358
John Fastabend219354d2013-11-08 00:50:32 -08009359#ifdef CONFIG_RPS
9360 if (vdev->num_rx_queues != vdev->num_tx_queues) {
9361 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
9362 vdev->name);
9363 return ERR_PTR(-EINVAL);
9364 }
9365#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08009366 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08009367 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08009368 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
9369 netdev_info(pdev,
9370 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
9371 pdev->name);
9372 return ERR_PTR(-EINVAL);
9373 }
9374
9375 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
9376 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
9377 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
9378 return ERR_PTR(-EBUSY);
9379
Maninder Singhbc52f952015-06-19 09:37:55 +05309380 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08009381 if (!fwd_adapter)
9382 return ERR_PTR(-ENOMEM);
9383
9384 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
9385 adapter->num_rx_pools++;
9386 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08009387 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08009388
9389 /* Enable VMDq flag so device will be set in VM mode */
9390 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08009391 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08009392 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08009393
9394 /* Force reinit of ring allocation with VMDQ enabled */
9395 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9396 if (err)
9397 goto fwd_add_err;
9398 fwd_adapter->pool = pool;
9399 fwd_adapter->real_adapter = adapter;
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009400
9401 if (netif_running(pdev)) {
9402 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
9403 if (err)
9404 goto fwd_add_err;
9405 netif_tx_start_all_queues(vdev);
9406 }
9407
John Fastabend2a47fa42013-11-06 09:54:52 -08009408 return fwd_adapter;
9409fwd_add_err:
9410 /* unwind counter and free adapter struct */
9411 netdev_info(pdev,
9412 "%s: dfwd hardware acceleration failed\n", vdev->name);
9413 clear_bit(pool, &adapter->fwd_bitmask);
9414 adapter->num_rx_pools--;
9415 kfree(fwd_adapter);
9416 return ERR_PTR(err);
9417}
9418
9419static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9420{
9421 struct ixgbe_fwd_adapter *fwd_adapter = priv;
9422 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08009423 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009424
9425 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
9426 adapter->num_rx_pools--;
9427
John Fastabend51f37732013-11-08 00:51:10 -08009428 limit = find_last_bit(&adapter->fwd_bitmask, 32);
9429 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009430 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
9431 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9432 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
9433 fwd_adapter->pool, adapter->num_rx_pools,
9434 fwd_adapter->rx_base_queue,
9435 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
9436 adapter->fwd_bitmask);
9437 kfree(fwd_adapter);
9438}
9439
Alexander Duyckb83e3012016-04-14 17:19:31 -04009440#define IXGBE_MAX_MAC_HDR_LEN 127
9441#define IXGBE_MAX_NETWORK_HDR_LEN 511
9442
Mark Rustadf467bc02015-06-15 11:33:20 -07009443static netdev_features_t
9444ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9445 netdev_features_t features)
9446{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009447 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009448
Alexander Duyckb83e3012016-04-14 17:19:31 -04009449 /* Make certain the headers can be described by a context descriptor */
9450 mac_hdr_len = skb_network_header(skb) - skb->data;
9451 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9452 return features & ~(NETIF_F_HW_CSUM |
9453 NETIF_F_SCTP_CRC |
9454 NETIF_F_HW_VLAN_CTAG_TX |
9455 NETIF_F_TSO |
9456 NETIF_F_TSO6);
9457
9458 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9459 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9460 return features & ~(NETIF_F_HW_CSUM |
9461 NETIF_F_SCTP_CRC |
9462 NETIF_F_TSO |
9463 NETIF_F_TSO6);
9464
9465 /* We can only support IPV4 TSO in tunnels if we can mangle the
9466 * inner IP ID field, so strip TSO if MANGLEID is not supported.
9467 */
9468 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
9469 features &= ~NETIF_F_TSO;
Mark Rustadf467bc02015-06-15 11:33:20 -07009470
9471 return features;
9472}
9473
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009474static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00009475 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009476 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08009477 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07009478 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00009479 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009480 .ndo_validate_addr = eth_validate_addr,
9481 .ndo_set_mac_address = ixgbe_set_mac,
9482 .ndo_change_mtu = ixgbe_change_mtu,
9483 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00009484 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009485 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
9486 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00009487 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00009488 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
9489 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04009490 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00009491 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03009492 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +00009493 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +00009494 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00009495 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -08009496 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009497#ifdef CONFIG_NET_POLL_CONTROLLER
9498 .ndo_poll_controller = ixgbe_netpoll,
9499#endif
Yi Zou332d4a72009-05-13 13:11:53 +00009500#ifdef IXGBE_FCOE
9501 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00009502 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00009503 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00009504 .ndo_fcoe_enable = ixgbe_fcoe_enable,
9505 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00009506 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00009507 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00009508#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00009509 .ndo_set_features = ixgbe_set_features,
9510 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009511 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00009512 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
9513 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08009514 .ndo_dfwd_add_station = ixgbe_fwd_add,
9515 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -07009516 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
9517 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -07009518 .ndo_features_check = ixgbe_features_check,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009519};
9520
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009521/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00009522 * ixgbe_enumerate_functions - Get the number of ports this device has
9523 * @adapter: adapter structure
9524 *
9525 * This function enumerates the phsyical functions co-located on a single slot,
9526 * in order to determine how many ports a device has. This is most useful in
9527 * determining the required GT/s of PCIe bandwidth necessary for optimal
9528 * performance.
9529 **/
9530static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
9531{
Jacob Kellercaafb952014-07-19 07:17:17 +00009532 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009533 int physfns = 0;
9534
Jacob Kellerf1f96572013-08-31 02:45:38 +00009535 /* Some cards can not use the generic count PCIe functions method,
9536 * because they are behind a parent switch, so we hardcode these with
9537 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00009538 */
Jacob Keller88189702014-07-19 07:17:16 +00009539 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00009540 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00009541
9542 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
9543 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00009544 if (entry->is_virtfn)
9545 continue;
9546
9547 /* When the devices on the bus don't all match our device ID,
9548 * we can't reliably determine the correct number of
9549 * functions. This can occur if a function has been direct
9550 * attached to a virtual machine using VT-d, for example. In
9551 * this case, simply return -1 to indicate this.
9552 */
9553 if ((entry->vendor != pdev->vendor) ||
9554 (entry->device != pdev->device))
9555 return -1;
9556
9557 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009558 }
9559
9560 return physfns;
9561}
9562
9563/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00009564 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -07009565 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +00009566 * @device_id: the device ID
9567 * @subdev_id: the subsystem device ID
9568 *
9569 * This function is used by probe and ethtool to determine
9570 * which devices have WoL support
9571 *
9572 **/
Emil Tantilov740234f2016-04-21 11:37:12 -07009573bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
9574 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +00009575{
9576 struct ixgbe_hw *hw = &adapter->hw;
9577 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009578
Emil Tantilov740234f2016-04-21 11:37:12 -07009579 /* WOL not supported on 82598 */
9580 if (hw->mac.type == ixgbe_mac_82598EB)
9581 return false;
9582
9583 /* check eeprom to see if WOL is enabled for X540 and newer */
9584 if (hw->mac.type >= ixgbe_mac_X540) {
9585 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
9586 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
9587 (hw->bus.func == 0)))
9588 return true;
9589 }
9590
9591 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +00009592 switch (device_id) {
9593 case IXGBE_DEV_ID_82599_SFP:
9594 /* Only these subdevices could supports WOL */
9595 switch (subdevice_id) {
9596 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009597 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
9598 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
9599 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009600 /* only support first port */
9601 if (hw->bus.func != 0)
9602 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00009603 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009604 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00009605 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00009606 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009607 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
9608 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
9609 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -07009610 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009611 }
9612 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009613 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -07009614 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +00009615 switch (subdevice_id) {
9616 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -07009617 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009618 }
9619 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009620 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
9621 /* All except this subdevice support WOL */
9622 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -07009623 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009624 break;
9625 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -07009626 return true;
9627 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009628 break;
9629 }
9630
Emil Tantilov740234f2016-04-21 11:37:12 -07009631 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009632}
9633
9634/**
Auke Kok9a799d72007-09-15 14:07:45 -07009635 * ixgbe_probe - Device Initialization Routine
9636 * @pdev: PCI device information struct
9637 * @ent: entry in ixgbe_pci_tbl
9638 *
9639 * Returns 0 on success, negative on failure
9640 *
9641 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
9642 * The OS initialization, configuring of the adapter private structure,
9643 * and a hardware reset occur.
9644 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00009645static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07009646{
9647 struct net_device *netdev;
9648 struct ixgbe_adapter *adapter = NULL;
9649 struct ixgbe_hw *hw;
9650 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +00009651 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009652 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00009653 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009654 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +00009655#ifdef IXGBE_FCOE
9656 u16 device_caps;
9657#endif
Don Skidmore289700db2010-12-03 03:32:58 +00009658 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07009659
Andy Gospodarekbded64a2010-07-21 06:40:31 +00009660 /* Catch broken hardware that put the wrong VF device ID in
9661 * the PCIe SR-IOV capability.
9662 */
9663 if (pdev->is_virtfn) {
9664 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
9665 pci_name(pdev), pdev->vendor, pdev->device);
9666 return -EINVAL;
9667 }
9668
gouji-new9ce77662009-05-06 10:44:45 +00009669 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009670 if (err)
9671 return err;
9672
Russell Kingf5f2eda2013-06-10 12:47:42 +01009673 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07009674 pci_using_dac = 1;
9675 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009676 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07009677 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009678 dev_err(&pdev->dev,
9679 "No usable DMA configuration, aborting\n");
9680 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07009681 }
9682 pci_using_dac = 0;
9683 }
9684
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02009685 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07009686 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00009687 dev_err(&pdev->dev,
9688 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07009689 goto err_pci_reg;
9690 }
9691
Frans Pop19d5afd2009-10-02 10:04:12 -07009692 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009693
Auke Kok9a799d72007-09-15 14:07:45 -07009694 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07009695 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009696
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009697 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00009698#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009699 /* 8 TC w/ 4 queues per TC */
9700 indices = 4 * MAX_TRAFFIC_CLASS;
9701#else
9702 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00009703#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009704 }
John Fastabende901acd2011-04-26 07:26:08 +00009705
John Fastabendc85a2612010-02-25 23:15:21 +00009706 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07009707 if (!netdev) {
9708 err = -ENOMEM;
9709 goto err_alloc_etherdev;
9710 }
9711
Auke Kok9a799d72007-09-15 14:07:45 -07009712 SET_NETDEV_DEV(netdev, &pdev->dev);
9713
Auke Kok9a799d72007-09-15 14:07:45 -07009714 adapter = netdev_priv(netdev);
9715
9716 adapter->netdev = netdev;
9717 adapter->pdev = pdev;
9718 hw = &adapter->hw;
9719 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00009720 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07009721
Jeff Kirsher05857982008-09-11 19:57:00 -07009722 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00009723 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08009724 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07009725 if (!hw->hw_addr) {
9726 err = -EIO;
9727 goto err_ioremap;
9728 }
9729
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009730 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009731 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009732 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +00009733 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -07009734
Auke Kok9a799d72007-09-15 14:07:45 -07009735 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -08009736 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009737 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009738 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -07009739 if (ii->link_ops)
9740 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009741
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009742 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -08009743 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009744 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +00009745 if (ixgbe_removed(hw->hw_addr)) {
9746 err = -EIO;
9747 goto err_ioremap;
9748 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009749 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07009750 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009751 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
9752
9753 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -08009754 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009755 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00009756 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
9757 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
9758 hw->phy.mdio.mmds = 0;
9759 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9760 hw->phy.mdio.dev = netdev;
9761 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
9762 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009763
Auke Kok9a799d72007-09-15 14:07:45 -07009764 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -07009765 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -07009766 if (err)
9767 goto err_sw_init;
9768
Don Skidmoredbd15b82016-03-09 16:45:00 -05009769 /* Make sure the SWFW semaphore is in a valid state */
9770 if (hw->mac.ops.init_swfw_sync)
9771 hw->mac.ops.init_swfw_sync(hw);
9772
Don Skidmoree86bff02010-02-11 04:14:08 +00009773 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08009774 switch (adapter->hw.mac.type) {
9775 case ixgbe_mac_82599EB:
9776 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00009777 case ixgbe_mac_X550:
9778 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07009779 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +00009780 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08009781 break;
9782 default:
9783 break;
9784 }
Don Skidmoree86bff02010-02-11 04:14:08 +00009785
Don Skidmorebf069c92009-05-07 10:39:54 +00009786 /*
9787 * If there is a fan on this device and it has failed log the
9788 * failure.
9789 */
9790 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
9791 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
9792 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00009793 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00009794 }
9795
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00009796 if (allow_unsupported_sfp)
9797 hw->allow_unsupported_sfp = allow_unsupported_sfp;
9798
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009799 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009800 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009801 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009802 hw->phy.reset_if_overtemp = false;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08009803 ixgbe_set_eee_capable(adapter);
Mark Rustad29a8dca2015-08-08 16:17:46 -07009804 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07009805 err = 0;
9806 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00009807 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
9808 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009809 goto err_sw_init;
9810 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009811 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009812 goto err_sw_init;
9813 }
9814
Alexander Duyck99d74482012-05-09 08:09:25 +00009815#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00009816 /* SR-IOV not supported on the 82598 */
9817 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
9818 goto skip_sriov;
9819 /* Mailbox */
9820 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -08009821 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -08009822 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ethan.zhao31ac9102014-01-16 19:41:05 -08009823 ixgbe_enable_sriov(adapter);
Greg Rose60a1a682012-12-11 08:26:33 +00009824skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009825
Alexander Duyck99d74482012-05-09 08:09:25 +00009826#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00009827 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +00009828 NETIF_F_TSO |
9829 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00009830 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -08009831 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -04009832 NETIF_F_HW_CSUM;
9833
9834#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
9835 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -07009836 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -07009837 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -04009838 NETIF_F_GSO_UDP_TUNNEL | \
9839 NETIF_F_GSO_UDP_TUNNEL_CSUM)
9840
9841 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
9842 netdev->features |= NETIF_F_GSO_PARTIAL |
9843 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -07009844
Alexander Duyck49763de2016-01-13 07:31:11 -08009845 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -08009846 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00009847
Alexander Duyck49763de2016-01-13 07:31:11 -08009848 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -04009849 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -07009850 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -04009851 NETIF_F_HW_VLAN_CTAG_RX |
9852 NETIF_F_HW_VLAN_CTAG_TX |
9853 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -08009854 NETIF_F_HW_L2FW_DOFFLOAD;
9855
9856 if (hw->mac.type >= ixgbe_mac_82599EB)
9857 netdev->hw_features |= NETIF_F_NTUPLE |
9858 NETIF_F_HW_TC;
9859
Alexander Duyckb83e3012016-04-14 17:19:31 -04009860 if (pci_using_dac)
9861 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -07009862
Alexander Duyck5eee87c2016-05-11 13:23:34 -07009863 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
9864 netdev->hw_enc_features |= netdev->vlan_features;
9865 netdev->mpls_features |= NETIF_F_HW_CSUM;
9866
Alexander Duyckb83e3012016-04-14 17:19:31 -04009867 /* set this bit last since it cannot be part of vlan_features */
9868 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
9869 NETIF_F_HW_VLAN_CTAG_RX |
9870 NETIF_F_HW_VLAN_CTAG_TX;
9871
Jiri Pirko01789342011-08-16 06:29:00 +00009872 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00009873 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00009874
Jarod Wilson91c527a2016-10-17 15:54:05 -04009875 /* MTU range: 68 - 9710 */
9876 netdev->min_mtu = ETH_MIN_MTU;
9877 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
9878
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08009879#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07009880 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
Stephen Hemminger3f40c742016-11-21 09:52:40 -08009881 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -08009882#endif
9883
Yi Zoueacd73f2009-05-13 13:11:06 +00009884#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00009885 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009886 unsigned int fcoe_l;
9887
Yi Zoueacd73f2009-05-13 13:11:06 +00009888 if (hw->mac.ops.get_device_caps) {
9889 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00009890 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
9891 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00009892 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009893
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009894
9895 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
9896 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009897
Alexander Duycka58915c2012-05-25 06:38:18 +00009898 netdev->features |= NETIF_F_FSO |
9899 NETIF_F_FCOE_CRC;
9900
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009901 netdev->vlan_features |= NETIF_F_FSO |
9902 NETIF_F_FCOE_CRC |
9903 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00009904 }
Yi Zoueacd73f2009-05-13 13:11:06 +00009905#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07009906
Don Skidmore082757a2011-07-21 05:55:00 +00009907 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
9908 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00009909 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00009910 netdev->features |= NETIF_F_LRO;
9911
Auke Kok9a799d72007-09-15 14:07:45 -07009912 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009913 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009914 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009915 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009916 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009917 }
9918
Sowmini Varadhanc7374b52016-01-12 19:32:30 -08009919 eth_platform_get_mac_address(&adapter->pdev->dev,
9920 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +00009921
Auke Kok9a799d72007-09-15 14:07:45 -07009922 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07009923
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00009924 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009925 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009926 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009927 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009928 }
9929
Tushar Dave56768042016-01-07 14:17:03 -08009930 /* Set hw->mac.addr to permanent MAC address */
9931 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07009932 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +00009933
Alexander Duyck70864002011-04-27 09:13:56 +00009934 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00009935 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009936
Mark Rustad58cf6632014-03-12 00:38:40 +00009937 if (ixgbe_removed(hw->hw_addr)) {
9938 err = -EIO;
9939 goto err_sw_init;
9940 }
Alexander Duyck70864002011-04-27 09:13:56 +00009941 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +00009942 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00009943 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009944
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009945 err = ixgbe_init_interrupt_scheme(adapter);
9946 if (err)
9947 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009948
Jacob Keller8e2813f2012-04-21 06:05:40 +00009949 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009950 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009951 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009952 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00009953 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009954 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00009955 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009956
PJ Waskiewicze8e26352009-02-27 15:45:05 +00009957 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
9958
Emil Tantilov15e52092011-09-29 05:01:29 +00009959 /* save off EEPROM version number */
9960 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
9961 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
9962
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009963 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +00009964 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00009965 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -04009966 else
9967 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009968
Jacob Kellere027d1a2013-07-31 06:53:31 +00009969 /* calculate the expected PCIe bandwidth required for optimal
9970 * performance. Note that some older parts will never have enough
9971 * bandwidth due to being older generation PCIe parts. We clamp these
9972 * parts to ensure no warning is displayed if it can't be fixed.
9973 */
9974 switch (hw->mac.type) {
9975 case ixgbe_mac_82598EB:
9976 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
9977 break;
9978 default:
9979 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
9980 break;
Auke Kok0c254d82008-02-11 09:25:56 -08009981 }
Jacob Kellercaafb952014-07-19 07:17:17 +00009982
9983 /* don't check link if we failed to enumerate functions */
9984 if (expected_gts > 0)
9985 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08009986
Mark Rustad339de302014-06-06 01:57:06 +00009987 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009988 if (err)
Mark Rustad339de302014-06-06 01:57:06 +00009989 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009990 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
9991 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
9992 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +00009993 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +00009994 else
9995 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
9996 hw->mac.type, hw->phy.type, part_str);
9997
9998 e_dev_info("%pM\n", netdev->dev_addr);
9999
Auke Kok9a799d72007-09-15 14:07:45 -070010000 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010001 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010002 if (err == IXGBE_ERR_EEPROM_VERSION) {
10003 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +000010004 e_dev_warn("This device is a pre-production adapter/LOM. "
10005 "Please be aware there may be issues associated "
10006 "with your hardware. If you are experiencing "
10007 "problems please contact your Intel or hardware "
10008 "representative who provided you with this "
10009 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010010 }
Auke Kok9a799d72007-09-15 14:07:45 -070010011 strcpy(netdev->name, "eth%d");
10012 err = register_netdev(netdev);
10013 if (err)
10014 goto err_register;
10015
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010016 pci_set_drvdata(pdev, adapter);
10017
Emil Tantilovec74a472012-09-20 03:33:56 +000010018 /* power down the optics for 82599 SFP+ fiber */
10019 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +000010020 hw->mac.ops.disable_tx_laser(hw);
10021
Jesse Brandeburg54386462009-04-17 20:44:27 +000010022 /* carrier off reporting is important to ethtool even BEFORE open */
10023 netif_carrier_off(netdev);
10024
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010025#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +030010026 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010027 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010028 ixgbe_setup_dca(adapter);
10029 }
10030#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010031 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010032 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010033 for (i = 0; i < adapter->num_vfs; i++)
10034 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10035 }
10036
Jacob Keller2466dd92011-09-08 03:50:54 +000010037 /* firmware requires driver version to be 0xFFFFFFFF
10038 * since os does not support feature
10039 */
Emil Tantilov9612de92011-05-07 07:40:20 +000010040 if (hw->mac.ops.set_fw_drv_ver)
Tony Nguyencb8e0512016-10-26 16:25:18 -070010041 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10042 sizeof(ixgbe_driver_version) - 1,
10043 ixgbe_driver_version);
Emil Tantilov9612de92011-05-07 07:40:20 +000010044
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010045 /* add san mac addr to netdev */
10046 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010047
Neerav Parikhea818752012-01-04 20:23:40 +000010048 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010049
Don Skidmore12109822012-05-04 06:07:08 +000010050#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010051 if (ixgbe_sysfs_init(adapter))
10052 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +000010053#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010054
Catherine Sullivan00949162012-08-10 01:59:10 +000010055 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010056
Emil Tantilovd1a35ee2014-05-13 08:24:00 +000010057 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10058 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +000010059 hw->mac.ops.setup_link(hw,
10060 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10061 true);
10062
Auke Kok9a799d72007-09-15 14:07:45 -070010063 return 0;
10064
10065err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010066 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010067 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010068err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +000010069 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +000010070 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -080010071 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010072 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010073 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -070010074err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010075 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010076 free_netdev(netdev);
10077err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010078 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010079err_pci_reg:
10080err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010081 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010082 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010083 return err;
10084}
10085
10086/**
10087 * ixgbe_remove - Device Removal Routine
10088 * @pdev: PCI device information struct
10089 *
10090 * ixgbe_remove is called by the PCI subsystem to alert the driver
10091 * that it should release a PCI device. The could be caused by a
10092 * Hot-Plug event, or because the driver is going to be removed from
10093 * memory.
10094 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010095static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -070010096{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010097 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010098 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010099 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010100 int i;
Auke Kok9a799d72007-09-15 14:07:45 -070010101
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010102 /* if !adapter then we already cleaned up in probe */
10103 if (!adapter)
10104 return;
10105
10106 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +000010107 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010108
Mark Rustad09f40ae2014-01-14 18:53:11 -080010109 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010110 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -070010111
Jacob Keller3a6a4ed2012-05-01 05:24:58 +000010112
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010113#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010114 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10115 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10116 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -070010117 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10118 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010119 }
10120
10121#endif
Don Skidmore12109822012-05-04 06:07:08 +000010122#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010123 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +000010124#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010125
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010126 /* remove the added san mac */
10127 ixgbe_del_sanmac_netdev(netdev);
10128
Greg Roseda36b642012-12-11 08:26:43 +000010129#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -060010130 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +000010131#endif
Alex Williamson6b010e92015-07-29 14:38:21 -060010132 if (netdev->reg_state == NETREG_REGISTERED)
10133 unregister_netdev(netdev);
10134
Alexander Duyck7a921c92009-05-06 10:43:28 +000010135 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010136
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010137 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010138
Alexander Duyck2b1588c2012-03-17 02:39:16 +000010139#ifdef CONFIG_DCB
10140 kfree(adapter->ixgbe_ieee_pfc);
10141 kfree(adapter->ixgbe_ieee_ets);
10142
10143#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -080010144 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010145 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010146
Emil Tantilov849c4542010-06-03 16:53:41 +000010147 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010148
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010149 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
10150 if (adapter->jump_tables[i]) {
10151 kfree(adapter->jump_tables[i]->input);
10152 kfree(adapter->jump_tables[i]->mask);
10153 }
10154 kfree(adapter->jump_tables[i]);
10155 }
10156
Jacob Keller5d7daa32014-03-29 06:51:25 +000010157 kfree(adapter->mac_table);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010158 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010159 free_netdev(netdev);
10160
Frans Pop19d5afd2009-10-02 10:04:12 -070010161 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010162
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010163 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010164 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010165}
10166
10167/**
10168 * ixgbe_io_error_detected - called when PCI error is detected
10169 * @pdev: Pointer to PCI device
10170 * @state: The current pci connection state
10171 *
10172 * This function is called after a PCI bus error affecting
10173 * this device has been detected.
10174 */
10175static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +000010176 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -070010177{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010178 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10179 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010180
Greg Rose83c61fa2011-09-07 05:59:35 +000010181#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -080010182 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +000010183 struct pci_dev *bdev, *vfdev;
10184 u32 dw0, dw1, dw2, dw3;
10185 int vf, pos;
10186 u16 req_id, pf_func;
10187
10188 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
10189 adapter->num_vfs == 0)
10190 goto skip_bad_vf_detection;
10191
10192 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +080010193 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +000010194 bdev = bdev->bus->self;
10195
10196 if (!bdev)
10197 goto skip_bad_vf_detection;
10198
10199 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
10200 if (!pos)
10201 goto skip_bad_vf_detection;
10202
Mark Rustad14438462014-02-28 15:48:57 -080010203 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
10204 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
10205 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
10206 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
10207 if (ixgbe_removed(hw->hw_addr))
10208 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +000010209
10210 req_id = dw1 >> 16;
10211 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10212 if (!(req_id & 0x0080))
10213 goto skip_bad_vf_detection;
10214
10215 pf_func = req_id & 0x01;
10216 if ((pf_func & 1) == (pdev->devfn & 1)) {
10217 unsigned int device_id;
10218
10219 vf = (req_id & 0x7F) >> 1;
10220 e_dev_err("VF %d has caused a PCIe error\n", vf);
10221 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10222 "%8.8x\tdw3: %8.8x\n",
10223 dw0, dw1, dw2, dw3);
10224 switch (adapter->hw.mac.type) {
10225 case ixgbe_mac_82599EB:
10226 device_id = IXGBE_82599_VF_DEVICE_ID;
10227 break;
10228 case ixgbe_mac_X540:
10229 device_id = IXGBE_X540_VF_DEVICE_ID;
10230 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010231 case ixgbe_mac_X550:
10232 device_id = IXGBE_DEV_ID_X550_VF;
10233 break;
10234 case ixgbe_mac_X550EM_x:
10235 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10236 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010237 case ixgbe_mac_x550em_a:
10238 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10239 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010240 default:
10241 device_id = 0;
10242 break;
10243 }
10244
10245 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010246 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010247 while (vfdev) {
10248 if (vfdev->devfn == (req_id & 0xFF))
10249 break;
Jon Mason36e90312012-07-19 21:02:09 +000010250 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010251 device_id, vfdev);
10252 }
10253 /*
10254 * There's a slim chance the VF could have been hot plugged,
10255 * so if it is no longer present we don't need to issue the
10256 * VFLR. Just clean up the AER in that case.
10257 */
10258 if (vfdev) {
Emil Tantilov9079e412014-11-19 03:18:19 +000010259 ixgbe_issue_vf_flr(adapter, vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010260 /* Free device reference count */
10261 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010262 }
10263
10264 pci_cleanup_aer_uncorrect_error_status(pdev);
10265 }
10266
10267 /*
10268 * Even though the error may have occurred on the other port
10269 * we still need to increment the vf error reference count for
10270 * both ports because the I/O resume function will be called
10271 * for both of them.
10272 */
10273 adapter->vferr_refcount++;
10274
10275 return PCI_ERS_RESULT_RECOVERED;
10276
10277skip_bad_vf_detection:
10278#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010279 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10280 return PCI_ERS_RESULT_DISCONNECT;
10281
Mark Rustad41c62842014-03-12 00:38:35 +000010282 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010283 netif_device_detach(netdev);
10284
Mark Rustad41c62842014-03-12 00:38:35 +000010285 if (state == pci_channel_io_perm_failure) {
10286 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010287 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010288 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010289
Auke Kok9a799d72007-09-15 14:07:45 -070010290 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010291 ixgbe_close_suspend(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +000010292
10293 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10294 pci_disable_device(pdev);
10295 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010296
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010297 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010298 return PCI_ERS_RESULT_NEED_RESET;
10299}
10300
10301/**
10302 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10303 * @pdev: Pointer to PCI device
10304 *
10305 * Restart the card from scratch, as if from a cold-boot.
10306 */
10307static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10308{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010309 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010310 pci_ers_result_t result;
10311 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010312
gouji-new9ce77662009-05-06 10:44:45 +000010313 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010314 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010315 result = PCI_ERS_RESULT_DISCONNECT;
10316 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010317 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010318 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010319 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010320 pci_set_master(pdev);
10321 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010322 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010323
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010324 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010325
10326 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010327 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010328 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010329 }
Auke Kok9a799d72007-09-15 14:07:45 -070010330
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010331 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10332 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010333 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10334 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010335 /* non-fatal, continue */
10336 }
Auke Kok9a799d72007-09-15 14:07:45 -070010337
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010338 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010339}
10340
10341/**
10342 * ixgbe_io_resume - called when traffic can start flowing again.
10343 * @pdev: Pointer to PCI device
10344 *
10345 * This callback is called when the error recovery driver tells us that
10346 * its OK to resume normal operation.
10347 */
10348static void ixgbe_io_resume(struct pci_dev *pdev)
10349{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010350 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10351 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010352
Greg Rose83c61fa2011-09-07 05:59:35 +000010353#ifdef CONFIG_PCI_IOV
10354 if (adapter->vferr_refcount) {
10355 e_info(drv, "Resuming after VF err\n");
10356 adapter->vferr_refcount--;
10357 return;
10358 }
10359
10360#endif
Emil Tantilov126db132016-11-16 09:48:02 -080010361 rtnl_lock();
Alexander Duyckc7ccde02011-07-21 00:40:40 +000010362 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010363 ixgbe_open(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010364
10365 netif_device_attach(netdev);
Emil Tantilov126db132016-11-16 09:48:02 -080010366 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010367}
10368
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070010369static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070010370 .error_detected = ixgbe_io_error_detected,
10371 .slot_reset = ixgbe_io_slot_reset,
10372 .resume = ixgbe_io_resume,
10373};
10374
10375static struct pci_driver ixgbe_driver = {
10376 .name = ixgbe_driver_name,
10377 .id_table = ixgbe_pci_tbl,
10378 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010379 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070010380#ifdef CONFIG_PM
10381 .suspend = ixgbe_suspend,
10382 .resume = ixgbe_resume,
10383#endif
10384 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000010385 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070010386 .err_handler = &ixgbe_err_handler
10387};
10388
10389/**
10390 * ixgbe_init_module - Driver Registration Routine
10391 *
10392 * ixgbe_init_module is the first routine called when the driver is
10393 * loaded. All it does is register with the PCI subsystem.
10394 **/
10395static int __init ixgbe_init_module(void)
10396{
10397 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000010398 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000010399 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070010400
Mark Rustad780484d2015-10-21 17:21:10 -070010401 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
10402 if (!ixgbe_wq) {
10403 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
10404 return -ENOMEM;
10405 }
10406
Catherine Sullivan00949162012-08-10 01:59:10 +000010407 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000010408
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010409 ret = pci_register_driver(&ixgbe_driver);
10410 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000010411 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010412 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010413 return ret;
10414 }
10415
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010416#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010417 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010418#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010419
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010420 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070010421}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010422
Auke Kok9a799d72007-09-15 14:07:45 -070010423module_init(ixgbe_init_module);
10424
10425/**
10426 * ixgbe_exit_module - Driver Exit Cleanup Routine
10427 *
10428 * ixgbe_exit_module is called just before the driver is removed
10429 * from memory.
10430 **/
10431static void __exit ixgbe_exit_module(void)
10432{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010433#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010434 dca_unregister_notify(&dca_notifier);
10435#endif
Auke Kok9a799d72007-09-15 14:07:45 -070010436 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000010437
Catherine Sullivan00949162012-08-10 01:59:10 +000010438 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070010439 if (ixgbe_wq) {
10440 destroy_workqueue(ixgbe_wq);
10441 ixgbe_wq = NULL;
10442 }
Auke Kok9a799d72007-09-15 14:07:45 -070010443}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010444
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010445#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010446static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010447 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010448{
10449 int ret_val;
10450
10451 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010452 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010453
10454 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
10455}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010456
Alexander Duyckb4533682009-03-31 21:32:42 +000010457#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000010458
Auke Kok9a799d72007-09-15 14:07:45 -070010459module_exit(ixgbe_exit_module);
10460
10461/* ixgbe_main.c */