blob: 852a2e7e25ed185917732df098174820c56e1295 [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{
511 int i = 0, j = 0;
512 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 Perchesc7689572010-09-07 21:35:17 +0000573 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000574 IXGBE_READ_REG(hw, reginfo->ofs));
575 return;
576 }
577
578 for (i = 0; i < 8; i++) {
579 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000580 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000581 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000582 pr_cont(" %08x", regs[i*8+j]);
583 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000584 }
585
586}
587
588/*
589 * ixgbe_dump - Print registers, tx-rings and rx-rings
590 */
591static void ixgbe_dump(struct ixgbe_adapter *adapter)
592{
593 struct net_device *netdev = adapter->netdev;
594 struct ixgbe_hw *hw = &adapter->hw;
595 struct ixgbe_reg_info *reginfo;
596 int n = 0;
597 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000598 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000599 union ixgbe_adv_tx_desc *tx_desc;
600 struct my_u0 { u64 a; u64 b; } *u0;
601 struct ixgbe_ring *rx_ring;
602 union ixgbe_adv_rx_desc *rx_desc;
603 struct ixgbe_rx_buffer *rx_buffer_info;
604 u32 staterr;
605 int i = 0;
606
607 if (!netif_msg_hw(adapter))
608 return;
609
610 /* Print netdevice Info */
611 if (netdev) {
612 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000613 pr_info("Device Name state "
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100614 "trans_start\n");
615 pr_info("%-15s %016lX %016lX\n",
Joe Perchesc7689572010-09-07 21:35:17 +0000616 netdev->name,
617 netdev->state,
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100618 dev_trans_start(netdev));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000619 }
620
621 /* Print Registers */
622 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000623 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000624 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
625 reginfo->name; reginfo++) {
626 ixgbe_regdump(hw, reginfo);
627 }
628
629 /* Print TX Ring Summary */
630 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000631 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000632
633 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000634 pr_info(" %s %s %s %s\n",
635 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
636 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000637 for (n = 0; n < adapter->num_tx_queues; n++) {
638 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000639 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000640 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000641 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000642 (u64)dma_unmap_addr(tx_buffer, dma),
643 dma_unmap_len(tx_buffer, len),
644 tx_buffer->next_to_watch,
645 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000646 }
647
648 /* Print TX Rings */
649 if (!netif_msg_tx_done(adapter))
650 goto rx_ring_summary;
651
652 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
653
654 /* Transmit Descriptor Formats
655 *
Josh Hay39ac8682012-09-26 05:59:36 +0000656 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000657 * +--------------------------------------------------------------+
658 * 0 | Buffer Address [63:0] |
659 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000660 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000661 * +--------------------------------------------------------------+
662 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000663 *
664 * 82598 Advanced Transmit Descriptor (Write-Back Format)
665 * +--------------------------------------------------------------+
666 * 0 | RSV [63:0] |
667 * +--------------------------------------------------------------+
668 * 8 | RSV | STA | NXTSEQ |
669 * +--------------------------------------------------------------+
670 * 63 36 35 32 31 0
671 *
672 * 82599+ Advanced Transmit Descriptor
673 * +--------------------------------------------------------------+
674 * 0 | Buffer Address [63:0] |
675 * +--------------------------------------------------------------+
676 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
677 * +--------------------------------------------------------------+
678 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
679 *
680 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
681 * +--------------------------------------------------------------+
682 * 0 | RSV [63:0] |
683 * +--------------------------------------------------------------+
684 * 8 | RSV | STA | RSV |
685 * +--------------------------------------------------------------+
686 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000687 */
688
689 for (n = 0; n < adapter->num_tx_queues; n++) {
690 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000691 pr_info("------------------------------------\n");
692 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
693 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000694 pr_info("%s%s %s %s %s %s\n",
695 "T [desc] [address 63:0 ] ",
696 "[PlPOIdStDDt Ln] [bi->dma ] ",
697 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000698
699 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000700 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000701 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000702 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000703 if (dma_unmap_len(tx_buffer, len) > 0) {
704 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
705 i,
706 le64_to_cpu(u0->a),
707 le64_to_cpu(u0->b),
708 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000709 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000710 tx_buffer->next_to_watch,
711 (u64)tx_buffer->time_stamp,
712 tx_buffer->skb);
713 if (i == tx_ring->next_to_use &&
714 i == tx_ring->next_to_clean)
715 pr_cont(" NTC/U\n");
716 else if (i == tx_ring->next_to_use)
717 pr_cont(" NTU\n");
718 else if (i == tx_ring->next_to_clean)
719 pr_cont(" NTC\n");
720 else
721 pr_cont("\n");
722
723 if (netif_msg_pktdata(adapter) &&
724 tx_buffer->skb)
725 print_hex_dump(KERN_INFO, "",
726 DUMP_PREFIX_ADDRESS, 16, 1,
727 tx_buffer->skb->data,
728 dma_unmap_len(tx_buffer, len),
729 true);
730 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000731 }
732 }
733
734 /* Print RX Rings Summary */
735rx_ring_summary:
736 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000737 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000738 for (n = 0; n < adapter->num_rx_queues; n++) {
739 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000740 pr_info("%5d %5X %5X\n",
741 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000742 }
743
744 /* Print RX Rings */
745 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000746 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000747
748 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
749
Josh Hay39ac8682012-09-26 05:59:36 +0000750 /* Receive Descriptor Formats
751 *
752 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000753 * 63 1 0
754 * +-----------------------------------------------------+
755 * 0 | Packet Buffer Address [63:1] |A0/NSE|
756 * +----------------------------------------------+------+
757 * 8 | Header Buffer Address [63:1] | DD |
758 * +-----------------------------------------------------+
759 *
760 *
Josh Hay39ac8682012-09-26 05:59:36 +0000761 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000762 *
763 * 63 48 47 32 31 30 21 20 16 15 4 3 0
764 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000765 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
766 * | Packet | IP | | | | Type | Type |
767 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000768 * +------------------------------------------------------+
769 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
770 * +------------------------------------------------------+
771 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000772 *
773 * 82599+ Advanced Receive Descriptor (Read) Format
774 * 63 1 0
775 * +-----------------------------------------------------+
776 * 0 | Packet Buffer Address [63:1] |A0/NSE|
777 * +----------------------------------------------+------+
778 * 8 | Header Buffer Address [63:1] | DD |
779 * +-----------------------------------------------------+
780 *
781 *
782 * 82599+ Advanced Receive Descriptor (Write-Back) Format
783 *
784 * 63 48 47 32 31 30 21 20 17 16 4 3 0
785 * +------------------------------------------------------+
786 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
787 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
788 * |/ Flow Dir Flt ID | | | | | |
789 * +------------------------------------------------------+
790 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
791 * +------------------------------------------------------+
792 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000793 */
Josh Hay39ac8682012-09-26 05:59:36 +0000794
Taku Izumidcd79ae2010-04-27 14:39:53 +0000795 for (n = 0; n < adapter->num_rx_queues; n++) {
796 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000797 pr_info("------------------------------------\n");
798 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
799 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000800 pr_info("%s%s%s",
801 "R [desc] [ PktBuf A0] ",
802 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000803 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000804 pr_info("%s%s%s",
805 "RWB[desc] [PcsmIpSHl PtRs] ",
806 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000807 "<-- Adv Rx Write-Back format\n");
808
809 for (i = 0; i < rx_ring->count; i++) {
810 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000811 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000812 u0 = (struct my_u0 *)rx_desc;
813 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
814 if (staterr & IXGBE_RXD_STAT_DD) {
815 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000816 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000817 "%016llX ---------------- %p", i,
818 le64_to_cpu(u0->a),
819 le64_to_cpu(u0->b),
820 rx_buffer_info->skb);
821 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000822 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000823 "%016llX %016llX %p", i,
824 le64_to_cpu(u0->a),
825 le64_to_cpu(u0->b),
826 (u64)rx_buffer_info->dma,
827 rx_buffer_info->skb);
828
Emil Tantilov9c50c032012-07-26 01:21:24 +0000829 if (netif_msg_pktdata(adapter) &&
830 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000831 print_hex_dump(KERN_INFO, "",
832 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000833 page_address(rx_buffer_info->page) +
834 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000835 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000836 }
837 }
838
839 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000840 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000841 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000842 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000843 else
Joe Perchesc7689572010-09-07 21:35:17 +0000844 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000845
846 }
847 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000848}
849
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800850static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
851{
852 u32 ctrl_ext;
853
854 /* Let firmware take over control of h/w */
855 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
856 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000857 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800858}
859
860static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
861{
862 u32 ctrl_ext;
863
864 /* Let firmware know the driver has taken over */
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}
Auke Kok9a799d72007-09-15 14:07:45 -0700869
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000870/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000871 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
872 * @adapter: pointer to adapter struct
873 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
874 * @queue: queue to map the corresponding interrupt to
875 * @msix_vector: the vector to map to the corresponding queue
876 *
877 */
878static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000879 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700880{
881 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000882 struct ixgbe_hw *hw = &adapter->hw;
883 switch (hw->mac.type) {
884 case ixgbe_mac_82598EB:
885 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
886 if (direction == -1)
887 direction = 0;
888 index = (((direction * 64) + queue) >> 2) & 0x1F;
889 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
890 ivar &= ~(0xFF << (8 * (queue & 0x3)));
891 ivar |= (msix_vector << (8 * (queue & 0x3)));
892 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
893 break;
894 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800895 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000896 case ixgbe_mac_X550:
897 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700898 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000899 if (direction == -1) {
900 /* other causes */
901 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
902 index = ((queue & 1) * 8);
903 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
904 ivar &= ~(0xFF << index);
905 ivar |= (msix_vector << index);
906 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
907 break;
908 } else {
909 /* tx or rx causes */
910 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
911 index = ((16 * (queue & 1)) + (8 * direction));
912 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
913 ivar &= ~(0xFF << index);
914 ivar |= (msix_vector << index);
915 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
916 break;
917 }
918 default:
919 break;
920 }
Auke Kok9a799d72007-09-15 14:07:45 -0700921}
922
Alexander Duyckfe49f042009-06-04 16:00:09 +0000923static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000924 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000925{
926 u32 mask;
927
Alexander Duyckbd508172010-11-16 19:27:03 -0800928 switch (adapter->hw.mac.type) {
929 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000930 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
931 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800932 break;
933 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800934 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000935 case ixgbe_mac_X550:
936 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700937 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000938 mask = (qmask & 0xFFFFFFFF);
939 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
940 mask = (qmask >> 32);
941 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800942 break;
943 default:
944 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000945 }
946}
947
Alexander Duyck943561d2012-05-09 22:14:44 -0700948static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
949{
950 struct ixgbe_hw *hw = &adapter->hw;
951 struct ixgbe_hw_stats *hwstats = &adapter->stats;
952 int i;
953 u32 data;
954
955 if ((hw->fc.current_mode != ixgbe_fc_full) &&
956 (hw->fc.current_mode != ixgbe_fc_rx_pause))
957 return;
958
959 switch (hw->mac.type) {
960 case ixgbe_mac_82598EB:
961 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
962 break;
963 default:
964 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
965 }
966 hwstats->lxoffrxc += data;
967
968 /* refill credits (no tx hang) if we received xoff */
969 if (!data)
970 return;
971
972 for (i = 0; i < adapter->num_tx_queues; i++)
973 clear_bit(__IXGBE_HANG_CHECK_ARMED,
974 &adapter->tx_ring[i]->state);
975}
976
John Fastabendc84d3242010-11-16 19:27:12 -0800977static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700978{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700979 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800980 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800981 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000982 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800983 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700984 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700985
Alexander Duyck943561d2012-05-09 22:14:44 -0700986 if (adapter->ixgbe_ieee_pfc)
987 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800988
Alexander Duyck943561d2012-05-09 22:14:44 -0700989 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
990 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800991 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700992 }
John Fastabendc84d3242010-11-16 19:27:12 -0800993
994 /* update stats for each tc, only valid with PFC enabled */
995 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000996 u32 pxoffrxc;
997
John Fastabendc84d3242010-11-16 19:27:12 -0800998 switch (hw->mac.type) {
999 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001000 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001001 break;
1002 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001003 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001004 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001005 hwstats->pxoffrxc[i] += pxoffrxc;
1006 /* Get the TC for given UP */
1007 tc = netdev_get_prio_tc_map(adapter->netdev, i);
1008 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -07001009 }
1010
John Fastabendc84d3242010-11-16 19:27:12 -08001011 /* disarm tx queues that have received xoff frames */
1012 for (i = 0; i < adapter->num_tx_queues; i++) {
1013 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -08001014
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001015 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001016 if (xoff[tc])
1017 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1018 }
1019}
1020
1021static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1022{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001023 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001024}
1025
1026static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1027{
John Fastabend2a47fa42013-11-06 09:54:52 -08001028 struct ixgbe_adapter *adapter;
1029 struct ixgbe_hw *hw;
1030 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001031
John Fastabend2a47fa42013-11-06 09:54:52 -08001032 if (ring->l2_accel_priv)
1033 adapter = ring->l2_accel_priv->real_adapter;
1034 else
1035 adapter = netdev_priv(ring->netdev);
1036
1037 hw = &adapter->hw;
1038 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1039 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001040
1041 if (head != tail)
1042 return (head < tail) ?
1043 tail - head : (tail + ring->count - head);
1044
1045 return 0;
1046}
1047
1048static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1049{
1050 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1051 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1052 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001053
1054 clear_check_for_tx_hang(tx_ring);
1055
1056 /*
1057 * Check for a hung queue, but be thorough. This verifies
1058 * that a transmit has been completed since the previous
1059 * check AND there is at least one packet pending. The
1060 * ARMED bit is set to indicate a potential hang. The
1061 * bit is cleared if a pause frame is received to remove
1062 * false hang detection due to PFC or 802.3x frames. By
1063 * requiring this to fail twice we avoid races with
1064 * pfc clearing the ARMED bit and conditions where we
1065 * run the check_tx_hang logic with a transmit completion
1066 * pending but without time to complete it yet.
1067 */
Mark Rustade90dd262014-07-22 06:51:08 +00001068 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001069 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001070 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1071 &tx_ring->state);
1072 /* update completed stats and continue */
1073 tx_ring->tx_stats.tx_done_old = tx_done;
1074 /* reset the countdown */
1075 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001076
Mark Rustade90dd262014-07-22 06:51:08 +00001077 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001078}
1079
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001080/**
1081 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1082 * @adapter: driver private struct
1083 **/
1084static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1085{
1086
1087 /* Do the reset outside of interrupt context */
1088 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
Emil Tantilov57ca2a42016-07-29 14:46:31 -07001089 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Jacob Keller12ff3f32012-12-01 07:57:17 +00001090 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001091 ixgbe_service_event_schedule(adapter);
1092 }
1093}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001094
Auke Kok9a799d72007-09-15 14:07:45 -07001095/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001096 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1097 **/
1098static int ixgbe_tx_maxrate(struct net_device *netdev,
1099 int queue_index, u32 maxrate)
1100{
1101 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1102 struct ixgbe_hw *hw = &adapter->hw;
1103 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1104
1105 if (!maxrate)
1106 return 0;
1107
1108 /* Calculate the rate factor values to set */
1109 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1110 bcnrc_val /= maxrate;
1111
1112 /* clear everything but the rate factor */
1113 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1114 IXGBE_RTTBCNRC_RF_DEC_MASK;
1115
1116 /* enable the rate scheduler */
1117 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1118
1119 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1120 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1121
1122 return 0;
1123}
1124
1125/**
Auke Kok9a799d72007-09-15 14:07:45 -07001126 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001127 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001128 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001129 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001130 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001131static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001132 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001133{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001134 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001135 struct ixgbe_tx_buffer *tx_buffer;
1136 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001137 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001138 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001139 unsigned int i = tx_ring->next_to_clean;
1140
1141 if (test_bit(__IXGBE_DOWN, &adapter->state))
1142 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001143
Alexander Duyckd3d00232011-07-15 02:31:25 +00001144 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001145 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001146 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001147
Alexander Duyck729739b2012-02-08 07:51:06 +00001148 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001149 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001150
Alexander Duyckd3d00232011-07-15 02:31:25 +00001151 /* if next_to_watch is not set then there is no work pending */
1152 if (!eop_desc)
1153 break;
1154
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001155 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001156 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001157
Alexander Duyckd3d00232011-07-15 02:31:25 +00001158 /* if DD is not set pending work has not been completed */
1159 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1160 break;
1161
Alexander Duyckd3d00232011-07-15 02:31:25 +00001162 /* clear next_to_watch to prevent false hangs */
1163 tx_buffer->next_to_watch = NULL;
1164
Alexander Duyck091a6242012-02-08 07:51:01 +00001165 /* update the statistics for this packet */
1166 total_bytes += tx_buffer->bytecount;
1167 total_packets += tx_buffer->gso_segs;
1168
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001169 /* free the skb */
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001170 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001171
Alexander Duyck729739b2012-02-08 07:51:06 +00001172 /* unmap skb header data */
1173 dma_unmap_single(tx_ring->dev,
1174 dma_unmap_addr(tx_buffer, dma),
1175 dma_unmap_len(tx_buffer, len),
1176 DMA_TO_DEVICE);
1177
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001178 /* clear tx_buffer data */
Alexander Duyck729739b2012-02-08 07:51:06 +00001179 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001180
Alexander Duyck729739b2012-02-08 07:51:06 +00001181 /* unmap remaining buffers */
1182 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001183 tx_buffer++;
1184 tx_desc++;
1185 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001186 if (unlikely(!i)) {
1187 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001188 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001189 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001190 }
1191
Alexander Duyck729739b2012-02-08 07:51:06 +00001192 /* unmap any remaining paged data */
1193 if (dma_unmap_len(tx_buffer, len)) {
1194 dma_unmap_page(tx_ring->dev,
1195 dma_unmap_addr(tx_buffer, dma),
1196 dma_unmap_len(tx_buffer, len),
1197 DMA_TO_DEVICE);
1198 dma_unmap_len_set(tx_buffer, len, 0);
1199 }
1200 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001201
Alexander Duyck729739b2012-02-08 07:51:06 +00001202 /* move us one more past the eop_desc for start of next pkt */
1203 tx_buffer++;
1204 tx_desc++;
1205 i++;
1206 if (unlikely(!i)) {
1207 i -= tx_ring->count;
1208 tx_buffer = tx_ring->tx_buffer_info;
1209 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1210 }
1211
1212 /* issue prefetch for next Tx descriptor */
1213 prefetch(tx_desc);
1214
1215 /* update budget accounting */
1216 budget--;
1217 } while (likely(budget));
1218
1219 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001220 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001221 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001222 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001223 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001224 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001225 q_vector->tx.total_bytes += total_bytes;
1226 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001227
John Fastabendc84d3242010-11-16 19:27:12 -08001228 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001229 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001230 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001231 e_err(drv, "Detected Tx Unit Hang\n"
1232 " Tx Queue <%d>\n"
1233 " TDH, TDT <%x>, <%x>\n"
1234 " next_to_use <%x>\n"
1235 " next_to_clean <%x>\n"
1236 "tx_buffer_info[next_to_clean]\n"
1237 " time_stamp <%lx>\n"
1238 " jiffies <%lx>\n",
1239 tx_ring->queue_index,
1240 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1241 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001242 tx_ring->next_to_use, i,
1243 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001244
1245 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1246
1247 e_info(probe,
1248 "tx hang %d detected on queue %d, resetting adapter\n",
1249 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1250
1251 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001252 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001253
1254 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001255 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001256 }
Auke Kok9a799d72007-09-15 14:07:45 -07001257
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001258 netdev_tx_completed_queue(txring_txq(tx_ring),
1259 total_packets, total_bytes);
1260
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001261#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001262 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001263 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001264 /* Make sure that anybody stopping the queue after this
1265 * sees the new next_to_clean.
1266 */
1267 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001268 if (__netif_subqueue_stopped(tx_ring->netdev,
1269 tx_ring->queue_index)
1270 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1271 netif_wake_subqueue(tx_ring->netdev,
1272 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001273 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001274 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001275 }
Auke Kok9a799d72007-09-15 14:07:45 -07001276
Alexander Duyck59224552011-08-31 00:01:06 +00001277 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001278}
1279
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001280#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001281static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001282 struct ixgbe_ring *tx_ring,
1283 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001284{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001285 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001286 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001287 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001288
Mark Rustad9de76052015-08-08 16:27:41 -07001289 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1290 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1291
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001292 switch (hw->mac.type) {
1293 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001294 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001295 break;
1296 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001297 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001298 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1299 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1300 break;
1301 default:
1302 /* for unknown hardware do not write register */
1303 return;
1304 }
1305
1306 /*
1307 * We can enable relaxed ordering for reads, but not writes when
1308 * DCA is enabled. This is due to a known issue in some chipsets
1309 * which will cause the DCA tag to be cleared.
1310 */
1311 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1312 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1313 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1314
1315 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1316}
1317
1318static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1319 struct ixgbe_ring *rx_ring,
1320 int cpu)
1321{
1322 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001323 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001324 u8 reg_idx = rx_ring->reg_idx;
1325
Mark Rustad9de76052015-08-08 16:27:41 -07001326 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1327 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001328
1329 switch (hw->mac.type) {
1330 case ixgbe_mac_82599EB:
1331 case ixgbe_mac_X540:
1332 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001333 break;
1334 default:
1335 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001336 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001337
1338 /*
1339 * We can enable relaxed ordering for reads, but not writes when
1340 * DCA is enabled. This is due to a known issue in some chipsets
1341 * which will cause the DCA tag to be cleared.
1342 */
1343 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Mark Rustad9de76052015-08-08 16:27:41 -07001344 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001345 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1346
1347 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001348}
1349
1350static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1351{
1352 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001353 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001354 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001355
1356 if (q_vector->cpu == cpu)
1357 goto out_no_update;
1358
Alexander Duycka5579282012-02-08 07:50:04 +00001359 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001360 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001361
Alexander Duycka5579282012-02-08 07:50:04 +00001362 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001363 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001364
1365 q_vector->cpu = cpu;
1366out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001367 put_cpu();
1368}
1369
1370static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1371{
1372 int i;
1373
Alexander Duycke35ec122009-05-21 13:07:12 +00001374 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001375 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1376 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1377 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1378 else
1379 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1380 IXGBE_DCA_CTRL_DCA_DISABLE);
Alexander Duycke35ec122009-05-21 13:07:12 +00001381
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001382 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001383 adapter->q_vector[i]->cpu = -1;
1384 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001385 }
1386}
1387
1388static int __ixgbe_notify_dca(struct device *dev, void *data)
1389{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001390 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001391 unsigned long event = *(unsigned long *)data;
1392
Don Skidmore2a72c312011-07-20 02:27:05 +00001393 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001394 return 0;
1395
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001396 switch (event) {
1397 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001398 /* if we're already enabled, don't do it again */
1399 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1400 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001401 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001402 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001403 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1404 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001405 break;
1406 }
1407 /* Fall Through since DCA is disabled. */
1408 case DCA_PROVIDER_REMOVE:
1409 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1410 dca_remove_requester(dev);
1411 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001412 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1413 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001414 }
1415 break;
1416 }
1417
Denis V. Lunev652f0932008-03-27 14:39:17 +03001418 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001419}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001420
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001421#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b82015-04-29 10:57:39 +08001422
1423#define IXGBE_RSS_L4_TYPES_MASK \
1424 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1425 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1426 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1427 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1428
Alexander Duyck8a0da212012-01-31 02:59:49 +00001429static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1430 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001431 struct sk_buff *skb)
1432{
Fan Du7edda4b82015-04-29 10:57:39 +08001433 u16 rss_type;
1434
1435 if (!(ring->netdev->features & NETIF_F_RXHASH))
1436 return;
1437
1438 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1439 IXGBE_RXDADV_RSSTYPE_MASK;
1440
1441 if (!rss_type)
1442 return;
1443
1444 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1445 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1446 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001447}
1448
Alexander Duyckf8003262012-03-03 02:35:52 +00001449#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001450/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001451 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001452 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001453 * @rx_desc: advanced rx descriptor
1454 *
1455 * Returns : true if it is FCoE pkt
1456 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001457static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001458 union ixgbe_adv_rx_desc *rx_desc)
1459{
1460 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1461
Alexander Duyck57efd442012-06-25 21:54:46 +00001462 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001463 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1464 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1465 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1466}
1467
Alexander Duyckf8003262012-03-03 02:35:52 +00001468#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001469/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001470 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001471 * @ring: structure containing ring specific data
1472 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001473 * @skb: skb currently being received and modified
1474 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001475static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001476 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001477 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001478{
Don Skidmore3f207802014-12-23 07:40:34 +00001479 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore3f207802014-12-23 07:40:34 +00001480 bool encap_pkt = false;
1481
Alexander Duyck8a0da212012-01-31 02:59:49 +00001482 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001483
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001484 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001485 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001486 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001487
Emil Tantilova21d0822016-08-10 11:19:23 -07001488 /* check for VXLAN and Geneve packets */
1489 if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
Don Skidmore3f207802014-12-23 07:40:34 +00001490 encap_pkt = true;
1491 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001492 }
1493
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001494 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001495 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1496 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001497 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001498 return;
1499 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001500
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001501 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001502 return;
1503
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001504 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001505 /*
1506 * 82599 errata, UDP frames with a 0 checksum can be marked as
1507 * checksum errors.
1508 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001509 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1510 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001511 return;
1512
Alexander Duyck8a0da212012-01-31 02:59:49 +00001513 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001514 return;
1515 }
1516
Auke Kok9a799d72007-09-15 14:07:45 -07001517 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001518 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001519 if (encap_pkt) {
1520 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1521 return;
1522
1523 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
Mark Rustadd4692512015-12-04 11:26:43 -08001524 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001525 return;
1526 }
1527 /* If we checked the outer header let the stack know */
1528 skb->csum_level = 1;
1529 }
Auke Kok9a799d72007-09-15 14:07:45 -07001530}
1531
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001532static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
1533{
1534 return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
1535}
1536
Alexander Duyckf990b792012-01-31 02:59:34 +00001537static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1538 struct ixgbe_rx_buffer *bi)
1539{
1540 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001541 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001542
Alexander Duyckf8003262012-03-03 02:35:52 +00001543 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001544 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001545 return true;
1546
Alexander Duyckf8003262012-03-03 02:35:52 +00001547 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001548 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1549 if (unlikely(!page)) {
1550 rx_ring->rx_stats.alloc_rx_page_failed++;
1551 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001552 }
1553
Alexander Duyckf8003262012-03-03 02:35:52 +00001554 /* map page for use */
Alexander Duyckf3213d92017-01-17 08:35:54 -08001555 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
1556 ixgbe_rx_pg_size(rx_ring),
1557 DMA_FROM_DEVICE,
1558 IXGBE_RX_DMA_ATTR);
Alexander Duyckf990b792012-01-31 02:59:34 +00001559
Alexander Duyckf8003262012-03-03 02:35:52 +00001560 /*
1561 * if mapping failed free memory back to system since
1562 * there isn't much point in holding memory we can't use
1563 */
1564 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001565 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001566
Alexander Duyckf990b792012-01-31 02:59:34 +00001567 rx_ring->rx_stats.alloc_rx_page_failed++;
1568 return false;
1569 }
1570
Alexander Duyckf8003262012-03-03 02:35:52 +00001571 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001572 bi->page = page;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001573 bi->page_offset = ixgbe_rx_offset(rx_ring);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001574 bi->pagecnt_bias = 1;
Alexander Duyckf8003262012-03-03 02:35:52 +00001575
Alexander Duyckf990b792012-01-31 02:59:34 +00001576 return true;
1577}
1578
Auke Kok9a799d72007-09-15 14:07:45 -07001579/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001580 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001581 * @rx_ring: ring to place buffers on
1582 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001583 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001584void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001585{
Auke Kok9a799d72007-09-15 14:07:45 -07001586 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001587 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001588 u16 i = rx_ring->next_to_use;
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001589 u16 bufsz;
Auke Kok9a799d72007-09-15 14:07:45 -07001590
Alexander Duyckf8003262012-03-03 02:35:52 +00001591 /* nothing to do */
1592 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001593 return;
1594
Alexander Duycke4f74022012-01-31 02:59:44 +00001595 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001596 bi = &rx_ring->rx_buffer_info[i];
1597 i -= rx_ring->count;
1598
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001599 bufsz = ixgbe_rx_bufsz(rx_ring);
1600
Alexander Duyckf8003262012-03-03 02:35:52 +00001601 do {
1602 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001603 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001604
Alexander Duyckf3213d92017-01-17 08:35:54 -08001605 /* sync the buffer for use by the device */
1606 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001607 bi->page_offset, bufsz,
Alexander Duyckf3213d92017-01-17 08:35:54 -08001608 DMA_FROM_DEVICE);
1609
Alexander Duyckf8003262012-03-03 02:35:52 +00001610 /*
1611 * Refresh the desc even if buffer_addrs didn't change
1612 * because each write-back erases this info.
1613 */
1614 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001615
Alexander Duyckf990b792012-01-31 02:59:34 +00001616 rx_desc++;
1617 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001618 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001619 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001620 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001621 bi = rx_ring->rx_buffer_info;
1622 i -= rx_ring->count;
1623 }
1624
Alexander Duyckc3630cc2017-01-17 08:36:28 -08001625 /* clear the length for the next_to_use descriptor */
1626 rx_desc->wb.upper.length = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001627
1628 cleaned_count--;
1629 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001630
Alexander Duyckf990b792012-01-31 02:59:34 +00001631 i += rx_ring->count;
1632
Alexander Duyckad435ec2014-11-14 00:56:35 +00001633 if (rx_ring->next_to_use != i) {
1634 rx_ring->next_to_use = i;
1635
1636 /* update next to alloc since we have filled the ring */
1637 rx_ring->next_to_alloc = i;
1638
1639 /* Force memory writes to complete before letting h/w
1640 * know there are new descriptors to fetch. (Only
1641 * applicable for weak-ordered memory model archs,
1642 * such as IA-64).
1643 */
1644 wmb();
1645 writel(i, rx_ring->tail);
1646 }
Auke Kok9a799d72007-09-15 14:07:45 -07001647}
1648
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001649static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1650 struct sk_buff *skb)
1651{
Alexander Duyckf8003262012-03-03 02:35:52 +00001652 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001653
1654 /* set gso_size to avoid messing up TCP MSS */
1655 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1656 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001657 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001658}
1659
1660static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1661 struct sk_buff *skb)
1662{
1663 /* if append_cnt is 0 then frame is not RSC */
1664 if (!IXGBE_CB(skb)->append_cnt)
1665 return;
1666
1667 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1668 rx_ring->rx_stats.rsc_flush++;
1669
1670 ixgbe_set_rsc_gso_size(rx_ring, skb);
1671
1672 /* gso_size is computed using append_cnt so always clear it last */
1673 IXGBE_CB(skb)->append_cnt = 0;
1674}
1675
Alexander Duyck8a0da212012-01-31 02:59:49 +00001676/**
1677 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1678 * @rx_ring: rx descriptor ring packet is being transacted on
1679 * @rx_desc: pointer to the EOP Rx descriptor
1680 * @skb: pointer to current skb being populated
1681 *
1682 * This function checks the ring, descriptor, and packet information in
1683 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1684 * other fields within the skb.
1685 **/
1686static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1687 union ixgbe_adv_rx_desc *rx_desc,
1688 struct sk_buff *skb)
1689{
John Fastabend43e95f12012-05-15 06:12:17 +00001690 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001691 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001692
Alexander Duyck8a0da212012-01-31 02:59:49 +00001693 ixgbe_update_rsc_stats(rx_ring, skb);
1694
1695 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1696
1697 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1698
Mark Rustada9763f32015-10-27 09:58:07 -07001699 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1700 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001701
Patrick McHardyf6469682013-04-19 02:04:27 +00001702 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001703 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001704 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001705 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001706 }
1707
1708 skb_record_rx_queue(skb, rx_ring->queue_index);
1709
John Fastabend43e95f12012-05-15 06:12:17 +00001710 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001711}
1712
1713static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1714 struct sk_buff *skb)
1715{
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08001716 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001717}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001718
Alexander Duyckf8003262012-03-03 02:35:52 +00001719/**
1720 * ixgbe_is_non_eop - process handling of non-EOP buffers
1721 * @rx_ring: Rx ring being processed
1722 * @rx_desc: Rx descriptor for current buffer
1723 * @skb: Current socket buffer containing buffer in progress
1724 *
1725 * This function updates next to clean. If the buffer is an EOP buffer
1726 * this function exits returning false, otherwise it will place the
1727 * sk_buff in the next buffer to be chained and return true indicating
1728 * that this is in fact a non-EOP buffer.
1729 **/
1730static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1731 union ixgbe_adv_rx_desc *rx_desc,
1732 struct sk_buff *skb)
1733{
1734 u32 ntc = rx_ring->next_to_clean + 1;
1735
1736 /* fetch, update, and store next to clean */
1737 ntc = (ntc < rx_ring->count) ? ntc : 0;
1738 rx_ring->next_to_clean = ntc;
1739
1740 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1741
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001742 /* update RSC append count if present */
1743 if (ring_is_rsc_enabled(rx_ring)) {
1744 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1745 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1746
1747 if (unlikely(rsc_enabled)) {
1748 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1749
1750 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1751 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1752
1753 /* update ntc based on RSC value */
1754 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1755 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1756 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1757 }
1758 }
1759
1760 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001761 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1762 return false;
1763
Alexander Duyckf8003262012-03-03 02:35:52 +00001764 /* place skb in next buffer to be received */
1765 rx_ring->rx_buffer_info[ntc].skb = skb;
1766 rx_ring->rx_stats.non_eop_descs++;
1767
1768 return true;
1769}
1770
1771/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001772 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1773 * @rx_ring: rx descriptor ring packet is being transacted on
1774 * @skb: pointer to current skb being adjusted
1775 *
1776 * This function is an ixgbe specific version of __pskb_pull_tail. The
1777 * main difference between this version and the original function is that
1778 * this function can make several assumptions about the state of things
1779 * that allow for significant optimizations versus the standard function.
1780 * As a result we can do things like drop a frag and maintain an accurate
1781 * truesize for the skb.
1782 */
1783static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1784 struct sk_buff *skb)
1785{
1786 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1787 unsigned char *va;
1788 unsigned int pull_len;
1789
1790 /*
1791 * it is valid to use page_address instead of kmap since we are
1792 * working with pages allocated out of the lomem pool per
1793 * alloc_page(GFP_ATOMIC)
1794 */
1795 va = skb_frag_address(frag);
1796
1797 /*
1798 * we need the header to contain the greater of either ETH_HLEN or
1799 * 60 bytes if the skb->len is less than 60 for skb_pad.
1800 */
Alexander Duyck8496e3382014-09-05 19:22:18 -04001801 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001802
1803 /* align pull length to size of long to optimize memcpy performance */
1804 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1805
1806 /* update all of the pointers */
1807 skb_frag_size_sub(frag, pull_len);
1808 frag->page_offset += pull_len;
1809 skb->data_len -= pull_len;
1810 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001811}
1812
1813/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001814 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1815 * @rx_ring: rx descriptor ring packet is being transacted on
1816 * @skb: pointer to current skb being updated
1817 *
1818 * This function provides a basic DMA sync up for the first fragment of an
1819 * skb. The reason for doing this is that the first fragment cannot be
1820 * unmapped until we have reached the end of packet descriptor for a buffer
1821 * chain.
1822 */
1823static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1824 struct sk_buff *skb)
1825{
1826 /* if the page was released unmap it, else just sync our portion */
1827 if (unlikely(IXGBE_CB(skb)->page_released)) {
Alexander Duyckf3213d92017-01-17 08:35:54 -08001828 dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
1829 ixgbe_rx_pg_size(rx_ring),
1830 DMA_FROM_DEVICE,
1831 IXGBE_RX_DMA_ATTR);
Alexander Duyck42073d92012-07-20 08:08:28 +00001832 } else {
1833 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1834
1835 dma_sync_single_range_for_cpu(rx_ring->dev,
1836 IXGBE_CB(skb)->dma,
1837 frag->page_offset,
Alexander Duyckf215af82017-01-17 08:35:44 -08001838 skb_frag_size(frag),
Alexander Duyck42073d92012-07-20 08:08:28 +00001839 DMA_FROM_DEVICE);
1840 }
Alexander Duyck42073d92012-07-20 08:08:28 +00001841}
1842
1843/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001844 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1845 * @rx_ring: rx descriptor ring packet is being transacted on
1846 * @rx_desc: pointer to the EOP Rx descriptor
1847 * @skb: pointer to current skb being fixed
1848 *
1849 * Check for corrupted packet headers caused by senders on the local L2
1850 * embedded NIC switch not setting up their Tx Descriptors right. These
1851 * should be very rare.
1852 *
1853 * Also address the case where we are pulling data in on pages only
1854 * and as such no data is present in the skb header.
1855 *
1856 * In addition if skb is not at least 60 bytes we need to pad it so that
1857 * it is large enough to qualify as a valid Ethernet frame.
1858 *
1859 * Returns true if an error was encountered and skb was freed.
1860 **/
1861static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1862 union ixgbe_adv_rx_desc *rx_desc,
1863 struct sk_buff *skb)
1864{
Alexander Duyckf8003262012-03-03 02:35:52 +00001865 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001866
1867 /* verify that the packet does not have any known errors */
1868 if (unlikely(ixgbe_test_staterr(rx_desc,
1869 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1870 !(netdev->features & NETIF_F_RXALL))) {
1871 dev_kfree_skb_any(skb);
1872 return true;
1873 }
1874
Alexander Duyck19861ce2012-07-20 08:08:33 +00001875 /* place header in linear portion of buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08001876 if (!skb_headlen(skb))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001877 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001878
Alexander Duyck57efd442012-06-25 21:54:46 +00001879#ifdef IXGBE_FCOE
1880 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1881 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1882 return false;
1883
1884#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001885 /* if eth_skb_pad returns an error the skb was freed */
1886 if (eth_skb_pad(skb))
1887 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001888
1889 return false;
1890}
1891
1892/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001893 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1894 * @rx_ring: rx descriptor ring to store buffers on
1895 * @old_buff: donor buffer to have page reused
1896 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001897 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001898 **/
1899static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1900 struct ixgbe_rx_buffer *old_buff)
1901{
1902 struct ixgbe_rx_buffer *new_buff;
1903 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001904
1905 new_buff = &rx_ring->rx_buffer_info[nta];
1906
1907 /* update, and store next to alloc */
1908 nta++;
1909 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1910
Alexander Duyck3fd218762017-01-17 08:36:45 -08001911 /* Transfer page from old buffer to new buffer.
1912 * Move each member individually to avoid possible store
1913 * forwarding stalls and unnecessary copy of skb.
1914 */
1915 new_buff->dma = old_buff->dma;
1916 new_buff->page = old_buff->page;
1917 new_buff->page_offset = old_buff->page_offset;
1918 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
Alexander Duyckf8003262012-03-03 02:35:52 +00001919}
1920
Alexander Duyck18cb6522014-11-14 00:56:29 +00001921static inline bool ixgbe_page_is_reserved(struct page *page)
1922{
Michal Hocko2f064f32015-08-21 14:11:51 -07001923 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001924}
1925
Alexander Duyck3fd218762017-01-17 08:36:45 -08001926static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
Alexander Duyckf8003262012-03-03 02:35:52 +00001927{
Alexander Duyck3fd218762017-01-17 08:36:45 -08001928 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
1929 struct page *page = rx_buffer->page;
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001930
Alexander Duyck09816fb2012-07-20 08:08:23 +00001931 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001932 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001933 return false;
1934
1935#if (PAGE_SIZE < 8192)
1936 /* if we are only owner of page we can reuse it */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001937 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001938 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001939#else
Alexander Duyck3fd218762017-01-17 08:36:45 -08001940 /* The last offset is a bit aggressive in that we assume the
1941 * worst case of FCoE being enabled and using a 3K buffer.
1942 * However this should have minimal impact as the 1K extra is
1943 * still less than one buffer in size.
1944 */
1945#define IXGBE_LAST_OFFSET \
1946 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
1947 if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
Alexander Duyck09816fb2012-07-20 08:08:23 +00001948 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001949#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001950
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001951 /* If we have drained the page fragment pool we need to update
1952 * the pagecnt_bias and page count so that we fully restock the
1953 * number of references the driver holds.
Alexander Duyck18cb6522014-11-14 00:56:29 +00001954 */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001955 if (unlikely(!pagecnt_bias)) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001956 page_ref_add(page, USHRT_MAX);
1957 rx_buffer->pagecnt_bias = USHRT_MAX;
1958 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00001959
Alexander Duyck0549ae22012-07-20 08:08:18 +00001960 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001961}
1962
Alexander Duyckaf43da02017-01-17 08:35:34 -08001963/**
1964 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1965 * @rx_ring: rx descriptor ring to transact packets on
1966 * @rx_buffer: buffer containing page to add
1967 * @rx_desc: descriptor containing length of buffer written by hardware
1968 * @skb: sk_buff to place the data into
1969 *
1970 * This function will add the data contained in rx_buffer->page to the skb.
1971 * This is done either through a direct copy if the data in the buffer is
1972 * less than the skb header size, otherwise it will just attach the page as
1973 * a frag to the skb.
1974 *
1975 * The function will then update the page offset if necessary and return
1976 * true if the buffer can be reused by the adapter.
1977 **/
Alexander Duyck3fd218762017-01-17 08:36:45 -08001978static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckaf43da02017-01-17 08:35:34 -08001979 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck3fd218762017-01-17 08:36:45 -08001980 struct sk_buff *skb,
1981 unsigned int size)
Alexander Duyckaf43da02017-01-17 08:35:34 -08001982{
Alexander Duyckaf43da02017-01-17 08:35:34 -08001983#if (PAGE_SIZE < 8192)
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001984 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
Alexander Duyckaf43da02017-01-17 08:35:34 -08001985#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001986 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
1987 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
1988 SKB_DATA_ALIGN(size);
Alexander Duyckaf43da02017-01-17 08:35:34 -08001989#endif
Alexander Duyck3fd218762017-01-17 08:36:45 -08001990 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
Alexander Duyckaf43da02017-01-17 08:35:34 -08001991 rx_buffer->page_offset, size, truesize);
Alexander Duyck3fd218762017-01-17 08:36:45 -08001992#if (PAGE_SIZE < 8192)
1993 rx_buffer->page_offset ^= truesize;
1994#else
1995 rx_buffer->page_offset += truesize;
1996#endif
Alexander Duyckaf43da02017-01-17 08:35:34 -08001997}
1998
Alexander Duyck3fd218762017-01-17 08:36:45 -08001999static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
2000 union ixgbe_adv_rx_desc *rx_desc,
2001 struct sk_buff **skb,
2002 const unsigned int size)
Alexander Duyck18806c92012-07-20 08:08:44 +00002003{
2004 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyck18806c92012-07-20 08:08:44 +00002005
2006 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
Alexander Duyck3fd218762017-01-17 08:36:45 -08002007 prefetchw(rx_buffer->page);
2008 *skb = rx_buffer->skb;
Alexander Duyck18806c92012-07-20 08:08:44 +00002009
Alexander Duyck3fd218762017-01-17 08:36:45 -08002010 /* Delay unmapping of the first packet. It carries the header
2011 * information, HW may still access the header after the writeback.
2012 * Only unmap it when EOP is reached
2013 */
2014 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
2015 if (!*skb)
2016 goto skip_sync;
Alexander Duyck18806c92012-07-20 08:08:44 +00002017 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002018 if (*skb)
2019 ixgbe_dma_sync_frag(rx_ring, *skb);
Alexander Duyck18806c92012-07-20 08:08:44 +00002020 }
2021
Alexander Duyck3fd218762017-01-17 08:36:45 -08002022 /* we are reusing so sync this buffer for CPU use */
2023 dma_sync_single_range_for_cpu(rx_ring->dev,
2024 rx_buffer->dma,
2025 rx_buffer->page_offset,
2026 size,
2027 DMA_FROM_DEVICE);
2028skip_sync:
2029 rx_buffer->pagecnt_bias--;
2030
2031 return rx_buffer;
2032}
2033
2034static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
2035 struct ixgbe_rx_buffer *rx_buffer,
2036 struct sk_buff *skb)
2037{
2038 if (ixgbe_can_reuse_rx_page(rx_buffer)) {
Alexander Duyck18806c92012-07-20 08:08:44 +00002039 /* hand second half of page back to the ring */
2040 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
Alexander Duyck18806c92012-07-20 08:08:44 +00002041 } else {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002042 if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
2043 /* the page has been released from the ring */
2044 IXGBE_CB(skb)->page_released = true;
2045 } else {
2046 /* we are not reusing the buffer so unmap it */
2047 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
2048 ixgbe_rx_pg_size(rx_ring),
2049 DMA_FROM_DEVICE,
2050 IXGBE_RX_DMA_ATTR);
2051 }
Alexander Duyck3fd218762017-01-17 08:36:45 -08002052 __page_frag_cache_drain(rx_buffer->page,
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002053 rx_buffer->pagecnt_bias);
Alexander Duyck18806c92012-07-20 08:08:44 +00002054 }
2055
Alexander Duyck3fd218762017-01-17 08:36:45 -08002056 /* clear contents of rx_buffer */
Alexander Duyck18806c92012-07-20 08:08:44 +00002057 rx_buffer->page = NULL;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002058 rx_buffer->skb = NULL;
2059}
2060
2061static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
2062 struct ixgbe_rx_buffer *rx_buffer,
2063 union ixgbe_adv_rx_desc *rx_desc,
2064 unsigned int size)
2065{
2066 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
2067#if (PAGE_SIZE < 8192)
2068 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2069#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08002070 unsigned int truesize = SKB_DATA_ALIGN(size);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002071#endif
2072 struct sk_buff *skb;
2073
2074 /* prefetch first cache line of first page */
2075 prefetch(va);
2076#if L1_CACHE_BYTES < 128
2077 prefetch(va + L1_CACHE_BYTES);
2078#endif
2079
2080 /* allocate a skb to store the frags */
2081 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
2082 if (unlikely(!skb))
2083 return NULL;
2084
2085 if (size > IXGBE_RX_HDR_SIZE) {
2086 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2087 IXGBE_CB(skb)->dma = rx_buffer->dma;
2088
2089 skb_add_rx_frag(skb, 0, rx_buffer->page,
2090 rx_buffer->page_offset,
2091 size, truesize);
2092#if (PAGE_SIZE < 8192)
2093 rx_buffer->page_offset ^= truesize;
2094#else
2095 rx_buffer->page_offset += truesize;
2096#endif
2097 } else {
2098 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
2099 rx_buffer->pagecnt_bias++;
2100 }
Alexander Duyck18806c92012-07-20 08:08:44 +00002101
2102 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002103}
2104
Alexander Duyck6f429222017-01-17 08:37:13 -08002105static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
2106 struct ixgbe_rx_buffer *rx_buffer,
2107 union ixgbe_adv_rx_desc *rx_desc,
2108 unsigned int size)
2109{
2110 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
2111#if (PAGE_SIZE < 8192)
2112 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2113#else
2114 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
2115 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size);
2116#endif
2117 struct sk_buff *skb;
2118
2119 /* prefetch first cache line of first page */
2120 prefetch(va);
2121#if L1_CACHE_BYTES < 128
2122 prefetch(va + L1_CACHE_BYTES);
2123#endif
2124
Alexander Duyck3a1eb6d2017-02-15 09:15:59 -08002125 /* build an skb around the page buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08002126 skb = build_skb(va - IXGBE_SKB_PAD, truesize);
2127 if (unlikely(!skb))
2128 return NULL;
2129
2130 /* update pointers within the skb to store the data */
2131 skb_reserve(skb, IXGBE_SKB_PAD);
2132 __skb_put(skb, size);
2133
2134 /* record DMA address if this is the start of a chain of buffers */
2135 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2136 IXGBE_CB(skb)->dma = rx_buffer->dma;
2137
2138 /* update buffer offset */
2139#if (PAGE_SIZE < 8192)
2140 rx_buffer->page_offset ^= truesize;
2141#else
2142 rx_buffer->page_offset += truesize;
2143#endif
2144
2145 return skb;
2146}
2147
Alexander Duyckf8003262012-03-03 02:35:52 +00002148/**
2149 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2150 * @q_vector: structure containing interrupt and ring information
2151 * @rx_ring: rx descriptor ring to transact packets on
2152 * @budget: Total limit on number of packets to process
2153 *
2154 * This function provides a "bounce buffer" approach to Rx interrupt
2155 * processing. The advantage to this is that on systems that have
2156 * expensive overhead for IOMMU access this provides a means of avoiding
2157 * it by maintaining the mapping of the page to the syste.
2158 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002159 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002160 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002161static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002162 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002163 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002164{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002165 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00002166#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00002167 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00002168 int ddp_bytes;
2169 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002170#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002171 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002172
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002173 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002174 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002175 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyckf8003262012-03-03 02:35:52 +00002176 struct sk_buff *skb;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002177 unsigned int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002178
Alexander Duyckf8003262012-03-03 02:35:52 +00002179 /* return some buffers to hardware, one at a time is too slow */
2180 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2181 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2182 cleaned_count = 0;
2183 }
Auke Kok9a799d72007-09-15 14:07:45 -07002184
Alexander Duyck18806c92012-07-20 08:08:44 +00002185 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002186 size = le16_to_cpu(rx_desc->wb.upper.length);
2187 if (!size)
Alexander Duyckf8003262012-03-03 02:35:52 +00002188 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002189
Alexander Duyck124b74c2014-12-11 15:02:28 -08002190 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002191 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002192 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002193 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002194 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002195
Alexander Duyck3fd218762017-01-17 08:36:45 -08002196 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
2197
Alexander Duyck18806c92012-07-20 08:08:44 +00002198 /* retrieve a buffer from the ring */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002199 if (skb)
2200 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
Alexander Duyck6f429222017-01-17 08:37:13 -08002201 else if (ring_uses_build_skb(rx_ring))
2202 skb = ixgbe_build_skb(rx_ring, rx_buffer,
2203 rx_desc, size);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002204 else
2205 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
2206 rx_desc, size);
Alexander Duyckf8003262012-03-03 02:35:52 +00002207
Alexander Duyck18806c92012-07-20 08:08:44 +00002208 /* exit if we failed to retrieve a buffer */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002209 if (!skb) {
2210 rx_ring->rx_stats.alloc_rx_buff_failed++;
2211 rx_buffer->pagecnt_bias++;
Alexander Duyck18806c92012-07-20 08:08:44 +00002212 break;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002213 }
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002214
Alexander Duyck3fd218762017-01-17 08:36:45 -08002215 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002216 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002217
Alexander Duyckf8003262012-03-03 02:35:52 +00002218 /* place incomplete frames back on ring for completion */
2219 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2220 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002221
Alexander Duyckf8003262012-03-03 02:35:52 +00002222 /* verify the packet layout is correct */
2223 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2224 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002225
2226 /* probably a little skewed due to removing CRC */
2227 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002228
Alexander Duyck8a0da212012-01-31 02:59:49 +00002229 /* populate checksum, timestamp, VLAN, and protocol */
2230 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2231
Yi Zou332d4a72009-05-13 13:11:53 +00002232#ifdef IXGBE_FCOE
2233 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002234 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002235 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002236 /* include DDPed FCoE data */
2237 if (ddp_bytes > 0) {
2238 if (!mss) {
2239 mss = rx_ring->netdev->mtu -
2240 sizeof(struct fcoe_hdr) -
2241 sizeof(struct fc_frame_header) -
2242 sizeof(struct fcoe_crc_eof);
2243 if (mss > 512)
2244 mss &= ~511;
2245 }
2246 total_rx_bytes += ddp_bytes;
2247 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2248 mss);
2249 }
David S. Miller823dcd22011-08-20 10:39:12 -07002250 if (!ddp_bytes) {
2251 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002252 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002253 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002254 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002255
Yi Zou332d4a72009-05-13 13:11:53 +00002256#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002257 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002258
Alexander Duyckf8003262012-03-03 02:35:52 +00002259 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002260 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002261 }
Auke Kok9a799d72007-09-15 14:07:45 -07002262
Alexander Duyckc267fc12010-11-16 19:27:00 -08002263 u64_stats_update_begin(&rx_ring->syncp);
2264 rx_ring->stats.packets += total_rx_packets;
2265 rx_ring->stats.bytes += total_rx_bytes;
2266 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002267 q_vector->rx.total_packets += total_rx_packets;
2268 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002269
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002270 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002271}
2272
Auke Kok9a799d72007-09-15 14:07:45 -07002273/**
2274 * ixgbe_configure_msix - Configure MSI-X hardware
2275 * @adapter: board private structure
2276 *
2277 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2278 * interrupts.
2279 **/
2280static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2281{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002282 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002283 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002284 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002285
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002286 /* Populate MSIX to EITR Select */
2287 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002288 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002289 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2290 }
2291
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002292 /*
2293 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002294 * corresponding register.
2295 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002296 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002297 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002298 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002299
Alexander Duycka5579282012-02-08 07:50:04 +00002300 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002301 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002302
Alexander Duycka5579282012-02-08 07:50:04 +00002303 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002304 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002305
Alexander Duyckfe49f042009-06-04 16:00:09 +00002306 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002307 }
2308
Alexander Duyckbd508172010-11-16 19:27:03 -08002309 switch (adapter->hw.mac.type) {
2310 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002311 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002312 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002313 break;
2314 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002315 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002316 case ixgbe_mac_X550:
2317 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002318 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002319 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002320 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002321 default:
2322 break;
2323 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002324 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002325
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002326 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002328 mask &= ~(IXGBE_EIMS_OTHER |
2329 IXGBE_EIMS_MAILBOX |
2330 IXGBE_EIMS_LSC);
2331
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002332 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002333}
2334
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002335enum latency_range {
2336 lowest_latency = 0,
2337 low_latency = 1,
2338 bulk_latency = 2,
2339 latency_invalid = 255
2340};
2341
2342/**
2343 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002344 * @q_vector: structure containing interrupt and ring information
2345 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002346 *
2347 * Stores a new ITR value based on packets and byte
2348 * counts during the last interrupt. The advantage of per interrupt
2349 * computation is faster updates and more accurate ITR for the current
2350 * traffic pattern. Constants in this function were computed
2351 * based on theoretical maximum wire speed and thresholds were set based
2352 * on testing data as well as attempting to minimize response time
2353 * while increasing bulk throughput.
2354 * this functionality is controlled by the InterruptThrottleRate module
2355 * parameter (see ixgbe_param.c)
2356 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002357static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2358 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002359{
Alexander Duyckbd198052011-06-11 01:45:08 +00002360 int bytes = ring_container->total_bytes;
2361 int packets = ring_container->total_packets;
2362 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002363 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002364 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002365
2366 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002367 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002368
2369 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002370 * 0-10MB/s lowest (100000 ints/s)
2371 * 10-20MB/s low (20000 ints/s)
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002372 * 20-1249MB/s bulk (12000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002373 */
2374 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002375 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002376 if (timepassed_us == 0)
2377 return;
2378
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002379 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2380
2381 switch (itr_setting) {
2382 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002383 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002384 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002385 break;
2386 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002387 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002388 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002389 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002390 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002391 break;
2392 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002393 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002394 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002395 break;
2396 }
2397
Alexander Duyckbd198052011-06-11 01:45:08 +00002398 /* clear work counters since we have the values we need */
2399 ring_container->total_bytes = 0;
2400 ring_container->total_packets = 0;
2401
2402 /* write updated itr to ring container */
2403 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002404}
2405
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002406/**
2407 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002408 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002409 *
2410 * This function is made to be called by ethtool and by the driver
2411 * when it needs to update EITR registers at runtime. Hardware
2412 * specific quirks/differences are taken care of here.
2413 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002414void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002415{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002416 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002417 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002418 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002419 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002420
Alexander Duyckbd508172010-11-16 19:27:03 -08002421 switch (adapter->hw.mac.type) {
2422 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002423 /* must write high and low 16 bits to reset counter */
2424 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002425 break;
2426 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002427 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002428 case ixgbe_mac_X550:
2429 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002430 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002431 /*
2432 * set the WDIS bit to not clear the timer bits and cause an
2433 * immediate assertion of the interrupt
2434 */
2435 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002436 break;
2437 default:
2438 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002439 }
2440 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2441}
2442
Alexander Duyckbd198052011-06-11 01:45:08 +00002443static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002444{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002445 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002446 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002447
Alexander Duyckbd198052011-06-11 01:45:08 +00002448 ixgbe_update_itr(q_vector, &q_vector->tx);
2449 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002450
Alexander Duyck08c88332011-06-11 01:45:03 +00002451 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002452
2453 switch (current_itr) {
2454 /* counts and packets in update_itr are dependent on these numbers */
2455 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002456 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002457 break;
2458 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002459 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002460 break;
2461 case bulk_latency:
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002462 new_itr = IXGBE_12K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002463 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002464 default:
2465 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002466 }
2467
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002468 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002469 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002470 new_itr = (10 * new_itr * q_vector->itr) /
2471 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002472
Alexander Duyckbd198052011-06-11 01:45:08 +00002473 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002474 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002475
2476 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002477 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002478}
2479
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002480/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002481 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002482 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002483 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002484static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002485{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002486 struct ixgbe_hw *hw = &adapter->hw;
2487 u32 eicr = adapter->interrupt_event;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002488 s32 rc;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002489
Alexander Duyckf0f97782011-04-22 04:08:09 +00002490 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002491 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002492
Alexander Duyckf0f97782011-04-22 04:08:09 +00002493 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2494 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2495 return;
2496
2497 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2498
Joe Perches7ca647b2010-09-07 21:35:40 +00002499 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002500 case IXGBE_DEV_ID_82599_T3_LOM:
2501 /*
2502 * Since the warning interrupt is for both ports
2503 * we don't have to check if:
2504 * - This interrupt wasn't for our port.
2505 * - We may have missed the interrupt so always have to
2506 * check if we got a LSC
2507 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002508 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002509 !(eicr & IXGBE_EICR_LSC))
2510 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002511
Alexander Duyckf0f97782011-04-22 04:08:09 +00002512 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002513 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002514 bool link_up = false;
2515
Josh Hay3d292262012-12-15 03:28:19 +00002516 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002517
Alexander Duyckf0f97782011-04-22 04:08:09 +00002518 if (link_up)
2519 return;
2520 }
2521
2522 /* Check if this is not due to overtemp */
2523 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2524 return;
2525
2526 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002527 case IXGBE_DEV_ID_X550EM_A_1G_T:
2528 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2529 rc = hw->phy.ops.check_overtemp(hw);
2530 if (rc != IXGBE_ERR_OVERTEMP)
2531 return;
2532 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002533 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002534 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2535 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002536 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002537 return;
2538 break;
2539 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002540 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002541
2542 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002543}
2544
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002545static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2546{
2547 struct ixgbe_hw *hw = &adapter->hw;
2548
2549 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002550 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002551 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002552 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002553 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002554 }
2555}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002556
Jacob Keller4f51bf72011-08-20 04:49:45 +00002557static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2558{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002559 struct ixgbe_hw *hw = &adapter->hw;
2560
Jacob Keller4f51bf72011-08-20 04:49:45 +00002561 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2562 return;
2563
2564 switch (adapter->hw.mac.type) {
2565 case ixgbe_mac_82599EB:
2566 /*
2567 * Need to check link state so complete overtemp check
2568 * on service task
2569 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002570 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2571 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002572 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2573 adapter->interrupt_event = eicr;
2574 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2575 ixgbe_service_event_schedule(adapter);
2576 return;
2577 }
2578 return;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002579 case ixgbe_mac_x550em_a:
2580 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2581 adapter->interrupt_event = eicr;
2582 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2583 ixgbe_service_event_schedule(adapter);
2584 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2585 IXGBE_EICR_GPI_SDP0_X550EM_a);
2586 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2587 IXGBE_EICR_GPI_SDP0_X550EM_a);
2588 }
2589 return;
2590 case ixgbe_mac_X550:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002591 case ixgbe_mac_X540:
2592 if (!(eicr & IXGBE_EICR_TS))
2593 return;
2594 break;
2595 default:
2596 return;
2597 }
2598
Don Skidmoref44e7512015-06-09 16:36:23 -07002599 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002600}
2601
Don Skidmore45788d22015-06-09 16:59:04 -07002602static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2603{
2604 switch (hw->mac.type) {
2605 case ixgbe_mac_82598EB:
2606 if (hw->phy.type == ixgbe_phy_nl)
2607 return true;
2608 return false;
2609 case ixgbe_mac_82599EB:
2610 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002611 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002612 switch (hw->mac.ops.get_media_type(hw)) {
2613 case ixgbe_media_type_fiber:
2614 case ixgbe_media_type_fiber_qsfp:
2615 return true;
2616 default:
2617 return false;
2618 }
2619 default:
2620 return false;
2621 }
2622}
2623
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002624static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2625{
2626 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002627 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002628
Don Skidmore4ccc6502015-09-02 13:47:54 -07002629 if (!ixgbe_is_sfp(hw))
2630 return;
2631
2632 /* Later MAC's use different SDP */
2633 if (hw->mac.type >= ixgbe_mac_X540)
2634 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2635
2636 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002637 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002638 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002639 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2640 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002641 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002642 ixgbe_service_event_schedule(adapter);
2643 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002644 }
2645
Don Skidmore4ccc6502015-09-02 13:47:54 -07002646 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2647 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002648 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002649 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002650 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2651 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2652 ixgbe_service_event_schedule(adapter);
2653 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002654 }
2655}
2656
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002657static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2658{
2659 struct ixgbe_hw *hw = &adapter->hw;
2660
2661 adapter->lsc_int++;
2662 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2663 adapter->link_check_timeout = jiffies;
2664 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2665 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002666 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002667 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002668 }
2669}
2670
Alexander Duyckfe49f042009-06-04 16:00:09 +00002671static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2672 u64 qmask)
2673{
2674 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002675 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002676
Alexander Duyckbd508172010-11-16 19:27:03 -08002677 switch (hw->mac.type) {
2678 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002679 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002680 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2681 break;
2682 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002683 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002684 case ixgbe_mac_X550:
2685 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002686 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002687 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002688 if (mask)
2689 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002690 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002691 if (mask)
2692 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2693 break;
2694 default:
2695 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002696 }
2697 /* skip the flush */
2698}
2699
2700static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002701 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002702{
2703 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002704 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002705
Alexander Duyckbd508172010-11-16 19:27:03 -08002706 switch (hw->mac.type) {
2707 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002708 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002709 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2710 break;
2711 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002712 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002713 case ixgbe_mac_X550:
2714 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002715 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002716 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002717 if (mask)
2718 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002719 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002720 if (mask)
2721 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2722 break;
2723 default:
2724 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002725 }
2726 /* skip the flush */
2727}
2728
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002729/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002730 * ixgbe_irq_enable - Enable default interrupt generation settings
2731 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002732 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002733static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2734 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002735{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002736 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002737 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002738
Alexander Duyck2c4af692011-07-15 07:29:55 +00002739 /* don't reenable LSC while waiting for link */
2740 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2741 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002742
Alexander Duyck2c4af692011-07-15 07:29:55 +00002743 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002744 switch (adapter->hw.mac.type) {
2745 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002746 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002747 break;
2748 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002749 case ixgbe_mac_X550:
2750 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002751 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002752 mask |= IXGBE_EIMS_TS;
2753 break;
2754 default:
2755 break;
2756 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002757 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002758 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002759 switch (adapter->hw.mac.type) {
2760 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002761 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2762 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002763 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00002764 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002765 case ixgbe_mac_X550:
2766 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002767 case ixgbe_mac_x550em_a:
2768 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07002769 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07002770 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07002771 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07002772 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
2773 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00002774 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002775 mask |= IXGBE_EIMS_MAILBOX;
2776 break;
2777 default:
2778 break;
2779 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002780
Alexander Duyck2c4af692011-07-15 07:29:55 +00002781 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2782 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2783 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002784
Alexander Duyck2c4af692011-07-15 07:29:55 +00002785 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2786 if (queues)
2787 ixgbe_irq_enable_queues(adapter, ~0);
2788 if (flush)
2789 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002790}
2791
Alexander Duyck2c4af692011-07-15 07:29:55 +00002792static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002793{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002794 struct ixgbe_adapter *adapter = data;
2795 struct ixgbe_hw *hw = &adapter->hw;
2796 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002797
Alexander Duyck2c4af692011-07-15 07:29:55 +00002798 /*
2799 * Workaround for Silicon errata. Use clear-by-write instead
2800 * of clear-by-read. Reading with EICS will return the
2801 * interrupt causes without clearing, which later be done
2802 * with the write to EICR.
2803 */
2804 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002805
2806 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08002807 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00002808 * the bits are high when ixgbe_msix_other is called. There is a race
2809 * condition otherwise which results in possible performance loss
2810 * especially if the ixgbe_msix_other interrupt is triggering
2811 * consistently (as it would when PPS is turned on for the X540 device)
2812 */
2813 eicr &= 0xFFFF0000;
2814
Alexander Duyck2c4af692011-07-15 07:29:55 +00002815 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002816
Alexander Duyck2c4af692011-07-15 07:29:55 +00002817 if (eicr & IXGBE_EICR_LSC)
2818 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002819
Alexander Duyck2c4af692011-07-15 07:29:55 +00002820 if (eicr & IXGBE_EICR_MAILBOX)
2821 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002822
Alexander Duyck2c4af692011-07-15 07:29:55 +00002823 switch (hw->mac.type) {
2824 case ixgbe_mac_82599EB:
2825 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002826 case ixgbe_mac_X550:
2827 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002828 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07002829 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
2830 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
2831 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
2832 ixgbe_service_event_schedule(adapter);
2833 IXGBE_WRITE_REG(hw, IXGBE_EICR,
2834 IXGBE_EICR_GPI_SDP0_X540);
2835 }
Don Skidmored773ce22014-02-25 17:58:53 -08002836 if (eicr & IXGBE_EICR_ECC) {
2837 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07002838 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08002839 ixgbe_service_event_schedule(adapter);
2840 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2841 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002842 /* Handle Flow Director Full threshold interrupt */
2843 if (eicr & IXGBE_EICR_FLOW_DIR) {
2844 int reinit_count = 0;
2845 int i;
2846 for (i = 0; i < adapter->num_tx_queues; i++) {
2847 struct ixgbe_ring *ring = adapter->tx_ring[i];
2848 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2849 &ring->state))
2850 reinit_count++;
2851 }
2852 if (reinit_count) {
2853 /* no more flow director interrupts until after init */
2854 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2855 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2856 ixgbe_service_event_schedule(adapter);
2857 }
2858 }
2859 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002860 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002861 break;
2862 default:
2863 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002864 }
2865
Alexander Duyck2c4af692011-07-15 07:29:55 +00002866 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002867
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002868 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07002869 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002870
Alexander Duyck2c4af692011-07-15 07:29:55 +00002871 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002872 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002873 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002874
Alexander Duyck2c4af692011-07-15 07:29:55 +00002875 return IRQ_HANDLED;
2876}
2877
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002878static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002879{
2880 struct ixgbe_q_vector *q_vector = data;
2881
Auke Kok9a799d72007-09-15 14:07:45 -07002882 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002883
2884 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07002885 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002886
2887 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002888}
2889
Auke Kok9a799d72007-09-15 14:07:45 -07002890/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002891 * ixgbe_poll - NAPI Rx polling callback
2892 * @napi: structure for representing this polling device
2893 * @budget: how many packets driver is allowed to clean
2894 *
2895 * This function is used for legacy and MSI, NAPI mode
2896 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002897int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002898{
2899 struct ixgbe_q_vector *q_vector =
2900 container_of(napi, struct ixgbe_q_vector, napi);
2901 struct ixgbe_adapter *adapter = q_vector->adapter;
2902 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002903 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00002904 bool clean_complete = true;
2905
2906#ifdef CONFIG_IXGBE_DCA
2907 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2908 ixgbe_update_dca(q_vector);
2909#endif
2910
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002911 ixgbe_for_each_ring(ring, q_vector->tx) {
2912 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
2913 clean_complete = false;
2914 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002915
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08002916 /* Exit if we are called by netpoll */
2917 if (budget <= 0)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002918 return budget;
2919
Alexander Duyckeb01b972012-02-08 07:51:27 +00002920 /* attempt to distribute budget to each queue fairly, but don't allow
2921 * the budget to go below 1 because we'll exit polling */
2922 if (q_vector->rx.count > 1)
2923 per_ring_budget = max(budget/q_vector->rx.count, 1);
2924 else
2925 per_ring_budget = budget;
2926
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002927 ixgbe_for_each_ring(ring, q_vector->rx) {
2928 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
2929 per_ring_budget);
2930
2931 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002932 if (cleaned >= per_ring_budget)
2933 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002934 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002935
2936 /* If all work not completed, return budget and keep polling */
2937 if (!clean_complete)
2938 return budget;
2939
2940 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002941 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002942 if (adapter->rx_itr_setting & 1)
2943 ixgbe_set_itr(q_vector);
2944 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002945 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00002946
Paolo Abeni4b732cd2016-06-15 15:37:59 +02002947 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002948}
2949
2950/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002951 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2952 * @adapter: board private structure
2953 *
2954 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2955 * interrupts from the kernel.
2956 **/
2957static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2958{
2959 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002960 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002961 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002962
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002963 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002964 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002965 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002966
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002967 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002968 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002969 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002970 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002971 } else if (q_vector->rx.ring) {
2972 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2973 "%s-%s-%d", netdev->name, "rx", ri++);
2974 } else if (q_vector->tx.ring) {
2975 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2976 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002977 } else {
2978 /* skip this unused q_vector */
2979 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002980 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002981 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2982 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002983 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002984 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002985 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002986 goto free_queue_irqs;
2987 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002988 /* If Flow Director is enabled, set interrupt affinity */
2989 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2990 /* assign the mask for this irq */
2991 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002992 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002993 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002994 }
2995
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002996 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002997 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002998 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002999 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003000 goto free_queue_irqs;
3001 }
3002
3003 return 0;
3004
3005free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00003006 while (vector) {
3007 vector--;
3008 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3009 NULL);
3010 free_irq(adapter->msix_entries[vector].vector,
3011 adapter->q_vector[vector]);
3012 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003013 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3014 pci_disable_msix(adapter->pdev);
3015 kfree(adapter->msix_entries);
3016 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003017 return err;
3018}
3019
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08003020/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003021 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07003022 * @irq: interrupt number
3023 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07003024 **/
3025static irqreturn_t ixgbe_intr(int irq, void *data)
3026{
Alexander Duycka65151ba22011-05-27 05:31:32 +00003027 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07003028 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003029 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003030 u32 eicr;
3031
Don Skidmore54037502009-02-21 15:42:56 -08003032 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00003033 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08003034 * before the read of EICR.
3035 */
3036 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3037
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003038 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003039 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003040 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003041 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003042 /*
3043 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003044 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003045 * have disabled interrupts due to EIAM
3046 * finish the workaround of silicon errata on 82598. Unmask
3047 * the interrupt that we masked before the EICR read.
3048 */
3049 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3050 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003051 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003052 }
Auke Kok9a799d72007-09-15 14:07:45 -07003053
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003054 if (eicr & IXGBE_EICR_LSC)
3055 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003056
Alexander Duyckbd508172010-11-16 19:27:03 -08003057 switch (hw->mac.type) {
3058 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003059 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003060 /* Fall through */
3061 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003062 case ixgbe_mac_X550:
3063 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003064 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003065 if (eicr & IXGBE_EICR_ECC) {
3066 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003067 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003068 ixgbe_service_event_schedule(adapter);
3069 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3070 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003071 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003072 break;
3073 default:
3074 break;
3075 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003076
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003077 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003078 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003079 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003080
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003081 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003082 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003083
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003084 /*
3085 * re-enable link(maybe) and non-queue interrupts, no flush.
3086 * ixgbe_poll will re-enable the queue interrupts
3087 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003088 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3089 ixgbe_irq_enable(adapter, false, false);
3090
Auke Kok9a799d72007-09-15 14:07:45 -07003091 return IRQ_HANDLED;
3092}
3093
3094/**
3095 * ixgbe_request_irq - initialize interrupts
3096 * @adapter: board private structure
3097 *
3098 * Attempts to configure interrupts using the best available
3099 * capabilities of the hardware and kernel.
3100 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003101static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003102{
3103 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003104 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003105
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003106 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003107 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003108 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003109 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003110 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003111 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003112 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003113 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003114
Alexander Duyckde88eee2012-02-08 07:49:59 +00003115 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003116 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003117
Auke Kok9a799d72007-09-15 14:07:45 -07003118 return err;
3119}
3120
3121static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3122{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003123 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003124
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003125 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003126 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003127 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003128 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003129
Mark Rustad1fa71252016-09-28 15:36:38 -07003130 if (!adapter->msix_entries)
3131 return;
3132
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003133 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3134 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3135 struct msix_entry *entry = &adapter->msix_entries[vector];
3136
3137 /* free only the irqs that were actually requested */
3138 if (!q_vector->rx.ring && !q_vector->tx.ring)
3139 continue;
3140
3141 /* clear the affinity_mask in the IRQ descriptor */
3142 irq_set_affinity_hint(entry->vector, NULL);
3143
3144 free_irq(entry->vector, q_vector);
3145 }
3146
Babu Moger90c6f872016-06-18 17:40:47 -07003147 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003148}
3149
3150/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003151 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3152 * @adapter: board private structure
3153 **/
3154static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3155{
Alexander Duyckbd508172010-11-16 19:27:03 -08003156 switch (adapter->hw.mac.type) {
3157 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003158 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003159 break;
3160 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003161 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003162 case ixgbe_mac_X550:
3163 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003164 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003165 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3166 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003167 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003168 break;
3169 default:
3170 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003171 }
3172 IXGBE_WRITE_FLUSH(&adapter->hw);
3173 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003174 int vector;
3175
3176 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3177 synchronize_irq(adapter->msix_entries[vector].vector);
3178
3179 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003180 } else {
3181 synchronize_irq(adapter->pdev->irq);
3182 }
3183}
3184
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003185/**
Auke Kok9a799d72007-09-15 14:07:45 -07003186 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3187 *
3188 **/
3189static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3190{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003191 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003192
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003193 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003194
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003195 ixgbe_set_ivar(adapter, 0, 0, 0);
3196 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003197
Emil Tantilov396e7992010-07-01 20:05:12 +00003198 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003199}
3200
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003201/**
3202 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3203 * @adapter: board private structure
3204 * @ring: structure containing ring specific data
3205 *
3206 * Configure the Tx descriptor ring after a reset.
3207 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003208void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3209 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003210{
3211 struct ixgbe_hw *hw = &adapter->hw;
3212 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003213 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003214 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003215 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003216
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003217 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003218 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003219 IXGBE_WRITE_FLUSH(hw);
3220
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003221 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003222 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003223 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3224 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3225 ring->count * sizeof(union ixgbe_adv_tx_desc));
3226 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3227 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003228 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003229
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003230 /*
3231 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003232 * higher than 1 when:
3233 * - ITR is 0 as it could cause false TX hangs
3234 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003235 *
3236 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3237 * to or less than the number of on chip descriptors, which is
3238 * currently 40.
3239 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003240 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003241 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003242 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003243 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003244
Alexander Duycke954b372012-02-08 07:49:38 +00003245 /*
3246 * Setting PTHRESH to 32 both improves performance
3247 * and avoids a TX hang with DFP enabled
3248 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003249 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003250 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003251
3252 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003253 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003254 ring->atr_sample_rate = adapter->atr_sample_rate;
3255 ring->atr_count = 0;
3256 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3257 } else {
3258 ring->atr_sample_rate = 0;
3259 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003260
Alexander Duyckfd786b72013-01-12 06:33:31 +00003261 /* initialize XPS */
3262 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3263 struct ixgbe_q_vector *q_vector = ring->q_vector;
3264
3265 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003266 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003267 &q_vector->affinity_mask,
3268 ring->queue_index);
3269 }
3270
John Fastabendc84d3242010-11-16 19:27:12 -08003271 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3272
Alexander Duyckffed21b2017-01-17 08:37:29 -08003273 /* reinitialize tx_buffer_info */
3274 memset(ring->tx_buffer_info, 0,
3275 sizeof(struct ixgbe_tx_buffer) * ring->count);
3276
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003277 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003278 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3279
3280 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3281 if (hw->mac.type == ixgbe_mac_82598EB &&
3282 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3283 return;
3284
3285 /* poll to verify queue is enabled */
3286 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003287 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003288 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3289 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3290 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003291 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003292}
3293
Alexander Duyck120ff942010-08-19 13:34:50 +00003294static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3295{
3296 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003297 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003298 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003299
3300 if (hw->mac.type == ixgbe_mac_82598EB)
3301 return;
3302
3303 /* disable the arbiter while setting MTQC */
3304 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3305 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3306 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3307
3308 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003309 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3310 mtqc = IXGBE_MTQC_VT_ENA;
3311 if (tcs > 4)
3312 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3313 else if (tcs > 1)
3314 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003315 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3316 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003317 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003318 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003319 mtqc |= IXGBE_MTQC_64VF;
3320 } else {
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;
3325 else
3326 mtqc = IXGBE_MTQC_64Q_1PB;
3327 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003328
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003329 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003330
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003331 /* Enable Security TX Buffer IFG for multiple pb */
3332 if (tcs) {
3333 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3334 sectx |= IXGBE_SECTX_DCB;
3335 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003336 }
3337
3338 /* re-enable the arbiter */
3339 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3340 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3341}
3342
Auke Kok9a799d72007-09-15 14:07:45 -07003343/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003344 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003345 * @adapter: board private structure
3346 *
3347 * Configure the Tx unit of the MAC after a reset.
3348 **/
3349static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3350{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003351 struct ixgbe_hw *hw = &adapter->hw;
3352 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003353 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003354
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003355 ixgbe_setup_mtqc(adapter);
3356
3357 if (hw->mac.type != ixgbe_mac_82598EB) {
3358 /* DMATXCTL.EN must be before Tx queues are enabled */
3359 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3360 dmatxctl |= IXGBE_DMATXCTL_TE;
3361 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3362 }
3363
Auke Kok9a799d72007-09-15 14:07:45 -07003364 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003365 for (i = 0; i < adapter->num_tx_queues; i++)
3366 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003367}
3368
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003369static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3370 struct ixgbe_ring *ring)
3371{
3372 struct ixgbe_hw *hw = &adapter->hw;
3373 u8 reg_idx = ring->reg_idx;
3374 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3375
3376 srrctl |= IXGBE_SRRCTL_DROP_EN;
3377
3378 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3379}
3380
3381static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3382 struct ixgbe_ring *ring)
3383{
3384 struct ixgbe_hw *hw = &adapter->hw;
3385 u8 reg_idx = ring->reg_idx;
3386 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3387
3388 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3389
3390 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3391}
3392
3393#ifdef CONFIG_IXGBE_DCB
3394void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3395#else
3396static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3397#endif
3398{
3399 int i;
3400 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3401
3402 if (adapter->ixgbe_ieee_pfc)
3403 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3404
3405 /*
3406 * We should set the drop enable bit if:
3407 * SR-IOV is enabled
3408 * or
3409 * Number of Rx queues > 1 and flow control is disabled
3410 *
3411 * This allows us to avoid head of line blocking for security
3412 * and performance reasons.
3413 */
3414 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3415 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3416 for (i = 0; i < adapter->num_rx_queues; i++)
3417 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3418 } else {
3419 for (i = 0; i < adapter->num_rx_queues; i++)
3420 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3421 }
3422}
3423
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003424#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003425
Yi Zoua6616b42009-08-06 13:05:23 +00003426static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003427 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003428{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003429 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003430 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003431 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003432
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003433 if (hw->mac.type == ixgbe_mac_82598EB) {
3434 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3435
3436 /*
3437 * if VMDq is not active we must program one srrctl register
3438 * per RSS queue since we have enabled RDRXCTL.MVMEN
3439 */
3440 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003441 }
3442
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003443 /* configure header buffer length, needed for RSC */
3444 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003445
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003446 /* configure the packet buffer length */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003447 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3448 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3449 else
3450 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003451
3452 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003453 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003454
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003455 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003456}
3457
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003458/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003459 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003460 * @adapter: device handle
3461 *
3462 * - 82598/82599/X540: 128
3463 * - X550(non-SRIOV mode): 512
3464 * - X550(SRIOV mode): 64
3465 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003466u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003467{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003468 if (adapter->hw.mac.type < ixgbe_mac_X550)
3469 return 128;
3470 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3471 return 64;
3472 else
3473 return 512;
3474}
3475
3476/**
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003477 * ixgbe_store_key - Write the RSS key to HW
3478 * @adapter: device handle
3479 *
3480 * Write the RSS key stored in adapter.rss_key to HW.
3481 */
3482void ixgbe_store_key(struct ixgbe_adapter *adapter)
3483{
3484 struct ixgbe_hw *hw = &adapter->hw;
3485 int i;
3486
3487 for (i = 0; i < 10; i++)
3488 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3489}
3490
3491/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003492 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003493 * @adapter: device handle
3494 *
3495 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3496 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003497void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003498{
3499 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003500 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003501 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003502 u32 indices_multi;
3503 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003504
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003505 /* Fill out the redirection table as follows:
3506 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3507 * indices.
3508 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3509 * - X550: 8 bit wide entries containing 6 bit RSS index
3510 */
3511 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3512 indices_multi = 0x11;
3513 else
3514 indices_multi = 0x1;
3515
3516 /* Write redirection table to HW */
3517 for (i = 0; i < reta_entries; i++) {
3518 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3519 if ((i & 3) == 3) {
3520 if (i < 128)
3521 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3522 else
3523 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3524 reta);
3525 reta = 0;
3526 }
3527 }
3528}
3529
3530/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003531 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003532 * @adapter: device handle
3533 *
3534 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3535 */
3536static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3537{
3538 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3539 struct ixgbe_hw *hw = &adapter->hw;
3540 u32 vfreta = 0;
3541 unsigned int pf_pool = adapter->num_vfs;
3542
3543 /* Write redirection table to HW */
3544 for (i = 0; i < reta_entries; i++) {
3545 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3546 if ((i & 3) == 3) {
3547 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3548 vfreta);
3549 vfreta = 0;
3550 }
3551 }
3552}
3553
3554static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3555{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003556 u32 i, j;
3557 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3558 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3559
Alexander Duycke24fcf22016-09-07 20:28:24 -07003560 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003561 * make full use of any rings they may have. We will use the
3562 * PSRTYPE register to control how many rings we use within the PF.
3563 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003564 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3565 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003566
Alexander Duyck05abb122010-08-19 13:35:41 +00003567 /* Fill out hash function seeds */
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003568 ixgbe_store_key(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003569
Alexander Duyck05abb122010-08-19 13:35:41 +00003570 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003571 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3572
Don Skidmore0f9b2322014-11-18 09:35:08 +00003573 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003574 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003575 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003576
3577 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003578 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003579
3580 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003581}
3582
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003583static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003584{
3585 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003586 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3587 unsigned int pf_pool = adapter->num_vfs;
3588 int i, j;
3589
3590 /* Fill out hash function seeds */
3591 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003592 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
3593 adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003594
3595 /* Fill out the redirection table */
3596 for (i = 0, j = 0; i < 64; i++, j++) {
3597 if (j == rss_i)
3598 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003599
3600 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003601 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003602
3603 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003604}
3605
3606static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3607{
3608 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003609 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003610 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003611
3612 /* Disable indicating checksum in descriptor, enables RSS hash */
3613 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3614 rxcsum |= IXGBE_RXCSUM_PCSD;
3615 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3616
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003617 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003618 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003619 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003620 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003621 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003622
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003623 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3624 if (tcs > 4)
3625 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3626 else if (tcs > 1)
3627 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003628 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3629 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003630 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3631 else
3632 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3633 } else {
3634 if (tcs > 4)
3635 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3636 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003637 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3638 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003639 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003640 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003641 }
3642
Alexander Duyck05abb122010-08-19 13:35:41 +00003643 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003644 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3645 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3646 IXGBE_MRQC_RSS_FIELD_IPV6 |
3647 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003648
Alexander Duyckef6afc02012-02-08 07:51:53 +00003649 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003650 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003651 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003652 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003653
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003654 netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003655 if ((hw->mac.type >= ixgbe_mac_X550) &&
3656 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3657 unsigned int pf_pool = adapter->num_vfs;
3658
3659 /* Enable VF RSS mode */
3660 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3661 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3662
3663 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003664 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003665 vfmrqc = IXGBE_MRQC_RSSEN;
3666 vfmrqc |= rss_field;
3667 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3668 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003669 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003670 mrqc |= rss_field;
3671 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3672 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003673}
3674
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003675/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003676 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3677 * @adapter: address of board private structure
3678 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003679 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003680static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003681 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003682{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003683 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003684 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003685 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003686
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003687 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003688 return;
3689
Alexander Duyck73670962010-08-19 13:38:34 +00003690 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003691 rscctrl |= IXGBE_RSCCTL_RSCEN;
3692 /*
3693 * we must limit the number of descriptors so that the
3694 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003695 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003696 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003697 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003698 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003699}
3700
Alexander Duyck9e10e042010-08-19 13:40:06 +00003701#define IXGBE_MAX_RX_DESC_POLL 10
3702static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3703 struct ixgbe_ring *ring)
3704{
3705 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003706 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3707 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003708 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003709
Mark Rustadb0483c82014-01-14 18:53:17 -08003710 if (ixgbe_removed(hw->hw_addr))
3711 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003712 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3713 if (hw->mac.type == ixgbe_mac_82598EB &&
3714 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3715 return;
3716
3717 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003718 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003719 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3720 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3721
3722 if (!wait_loop) {
3723 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3724 "the polling period\n", reg_idx);
3725 }
3726}
3727
Yi Zou2d39d572011-01-06 14:29:56 +00003728void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3729 struct ixgbe_ring *ring)
3730{
3731 struct ixgbe_hw *hw = &adapter->hw;
3732 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3733 u32 rxdctl;
3734 u8 reg_idx = ring->reg_idx;
3735
Mark Rustadb0483c82014-01-14 18:53:17 -08003736 if (ixgbe_removed(hw->hw_addr))
3737 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003738 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3739 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3740
3741 /* write value back with RXDCTL.ENABLE bit cleared */
3742 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3743
3744 if (hw->mac.type == ixgbe_mac_82598EB &&
3745 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3746 return;
3747
3748 /* the hardware may take up to 100us to really disable the rx queue */
3749 do {
3750 udelay(10);
3751 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3752 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3753
3754 if (!wait_loop) {
3755 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3756 "the polling period\n", reg_idx);
3757 }
3758}
3759
Alexander Duyck84418e32010-08-19 13:40:54 +00003760void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3761 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003762{
3763 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc3630cc2017-01-17 08:36:28 -08003764 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyckacd37172010-08-19 13:36:05 +00003765 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003766 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003767 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003768
Alexander Duyck9e10e042010-08-19 13:40:06 +00003769 /* disable queue to avoid issues while updating state */
3770 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003771 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003772
Alexander Duyckacd37172010-08-19 13:36:05 +00003773 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3774 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3775 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3776 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08003777 /* Force flushing of IXGBE_RDLEN to prevent MDD */
3778 IXGBE_WRITE_FLUSH(hw);
3779
Alexander Duyckacd37172010-08-19 13:36:05 +00003780 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3781 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003782 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003783
3784 ixgbe_configure_srrctl(adapter, ring);
3785 ixgbe_configure_rscctl(adapter, ring);
3786
3787 if (hw->mac.type == ixgbe_mac_82598EB) {
3788 /*
3789 * enable cache line friendly hardware writes:
3790 * PTHRESH=32 descriptors (half the internal cache),
3791 * this also removes ugly rx_no_buffer_count increment
3792 * HTHRESH=4 descriptors (to minimize latency on fetch)
3793 * WTHRESH=8 burst writeback up to two cache lines
3794 */
3795 rxdctl &= ~0x3FFFFF;
3796 rxdctl |= 0x080420;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003797#if (PAGE_SIZE < 8192)
3798 } else {
3799 rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
3800 IXGBE_RXDCTL_RLPML_EN);
3801
3802 /* Limit the maximum frame size so we don't overrun the skb */
3803 if (ring_uses_build_skb(ring) &&
3804 !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
3805 rxdctl |= IXGBE_MAX_FRAME_BUILD_SKB |
3806 IXGBE_RXDCTL_RLPML_EN;
3807#endif
Alexander Duyck9e10e042010-08-19 13:40:06 +00003808 }
3809
Alexander Duyckffed21b2017-01-17 08:37:29 -08003810 /* initialize rx_buffer_info */
3811 memset(ring->rx_buffer_info, 0,
3812 sizeof(struct ixgbe_rx_buffer) * ring->count);
3813
Alexander Duyckc3630cc2017-01-17 08:36:28 -08003814 /* initialize Rx descriptor 0 */
3815 rx_desc = IXGBE_RX_DESC(ring, 0);
3816 rx_desc->wb.upper.length = 0;
3817
Alexander Duyck9e10e042010-08-19 13:40:06 +00003818 /* enable receive descriptor ring */
3819 rxdctl |= IXGBE_RXDCTL_ENABLE;
3820 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3821
3822 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003823 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003824}
3825
Alexander Duyck48654522010-08-19 13:36:27 +00003826static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3827{
3828 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003829 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003830 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003831
3832 /* PSRTYPE must be initialized in non 82598 adapters */
3833 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003834 IXGBE_PSRTYPE_UDPHDR |
3835 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003836 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003837 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003838
3839 if (hw->mac.type == ixgbe_mac_82598EB)
3840 return;
3841
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003842 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003843 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003844 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003845 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003846
John Fastabend2a47fa42013-11-06 09:54:52 -08003847 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3848 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003849}
3850
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003851static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3852{
3853 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003854 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003855 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003856 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003857
3858 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3859 return;
3860
3861 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003862 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3863 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003864 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003865 vmdctl |= IXGBE_VT_CTL_REPLEN;
3866 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003867
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003868 vf_shift = VMDQ_P(0) % 32;
3869 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003870
3871 /* Enable only the PF's pool for Tx/Rx */
Emil Tantilov11f2b492016-05-04 15:01:27 -07003872 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00003873 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
Emil Tantilov11f2b492016-05-04 15:01:27 -07003874 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00003875 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07003876 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00003877 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003878
3879 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003880 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003881
Alexander Duyck16369562015-11-02 17:10:13 -08003882 /* clear VLAN promisc flag so VFTA will be updated if necessary */
3883 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
3884
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003885 /*
3886 * Set up VF register offsets for selected VT Mode,
3887 * i.e. 32 or 64 VFs for SR-IOV
3888 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003889 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3890 case IXGBE_82599_VMDQ_8Q_MASK:
3891 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3892 break;
3893 case IXGBE_82599_VMDQ_4Q_MASK:
3894 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3895 break;
3896 default:
3897 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3898 break;
3899 }
3900
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003901 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3902
Greg Rosede4c7f62011-09-29 05:57:33 +00003903 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07003904 /* configure spoof checking */
3905 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
3906 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03003907
3908 /* Enable/Disable RSS query feature */
3909 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
3910 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00003911 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003912}
3913
Alexander Duyck477de6e2010-08-19 13:38:11 +00003914static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003915{
Auke Kok9a799d72007-09-15 14:07:45 -07003916 struct ixgbe_hw *hw = &adapter->hw;
3917 struct net_device *netdev = adapter->netdev;
3918 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003919 struct ixgbe_ring *rx_ring;
3920 int i;
3921 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003922
Alexander Duyck477de6e2010-08-19 13:38:11 +00003923#ifdef IXGBE_FCOE
3924 /* adjust max frame to be able to do baby jumbo for FCoE */
3925 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3926 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3927 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3928
3929#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003930
3931 /* adjust max frame to be at least the size of a standard frame */
3932 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3933 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3934
Alexander Duyck477de6e2010-08-19 13:38:11 +00003935 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3936 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3937 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3938 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3939
3940 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003941 }
3942
Auke Kok9a799d72007-09-15 14:07:45 -07003943 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003944 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3945 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003946 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3947
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003948 /*
3949 * Setup the HW Rx Head and Tail Descriptor Pointers and
3950 * the Base and Length of the Rx Descriptor Ring
3951 */
Auke Kok9a799d72007-09-15 14:07:45 -07003952 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003953 rx_ring = adapter->rx_ring[i];
Alexander Duyck4f4542b2017-01-17 08:36:14 -08003954
3955 clear_ring_rsc_enabled(rx_ring);
3956 clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003957 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08003958
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003959 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3960 set_ring_rsc_enabled(rx_ring);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08003961
3962 if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
3963 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003964
Alexander Duyck6f429222017-01-17 08:37:13 -08003965 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003966 if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
3967 continue;
3968
3969 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
3970
3971#if (PAGE_SIZE < 8192)
3972 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3973 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
3974
Alexander Duyckc74042f2017-02-03 09:19:40 -08003975 if ((max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
3976 (max_frame > IXGBE_MAX_FRAME_BUILD_SKB))
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003977 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
3978#endif
Alexander Duyck477de6e2010-08-19 13:38:11 +00003979 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003980}
3981
Alexander Duyck73670962010-08-19 13:38:34 +00003982static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3983{
3984 struct ixgbe_hw *hw = &adapter->hw;
3985 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3986
3987 switch (hw->mac.type) {
3988 case ixgbe_mac_82598EB:
3989 /*
3990 * For VMDq support of different descriptor types or
3991 * buffer sizes through the use of multiple SRRCTL
3992 * registers, RDRXCTL.MVMEN must be set to 1
3993 *
3994 * also, the manual doesn't mention it clearly but DCA hints
3995 * will only use queue 0's tags unless this bit is set. Side
3996 * effects of setting this bit are only that SRRCTL must be
3997 * fully programmed [0..15]
3998 */
3999 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
4000 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07004001 case ixgbe_mac_X550:
4002 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004003 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07004004 if (adapter->num_vfs)
4005 rdrxctl |= IXGBE_RDRXCTL_PSP;
4006 /* fall through for older HW */
Alexander Duyck73670962010-08-19 13:38:34 +00004007 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004008 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00004009 /* Disable RSC for ACK packets */
4010 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
4011 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
4012 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
4013 /* hardware requires some bits to be set by default */
4014 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
4015 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
4016 break;
4017 default:
4018 /* We should do nothing since we don't know this hardware */
4019 return;
4020 }
4021
4022 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
4023}
4024
Alexander Duyck477de6e2010-08-19 13:38:11 +00004025/**
4026 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4027 * @adapter: board private structure
4028 *
4029 * Configure the Rx unit of the MAC after a reset.
4030 **/
4031static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
4032{
4033 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004034 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004035 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004036
4037 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07004038 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004039
4040 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00004041 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004042
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004043 /* RSC Setup */
4044 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4045 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
4046 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
4047 rfctl |= IXGBE_RFCTL_RSC_DIS;
Emil Tantilova21d0822016-08-10 11:19:23 -07004048
4049 /* disable NFS filtering */
4050 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004051 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
4052
Alexander Duyck9e10e042010-08-19 13:40:06 +00004053 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004054 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004055
Alexander Duyck477de6e2010-08-19 13:38:11 +00004056 /* set_rx_buffer_len must be called before ring initialization */
4057 ixgbe_set_rx_buffer_len(adapter);
4058
4059 /*
4060 * Setup the HW Rx Head and Tail Descriptor Pointers and
4061 * the Base and Length of the Rx Descriptor Ring
4062 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00004063 for (i = 0; i < adapter->num_rx_queues; i++)
4064 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004065
Don Skidmore1f9ac572015-03-13 13:54:30 -07004066 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004067 /* disable drop enable for 82598 parts */
4068 if (hw->mac.type == ixgbe_mac_82598EB)
4069 rxctrl |= IXGBE_RXCTRL_DMBYPS;
4070
4071 /* enable all receives */
4072 rxctrl |= IXGBE_RXCTRL_RXEN;
4073 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004074}
4075
Patrick McHardy80d5c362013-04-19 02:04:28 +00004076static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
4077 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004078{
4079 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004080 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004081
4082 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004083 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4084 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
4085
Jesse Grossf62bbb52010-10-20 13:56:10 +00004086 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004087
4088 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004089}
4090
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004091static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
4092{
4093 u32 vlvf;
4094 int idx;
4095
4096 /* short cut the special case */
4097 if (vlan == 0)
4098 return 0;
4099
4100 /* Search for the vlan id in the VLVF entries */
4101 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
4102 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
4103 if ((vlvf & VLAN_VID_MASK) == vlan)
4104 break;
4105 }
4106
4107 return idx;
4108}
4109
4110void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
4111{
4112 struct ixgbe_hw *hw = &adapter->hw;
4113 u32 bits, word;
4114 int idx;
4115
4116 idx = ixgbe_find_vlvf_entry(hw, vid);
4117 if (!idx)
4118 return;
4119
4120 /* See if any other pools are set for this VLAN filter
4121 * entry other than the PF.
4122 */
4123 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004124 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004125 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4126
4127 /* Disable the filter so this falls into the default pool. */
4128 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4129 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4130 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4131 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4132 }
4133}
4134
Patrick McHardy80d5c362013-04-19 02:04:28 +00004135static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4136 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004137{
4138 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004139 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004140
Auke Kok9a799d72007-09-15 14:07:45 -07004141 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004142 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004143 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4144
Jesse Grossf62bbb52010-10-20 13:56:10 +00004145 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004146
4147 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004148}
4149
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004150/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004151 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4152 * @adapter: driver data
4153 */
4154static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4155{
4156 struct ixgbe_hw *hw = &adapter->hw;
4157 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004158 int i, j;
4159
4160 switch (hw->mac.type) {
4161 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004162 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4163 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004164 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4165 break;
4166 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004167 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004168 case ixgbe_mac_X550:
4169 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004170 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004171 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004172 struct ixgbe_ring *ring = adapter->rx_ring[i];
4173
4174 if (ring->l2_accel_priv)
4175 continue;
4176 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004177 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4178 vlnctrl &= ~IXGBE_RXDCTL_VME;
4179 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4180 }
4181 break;
4182 default:
4183 break;
4184 }
4185}
4186
4187/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004188 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004189 * @adapter: driver data
4190 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004191static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004192{
4193 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004194 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004195 int i, j;
4196
4197 switch (hw->mac.type) {
4198 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004199 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4200 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004201 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4202 break;
4203 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004204 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004205 case ixgbe_mac_X550:
4206 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004207 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004208 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004209 struct ixgbe_ring *ring = adapter->rx_ring[i];
4210
4211 if (ring->l2_accel_priv)
4212 continue;
4213 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004214 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4215 vlnctrl |= IXGBE_RXDCTL_VME;
4216 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4217 }
4218 break;
4219 default:
4220 break;
4221 }
4222}
4223
Alexander Duyck16369562015-11-02 17:10:13 -08004224static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4225{
4226 struct ixgbe_hw *hw = &adapter->hw;
4227 u32 vlnctrl, i;
4228
Alexander Duyckf60439b2016-08-11 14:51:56 -07004229 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4230
Emil Tantilov691e4122016-08-22 16:17:46 -07004231 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4232 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4233 vlnctrl |= IXGBE_VLNCTRL_VFE;
4234 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4235 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004236 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004237 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4238 return;
4239 }
4240
Emil Tantilov691e4122016-08-22 16:17:46 -07004241 /* Nothing to do for 82598 */
4242 if (hw->mac.type == ixgbe_mac_82598EB)
4243 return;
4244
Alexander Duyck16369562015-11-02 17:10:13 -08004245 /* We are already in VLAN promisc, nothing to do */
4246 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4247 return;
4248
4249 /* Set flag so we don't redo unnecessary work */
4250 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4251
4252 /* Add PF to all active pools */
4253 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4254 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4255 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4256
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004257 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004258 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4259 }
4260
4261 /* Set all bits in the VLAN filter table array */
4262 for (i = hw->mac.vft_size; i--;)
4263 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4264}
4265
4266#define VFTA_BLOCK_SIZE 8
4267static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4268{
4269 struct ixgbe_hw *hw = &adapter->hw;
4270 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4271 u32 vid_start = vfta_offset * 32;
4272 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4273 u32 i, vid, word, bits;
4274
4275 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4276 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4277
4278 /* pull VLAN ID from VLVF */
4279 vid = vlvf & VLAN_VID_MASK;
4280
4281 /* only concern outselves with a certain range */
4282 if (vid < vid_start || vid >= vid_end)
4283 continue;
4284
4285 if (vlvf) {
4286 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004287 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004288
4289 /* if PF is part of this then continue */
4290 if (test_bit(vid, adapter->active_vlans))
4291 continue;
4292 }
4293
4294 /* remove PF from the pool */
4295 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004296 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004297 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4298 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4299 }
4300
4301 /* extract values from active_vlans and write back to VFTA */
4302 for (i = VFTA_BLOCK_SIZE; i--;) {
4303 vid = (vfta_offset + i) * 32;
4304 word = vid / BITS_PER_LONG;
4305 bits = vid % BITS_PER_LONG;
4306
4307 vfta[i] |= adapter->active_vlans[word] >> bits;
4308
4309 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4310 }
4311}
4312
4313static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4314{
4315 struct ixgbe_hw *hw = &adapter->hw;
4316 u32 vlnctrl, i;
4317
Alexander Duyckf60439b2016-08-11 14:51:56 -07004318 /* Set VLAN filtering to enabled */
4319 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4320 vlnctrl |= IXGBE_VLNCTRL_VFE;
4321 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4322
Emil Tantilov691e4122016-08-22 16:17:46 -07004323 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4324 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004325 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004326
4327 /* We are not in VLAN promisc, nothing to do */
4328 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4329 return;
4330
4331 /* Set flag so we don't redo unnecessary work */
4332 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4333
4334 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4335 ixgbe_scrub_vfta(adapter, i);
4336}
4337
Auke Kok9a799d72007-09-15 14:07:45 -07004338static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4339{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004340 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004341
Patrick McHardy80d5c362013-04-19 02:04:28 +00004342 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004343
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004344 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004345 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004346}
4347
4348/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004349 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4350 * @netdev: network interface device structure
4351 *
4352 * Writes multicast address list to the MTA hash table.
4353 * Returns: -ENOMEM on failure
4354 * 0 on no addresses written
4355 * X on writing X addresses to MTA
4356 **/
4357static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4358{
4359 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4360 struct ixgbe_hw *hw = &adapter->hw;
4361
4362 if (!netif_running(netdev))
4363 return 0;
4364
4365 if (hw->mac.ops.update_mc_addr_list)
4366 hw->mac.ops.update_mc_addr_list(hw, netdev);
4367 else
4368 return -ENOMEM;
4369
4370#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004371 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004372#endif
4373
4374 return netdev_mc_count(netdev);
4375}
4376
Jacob Keller5d7daa32014-03-29 06:51:25 +00004377#ifdef CONFIG_PCI_IOV
4378void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4379{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004380 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004381 struct ixgbe_hw *hw = &adapter->hw;
4382 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004383
4384 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4385 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4386
4387 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4388 hw->mac.ops.set_rar(hw, i,
4389 mac_table->addr,
4390 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004391 IXGBE_RAH_AV);
4392 else
4393 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004394 }
4395}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004396
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004397#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004398static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4399{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004400 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004401 struct ixgbe_hw *hw = &adapter->hw;
4402 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004403
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004404 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4405 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4406 continue;
4407
4408 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4409
4410 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4411 hw->mac.ops.set_rar(hw, i,
4412 mac_table->addr,
4413 mac_table->pool,
4414 IXGBE_RAH_AV);
4415 else
4416 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004417 }
4418}
4419
4420static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4421{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004422 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004423 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004424 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004425
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004426 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4427 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4428 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004429 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004430
Jacob Keller5d7daa32014-03-29 06:51:25 +00004431 ixgbe_sync_mac_table(adapter);
4432}
4433
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004434static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004435{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004436 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004437 struct ixgbe_hw *hw = &adapter->hw;
4438 int i, count = 0;
4439
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004440 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4441 /* do not count default RAR as available */
4442 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4443 continue;
4444
4445 /* only count unused and addresses that belong to us */
4446 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4447 if (mac_table->pool != pool)
4448 continue;
4449 }
4450
4451 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004452 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004453
Jacob Keller5d7daa32014-03-29 06:51:25 +00004454 return count;
4455}
4456
4457/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004458static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004459{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004460 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004461 struct ixgbe_hw *hw = &adapter->hw;
4462
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004463 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4464 mac_table->pool = VMDQ_P(0);
4465
4466 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4467
4468 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004469 IXGBE_RAH_AV);
4470}
4471
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004472int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4473 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004474{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004475 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004476 struct ixgbe_hw *hw = &adapter->hw;
4477 int i;
4478
4479 if (is_zero_ether_addr(addr))
4480 return -EINVAL;
4481
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004482 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4483 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004484 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004485
4486 ether_addr_copy(mac_table->addr, addr);
4487 mac_table->pool = pool;
4488
4489 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4490 IXGBE_MAC_STATE_IN_USE;
4491
Jacob Keller5d7daa32014-03-29 06:51:25 +00004492 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004493
Jacob Keller5d7daa32014-03-29 06:51:25 +00004494 return i;
4495 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004496
Jacob Keller5d7daa32014-03-29 06:51:25 +00004497 return -ENOMEM;
4498}
4499
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004500int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4501 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004502{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004503 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004504 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004505 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004506
4507 if (is_zero_ether_addr(addr))
4508 return -EINVAL;
4509
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004510 /* search table for addr, if found clear IN_USE flag and sync */
4511 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4512 /* we can only delete an entry if it is in use */
4513 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4514 continue;
4515 /* we only care about entries that belong to the given pool */
4516 if (mac_table->pool != pool)
4517 continue;
4518 /* we only care about a specific MAC address */
4519 if (!ether_addr_equal(addr, mac_table->addr))
4520 continue;
4521
4522 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4523 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4524
4525 ixgbe_sync_mac_table(adapter);
4526
4527 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004528 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004529
Jacob Keller5d7daa32014-03-29 06:51:25 +00004530 return -ENOMEM;
4531}
Jacob Kellerb335e752014-03-25 07:45:27 +00004532/**
Alexander Duyck28500622010-06-15 09:25:48 +00004533 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4534 * @netdev: network interface device structure
4535 *
4536 * Writes unicast address list to the RAR table.
4537 * Returns: -ENOMEM on failure/insufficient address space
4538 * 0 on no addresses written
4539 * X on writing X addresses to the RAR table
4540 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004541static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004542{
4543 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004544 int count = 0;
4545
4546 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004547 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004548 return -ENOMEM;
4549
John Fastabend95447462012-05-31 12:42:26 +00004550 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004551 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004552 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004553 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4554 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004555 count++;
4556 }
4557 }
Alexander Duyck28500622010-06-15 09:25:48 +00004558 return count;
4559}
4560
Alexander Duyck0f079d22015-10-22 16:26:36 -07004561static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4562{
4563 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4564 int ret;
4565
4566 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4567
4568 return min_t(int, ret, 0);
4569}
4570
4571static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4572{
4573 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4574
4575 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4576
4577 return 0;
4578}
4579
Alexander Duyck28500622010-06-15 09:25:48 +00004580/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004581 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004582 * @netdev: network interface device structure
4583 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004584 * The set_rx_method entry point is called whenever the unicast/multicast
4585 * address list or the network interface flags are updated. This routine is
4586 * responsible for configuring the hardware for proper unicast, multicast and
4587 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004588 **/
Greg Rose7f870472010-01-09 02:25:29 +00004589void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004590{
4591 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4592 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004593 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004594 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004595 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004596
4597 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004598 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4599
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004600 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004601 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004602 fctrl |= IXGBE_FCTRL_BAM;
4603 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4604 fctrl |= IXGBE_FCTRL_PMCF;
4605
Alexander Duyck28500622010-06-15 09:25:48 +00004606 /* clear the bits we are changing the status of */
4607 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004608 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004609 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004610 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004611 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004612 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004613 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004614 if (netdev->flags & IFF_ALLMULTI) {
4615 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004616 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004617 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004618 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004619 }
4620
4621 /*
4622 * Write addresses to available RAR registers, if there is not
4623 * sufficient space to store all the addresses then enable
4624 * unicast promiscuous mode
4625 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004626 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004627 fctrl |= IXGBE_FCTRL_UPE;
4628 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004629 }
4630
Emil Tantilovcf789592013-10-26 08:13:20 +00004631 /* Write addresses to the MTA, if the attempt fails
4632 * then we should just turn on promiscuous mode so
4633 * that we can at least receive multicast traffic
4634 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004635 count = ixgbe_write_mc_addr_list(netdev);
4636 if (count < 0) {
4637 fctrl |= IXGBE_FCTRL_MPE;
4638 vmolr |= IXGBE_VMOLR_MPE;
4639 } else if (count) {
4640 vmolr |= IXGBE_VMOLR_ROMPE;
4641 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004642
4643 if (hw->mac.type != ixgbe_mac_82598EB) {
4644 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004645 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4646 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004647 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004648 }
4649
Ben Greear3f2d1c02012-03-08 08:28:41 +00004650 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004651 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004652 /* UPE and MPE will be handled by normal PROMISC logic
4653 * in e1000e_set_rx_mode */
4654 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4655 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4656 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4657
4658 fctrl &= ~(IXGBE_FCTRL_DPF);
4659 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4660 }
4661
Auke Kok9a799d72007-09-15 14:07:45 -07004662 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004663
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004664 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004665 ixgbe_vlan_strip_enable(adapter);
4666 else
4667 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004668
4669 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4670 ixgbe_vlan_promisc_disable(adapter);
4671 else
4672 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004673}
4674
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004675static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4676{
4677 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004678
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004679 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004680 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004681}
4682
4683static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4684{
4685 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004686
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004687 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004688 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004689}
4690
Emil Tantilova21d0822016-08-10 11:19:23 -07004691static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07004692{
Emil Tantilova21d0822016-08-10 11:19:23 -07004693 struct ixgbe_hw *hw = &adapter->hw;
4694 u32 vxlanctrl;
4695
4696 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
4697 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
4698 return;
4699
4700 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask;
4701 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
4702
4703 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07004704 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07004705
4706 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
4707 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07004708}
4709
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004710#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004711/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004712 * ixgbe_configure_dcb - Configure DCB hardware
4713 * @adapter: ixgbe adapter struct
4714 *
4715 * This is called by the driver on open to configure the DCB hardware.
4716 * This is also called by the gennetlink interface when reconfiguring
4717 * the DCB state.
4718 */
4719static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4720{
4721 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00004722 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004723
Alexander Duyck67ebd792010-08-19 13:34:04 +00004724 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4725 if (hw->mac.type == ixgbe_mac_82598EB)
4726 netif_set_gso_max_size(adapter->netdev, 65536);
4727 return;
4728 }
4729
4730 if (hw->mac.type == ixgbe_mac_82598EB)
4731 netif_set_gso_max_size(adapter->netdev, 32768);
4732
John Fastabendb1208182011-10-15 05:00:10 +00004733#ifdef IXGBE_FCOE
4734 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4735 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4736#endif
4737
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004738 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004739 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004740 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4741 DCB_TX_CONFIG);
4742 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4743 DCB_RX_CONFIG);
4744 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004745 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4746 ixgbe_dcb_hw_ets(&adapter->hw,
4747 adapter->ixgbe_ieee_ets,
4748 max_frame);
4749 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4750 adapter->ixgbe_ieee_pfc->pfc_en,
4751 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004752 }
John Fastabend8187cd42011-02-23 05:58:08 +00004753
4754 /* Enable RSS Hash per TC */
4755 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004756 u32 msb = 0;
4757 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004758
Alexander Duyckd411a932012-06-30 00:14:01 +00004759 while (rss_i) {
4760 msb++;
4761 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004762 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004763
Alexander Duyck4ae63732012-06-22 06:46:33 +00004764 /* write msb to all 8 TCs in one write */
4765 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004766 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004767}
John Fastabend9da712d2011-08-23 03:14:22 +00004768#endif
4769
4770/* Additional bittime to account for IXGBE framing */
4771#define IXGBE_ETH_FRAMING 20
4772
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004773/**
John Fastabend9da712d2011-08-23 03:14:22 +00004774 * ixgbe_hpbthresh - calculate high water mark for flow control
4775 *
4776 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004777 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004778 */
4779static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4780{
4781 struct ixgbe_hw *hw = &adapter->hw;
4782 struct net_device *dev = adapter->netdev;
4783 int link, tc, kb, marker;
4784 u32 dv_id, rx_pba;
4785
4786 /* Calculate max LAN frame size */
4787 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4788
4789#ifdef IXGBE_FCOE
4790 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004791 if ((dev->features & NETIF_F_FCOE_MTU) &&
4792 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4793 (pb == ixgbe_fcoe_get_tc(adapter)))
4794 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004795#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004796
John Fastabend9da712d2011-08-23 03:14:22 +00004797 /* Calculate delay value for device */
4798 switch (hw->mac.type) {
4799 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004800 case ixgbe_mac_X550:
4801 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004802 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004803 dv_id = IXGBE_DV_X540(link, tc);
4804 break;
4805 default:
4806 dv_id = IXGBE_DV(link, tc);
4807 break;
4808 }
4809
4810 /* Loopback switch introduces additional latency */
4811 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4812 dv_id += IXGBE_B2BT(tc);
4813
4814 /* Delay value is calculated in bit times convert to KB */
4815 kb = IXGBE_BT2KB(dv_id);
4816 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4817
4818 marker = rx_pba - kb;
4819
4820 /* It is possible that the packet buffer is not large enough
4821 * to provide required headroom. In this case throw an error
4822 * to user and a do the best we can.
4823 */
4824 if (marker < 0) {
4825 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4826 "headroom to support flow control."
4827 "Decrease MTU or number of traffic classes\n", pb);
4828 marker = tc + 1;
4829 }
4830
4831 return marker;
4832}
4833
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004834/**
John Fastabend9da712d2011-08-23 03:14:22 +00004835 * ixgbe_lpbthresh - calculate low water mark for for flow control
4836 *
4837 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004838 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004839 */
Jacob Kellere5776622014-04-05 02:35:52 +00004840static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00004841{
4842 struct ixgbe_hw *hw = &adapter->hw;
4843 struct net_device *dev = adapter->netdev;
4844 int tc;
4845 u32 dv_id;
4846
4847 /* Calculate max LAN frame size */
4848 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4849
Jacob Kellere5776622014-04-05 02:35:52 +00004850#ifdef IXGBE_FCOE
4851 /* FCoE traffic class uses FCOE jumbo frames */
4852 if ((dev->features & NETIF_F_FCOE_MTU) &&
4853 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4854 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4855 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4856#endif
4857
John Fastabend9da712d2011-08-23 03:14:22 +00004858 /* Calculate delay value for device */
4859 switch (hw->mac.type) {
4860 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004861 case ixgbe_mac_X550:
4862 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004863 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004864 dv_id = IXGBE_LOW_DV_X540(tc);
4865 break;
4866 default:
4867 dv_id = IXGBE_LOW_DV(tc);
4868 break;
4869 }
4870
4871 /* Delay value is calculated in bit times convert to KB */
4872 return IXGBE_BT2KB(dv_id);
4873}
4874
4875/*
4876 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4877 */
4878static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4879{
4880 struct ixgbe_hw *hw = &adapter->hw;
4881 int num_tc = netdev_get_num_tc(adapter->netdev);
4882 int i;
4883
4884 if (!num_tc)
4885 num_tc = 1;
4886
John Fastabend9da712d2011-08-23 03:14:22 +00004887 for (i = 0; i < num_tc; i++) {
4888 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00004889 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00004890
4891 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00004892 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4893 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004894 }
Jacob Kellere5776622014-04-05 02:35:52 +00004895
4896 for (; i < MAX_TRAFFIC_CLASS; i++)
4897 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004898}
John Fastabend80605c652011-05-02 12:34:10 +00004899
4900static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4901{
John Fastabend80605c652011-05-02 12:34:10 +00004902 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004903 int hdrm;
4904 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004905
4906 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4907 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004908 hdrm = 32 << adapter->fdir_pballoc;
4909 else
4910 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004911
Alexander Duyckf7e10272011-07-21 00:40:35 +00004912 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004913 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004914}
4915
Alexander Duycke4911d52011-05-11 07:18:52 +00004916static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4917{
4918 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004919 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004920 struct ixgbe_fdir_filter *filter;
4921
4922 spin_lock(&adapter->fdir_perfect_lock);
4923
4924 if (!hlist_empty(&adapter->fdir_filter_list))
4925 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4926
Sasha Levinb67bfe02013-02-27 17:06:00 -08004927 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004928 &adapter->fdir_filter_list, fdir_node) {
4929 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004930 &filter->filter,
4931 filter->sw_idx,
4932 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4933 IXGBE_FDIR_DROP_QUEUE :
4934 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004935 }
4936
4937 spin_unlock(&adapter->fdir_perfect_lock);
4938}
4939
John Fastabend2a47fa42013-11-06 09:54:52 -08004940static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4941 struct ixgbe_adapter *adapter)
4942{
4943 struct ixgbe_hw *hw = &adapter->hw;
4944 u32 vmolr;
4945
4946 /* No unicast promiscuous support for VMDQ devices. */
4947 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4948 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4949
4950 /* clear the affected bit */
4951 vmolr &= ~IXGBE_VMOLR_MPE;
4952
4953 if (dev->flags & IFF_ALLMULTI) {
4954 vmolr |= IXGBE_VMOLR_MPE;
4955 } else {
4956 vmolr |= IXGBE_VMOLR_ROMPE;
4957 hw->mac.ops.update_mc_addr_list(hw, dev);
4958 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00004959 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08004960 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4961}
4962
John Fastabend2a47fa42013-11-06 09:54:52 -08004963static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4964{
4965 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004966 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004967 struct ixgbe_hw *hw = &adapter->hw;
4968 u16 pool = vadapter->pool;
4969 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4970 IXGBE_PSRTYPE_UDPHDR |
4971 IXGBE_PSRTYPE_IPV4HDR |
4972 IXGBE_PSRTYPE_L2HDR |
4973 IXGBE_PSRTYPE_IPV6HDR;
4974
4975 if (hw->mac.type == ixgbe_mac_82598EB)
4976 return;
4977
4978 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004979 psrtype |= 2u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004980 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004981 psrtype |= 1u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004982
4983 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4984}
4985
4986/**
4987 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4988 * @rx_ring: ring to free buffers from
4989 **/
4990static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4991{
Alexander Duyckffed21b2017-01-17 08:37:29 -08004992 u16 i = rx_ring->next_to_clean;
4993 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08004994
4995 /* Free all the Rx ring sk_buffs */
Alexander Duyckffed21b2017-01-17 08:37:29 -08004996 while (i != rx_ring->next_to_alloc) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004997 if (rx_buffer->skb) {
4998 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00004999 if (IXGBE_CB(skb)->page_released)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005000 dma_unmap_page_attrs(rx_ring->dev,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005001 IXGBE_CB(skb)->dma,
5002 ixgbe_rx_pg_size(rx_ring),
5003 DMA_FROM_DEVICE,
5004 IXGBE_RX_DMA_ATTR);
John Fastabend2a47fa42013-11-06 09:54:52 -08005005 dev_kfree_skb(skb);
5006 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00005007
Alexander Duyckf3213d92017-01-17 08:35:54 -08005008 /* Invalidate cache lines that may have been written to by
5009 * device so that we avoid corrupting memory.
5010 */
5011 dma_sync_single_range_for_cpu(rx_ring->dev,
5012 rx_buffer->dma,
5013 rx_buffer->page_offset,
5014 ixgbe_rx_bufsz(rx_ring),
5015 DMA_FROM_DEVICE);
5016
5017 /* free resources associated with mapping */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005018 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005019 ixgbe_rx_pg_size(rx_ring),
5020 DMA_FROM_DEVICE,
5021 IXGBE_RX_DMA_ATTR);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08005022 __page_frag_cache_drain(rx_buffer->page,
5023 rx_buffer->pagecnt_bias);
Alexander Duyck18cb6522014-11-14 00:56:29 +00005024
Alexander Duyckffed21b2017-01-17 08:37:29 -08005025 i++;
5026 rx_buffer++;
5027 if (i == rx_ring->count) {
5028 i = 0;
5029 rx_buffer = rx_ring->rx_buffer_info;
5030 }
John Fastabend2a47fa42013-11-06 09:54:52 -08005031 }
5032
John Fastabend2a47fa42013-11-06 09:54:52 -08005033 rx_ring->next_to_alloc = 0;
5034 rx_ring->next_to_clean = 0;
5035 rx_ring->next_to_use = 0;
5036}
5037
5038static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
5039 struct ixgbe_ring *rx_ring)
5040{
5041 struct ixgbe_adapter *adapter = vadapter->real_adapter;
5042 int index = rx_ring->queue_index + vadapter->rx_base_queue;
5043
5044 /* shutdown specific queue receive and wait for dma to settle */
5045 ixgbe_disable_rx_queue(adapter, rx_ring);
5046 usleep_range(10000, 20000);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005047 ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
John Fastabend2a47fa42013-11-06 09:54:52 -08005048 ixgbe_clean_rx_ring(rx_ring);
5049 rx_ring->l2_accel_priv = NULL;
5050}
5051
John Fastabendae72c8d2013-11-09 07:11:26 +00005052static int ixgbe_fwd_ring_down(struct net_device *vdev,
5053 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08005054{
5055 struct ixgbe_adapter *adapter = accel->real_adapter;
5056 unsigned int rxbase = accel->rx_base_queue;
5057 unsigned int txbase = accel->tx_base_queue;
5058 int i;
5059
5060 netif_tx_stop_all_queues(vdev);
5061
5062 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5063 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5064 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
5065 }
5066
5067 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5068 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
5069 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
5070 }
5071
5072
5073 return 0;
5074}
5075
5076static int ixgbe_fwd_ring_up(struct net_device *vdev,
5077 struct ixgbe_fwd_adapter *accel)
5078{
5079 struct ixgbe_adapter *adapter = accel->real_adapter;
5080 unsigned int rxbase, txbase, queues;
5081 int i, baseq, err = 0;
5082
5083 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
5084 return 0;
5085
5086 baseq = accel->pool * adapter->num_rx_queues_per_pool;
5087 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
5088 accel->pool, adapter->num_rx_pools,
5089 baseq, baseq + adapter->num_rx_queues_per_pool,
5090 adapter->fwd_bitmask);
5091
5092 accel->netdev = vdev;
5093 accel->rx_base_queue = rxbase = baseq;
5094 accel->tx_base_queue = txbase = baseq;
5095
5096 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5097 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5098
5099 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5100 adapter->rx_ring[rxbase + i]->netdev = vdev;
5101 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
5102 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
5103 }
5104
5105 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5106 adapter->tx_ring[txbase + i]->netdev = vdev;
5107 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
5108 }
5109
5110 queues = min_t(unsigned int,
5111 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
5112 err = netif_set_real_num_tx_queues(vdev, queues);
5113 if (err)
5114 goto fwd_queue_err;
5115
John Fastabend2a47fa42013-11-06 09:54:52 -08005116 err = netif_set_real_num_rx_queues(vdev, queues);
5117 if (err)
5118 goto fwd_queue_err;
5119
5120 if (is_valid_ether_addr(vdev->dev_addr))
5121 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
5122
5123 ixgbe_fwd_psrtype(accel);
5124 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
5125 return err;
5126fwd_queue_err:
5127 ixgbe_fwd_ring_down(vdev, accel);
5128 return err;
5129}
5130
David Ahern1cd127f2016-10-17 19:15:48 -07005131static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
5132{
5133 if (netif_is_macvlan(upper)) {
5134 struct macvlan_dev *dfwd = netdev_priv(upper);
5135 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5136
5137 if (dfwd->fwd_priv)
5138 ixgbe_fwd_ring_up(upper, vadapter);
5139 }
5140
5141 return 0;
5142}
5143
John Fastabend2a47fa42013-11-06 09:54:52 -08005144static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5145{
David Ahern1cd127f2016-10-17 19:15:48 -07005146 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5147 ixgbe_upper_dev_walk, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005148}
5149
Auke Kok9a799d72007-09-15 14:07:45 -07005150static void ixgbe_configure(struct ixgbe_adapter *adapter)
5151{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005152 struct ixgbe_hw *hw = &adapter->hw;
5153
John Fastabend80605c652011-05-02 12:34:10 +00005154 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005155#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005156 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005157#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005158 /*
5159 * We must restore virtualization before VLANs or else
5160 * the VLVF registers will not be populated
5161 */
5162 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005163
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005164 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005165 ixgbe_restore_vlan(adapter);
5166
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005167 switch (hw->mac.type) {
5168 case ixgbe_mac_82599EB:
5169 case ixgbe_mac_X540:
5170 hw->mac.ops.disable_rx_buff(hw);
5171 break;
5172 default:
5173 break;
5174 }
5175
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005176 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005177 ixgbe_init_fdir_signature_82599(&adapter->hw,
5178 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005179 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5180 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5181 adapter->fdir_pballoc);
5182 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005183 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005184
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005185 switch (hw->mac.type) {
5186 case ixgbe_mac_82599EB:
5187 case ixgbe_mac_X540:
5188 hw->mac.ops.enable_rx_buff(hw);
5189 break;
5190 default:
5191 break;
5192 }
5193
Mark Rustad9de76052015-08-08 16:27:41 -07005194#ifdef CONFIG_IXGBE_DCA
5195 /* configure DCA */
5196 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5197 ixgbe_setup_dca(adapter);
5198#endif /* CONFIG_IXGBE_DCA */
5199
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005200#ifdef IXGBE_FCOE
5201 /* configure FCoE L2 filters, redirection table, and Rx control */
5202 ixgbe_configure_fcoe(adapter);
5203
5204#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005205 ixgbe_configure_tx(adapter);
5206 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005207 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005208}
5209
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005210/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005211 * ixgbe_sfp_link_config - set up SFP+ link
5212 * @adapter: pointer to private adapter struct
5213 **/
5214static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5215{
Alexander Duyck70864002011-04-27 09:13:56 +00005216 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005217 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005218 * is that an SFP was inserted/removed after the reset
5219 * but before SFP detection was enabled. As such the best
5220 * solution is to just start searching as soon as we start
5221 */
5222 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5223 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005224
Alexander Duyck70864002011-04-27 09:13:56 +00005225 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005226 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005227}
5228
5229/**
5230 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005231 * @hw: pointer to private hardware struct
5232 *
5233 * Returns 0 on success, negative on failure
5234 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005235static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005236{
Josh Hay3d292262012-12-15 03:28:19 +00005237 u32 speed;
5238 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005239 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005240
5241 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005242 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005243
5244 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005245 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005246
Josh Hay3d292262012-12-15 03:28:19 +00005247 speed = hw->phy.autoneg_advertised;
5248 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5249 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5250 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005251 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005252 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005253
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005254 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005255 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005256
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005257 return ret;
5258}
5259
Alexander Duycka34bcff2010-08-19 13:39:20 +00005260static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005261{
Auke Kok9a799d72007-09-15 14:07:45 -07005262 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005263 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005264
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005265 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005266 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5267 IXGBE_GPIE_OCD;
5268 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005269 /*
5270 * use EIAM to auto-mask when MSI-X interrupt is asserted
5271 * this saves a register write for every interrupt
5272 */
5273 switch (hw->mac.type) {
5274 case ixgbe_mac_82598EB:
5275 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5276 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005277 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005278 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005279 case ixgbe_mac_X550:
5280 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005281 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005282 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005283 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5284 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5285 break;
5286 }
5287 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005288 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5289 * specifically only auto mask tx and rx interrupts */
5290 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005291 }
5292
Alexander Duycka34bcff2010-08-19 13:39:20 +00005293 /* XXX: to interrupt immediately for EICS writes, enable this */
5294 /* gpie |= IXGBE_GPIE_EIMEN; */
5295
5296 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5297 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005298
5299 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5300 case IXGBE_82599_VMDQ_8Q_MASK:
5301 gpie |= IXGBE_GPIE_VTMODE_16;
5302 break;
5303 case IXGBE_82599_VMDQ_4Q_MASK:
5304 gpie |= IXGBE_GPIE_VTMODE_32;
5305 break;
5306 default:
5307 gpie |= IXGBE_GPIE_VTMODE_64;
5308 break;
5309 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005310 }
5311
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005312 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005313 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5314 switch (adapter->hw.mac.type) {
5315 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005316 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005317 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005318 default:
5319 break;
5320 }
5321 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005322
Alexander Duycka34bcff2010-08-19 13:39:20 +00005323 /* Enable fan failure interrupt */
5324 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005325 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005326
Don Skidmorea023bbd2015-06-24 16:38:53 -04005327 switch (hw->mac.type) {
5328 case ixgbe_mac_82599EB:
5329 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5330 break;
5331 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005332 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005333 gpie |= IXGBE_SDP0_GPIEN_X540;
5334 break;
5335 default:
5336 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005337 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005338
5339 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5340}
5341
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005342static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005343{
5344 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005345 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005346 u32 ctrl_ext;
5347
5348 ixgbe_get_hw_control(adapter);
5349 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005350
Auke Kok9a799d72007-09-15 14:07:45 -07005351 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5352 ixgbe_configure_msix(adapter);
5353 else
5354 ixgbe_configure_msi_and_legacy(adapter);
5355
Emil Tantilovec74a472012-09-20 03:33:56 +00005356 /* enable the optics for 82599 SFP+ fiber */
5357 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005358 hw->mac.ops.enable_tx_laser(hw);
5359
Don Skidmore961fac82015-06-09 16:09:47 -07005360 if (hw->phy.ops.set_phy_power)
5361 hw->phy.ops.set_phy_power(hw, true);
5362
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005363 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005364 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005365 ixgbe_napi_enable_all(adapter);
5366
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005367 if (ixgbe_is_sfp(hw)) {
5368 ixgbe_sfp_link_config(adapter);
5369 } else {
5370 err = ixgbe_non_sfp_link_config(hw);
5371 if (err)
5372 e_err(probe, "link_config FAILED %d\n", err);
5373 }
5374
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005375 /* clear any pending interrupts, may auto mask */
5376 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005377 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005378
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005379 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005380 * If this adapter has a fan, check to see if we had a failure
5381 * before we enabled the interrupt.
5382 */
5383 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5384 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5385 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005386 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005387 }
5388
Auke Kok9a799d72007-09-15 14:07:45 -07005389 /* bring the link up in the watchdog, this could race with our first
5390 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005391 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5392 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005393 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005394
5395 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5396 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5397 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5398 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005399}
5400
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005401void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5402{
5403 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005404 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005405 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005406
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005407 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005408 usleep_range(1000, 2000);
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005409 if (adapter->hw.phy.type == ixgbe_phy_fw)
5410 ixgbe_watchdog_link_is_down(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005411 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005412 /*
5413 * If SR-IOV enabled then wait a bit before bringing the adapter
5414 * back up to give the VFs time to respond to the reset. The
5415 * two second wait is based upon the watchdog timer cycle in
5416 * the VF driver.
5417 */
5418 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5419 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005420 ixgbe_up(adapter);
5421 clear_bit(__IXGBE_RESETTING, &adapter->state);
5422}
5423
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005424void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005425{
5426 /* hardware has been reset, we need to reload some things */
5427 ixgbe_configure(adapter);
5428
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005429 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005430}
5431
5432void ixgbe_reset(struct ixgbe_adapter *adapter)
5433{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005434 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005435 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005436 int err;
5437
Mark Rustadb0483c82014-01-14 18:53:17 -08005438 if (ixgbe_removed(hw->hw_addr))
5439 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005440 /* lock SFP init bit to prevent race conditions with the watchdog */
5441 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5442 usleep_range(1000, 2000);
5443
5444 /* clear all SFP and link config related flags while holding SFP_INIT */
5445 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5446 IXGBE_FLAG2_SFP_NEEDS_RESET);
5447 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5448
Don Skidmore8ca783a2009-05-26 20:40:47 -07005449 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005450 switch (err) {
5451 case 0:
5452 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005453 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005454 break;
5455 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005456 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005457 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005458 case IXGBE_ERR_EEPROM_VERSION:
5459 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005460 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005461 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005462 "your hardware. If you are experiencing problems "
5463 "please contact your Intel or hardware "
5464 "representative who provided you with this "
5465 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005466 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005467 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005468 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005469 }
Auke Kok9a799d72007-09-15 14:07:45 -07005470
Alexander Duyck70864002011-04-27 09:13:56 +00005471 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005472
5473 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005474 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005475 __dev_uc_unsync(netdev, NULL);
5476
5477 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005478 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005479
5480 /* update SAN MAC vmdq pool selection */
5481 if (hw->mac.san_mac_rar_index)
5482 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005483
Jacob Keller8fecf672013-06-21 08:14:32 +00005484 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005485 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005486
5487 if (hw->phy.ops.set_phy_power) {
5488 if (!netif_running(adapter->netdev) && !adapter->wol)
5489 hw->phy.ops.set_phy_power(hw, false);
5490 else
5491 hw->phy.ops.set_phy_power(hw, true);
5492 }
Auke Kok9a799d72007-09-15 14:07:45 -07005493}
5494
Auke Kok9a799d72007-09-15 14:07:45 -07005495/**
Auke Kok9a799d72007-09-15 14:07:45 -07005496 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005497 * @tx_ring: ring to be cleaned
5498 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005499static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005500{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005501 u16 i = tx_ring->next_to_clean;
5502 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07005503
Alexander Duyckffed21b2017-01-17 08:37:29 -08005504 while (i != tx_ring->next_to_use) {
5505 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -07005506
Alexander Duyckffed21b2017-01-17 08:37:29 -08005507 /* Free all the Tx ring sk_buffs */
5508 dev_kfree_skb_any(tx_buffer->skb);
5509
5510 /* unmap skb header data */
5511 dma_unmap_single(tx_ring->dev,
5512 dma_unmap_addr(tx_buffer, dma),
5513 dma_unmap_len(tx_buffer, len),
5514 DMA_TO_DEVICE);
5515
5516 /* check for eop_desc to determine the end of the packet */
5517 eop_desc = tx_buffer->next_to_watch;
5518 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5519
5520 /* unmap remaining buffers */
5521 while (tx_desc != eop_desc) {
5522 tx_buffer++;
5523 tx_desc++;
5524 i++;
5525 if (unlikely(i == tx_ring->count)) {
5526 i = 0;
5527 tx_buffer = tx_ring->tx_buffer_info;
5528 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5529 }
5530
5531 /* unmap any remaining paged data */
5532 if (dma_unmap_len(tx_buffer, len))
5533 dma_unmap_page(tx_ring->dev,
5534 dma_unmap_addr(tx_buffer, dma),
5535 dma_unmap_len(tx_buffer, len),
5536 DMA_TO_DEVICE);
5537 }
5538
5539 /* move us one more past the eop_desc for start of next pkt */
5540 tx_buffer++;
5541 i++;
5542 if (unlikely(i == tx_ring->count)) {
5543 i = 0;
5544 tx_buffer = tx_ring->tx_buffer_info;
5545 }
Auke Kok9a799d72007-09-15 14:07:45 -07005546 }
5547
Alexander Duyckffed21b2017-01-17 08:37:29 -08005548 /* reset BQL for queue */
John Fastabenddad8a3b2012-04-23 12:22:39 +00005549 netdev_tx_reset_queue(txring_txq(tx_ring));
5550
Alexander Duyckffed21b2017-01-17 08:37:29 -08005551 /* reset next_to_use and next_to_clean */
Auke Kok9a799d72007-09-15 14:07:45 -07005552 tx_ring->next_to_use = 0;
5553 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005554}
5555
5556/**
Auke Kok9a799d72007-09-15 14:07:45 -07005557 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5558 * @adapter: board private structure
5559 **/
5560static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5561{
5562 int i;
5563
5564 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005565 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005566}
5567
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005568/**
5569 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5570 * @adapter: board private structure
5571 **/
5572static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5573{
5574 int i;
5575
5576 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005577 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005578}
5579
Alexander Duycke4911d52011-05-11 07:18:52 +00005580static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5581{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005582 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005583 struct ixgbe_fdir_filter *filter;
5584
5585 spin_lock(&adapter->fdir_perfect_lock);
5586
Sasha Levinb67bfe02013-02-27 17:06:00 -08005587 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005588 &adapter->fdir_filter_list, fdir_node) {
5589 hlist_del(&filter->fdir_node);
5590 kfree(filter);
5591 }
5592 adapter->fdir_filter_count = 0;
5593
5594 spin_unlock(&adapter->fdir_perfect_lock);
5595}
5596
David Ahern1cd127f2016-10-17 19:15:48 -07005597static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
5598{
5599 if (netif_is_macvlan(upper)) {
5600 struct macvlan_dev *vlan = netdev_priv(upper);
5601
5602 if (vlan->fwd_priv) {
5603 netif_tx_stop_all_queues(upper);
5604 netif_carrier_off(upper);
5605 netif_tx_disable(upper);
5606 }
5607 }
5608
5609 return 0;
5610}
5611
Auke Kok9a799d72007-09-15 14:07:45 -07005612void ixgbe_down(struct ixgbe_adapter *adapter)
5613{
5614 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005615 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005616 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005617
5618 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005619 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5620 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005621
5622 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005623 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005624
Yi Zou2d39d572011-01-06 14:29:56 +00005625 /* disable all enabled rx queues */
5626 for (i = 0; i < adapter->num_rx_queues; i++)
5627 /* this call also flushes the previous write */
5628 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5629
Don Skidmore032b4322011-03-18 09:32:53 +00005630 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005631
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005632 netif_tx_stop_all_queues(netdev);
5633
Alexander Duyck70864002011-04-27 09:13:56 +00005634 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005635 netif_carrier_off(netdev);
5636 netif_tx_disable(netdev);
5637
John Fastabend2a47fa42013-11-06 09:54:52 -08005638 /* disable any upper devices */
David Ahern1cd127f2016-10-17 19:15:48 -07005639 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5640 ixgbe_disable_macvlan, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005641
John Fastabendc0dfb902010-04-27 02:13:39 +00005642 ixgbe_irq_disable(adapter);
5643
5644 ixgbe_napi_disable_all(adapter);
5645
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005646 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5647 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005648 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5649
5650 del_timer_sync(&adapter->service_timer);
5651
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005652 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005653 /* Clear EITR Select mapping */
5654 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5655
5656 /* Mark all the VFs as inactive */
5657 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005658 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005659
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005660 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005661 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005662
Auke Kok9a799d72007-09-15 14:07:45 -07005663 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005664 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005665 }
5666
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005667 /* disable transmits in the hardware now that interrupts are off */
5668 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005669 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005670 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005671 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005672
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005673 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005674 switch (hw->mac.type) {
5675 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005676 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005677 case ixgbe_mac_X550:
5678 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005679 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005680 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005681 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5682 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005683 break;
5684 default:
5685 break;
5686 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005687
Paul Larson6f4a0e42008-06-24 17:00:56 -07005688 if (!pci_channel_offline(adapter->pdev))
5689 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005690
Emil Tantilovec74a472012-09-20 03:33:56 +00005691 /* power down the optics for 82599 SFP+ fiber */
5692 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005693 hw->mac.ops.disable_tx_laser(hw);
5694
Auke Kok9a799d72007-09-15 14:07:45 -07005695 ixgbe_clean_all_tx_rings(adapter);
5696 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005697}
5698
Auke Kok9a799d72007-09-15 14:07:45 -07005699/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005700 * ixgbe_eee_capable - helper function to determine EEE support on X550
5701 * @adapter: board private structure
5702 */
5703static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
5704{
5705 struct ixgbe_hw *hw = &adapter->hw;
5706
5707 switch (hw->device_id) {
5708 case IXGBE_DEV_ID_X550EM_A_1G_T:
5709 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
5710 if (!hw->phy.eee_speeds_supported)
5711 break;
5712 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
5713 if (!hw->phy.eee_speeds_advertised)
5714 break;
5715 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
5716 break;
5717 default:
5718 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
5719 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
5720 break;
5721 }
5722}
5723
5724/**
Auke Kok9a799d72007-09-15 14:07:45 -07005725 * ixgbe_tx_timeout - Respond to a Tx Hang
5726 * @netdev: network interface device structure
5727 **/
5728static void ixgbe_tx_timeout(struct net_device *netdev)
5729{
5730 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5731
5732 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005733 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005734}
5735
Usha Ketineni88290092016-04-26 05:00:26 -07005736#ifdef CONFIG_IXGBE_DCB
5737static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
5738{
5739 struct ixgbe_hw *hw = &adapter->hw;
5740 struct tc_configuration *tc;
5741 int j;
5742
5743 switch (hw->mac.type) {
5744 case ixgbe_mac_82598EB:
5745 case ixgbe_mac_82599EB:
5746 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5747 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5748 break;
5749 case ixgbe_mac_X540:
5750 case ixgbe_mac_X550:
5751 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5752 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5753 break;
5754 case ixgbe_mac_X550EM_x:
5755 case ixgbe_mac_x550em_a:
5756 default:
5757 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
5758 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
5759 break;
5760 }
5761
5762 /* Configure DCB traffic classes */
5763 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5764 tc = &adapter->dcb_cfg.tc_config[j];
5765 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5766 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5767 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5768 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5769 tc->dcb_pfc = pfc_disabled;
5770 }
5771
5772 /* Initialize default user to priority mapping, UPx->TC0 */
5773 tc = &adapter->dcb_cfg.tc_config[0];
5774 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5775 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5776
5777 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5778 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5779 adapter->dcb_cfg.pfc_mode_enable = false;
5780 adapter->dcb_set_bitmap = 0x00;
5781 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
5782 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5783 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5784 sizeof(adapter->temp_dcb_cfg));
5785}
5786#endif
5787
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005788/**
Auke Kok9a799d72007-09-15 14:07:45 -07005789 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5790 * @adapter: board private structure to initialize
5791 *
5792 * ixgbe_sw_init initializes the Adapter private data structure.
5793 * Fields are initialized based on PCI device information and
5794 * OS network device settings (MTU size).
5795 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07005796static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
5797 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07005798{
5799 struct ixgbe_hw *hw = &adapter->hw;
5800 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005801 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005802 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005803 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005804
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005805 /* PCI config space info */
5806
5807 hw->vendor_id = pdev->vendor;
5808 hw->device_id = pdev->device;
5809 hw->revision_id = pdev->revision;
5810 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5811 hw->subsystem_device_id = pdev->subsystem_device;
5812
Emil Tantilov55570b62016-10-12 12:34:25 -07005813 /* get_invariants needs the device IDs */
5814 ii->get_invariants(hw);
5815
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005816 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00005817 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005818 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005819 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005820 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5821 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005822 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5823 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005824 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5825#ifdef CONFIG_IXGBE_DCA
5826 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5827#endif
Usha Ketineni88290092016-04-26 05:00:26 -07005828#ifdef CONFIG_IXGBE_DCB
5829 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
5830 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
5831#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005832#ifdef IXGBE_FCOE
5833 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5834 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5835#ifdef CONFIG_IXGBE_DCB
5836 /* Default traffic class to use for FCoE */
5837 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5838#endif /* CONFIG_IXGBE_DCB */
5839#endif /* IXGBE_FCOE */
5840
John Fastabendb82b17d2016-02-16 21:18:53 -08005841 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005842 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
5843 GFP_KERNEL);
5844 if (!adapter->jump_tables[0])
5845 return -ENOMEM;
5846 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
5847
5848 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
5849 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08005850
Jacob Keller5d7daa32014-03-29 06:51:25 +00005851 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5852 hw->mac.num_rar_entries,
5853 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08005854 if (!adapter->mac_table)
5855 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005856
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005857 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005858 switch (hw->mac.type) {
5859 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005860 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005861
Don Skidmorebf069c92009-05-07 10:39:54 +00005862 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5863 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005864
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005865 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005866 adapter->ring_feature[RING_F_FDIR].limit = 0;
5867 adapter->atr_sample_rate = 0;
5868 adapter->fdir_pballoc = 0;
5869#ifdef IXGBE_FCOE
5870 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5871 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5872#ifdef CONFIG_IXGBE_DCB
5873 adapter->fcoe.up = 0;
5874#endif /* IXGBE_DCB */
5875#endif /* IXGBE_FCOE */
5876 break;
5877 case ixgbe_mac_82599EB:
5878 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5879 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005880 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005881 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005882 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005883 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5884 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005885 break;
Mark Rustad49425df2016-04-01 12:18:09 -07005886 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07005887 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005888 switch (hw->device_id) {
5889 case IXGBE_DEV_ID_X550EM_A_1G_T:
5890 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
5891 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5892 break;
5893 default:
5894 break;
5895 }
Emil Tantilova21d0822016-08-10 11:19:23 -07005896 /* fall through */
5897 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07005898#ifdef CONFIG_IXGBE_DCB
5899 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
5900#endif
5901#ifdef IXGBE_FCOE
5902 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5903#ifdef CONFIG_IXGBE_DCB
5904 adapter->fcoe.up = 0;
5905#endif /* IXGBE_DCB */
5906#endif /* IXGBE_FCOE */
5907 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005908 case ixgbe_mac_X550:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005909 if (hw->mac.type == ixgbe_mac_X550)
5910 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005911#ifdef CONFIG_IXGBE_DCA
5912 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
5913#endif
Mark Rustad67359c32015-06-15 11:33:25 -07005914 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005915 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08005916 default:
5917 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005918 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005919
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005920#ifdef IXGBE_FCOE
5921 /* FCoE support exists, always init the FCoE lock */
5922 spin_lock_init(&adapter->fcoe.lock);
5923
5924#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005925 /* n-tuple support exists, always init our spinlock */
5926 spin_lock_init(&adapter->fdir_perfect_lock);
5927
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005928#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07005929 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005930#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005931
5932 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005933 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005934 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005935 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005936 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5937 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005938 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005939
Alexander Duyck99d74482012-05-09 08:09:25 +00005940#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005941 if (max_vfs > 0)
5942 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 +00005943
Jacob Keller170e8542013-11-09 04:52:32 -08005944 /* assign number of SR-IOV VFs */
5945 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005946 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Jacob Keller170e8542013-11-09 04:52:32 -08005947 adapter->num_vfs = 0;
5948 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5949 } else {
5950 adapter->num_vfs = max_vfs;
5951 }
5952 }
5953#endif /* CONFIG_PCI_IOV */
5954
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005955 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005956 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005957 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005958
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005959 /* set default ring sizes */
5960 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5961 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5962
Alexander Duyckbd198052011-06-11 01:45:08 +00005963 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005964 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005965
Auke Kok9a799d72007-09-15 14:07:45 -07005966 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005967 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005968 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005969 return -EIO;
5970 }
5971
John Fastabend2a47fa42013-11-06 09:54:52 -08005972 /* PF holds first pool slot */
5973 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005974 set_bit(__IXGBE_DOWN, &adapter->state);
5975
5976 return 0;
5977}
5978
5979/**
5980 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005981 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005982 *
5983 * Return 0 on success, negative on failure
5984 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005985int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005986{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005987 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005988 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005989 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005990 int size;
5991
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005992 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005993
5994 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005995 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005996
Alexander Duyckffed21b2017-01-17 08:37:29 -08005997 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005998 if (!tx_ring->tx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005999 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006000 if (!tx_ring->tx_buffer_info)
6001 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006002
John Stultz827da442013-10-07 15:51:58 -07006003 u64_stats_init(&tx_ring->syncp);
6004
Auke Kok9a799d72007-09-15 14:07:45 -07006005 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08006006 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006007 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006008
Mark Rustadca8dfe22014-07-24 06:19:24 +00006009 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006010 tx_ring->desc = dma_alloc_coherent(dev,
6011 tx_ring->size,
6012 &tx_ring->dma,
6013 GFP_KERNEL);
6014 set_dev_node(dev, orig_node);
6015 if (!tx_ring->desc)
6016 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6017 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006018 if (!tx_ring->desc)
6019 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006020
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006021 tx_ring->next_to_use = 0;
6022 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006023 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006024
6025err:
6026 vfree(tx_ring->tx_buffer_info);
6027 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006028 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006029 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006030}
6031
6032/**
Alexander Duyck69888672008-09-11 20:05:39 -07006033 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6034 * @adapter: board private structure
6035 *
6036 * If this function returns with an error, then it's possible one or
6037 * more of the rings is populated (while the rest are not). It is the
6038 * callers duty to clean those orphaned rings.
6039 *
6040 * Return 0 on success, negative on failure
6041 **/
6042static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6043{
6044 int i, err = 0;
6045
6046 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006047 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006048 if (!err)
6049 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006050
Emil Tantilov396e7992010-07-01 20:05:12 +00006051 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006052 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07006053 }
6054
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006055 return 0;
6056err_setup_tx:
6057 /* rewind the index freeing the rings as we go */
6058 while (i--)
6059 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006060 return err;
6061}
6062
6063/**
Auke Kok9a799d72007-09-15 14:07:45 -07006064 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006065 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006066 *
6067 * Returns 0 on success, negative on failure
6068 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006069int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006070{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006071 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006072 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006073 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006074 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07006075
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006076 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006077
6078 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006079 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006080
Alexander Duyckffed21b2017-01-17 08:37:29 -08006081 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006082 if (!rx_ring->rx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006083 rx_ring->rx_buffer_info = vmalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006084 if (!rx_ring->rx_buffer_info)
6085 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006086
John Stultz827da442013-10-07 15:51:58 -07006087 u64_stats_init(&rx_ring->syncp);
6088
Auke Kok9a799d72007-09-15 14:07:45 -07006089 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006090 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6091 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006092
Mark Rustadca8dfe22014-07-24 06:19:24 +00006093 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006094 rx_ring->desc = dma_alloc_coherent(dev,
6095 rx_ring->size,
6096 &rx_ring->dma,
6097 GFP_KERNEL);
6098 set_dev_node(dev, orig_node);
6099 if (!rx_ring->desc)
6100 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6101 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006102 if (!rx_ring->desc)
6103 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006104
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006105 rx_ring->next_to_clean = 0;
6106 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006107
6108 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006109err:
6110 vfree(rx_ring->rx_buffer_info);
6111 rx_ring->rx_buffer_info = NULL;
6112 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07006113 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006114}
6115
6116/**
Alexander Duyck69888672008-09-11 20:05:39 -07006117 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6118 * @adapter: board private structure
6119 *
6120 * If this function returns with an error, then it's possible one or
6121 * more of the rings is populated (while the rest are not). It is the
6122 * callers duty to clean those orphaned rings.
6123 *
6124 * Return 0 on success, negative on failure
6125 **/
Alexander Duyck69888672008-09-11 20:05:39 -07006126static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6127{
6128 int i, err = 0;
6129
6130 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006131 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006132 if (!err)
6133 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006134
Emil Tantilov396e7992010-07-01 20:05:12 +00006135 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006136 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07006137 }
6138
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006139#ifdef IXGBE_FCOE
6140 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6141 if (!err)
6142#endif
6143 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006144err_setup_rx:
6145 /* rewind the index freeing the rings as we go */
6146 while (i--)
6147 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006148 return err;
6149}
6150
6151/**
Auke Kok9a799d72007-09-15 14:07:45 -07006152 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07006153 * @tx_ring: Tx descriptor ring for a specific queue
6154 *
6155 * Free all transmit software resources
6156 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006157void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006158{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006159 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006160
6161 vfree(tx_ring->tx_buffer_info);
6162 tx_ring->tx_buffer_info = NULL;
6163
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006164 /* if not set, then don't free */
6165 if (!tx_ring->desc)
6166 return;
6167
6168 dma_free_coherent(tx_ring->dev, tx_ring->size,
6169 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006170
6171 tx_ring->desc = NULL;
6172}
6173
6174/**
6175 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6176 * @adapter: board private structure
6177 *
6178 * Free all transmit software resources
6179 **/
6180static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6181{
6182 int i;
6183
6184 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006185 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006186 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006187}
6188
6189/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006190 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006191 * @rx_ring: ring to clean the resources from
6192 *
6193 * Free all receive software resources
6194 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006195void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006196{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006197 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006198
6199 vfree(rx_ring->rx_buffer_info);
6200 rx_ring->rx_buffer_info = NULL;
6201
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006202 /* if not set, then don't free */
6203 if (!rx_ring->desc)
6204 return;
6205
6206 dma_free_coherent(rx_ring->dev, rx_ring->size,
6207 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006208
6209 rx_ring->desc = NULL;
6210}
6211
6212/**
6213 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6214 * @adapter: board private structure
6215 *
6216 * Free all receive software resources
6217 **/
6218static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6219{
6220 int i;
6221
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006222#ifdef IXGBE_FCOE
6223 ixgbe_free_fcoe_ddp_resources(adapter);
6224
6225#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006226 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006227 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006228 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006229}
6230
6231/**
Auke Kok9a799d72007-09-15 14:07:45 -07006232 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6233 * @netdev: network interface device structure
6234 * @new_mtu: new value for maximum frame size
6235 *
6236 * Returns 0 on success, negative on failure
6237 **/
6238static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6239{
6240 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck655309e2012-02-08 07:50:35 +00006241
6242 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006243 * For 82599EB we cannot allow legacy VFs to enable their receive
6244 * paths when MTU greater than 1500 is configured. So display a
6245 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006246 */
6247 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6248 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Jarod Wilson91c527a2016-10-17 15:54:05 -04006249 (new_mtu > ETH_DATA_LEN))
Alexander Duyck872844d2012-08-15 02:10:43 +00006250 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006251
Emil Tantilov396e7992010-07-01 20:05:12 +00006252 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006253
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006254 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006255 netdev->mtu = new_mtu;
6256
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006257 if (netif_running(netdev))
6258 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006259
6260 return 0;
6261}
6262
6263/**
6264 * ixgbe_open - Called when a network interface is made active
6265 * @netdev: network interface device structure
6266 *
6267 * Returns 0 on success, negative value on failure
6268 *
6269 * The open entry point is called when a network interface is made
6270 * active by the system (IFF_UP). At this point all resources needed
6271 * for transmit and receive operations are allocated, the interrupt
6272 * handler is registered with the OS, the watchdog timer is started,
6273 * and the stack is notified that the interface is ready.
6274 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006275int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006276{
6277 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006278 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006279 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006280
Auke Kok4bebfaa2008-02-11 09:26:01 -08006281 /* disallow open during test */
6282 if (test_bit(__IXGBE_TESTING, &adapter->state))
6283 return -EBUSY;
6284
Jesse Brandeburg54386462009-04-17 20:44:27 +00006285 netif_carrier_off(netdev);
6286
Auke Kok9a799d72007-09-15 14:07:45 -07006287 /* allocate transmit descriptors */
6288 err = ixgbe_setup_all_tx_resources(adapter);
6289 if (err)
6290 goto err_setup_tx;
6291
Auke Kok9a799d72007-09-15 14:07:45 -07006292 /* allocate receive descriptors */
6293 err = ixgbe_setup_all_rx_resources(adapter);
6294 if (err)
6295 goto err_setup_rx;
6296
6297 ixgbe_configure(adapter);
6298
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006299 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006300 if (err)
6301 goto err_req_irq;
6302
Alexander Duyckac802f52012-07-12 05:52:53 +00006303 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08006304 if (adapter->num_rx_pools > 1)
6305 queues = adapter->num_rx_queues_per_pool;
6306 else
6307 queues = adapter->num_tx_queues;
6308
6309 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006310 if (err)
6311 goto err_set_queues;
6312
John Fastabend2a47fa42013-11-06 09:54:52 -08006313 if (adapter->num_rx_pools > 1 &&
6314 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
6315 queues = IXGBE_MAX_L2A_QUEUES;
6316 else
6317 queues = adapter->num_rx_queues;
6318 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006319 if (err)
6320 goto err_set_queues;
6321
Jacob Keller1a71ab22012-08-25 03:54:19 +00006322 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006323
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006324 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006325
Emil Tantilova21d0822016-08-10 11:19:23 -07006326 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
Alexander Duyckb3a49552016-06-16 12:22:19 -07006327 udp_tunnel_get_rx_info(netdev);
Mark Rustad67359c32015-06-15 11:33:25 -07006328
Auke Kok9a799d72007-09-15 14:07:45 -07006329 return 0;
6330
Alexander Duyckac802f52012-07-12 05:52:53 +00006331err_set_queues:
6332 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006333err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006334 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006335 if (hw->phy.ops.set_phy_power && !adapter->wol)
6336 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006337err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006338 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006339err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006340 ixgbe_reset(adapter);
6341
6342 return err;
6343}
6344
Jacob Kellera0cccce2014-05-16 05:12:29 +00006345static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6346{
6347 ixgbe_ptp_suspend(adapter);
6348
Don Skidmore6ac74392015-06-17 17:34:31 -04006349 if (adapter->hw.phy.ops.enter_lplu) {
6350 adapter->hw.phy.reset_disable = true;
6351 ixgbe_down(adapter);
6352 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6353 adapter->hw.phy.reset_disable = false;
6354 } else {
6355 ixgbe_down(adapter);
6356 }
6357
Jacob Kellera0cccce2014-05-16 05:12:29 +00006358 ixgbe_free_irq(adapter);
6359
6360 ixgbe_free_all_tx_resources(adapter);
6361 ixgbe_free_all_rx_resources(adapter);
6362}
6363
Auke Kok9a799d72007-09-15 14:07:45 -07006364/**
6365 * ixgbe_close - Disables a network interface
6366 * @netdev: network interface device structure
6367 *
6368 * Returns 0, this is not allowed to fail
6369 *
6370 * The close entry point is called when an interface is de-activated
6371 * by the OS. The hardware is still under the drivers control, but
6372 * needs to be disabled. A global MAC reset is issued to stop the
6373 * hardware, and all transmit and receive resources are freed.
6374 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006375int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006376{
6377 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006378
Jacob Keller1a71ab22012-08-25 03:54:19 +00006379 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006380
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006381 if (netif_device_present(netdev))
6382 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006383
Alexander Duycke4911d52011-05-11 07:18:52 +00006384 ixgbe_fdir_filter_exit(adapter);
6385
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006386 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006387
6388 return 0;
6389}
6390
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006391#ifdef CONFIG_PM
6392static int ixgbe_resume(struct pci_dev *pdev)
6393{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006394 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6395 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006396 u32 err;
6397
Mark Rustad0391bbe2014-02-28 15:48:55 -08006398 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006399 pci_set_power_state(pdev, PCI_D0);
6400 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006401 /*
6402 * pci_restore_state clears dev->state_saved so call
6403 * pci_save_state to restore it.
6404 */
6405 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006406
6407 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006408 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006409 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006410 return err;
6411 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006412 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006413 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006414 pci_set_master(pdev);
6415
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006416 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006417
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006418 ixgbe_reset(adapter);
6419
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006420 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6421
Alexander Duyckac802f52012-07-12 05:52:53 +00006422 rtnl_lock();
6423 err = ixgbe_init_interrupt_scheme(adapter);
6424 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006425 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006426
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006427
6428 if (!err)
6429 netif_device_attach(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006430 rtnl_unlock();
6431
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006432 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006433}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006434#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006435
6436static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006437{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006438 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6439 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006440 struct ixgbe_hw *hw = &adapter->hw;
6441 u32 ctrl, fctrl;
6442 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006443#ifdef CONFIG_PM
6444 int retval = 0;
6445#endif
6446
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006447 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006448 netif_device_detach(netdev);
6449
Jacob Kellera0cccce2014-05-16 05:12:29 +00006450 if (netif_running(netdev))
6451 ixgbe_close_suspend(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006452
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006453 ixgbe_clear_interrupt_scheme(adapter);
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006454 rtnl_unlock();
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006455
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006456#ifdef CONFIG_PM
6457 retval = pci_save_state(pdev);
6458 if (retval)
6459 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006460
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006461#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006462 if (hw->mac.ops.stop_link_on_d3)
6463 hw->mac.ops.stop_link_on_d3(hw);
6464
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006465 if (wufc) {
6466 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006467
Emil Tantilovec74a472012-09-20 03:33:56 +00006468 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6469 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006470 hw->mac.ops.enable_tx_laser(hw);
6471
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006472 /* turn on all-multi mode if wake on multicast is enabled */
6473 if (wufc & IXGBE_WUFC_MC) {
6474 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6475 fctrl |= IXGBE_FCTRL_MPE;
6476 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
6477 }
6478
6479 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6480 ctrl |= IXGBE_CTRL_GIO_DIS;
6481 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6482
6483 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6484 } else {
6485 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6486 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6487 }
6488
Alexander Duyckbd508172010-11-16 19:27:03 -08006489 switch (hw->mac.type) {
6490 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006491 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006492 break;
6493 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006494 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006495 case ixgbe_mac_X550:
6496 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006497 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006498 pci_wake_from_d3(pdev, !!wufc);
6499 break;
6500 default:
6501 break;
6502 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006503
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006504 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006505 if (hw->phy.ops.set_phy_power && !*enable_wake)
6506 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006507
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006508 ixgbe_release_hw_control(adapter);
6509
Mark Rustad41c62842014-03-12 00:38:35 +00006510 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6511 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006512
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006513 return 0;
6514}
6515
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006516#ifdef CONFIG_PM
6517static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6518{
6519 int retval;
6520 bool wake;
6521
6522 retval = __ixgbe_shutdown(pdev, &wake);
6523 if (retval)
6524 return retval;
6525
6526 if (wake) {
6527 pci_prepare_to_sleep(pdev);
6528 } else {
6529 pci_wake_from_d3(pdev, false);
6530 pci_set_power_state(pdev, PCI_D3hot);
6531 }
6532
6533 return 0;
6534}
6535#endif /* CONFIG_PM */
6536
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006537static void ixgbe_shutdown(struct pci_dev *pdev)
6538{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006539 bool wake;
6540
6541 __ixgbe_shutdown(pdev, &wake);
6542
6543 if (system_state == SYSTEM_POWER_OFF) {
6544 pci_wake_from_d3(pdev, wake);
6545 pci_set_power_state(pdev, PCI_D3hot);
6546 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006547}
6548
6549/**
Auke Kok9a799d72007-09-15 14:07:45 -07006550 * ixgbe_update_stats - Update the board statistics counters.
6551 * @adapter: board private structure
6552 **/
6553void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6554{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006555 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006556 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006557 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006558 u64 total_mpc = 0;
6559 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006560 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6561 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006562 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006563
Don Skidmored08935c2010-06-11 13:20:29 +00006564 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6565 test_bit(__IXGBE_RESETTING, &adapter->state))
6566 return;
6567
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006568 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006569 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006570 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006571 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006572 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6573 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006574 }
6575 adapter->rsc_total_count = rsc_count;
6576 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006577 }
6578
Alexander Duyck5b7da512010-11-16 19:26:50 -08006579 for (i = 0; i < adapter->num_rx_queues; i++) {
6580 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6581 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
6582 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6583 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006584 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006585 bytes += rx_ring->stats.bytes;
6586 packets += rx_ring->stats.packets;
6587 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006588 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006589 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6590 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006591 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006592 netdev->stats.rx_bytes = bytes;
6593 netdev->stats.rx_packets = packets;
6594
6595 bytes = 0;
6596 packets = 0;
6597 /* gather some stats to the adapter struct that are per queue */
6598 for (i = 0; i < adapter->num_tx_queues; i++) {
6599 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6600 restart_queue += tx_ring->tx_stats.restart_queue;
6601 tx_busy += tx_ring->tx_stats.tx_busy;
6602 bytes += tx_ring->stats.bytes;
6603 packets += tx_ring->stats.packets;
6604 }
6605 adapter->restart_queue = restart_queue;
6606 adapter->tx_busy = tx_busy;
6607 netdev->stats.tx_bytes = bytes;
6608 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006609
Joe Perches7ca647b2010-09-07 21:35:40 +00006610 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006611
6612 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006613 for (i = 0; i < 8; i++) {
6614 /* for packet buffers not used, the register should read 0 */
6615 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6616 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006617 hwstats->mpc[i] += mpc;
6618 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006619 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6620 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006621 switch (hw->mac.type) {
6622 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006623 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6624 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6625 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006626 hwstats->pxonrxc[i] +=
6627 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006628 break;
6629 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006630 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006631 case ixgbe_mac_X550:
6632 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006633 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006634 hwstats->pxonrxc[i] +=
6635 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006636 break;
6637 default:
6638 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006639 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006640 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006641
6642 /*16 register reads */
6643 for (i = 0; i < 16; i++) {
6644 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6645 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6646 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006647 (hw->mac.type == ixgbe_mac_X540) ||
6648 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006649 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6650 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006651 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6652 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6653 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6654 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6655 }
6656 }
6657
Joe Perches7ca647b2010-09-07 21:35:40 +00006658 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006659 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006660 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006661
John Fastabendc84d3242010-11-16 19:27:12 -08006662 ixgbe_update_xoff_received(adapter);
6663
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006664 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006665 switch (hw->mac.type) {
6666 case ixgbe_mac_82598EB:
6667 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006668 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6669 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6670 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6671 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006672 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006673 case ixgbe_mac_X550:
6674 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006675 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006676 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006677 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6678 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6679 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6680 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6681 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006682 for (i = 0; i < 16; i++)
6683 adapter->hw_rx_no_dma_resources +=
6684 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006685 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006686 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006687 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006688 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006689 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006690 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006691 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006692 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6693 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006694#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006695 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6696 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6697 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6698 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6699 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6700 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006701 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006702 if (adapter->fcoe.ddp_pool) {
6703 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6704 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6705 unsigned int cpu;
6706 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006707 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006708 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6709 noddp += ddp_pool->noddp;
6710 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006711 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006712 hwstats->fcoe_noddp = noddp;
6713 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006714 }
Yi Zou6d455222009-05-13 13:12:16 +00006715#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006716 break;
6717 default:
6718 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006719 }
Auke Kok9a799d72007-09-15 14:07:45 -07006720 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006721 hwstats->bprc += bprc;
6722 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006723 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006724 hwstats->mprc -= bprc;
6725 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6726 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6727 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6728 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6729 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6730 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6731 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6732 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006733 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006734 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006735 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006736 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006737 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6738 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006739 /*
6740 * 82598 errata - tx of flow control packets is included in tx counters
6741 */
6742 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006743 hwstats->gptc -= xon_off_tot;
6744 hwstats->mptc -= xon_off_tot;
6745 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6746 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6747 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6748 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6749 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6750 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6751 hwstats->ptc64 -= xon_off_tot;
6752 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6753 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6754 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6755 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6756 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6757 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006758
6759 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006760 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006761
6762 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006763 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006764 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006765 netdev->stats.rx_length_errors = hwstats->rlec;
6766 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006767 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006768}
6769
6770/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006771 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006772 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006773 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006774static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006775{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006776 struct ixgbe_hw *hw = &adapter->hw;
6777 int i;
6778
Alexander Duyckd034acf2011-04-27 09:25:34 +00006779 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6780 return;
6781
6782 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6783
6784 /* if interface is down do nothing */
6785 if (test_bit(__IXGBE_DOWN, &adapter->state))
6786 return;
6787
6788 /* do nothing if we are not using signature filters */
6789 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6790 return;
6791
6792 adapter->fdir_overflow++;
6793
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006794 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6795 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006796 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00006797 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006798 /* re-enable flow director interrupts */
6799 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006800 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006801 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006802 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006803 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006804}
6805
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006806/**
6807 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006808 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006809 *
6810 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006811 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006812 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006813 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006814 */
6815static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6816{
Auke Kok9a799d72007-09-15 14:07:45 -07006817 struct ixgbe_hw *hw = &adapter->hw;
6818 u64 eics = 0;
6819 int i;
6820
Mark Rustad09f40ae2014-01-14 18:53:11 -08006821 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006822 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006823 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006824 test_bit(__IXGBE_RESETTING, &adapter->state))
6825 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006826
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006827 /* Force detection of hung controller */
6828 if (netif_carrier_ok(adapter->netdev)) {
6829 for (i = 0; i < adapter->num_tx_queues; i++)
6830 set_check_for_tx_hang(adapter->tx_ring[i]);
6831 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006832
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006833 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006834 /*
6835 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006836 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006837 * would set *both* EIMS and EICS for any bit in EIAM
6838 */
6839 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6840 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006841 } else {
6842 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006843 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006844 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006845 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07006846 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006847 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006848 }
6849
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006850 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006851 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00006852}
6853
6854/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006855 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006856 * @adapter: pointer to the device adapter structure
6857 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006858 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006859static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006860{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006861 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006862 u32 link_speed = adapter->link_speed;
6863 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006864 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006865
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006866 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6867 return;
6868
6869 if (hw->mac.ops.check_link) {
6870 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006871 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006872 /* always assume link is up, if no check link function */
6873 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6874 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006875 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006876
6877 if (adapter->ixgbe_ieee_pfc)
6878 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6879
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006880 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006881 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006882 ixgbe_set_rx_drop_en(adapter);
6883 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006884
6885 if (link_up ||
6886 time_after(jiffies, (adapter->link_check_timeout +
6887 IXGBE_TRY_LINK_TIMEOUT))) {
6888 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6889 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6890 IXGBE_WRITE_FLUSH(hw);
6891 }
6892
6893 adapter->link_up = link_up;
6894 adapter->link_speed = link_speed;
6895}
6896
Alexander Duyck107d3012012-10-02 00:17:03 +00006897static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6898{
6899#ifdef CONFIG_IXGBE_DCB
6900 struct net_device *netdev = adapter->netdev;
6901 struct dcb_app app = {
6902 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6903 .protocol = 0,
6904 };
6905 u8 up = 0;
6906
6907 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6908 up = dcb_ieee_getapp_mask(netdev, &app);
6909
6910 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6911#endif
6912}
6913
David Ahern1cd127f2016-10-17 19:15:48 -07006914static int ixgbe_enable_macvlan(struct net_device *upper, void *data)
6915{
6916 if (netif_is_macvlan(upper)) {
6917 struct macvlan_dev *vlan = netdev_priv(upper);
6918
6919 if (vlan->fwd_priv)
6920 netif_tx_wake_all_queues(upper);
6921 }
6922
6923 return 0;
6924}
6925
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006926/**
6927 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6928 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006929 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006930 **/
6931static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6932{
6933 struct net_device *netdev = adapter->netdev;
6934 struct ixgbe_hw *hw = &adapter->hw;
6935 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07006936 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006937 bool flow_rx, flow_tx;
6938
6939 /* only continue if link was previously down */
6940 if (netif_carrier_ok(netdev))
6941 return;
6942
6943 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6944
6945 switch (hw->mac.type) {
6946 case ixgbe_mac_82598EB: {
6947 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6948 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6949 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6950 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6951 }
6952 break;
6953 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006954 case ixgbe_mac_X550:
6955 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006956 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006957 case ixgbe_mac_82599EB: {
6958 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6959 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6960 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6961 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6962 }
6963 break;
6964 default:
6965 flow_tx = false;
6966 flow_rx = false;
6967 break;
6968 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006969
Jacob Keller6cb562d2012-12-05 07:24:41 +00006970 adapter->last_rx_ptp_check = jiffies;
6971
Jacob Keller8fecf672013-06-21 08:14:32 +00006972 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006973 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006974
Mark Rustad454adb02015-07-10 14:19:22 -07006975 switch (link_speed) {
6976 case IXGBE_LINK_SPEED_10GB_FULL:
6977 speed_str = "10 Gbps";
6978 break;
6979 case IXGBE_LINK_SPEED_2_5GB_FULL:
6980 speed_str = "2.5 Gbps";
6981 break;
6982 case IXGBE_LINK_SPEED_1GB_FULL:
6983 speed_str = "1 Gbps";
6984 break;
6985 case IXGBE_LINK_SPEED_100_FULL:
6986 speed_str = "100 Mbps";
6987 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006988 case IXGBE_LINK_SPEED_10_FULL:
6989 speed_str = "10 Mbps";
6990 break;
Mark Rustad454adb02015-07-10 14:19:22 -07006991 default:
6992 speed_str = "unknown speed";
6993 break;
6994 }
6995 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006996 ((flow_rx && flow_tx) ? "RX/TX" :
6997 (flow_rx ? "RX" :
6998 (flow_tx ? "TX" : "None"))));
6999
7000 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007001 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007002
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007003 /* enable transmits */
7004 netif_tx_wake_all_queues(adapter->netdev);
7005
7006 /* enable any upper devices */
7007 rtnl_lock();
David Ahern1cd127f2016-10-17 19:15:48 -07007008 netdev_walk_all_upper_dev_rcu(adapter->netdev,
7009 ixgbe_enable_macvlan, NULL);
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007010 rtnl_unlock();
7011
Alexander Duyck107d3012012-10-02 00:17:03 +00007012 /* update the default user priority for VFs */
7013 ixgbe_update_default_up(adapter);
7014
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007015 /* ping all the active vfs to let them know link has changed */
7016 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007017}
7018
7019/**
7020 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7021 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007022 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007023 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00007024static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007025{
7026 struct net_device *netdev = adapter->netdev;
7027 struct ixgbe_hw *hw = &adapter->hw;
7028
7029 adapter->link_up = false;
7030 adapter->link_speed = 0;
7031
7032 /* only continue if link was up previously */
7033 if (!netif_carrier_ok(netdev))
7034 return;
7035
7036 /* poll for SFP+ cable when link is down */
7037 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
7038 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
7039
Jacob Keller8fecf672013-06-21 08:14:32 +00007040 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007041 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007042
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007043 e_info(drv, "NIC Link is Down\n");
7044 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007045
7046 /* ping all the active vfs to let them know link has changed */
7047 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007048}
7049
Emil Tantilov07923c12014-08-12 07:12:08 +00007050static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
7051{
7052 int i;
7053
7054 for (i = 0; i < adapter->num_tx_queues; i++) {
7055 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
7056
7057 if (tx_ring->next_to_use != tx_ring->next_to_clean)
7058 return true;
7059 }
7060
7061 return false;
7062}
7063
7064static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
7065{
7066 struct ixgbe_hw *hw = &adapter->hw;
7067 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
7068 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
7069
7070 int i, j;
7071
7072 if (!adapter->num_vfs)
7073 return false;
7074
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007075 /* resetting the PF is only needed for MAC before X550 */
7076 if (hw->mac.type >= ixgbe_mac_X550)
7077 return false;
7078
Emil Tantilov07923c12014-08-12 07:12:08 +00007079 for (i = 0; i < adapter->num_vfs; i++) {
7080 for (j = 0; j < q_per_pool; j++) {
7081 u32 h, t;
7082
7083 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
7084 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
7085
7086 if (h != t)
7087 return true;
7088 }
7089 }
7090
7091 return false;
7092}
7093
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007094/**
7095 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007096 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007097 **/
7098static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
7099{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007100 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00007101 if (ixgbe_ring_tx_pending(adapter) ||
7102 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007103 /* We've lost link, so the controller stops DMA,
7104 * but we've got queued Tx work that's never going
7105 * to get done, so reset controller to flush Tx.
7106 * (Do the reset outside of interrupt context).
7107 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00007108 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007109 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007110 }
7111 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007112}
7113
Emil Tantilov9079e412014-11-19 03:18:19 +00007114#ifdef CONFIG_PCI_IOV
7115static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
7116 struct pci_dev *vfdev)
7117{
7118 if (!pci_wait_for_pending_transaction(vfdev))
7119 e_dev_warn("Issuing VFLR with pending transactions\n");
7120
7121 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
7122 pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
7123
7124 msleep(100);
7125}
7126
7127static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
7128{
7129 struct ixgbe_hw *hw = &adapter->hw;
7130 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07007131 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00007132 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00007133
7134 if (!(netif_carrier_ok(adapter->netdev)))
7135 return;
7136
7137 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
7138 if (gpc) /* If incrementing then no need for the check below */
7139 return;
7140 /* Check to see if a bad DMA write target from an errant or
7141 * malicious VF has caused a PCIe error. If so then we can
7142 * issue a VFLR to the offending VF(s) and then resume without
7143 * requesting a full slot reset.
7144 */
7145
7146 if (!pdev)
7147 return;
7148
Emil Tantilov9079e412014-11-19 03:18:19 +00007149 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07007150 for (vf = 0; vf < adapter->num_vfs; ++vf) {
7151 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
7152 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00007153
Mark Rustad988d1302015-10-30 15:29:34 -07007154 if (!vfdev)
7155 continue;
7156 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
7157 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
7158 status_reg & PCI_STATUS_REC_MASTER_ABORT)
7159 ixgbe_issue_vf_flr(adapter, vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00007160 }
7161}
7162
Greg Rosea985b6c32010-11-18 03:02:52 +00007163static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
7164{
7165 u32 ssvpc;
7166
Greg Rose0584d992012-08-08 00:00:58 +00007167 /* Do not perform spoof check for 82598 or if not in IOV mode */
7168 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7169 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00007170 return;
7171
7172 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
7173
7174 /*
7175 * ssvpc register is cleared on read, if zero then no
7176 * spoofed packets in the last interval.
7177 */
7178 if (!ssvpc)
7179 return;
7180
Emil Tantilovd6ea0752012-08-08 06:28:37 +00007181 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00007182}
Emil Tantilov9079e412014-11-19 03:18:19 +00007183#else
7184static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7185{
7186}
7187
7188static void
7189ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7190{
7191}
7192#endif /* CONFIG_PCI_IOV */
7193
Greg Rosea985b6c32010-11-18 03:02:52 +00007194
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007195/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007196 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007197 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007198 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007199static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007200{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007201 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007202 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007203 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007204 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007205 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007206
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007207 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007208
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007209 if (adapter->link_up)
7210 ixgbe_watchdog_link_is_up(adapter);
7211 else
7212 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007213
Emil Tantilov9079e412014-11-19 03:18:19 +00007214 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007215 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007216 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007217
7218 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007219}
7220
Alexander Duyck70864002011-04-27 09:13:56 +00007221/**
7222 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007223 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007224 **/
7225static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7226{
7227 struct ixgbe_hw *hw = &adapter->hw;
7228 s32 err;
7229
7230 /* not searching for SFP so there is nothing to do here */
7231 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7232 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7233 return;
7234
Mark Rustad58e7cd22015-08-08 16:18:48 -07007235 if (adapter->sfp_poll_time &&
7236 time_after(adapter->sfp_poll_time, jiffies))
7237 return; /* If not yet time to poll for SFP */
7238
Alexander Duyck70864002011-04-27 09:13:56 +00007239 /* someone else is in init, wait until next service event */
7240 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7241 return;
7242
Mark Rustad58e7cd22015-08-08 16:18:48 -07007243 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7244
Alexander Duyck70864002011-04-27 09:13:56 +00007245 err = hw->phy.ops.identify_sfp(hw);
7246 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7247 goto sfp_out;
7248
7249 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7250 /* If no cable is present, then we need to reset
7251 * the next time we find a good cable. */
7252 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7253 }
7254
7255 /* exit on error */
7256 if (err)
7257 goto sfp_out;
7258
7259 /* exit if reset not needed */
7260 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7261 goto sfp_out;
7262
7263 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7264
7265 /*
7266 * A module may be identified correctly, but the EEPROM may not have
7267 * support for that module. setup_sfp() will fail in that case, so
7268 * we should not allow that module to load.
7269 */
7270 if (hw->mac.type == ixgbe_mac_82598EB)
7271 err = hw->phy.ops.reset(hw);
7272 else
7273 err = hw->mac.ops.setup_sfp(hw);
7274
7275 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7276 goto sfp_out;
7277
7278 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7279 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7280
7281sfp_out:
7282 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7283
7284 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7285 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7286 e_dev_err("failed to initialize because an unsupported "
7287 "SFP+ module type was detected.\n");
7288 e_dev_err("Reload the driver after installing a "
7289 "supported module.\n");
7290 unregister_netdev(adapter->netdev);
7291 }
7292}
7293
7294/**
7295 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007296 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007297 **/
7298static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7299{
7300 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00007301 u32 speed;
7302 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007303
7304 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7305 return;
7306
7307 /* someone else is in init, wait until next service event */
7308 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7309 return;
7310
7311 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7312
Josh Hay3d292262012-12-15 03:28:19 +00007313 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00007314 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00007315 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007316
7317 /* setup the highest link when no autoneg */
7318 if (!autoneg) {
7319 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
7320 speed = IXGBE_LINK_SPEED_10GB_FULL;
7321 }
7322 }
7323
Alexander Duyck70864002011-04-27 09:13:56 +00007324 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007325 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007326
7327 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7328 adapter->link_check_timeout = jiffies;
7329 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7330}
7331
7332/**
7333 * ixgbe_service_timer - Timer Call-back
7334 * @data: pointer to adapter cast into an unsigned long
7335 **/
7336static void ixgbe_service_timer(unsigned long data)
7337{
7338 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
7339 unsigned long next_event_offset;
7340
7341 /* poll faster when waiting for link */
7342 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7343 next_event_offset = HZ / 10;
7344 else
7345 next_event_offset = HZ * 2;
7346
7347 /* Reset the timer */
7348 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7349
Emil Tantilov9079e412014-11-19 03:18:19 +00007350 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007351}
7352
Don Skidmore597f22d2015-06-09 16:52:02 -07007353static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7354{
7355 struct ixgbe_hw *hw = &adapter->hw;
7356 u32 status;
7357
7358 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7359 return;
7360
7361 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7362
7363 if (!hw->phy.ops.handle_lasi)
7364 return;
7365
7366 status = hw->phy.ops.handle_lasi(&adapter->hw);
7367 if (status != IXGBE_ERR_OVERTEMP)
7368 return;
7369
7370 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7371}
7372
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007373static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7374{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007375 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007376 return;
7377
Mark Rustad09f40ae2014-01-14 18:53:11 -08007378 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007379 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007380 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007381 test_bit(__IXGBE_RESETTING, &adapter->state))
7382 return;
7383
7384 ixgbe_dump(adapter);
7385 netdev_err(adapter->netdev, "Reset adapter\n");
7386 adapter->tx_timeout_count++;
7387
John Fastabend8f4c5c92014-01-16 02:30:05 -08007388 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007389 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007390 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007391}
7392
Alexander Duyck70864002011-04-27 09:13:56 +00007393/**
7394 * ixgbe_service_task - manages and runs subtasks
7395 * @work: pointer to work_struct containing our data
7396 **/
7397static void ixgbe_service_task(struct work_struct *work)
7398{
7399 struct ixgbe_adapter *adapter = container_of(work,
7400 struct ixgbe_adapter,
7401 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007402 if (ixgbe_removed(adapter->hw.hw_addr)) {
7403 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7404 rtnl_lock();
7405 ixgbe_down(adapter);
7406 rtnl_unlock();
7407 }
7408 ixgbe_service_event_complete(adapter);
7409 return;
7410 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007411 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007412 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007413 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007414 udp_tunnel_get_rx_info(adapter->netdev);
7415 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007416 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007417 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007418 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007419 ixgbe_sfp_detection_subtask(adapter);
7420 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007421 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007422 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007423 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007424 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007425
Jacob Keller8fecf672013-06-21 08:14:32 +00007426 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007427 ixgbe_ptp_overflow_check(adapter);
7428 ixgbe_ptp_rx_hang(adapter);
7429 }
Alexander Duyck70864002011-04-27 09:13:56 +00007430
7431 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007432}
7433
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007434static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7435 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007436 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007437{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007438 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007439 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007440 union {
7441 struct iphdr *v4;
7442 struct ipv6hdr *v6;
7443 unsigned char *hdr;
7444 } ip;
7445 union {
7446 struct tcphdr *tcp;
7447 unsigned char *hdr;
7448 } l4;
7449 u32 paylen, l4_offset;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007450 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007451
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007452 if (skb->ip_summed != CHECKSUM_PARTIAL)
7453 return 0;
7454
Alexander Duyck897ab152011-05-27 05:31:47 +00007455 if (!skb_is_gso(skb))
7456 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007457
Francois Romieu2049e1f2014-03-30 03:14:27 +00007458 err = skb_cow_head(skb, 0);
7459 if (err < 0)
7460 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007461
Alexander Duyckb83e3012016-04-14 17:19:31 -04007462 ip.hdr = skb_network_header(skb);
7463 l4.hdr = skb_checksum_start(skb);
7464
Alexander Duyck897ab152011-05-27 05:31:47 +00007465 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7466 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7467
Alexander Duyckb83e3012016-04-14 17:19:31 -04007468 /* initialize outer IP header fields */
7469 if (ip.v4->version == 4) {
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007470 unsigned char *csum_start = skb_checksum_start(skb);
7471 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
7472
Alexander Duyckb83e3012016-04-14 17:19:31 -04007473 /* IP header will have to cancel out any data that
7474 * is not a part of the outer IP header
7475 */
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007476 ip.v4->check = csum_fold(csum_partial(trans_start,
7477 csum_start - trans_start,
7478 0));
Alexander Duyck897ab152011-05-27 05:31:47 +00007479 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007480
7481 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007482 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7483 IXGBE_TX_FLAGS_CSUM |
7484 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007485 } else {
7486 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007487 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7488 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007489 }
7490
Alexander Duyckb83e3012016-04-14 17:19:31 -04007491 /* determine offset of inner transport header */
7492 l4_offset = l4.hdr - skb->data;
7493
7494 /* compute length of segmentation header */
7495 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7496
7497 /* remove payload length from inner checksum */
7498 paylen = skb->len - l4_offset;
7499 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007500
Alexander Duyck091a6242012-02-08 07:51:01 +00007501 /* update gso size and bytecount with header size */
7502 first->gso_segs = skb_shinfo(skb)->gso_segs;
7503 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7504
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007505 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007506 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007507 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007508
7509 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007510 vlan_macip_lens = l4.hdr - ip.hdr;
7511 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007512 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007513
7514 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007515 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007516
7517 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007518}
7519
Alexander Duyck49763de2016-01-13 07:31:11 -08007520static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7521{
7522 unsigned int offset = 0;
7523
7524 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7525
7526 return offset == skb_checksum_start_offset(skb);
7527}
7528
Alexander Duyck244e27a2012-02-08 07:51:11 +00007529static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7530 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007531{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007532 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007533 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007534 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007535
Alexander Duyck897ab152011-05-27 05:31:47 +00007536 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007537csum_failed:
7538 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7539 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007540 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007541 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007542 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007543
Alexander Duyck49763de2016-01-13 07:31:11 -08007544 switch (skb->csum_offset) {
7545 case offsetof(struct tcphdr, check):
7546 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7547 /* fall through */
7548 case offsetof(struct udphdr, check):
7549 break;
7550 case offsetof(struct sctphdr, checksum):
7551 /* validate that this is actually an SCTP request */
7552 if (((first->protocol == htons(ETH_P_IP)) &&
7553 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7554 ((first->protocol == htons(ETH_P_IPV6)) &&
7555 ixgbe_ipv6_csum_is_sctp(skb))) {
7556 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7557 break;
7558 }
7559 /* fall through */
7560 default:
7561 skb_checksum_help(skb);
7562 goto csum_failed;
7563 }
7564
7565 /* update TX checksum flag */
7566 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7567 vlan_macip_lens = skb_checksum_start_offset(skb) -
7568 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007569no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007570 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007571 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007572 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007573
Alexander Duyck49763de2016-01-13 07:31:11 -08007574 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007575}
7576
Alexander Duyck472148c2012-11-07 02:34:28 +00007577#define IXGBE_SET_FLAG(_input, _flag, _result) \
7578 ((_flag <= _result) ? \
7579 ((u32)(_input & _flag) * (_result / _flag)) : \
7580 ((u32)(_input & _flag) / (_flag / _result)))
7581
7582static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007583{
7584 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007585 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7586 IXGBE_ADVTXD_DCMD_DEXT |
7587 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007588
7589 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007590 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7591 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007592
Alexander Duyckd3d00232011-07-15 02:31:25 +00007593 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007594 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7595 IXGBE_ADVTXD_DCMD_TSE);
7596
7597 /* set timestamp bit if present */
7598 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7599 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007600
Alexander Duyck62748b72012-07-20 08:09:01 +00007601 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007602 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007603
Alexander Duyckd3d00232011-07-15 02:31:25 +00007604 return cmd_type;
7605}
7606
Alexander Duyck729739b2012-02-08 07:51:06 +00007607static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7608 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007609{
Alexander Duyck472148c2012-11-07 02:34:28 +00007610 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007611
7612 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007613 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7614 IXGBE_TX_FLAGS_CSUM,
7615 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007616
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007617 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007618 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7619 IXGBE_TX_FLAGS_IPV4,
7620 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007621
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007622 /*
7623 * Check Context must be set if Tx switch is enabled, which it
7624 * always is for case where virtual functions are running
7625 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007626 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7627 IXGBE_TX_FLAGS_CC,
7628 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007629
Alexander Duyck472148c2012-11-07 02:34:28 +00007630 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007631}
7632
Daniel Borkmann2367a172014-08-26 19:34:18 +02007633static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7634{
7635 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7636
7637 /* Herbert's original patch had:
7638 * smp_mb__after_netif_stop_queue();
7639 * but since that doesn't exist yet, just open code it.
7640 */
7641 smp_mb();
7642
7643 /* We need to check again in a case another CPU has just
7644 * made room available.
7645 */
7646 if (likely(ixgbe_desc_unused(tx_ring) < size))
7647 return -EBUSY;
7648
7649 /* A reprieve! - use start_queue because it doesn't call schedule */
7650 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7651 ++tx_ring->tx_stats.restart_queue;
7652 return 0;
7653}
7654
7655static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7656{
7657 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7658 return 0;
7659
7660 return __ixgbe_maybe_stop_tx(tx_ring, size);
7661}
7662
Alexander Duyckd3d00232011-07-15 02:31:25 +00007663#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7664 IXGBE_TXD_CMD_RS)
7665
7666static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007667 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007668 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007669{
Alexander Duyck729739b2012-02-08 07:51:06 +00007670 struct sk_buff *skb = first->skb;
7671 struct ixgbe_tx_buffer *tx_buffer;
7672 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007673 struct skb_frag_struct *frag;
7674 dma_addr_t dma;
7675 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007676 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007677 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007678 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007679
Alexander Duyck729739b2012-02-08 07:51:06 +00007680 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7681
Alexander Duyckec718252012-10-30 06:01:55 +00007682 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7683
7684 size = skb_headlen(skb);
7685 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007686
Alexander Duyckd3d00232011-07-15 02:31:25 +00007687#ifdef IXGBE_FCOE
7688 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007689 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007690 size -= sizeof(struct fcoe_crc_eof) - data_len;
7691 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007692 } else {
7693 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007694 }
Auke Kok9a799d72007-09-15 14:07:45 -07007695 }
7696
Alexander Duyckd3d00232011-07-15 02:31:25 +00007697#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007698 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007699
Alexander Duyckec718252012-10-30 06:01:55 +00007700 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007701
Alexander Duyckec718252012-10-30 06:01:55 +00007702 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7703 if (dma_mapping_error(tx_ring->dev, dma))
7704 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007705
Alexander Duyckec718252012-10-30 06:01:55 +00007706 /* record length, and DMA address */
7707 dma_unmap_len_set(tx_buffer, len, size);
7708 dma_unmap_addr_set(tx_buffer, dma, dma);
7709
7710 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7711
Alexander Duyck729739b2012-02-08 07:51:06 +00007712 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007713 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007714 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007715
Alexander Duyckd3d00232011-07-15 02:31:25 +00007716 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007717 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007718 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007719 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007720 i = 0;
7721 }
Alexander Duyckec718252012-10-30 06:01:55 +00007722 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007723
7724 dma += IXGBE_MAX_DATA_PER_TXD;
7725 size -= IXGBE_MAX_DATA_PER_TXD;
7726
7727 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007728 }
7729
Alexander Duyck729739b2012-02-08 07:51:06 +00007730 if (likely(!data_len))
7731 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007732
Alexander Duyck472148c2012-11-07 02:34:28 +00007733 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007734
Alexander Duyck729739b2012-02-08 07:51:06 +00007735 i++;
7736 tx_desc++;
7737 if (i == tx_ring->count) {
7738 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7739 i = 0;
7740 }
Alexander Duyckec718252012-10-30 06:01:55 +00007741 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007742
Alexander Duyckd3d00232011-07-15 02:31:25 +00007743#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007744 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007745#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007746 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007747#endif
7748 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007749
Alexander Duyck729739b2012-02-08 07:51:06 +00007750 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7751 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007752
Alexander Duyck729739b2012-02-08 07:51:06 +00007753 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007754 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007755
Alexander Duyck729739b2012-02-08 07:51:06 +00007756 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007757 cmd_type |= size | IXGBE_TXD_CMD;
7758 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007759
Alexander Duyck091a6242012-02-08 07:51:01 +00007760 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007761
Alexander Duyckd3d00232011-07-15 02:31:25 +00007762 /* set the timestamp */
7763 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007764
7765 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007766 * Force memory writes to complete before letting h/w know there
7767 * are new descriptors to fetch. (Only applicable for weak-ordered
7768 * memory model archs, such as IA-64).
7769 *
7770 * We also need this memory barrier to make certain all of the
7771 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007772 */
7773 wmb();
7774
Alexander Duyckd3d00232011-07-15 02:31:25 +00007775 /* set next_to_watch value indicating a packet is present */
7776 first->next_to_watch = tx_desc;
7777
Alexander Duyck729739b2012-02-08 07:51:06 +00007778 i++;
7779 if (i == tx_ring->count)
7780 i = 0;
7781
7782 tx_ring->next_to_use = i;
7783
Daniel Borkmann2367a172014-08-26 19:34:18 +02007784 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7785
7786 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00007787 writel(i, tx_ring->tail);
7788
7789 /* we need this if more than one processor can write to our tail
7790 * at a time, it synchronizes IO on IA64/Altix systems
7791 */
7792 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02007793 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02007794
Alexander Duyckd3d00232011-07-15 02:31:25 +00007795 return;
7796dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00007797 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckffed21b2017-01-17 08:37:29 -08007798 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckd3d00232011-07-15 02:31:25 +00007799
7800 /* clear dma mappings for failed tx_buffer_info map */
Alexander Duyckffed21b2017-01-17 08:37:29 -08007801 while (tx_buffer != first) {
7802 if (dma_unmap_len(tx_buffer, len))
7803 dma_unmap_page(tx_ring->dev,
7804 dma_unmap_addr(tx_buffer, dma),
7805 dma_unmap_len(tx_buffer, len),
7806 DMA_TO_DEVICE);
7807 dma_unmap_len_set(tx_buffer, len, 0);
7808
7809 if (i--)
7810 i += tx_ring->count;
Alexander Duyck729739b2012-02-08 07:51:06 +00007811 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckd3d00232011-07-15 02:31:25 +00007812 }
7813
Alexander Duyckffed21b2017-01-17 08:37:29 -08007814 if (dma_unmap_len(tx_buffer, len))
7815 dma_unmap_single(tx_ring->dev,
7816 dma_unmap_addr(tx_buffer, dma),
7817 dma_unmap_len(tx_buffer, len),
7818 DMA_TO_DEVICE);
7819 dma_unmap_len_set(tx_buffer, len, 0);
7820
7821 dev_kfree_skb_any(first->skb);
7822 first->skb = NULL;
7823
Alexander Duyckd3d00232011-07-15 02:31:25 +00007824 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07007825}
7826
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007827static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007828 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007829{
Alexander Duyck69830522011-01-06 14:29:58 +00007830 struct ixgbe_q_vector *q_vector = ring->q_vector;
7831 union ixgbe_atr_hash_dword input = { .dword = 0 };
7832 union ixgbe_atr_hash_dword common = { .dword = 0 };
7833 union {
7834 unsigned char *network;
7835 struct iphdr *ipv4;
7836 struct ipv6hdr *ipv6;
7837 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007838 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08007839 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07007840 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00007841 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08007842 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007843
Alexander Duyck69830522011-01-06 14:29:58 +00007844 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7845 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00007846 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007847
Alexander Duyck69830522011-01-06 14:29:58 +00007848 /* do nothing if sampling is disabled */
7849 if (!ring->atr_sample_rate)
7850 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007851
Alexander Duyck69830522011-01-06 14:29:58 +00007852 ring->atr_count++;
7853
Alexander Duycke2873d42016-01-25 19:39:40 -08007854 /* currently only IPv4/IPv6 with TCP is supported */
7855 if ((first->protocol != htons(ETH_P_IP)) &&
7856 (first->protocol != htons(ETH_P_IPV6)))
7857 return;
7858
Alexander Duyck69830522011-01-06 14:29:58 +00007859 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07007860 skb = first->skb;
7861 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007862 if (unlikely(hdr.network <= skb->data))
7863 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08007864 if (skb->encapsulation &&
7865 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07007866 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07007867 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00007868
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007869 if (unlikely(skb_tail_pointer(skb) < hdr.network +
7870 VXLAN_HEADROOM))
7871 return;
7872
Alexander Duyck9f12df92016-01-25 19:36:29 -08007873 /* verify the port is recognized as VXLAN */
7874 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08007875 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08007876 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07007877
7878 if (adapter->geneve_port &&
7879 udp_hdr(skb)->dest == adapter->geneve_port)
7880 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08007881 }
7882
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007883 /* Make sure we have at least [minimum IPv4 header + TCP]
7884 * or [IPv6 header] bytes
7885 */
7886 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
7887 return;
7888
Mark Rustade19dcde2015-12-09 14:55:37 -08007889 /* Currently only IPv4/IPv6 with TCP is supported */
7890 switch (hdr.ipv4->version) {
7891 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08007892 /* access ihl as u8 to avoid unaligned access on ia64 */
7893 hlen = (hdr.network[0] & 0x0F) << 2;
7894 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08007895 break;
7896 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08007897 hlen = hdr.network - skb->data;
7898 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
7899 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08007900 break;
7901 default:
7902 return;
Mark Rustad67359c32015-06-15 11:33:25 -07007903 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007904
Alexander Duycke2873d42016-01-25 19:39:40 -08007905 if (l4_proto != IPPROTO_TCP)
7906 return;
7907
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007908 if (unlikely(skb_tail_pointer(skb) < hdr.network +
7909 hlen + sizeof(struct tcphdr)))
7910 return;
7911
Alexander Duycke2873d42016-01-25 19:39:40 -08007912 th = (struct tcphdr *)(hdr.network + hlen);
7913
7914 /* skip this packet since the socket is closing */
7915 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00007916 return;
7917
7918 /* sample on all syn packets or once every atr sample count */
7919 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
7920 return;
7921
7922 /* reset sample count */
7923 ring->atr_count = 0;
7924
Alexander Duyck244e27a2012-02-08 07:51:11 +00007925 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00007926
7927 /*
7928 * src and dst are inverted, think how the receiver sees them
7929 *
7930 * The input is broken into two sections, a non-compressed section
7931 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7932 * is XORed together and stored in the compressed dword.
7933 */
7934 input.formatted.vlan_id = vlan_id;
7935
7936 /*
7937 * since src port and flex bytes occupy the same word XOR them together
7938 * and write the value to source port portion of compressed dword
7939 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007940 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00007941 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00007942 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00007943 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00007944 common.port.dst ^= th->source;
7945
Mark Rustade19dcde2015-12-09 14:55:37 -08007946 switch (hdr.ipv4->version) {
7947 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00007948 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7949 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08007950 break;
7951 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00007952 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7953 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7954 hdr.ipv6->saddr.s6_addr32[1] ^
7955 hdr.ipv6->saddr.s6_addr32[2] ^
7956 hdr.ipv6->saddr.s6_addr32[3] ^
7957 hdr.ipv6->daddr.s6_addr32[0] ^
7958 hdr.ipv6->daddr.s6_addr32[1] ^
7959 hdr.ipv6->daddr.s6_addr32[2] ^
7960 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08007961 break;
7962 default:
7963 break;
Alexander Duyck69830522011-01-06 14:29:58 +00007964 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007965
Alexander Duyck9f12df92016-01-25 19:36:29 -08007966 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07007967 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07007968
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007969 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007970 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7971 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007972}
7973
Jason Wangf663dd92014-01-10 16:18:26 +08007974static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01007975 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007976{
Jason Wangf663dd92014-01-10 16:18:26 +08007977 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7978#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00007979 struct ixgbe_adapter *adapter;
7980 struct ixgbe_ring_feature *f;
7981 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08007982#endif
7983
7984 if (fwd_adapter)
7985 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7986
7987#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00007988
Alexander Duyck97488bd2013-01-12 06:33:37 +00007989 /*
7990 * only execute the code below if protocol is FCoE
7991 * or FIP and we have FCoE enabled on the adapter
7992 */
7993 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00007994 case htons(ETH_P_FCOE):
7995 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00007996 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00007997
Alexander Duyck97488bd2013-01-12 06:33:37 +00007998 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7999 break;
8000 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01008001 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00008002 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008003
Alexander Duyck97488bd2013-01-12 06:33:37 +00008004 f = &adapter->ring_feature[RING_F_FCOE];
8005
8006 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8007 smp_processor_id();
8008
8009 while (txq >= f->indices)
8010 txq -= f->indices;
8011
8012 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08008013#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01008014 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08008015#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008016}
8017
Alexander Duyckfc77dc32010-11-16 19:26:51 -08008018netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00008019 struct ixgbe_adapter *adapter,
8020 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008021{
Alexander Duyckd3d00232011-07-15 02:31:25 +00008022 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00008023 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008024 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00008025 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00008026 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00008027 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00008028 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00008029
Alexander Duycka535c302011-05-27 05:31:52 +00008030 /*
8031 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00008032 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00008033 * + 2 desc gap to keep tail from touching head,
8034 * + 1 desc for context descriptor,
8035 * otherwise try next time
8036 */
Alexander Duycka535c302011-05-27 05:31:52 +00008037 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8038 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00008039
Alexander Duycka535c302011-05-27 05:31:52 +00008040 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8041 tx_ring->tx_stats.tx_busy++;
8042 return NETDEV_TX_BUSY;
8043 }
8044
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008045 /* record the location of the first descriptor for this packet */
8046 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8047 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00008048 first->bytecount = skb->len;
8049 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008050
Alexander Duyck66f32a82011-06-29 05:43:22 +00008051 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01008052 if (skb_vlan_tag_present(skb)) {
8053 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008054 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8055 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008056 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008057 struct vlan_hdr *vhdr, _vhdr;
8058 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8059 if (!vhdr)
8060 goto out_drop;
8061
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008062 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8063 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008064 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07008065 }
Toshiaki Makita02136682015-01-29 20:37:09 +09008066 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00008067
Mark Rustadd5234932014-08-09 07:02:09 +00008068 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
8069 adapter->ptp_clock &&
8070 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8071 &adapter->state)) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008072 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8073 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00008074
8075 /* schedule check for Tx timestamp */
8076 adapter->ptp_tx_skb = skb_get(skb);
8077 adapter->ptp_tx_start = jiffies;
8078 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008079 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008080
Jakub Kicinskiff29a862014-03-15 14:55:16 +00008081 skb_tx_timestamp(skb);
8082
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008083#ifdef CONFIG_PCI_IOV
8084 /*
8085 * Use the l2switch_enable flag - would be false if the DMA
8086 * Tx switch had been disabled.
8087 */
8088 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00008089 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008090
8091#endif
John Fastabend32701dc2011-09-27 03:51:56 +00008092 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00008093 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00008094 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8095 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008096 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00008097 tx_flags |= (skb->priority & 0x7) <<
8098 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008099 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8100 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00008101
8102 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00008103 goto out_drop;
8104 vhdr = (struct vlan_ethhdr *)skb->data;
8105 vhdr->h_vlan_TCI = htons(tx_flags >>
8106 IXGBE_TX_FLAGS_VLAN_SHIFT);
8107 } else {
8108 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8109 }
8110 }
Alexander Duycka535c302011-05-27 05:31:52 +00008111
Alexander Duyck244e27a2012-02-08 07:51:11 +00008112 /* record initial flags and protocol */
8113 first->tx_flags = tx_flags;
8114 first->protocol = protocol;
8115
Yi Zoueacd73f2009-05-13 13:11:06 +00008116#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00008117 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008118 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00008119 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00008120 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00008121 if (tso < 0)
8122 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07008123
Alexander Duyck66f32a82011-06-29 05:43:22 +00008124 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00008125 }
Auke Kok9a799d72007-09-15 14:07:45 -07008126
Auke Kok9a799d72007-09-15 14:07:45 -07008127#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008128 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008129 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07008130 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008131 else if (!tso)
8132 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008133
8134 /* add the ATR filter if ATR is on */
8135 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00008136 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008137
8138#ifdef IXGBE_FCOE
8139xmit_fcoe:
8140#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008141 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008142
Auke Kok9a799d72007-09-15 14:07:45 -07008143 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00008144
8145out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008146 dev_kfree_skb_any(first->skb);
8147 first->skb = NULL;
8148
Alexander Duyck897ab152011-05-27 05:31:47 +00008149 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07008150}
8151
John Fastabend2a47fa42013-11-06 09:54:52 -08008152static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8153 struct net_device *netdev,
8154 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008155{
8156 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008157 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07008158
Alexander Duycka50c29d2012-02-08 07:50:40 +00008159 /*
8160 * The minimum packet size for olinfo paylen is 17 so pad the skb
8161 * in order to meet this minimum size requirement.
8162 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08008163 if (skb_put_padto(skb, 17))
8164 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00008165
John Fastabend2a47fa42013-11-06 09:54:52 -08008166 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8167
Auke Kok9a799d72007-09-15 14:07:45 -07008168 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8169}
8170
John Fastabend2a47fa42013-11-06 09:54:52 -08008171static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8172 struct net_device *netdev)
8173{
8174 return __ixgbe_xmit_frame(skb, netdev, NULL);
8175}
8176
Auke Kok9a799d72007-09-15 14:07:45 -07008177/**
8178 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8179 * @netdev: network interface device structure
8180 * @p: pointer to an address structure
8181 *
8182 * Returns 0 on success, negative on failure
8183 **/
8184static int ixgbe_set_mac(struct net_device *netdev, void *p)
8185{
8186 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8187 struct ixgbe_hw *hw = &adapter->hw;
8188 struct sockaddr *addr = p;
8189
8190 if (!is_valid_ether_addr(addr->sa_data))
8191 return -EADDRNOTAVAIL;
8192
8193 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008194 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008195
Alexander Duyckc9f53e62015-10-22 16:26:30 -07008196 ixgbe_mac_set_default_filter(adapter);
8197
8198 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008199}
8200
Ben Hutchings6b73e102009-04-29 08:08:58 +00008201static int
8202ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8203{
8204 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8205 struct ixgbe_hw *hw = &adapter->hw;
8206 u16 value;
8207 int rc;
8208
8209 if (prtad != hw->phy.mdio.prtad)
8210 return -EINVAL;
8211 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8212 if (!rc)
8213 rc = value;
8214 return rc;
8215}
8216
8217static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8218 u16 addr, u16 value)
8219{
8220 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8221 struct ixgbe_hw *hw = &adapter->hw;
8222
8223 if (prtad != hw->phy.mdio.prtad)
8224 return -EINVAL;
8225 return hw->phy.ops.write_reg(hw, addr, devad, value);
8226}
8227
8228static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8229{
8230 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8231
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008232 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008233 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008234 return ixgbe_ptp_set_ts_config(adapter, req);
8235 case SIOCGHWTSTAMP:
8236 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008237 default:
8238 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8239 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008240}
8241
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008242/**
8243 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008244 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008245 * @netdev: network interface device structure
8246 *
8247 * Returns non-zero on failure
8248 **/
8249static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8250{
8251 int err = 0;
8252 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008253 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008254
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008255 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008256 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008257 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008258 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008259
8260 /* update SAN MAC vmdq pool selection */
8261 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008262 }
8263 return err;
8264}
8265
8266/**
8267 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008268 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008269 * @netdev: network interface device structure
8270 *
8271 * Returns non-zero on failure
8272 **/
8273static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8274{
8275 int err = 0;
8276 struct ixgbe_adapter *adapter = netdev_priv(dev);
8277 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8278
8279 if (is_valid_ether_addr(mac->san_addr)) {
8280 rtnl_lock();
8281 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8282 rtnl_unlock();
8283 }
8284 return err;
8285}
8286
Auke Kok9a799d72007-09-15 14:07:45 -07008287#ifdef CONFIG_NET_POLL_CONTROLLER
8288/*
8289 * Polling 'interrupt' - used by things like netconsole to send skbs
8290 * without having to re-enable interrupts. It's not called while
8291 * the interrupt routine is executing.
8292 */
8293static void ixgbe_netpoll(struct net_device *netdev)
8294{
8295 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008296 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008297
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008298 /* if interface is down do nothing */
8299 if (test_bit(__IXGBE_DOWN, &adapter->state))
8300 return;
8301
Alexander Duyck856f6062015-02-25 17:45:54 +00008302 /* loop through and schedule all active queues */
8303 for (i = 0; i < adapter->num_q_vectors; i++)
8304 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008305}
Auke Kok9a799d72007-09-15 14:07:45 -07008306
Alexander Duyck581330b2012-02-08 07:51:47 +00008307#endif
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008308
8309static void ixgbe_get_stats64(struct net_device *netdev,
8310 struct rtnl_link_stats64 *stats)
Eric Dumazetde1036b2010-10-20 23:00:04 +00008311{
8312 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8313 int i;
8314
Eric Dumazet1a515022010-11-16 19:26:42 -08008315 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008316 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08008317 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008318 u64 bytes, packets;
8319 unsigned int start;
8320
Eric Dumazet1a515022010-11-16 19:26:42 -08008321 if (ring) {
8322 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008323 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008324 packets = ring->stats.packets;
8325 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008326 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008327 stats->rx_packets += packets;
8328 stats->rx_bytes += bytes;
8329 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008330 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008331
8332 for (i = 0; i < adapter->num_tx_queues; i++) {
8333 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
8334 u64 bytes, packets;
8335 unsigned int start;
8336
8337 if (ring) {
8338 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008339 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008340 packets = ring->stats.packets;
8341 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008342 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008343 stats->tx_packets += packets;
8344 stats->tx_bytes += bytes;
8345 }
8346 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008347 rcu_read_unlock();
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008348
Eric Dumazetde1036b2010-10-20 23:00:04 +00008349 /* following stats updated by ixgbe_watchdog_task() */
8350 stats->multicast = netdev->stats.multicast;
8351 stats->rx_errors = netdev->stats.rx_errors;
8352 stats->rx_length_errors = netdev->stats.rx_length_errors;
8353 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8354 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
Eric Dumazetde1036b2010-10-20 23:00:04 +00008355}
8356
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008357#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008358/**
8359 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8360 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008361 * @tc: number of traffic classes currently enabled
8362 *
8363 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8364 * 802.1Q priority maps to a packet buffer that exists.
8365 */
8366static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8367{
8368 struct ixgbe_hw *hw = &adapter->hw;
8369 u32 reg, rsave;
8370 int i;
8371
8372 /* 82598 have a static priority to TC mapping that can not
8373 * be changed so no validation is needed.
8374 */
8375 if (hw->mac.type == ixgbe_mac_82598EB)
8376 return;
8377
8378 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8379 rsave = reg;
8380
8381 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8382 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8383
8384 /* If up2tc is out of bounds default to zero */
8385 if (up2tc > tc)
8386 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8387 }
8388
8389 if (reg != rsave)
8390 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8391
8392 return;
8393}
8394
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008395/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008396 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8397 * @adapter: Pointer to adapter struct
8398 *
8399 * Populate the netdev user priority to tc map
8400 */
8401static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8402{
8403 struct net_device *dev = adapter->netdev;
8404 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8405 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8406 u8 prio;
8407
8408 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8409 u8 tc = 0;
8410
8411 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8412 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8413 else if (ets)
8414 tc = ets->prio_tc[prio];
8415
8416 netdev_set_prio_tc_map(dev, prio, tc);
8417 }
8418}
8419
Alexander Duyckcca73c52013-01-12 06:33:44 +00008420#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008421/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008422 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008423 *
8424 * @netdev: net device to configure
8425 * @tc: number of traffic classes to enable
8426 */
8427int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8428{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008429 struct ixgbe_adapter *adapter = netdev_priv(dev);
8430 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08008431 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008432
John Fastabend8b1c0b22011-05-03 02:26:48 +00008433 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008434 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8435 return -EINVAL;
8436
8437 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008438 return -EINVAL;
8439
John Fastabend2a47fa42013-11-06 09:54:52 -08008440 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
8441 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
8442 return -EBUSY;
8443
John Fastabend8b1c0b22011-05-03 02:26:48 +00008444 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008445 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008446 * hardware is not flexible enough to do this dynamically.
8447 */
8448 if (netif_running(dev))
8449 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008450 else
8451 ixgbe_reset(adapter);
8452
John Fastabend8b1c0b22011-05-03 02:26:48 +00008453 ixgbe_clear_interrupt_scheme(adapter);
8454
Alexander Duyckcca73c52013-01-12 06:33:44 +00008455#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008456 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008457 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008458 ixgbe_set_prio_tc_map(adapter);
8459
John Fastabende7589ea2011-07-18 22:38:36 +00008460 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008461
Alexander Duyck943561d2012-05-09 22:14:44 -07008462 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8463 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008464 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008465 }
John Fastabende7589ea2011-07-18 22:38:36 +00008466 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008467 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008468
Alexander Duyck943561d2012-05-09 22:14:44 -07008469 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8470 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008471
8472 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008473
8474 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8475 adapter->dcb_cfg.pfc_mode_enable = false;
8476 }
8477
John Fastabend8b1c0b22011-05-03 02:26:48 +00008478 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008479
8480#endif /* CONFIG_IXGBE_DCB */
8481 ixgbe_init_interrupt_scheme(adapter);
8482
John Fastabend8b1c0b22011-05-03 02:26:48 +00008483 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008484 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008485
8486 return 0;
8487}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008488
John Fastabendb82b17d2016-02-16 21:18:53 -08008489static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8490 struct tc_cls_u32_offload *cls)
8491{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008492 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008493 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008494 u32 loc = cls->knode.handle & 0xfffff;
8495 int err = 0, i, j;
8496 struct ixgbe_jump_table *jump = NULL;
8497
8498 if (loc > IXGBE_MAX_HW_ENTRIES)
8499 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008500
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008501 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8502 return -EINVAL;
8503
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008504 /* Clear this filter in the link data it is associated with */
8505 if (uhtid != 0x800) {
8506 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008507 if (!jump)
8508 return -EINVAL;
8509 if (!test_bit(loc - 1, jump->child_loc_map))
8510 return -EINVAL;
8511 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008512 }
8513
8514 /* Check if the filter being deleted is a link */
8515 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8516 jump = adapter->jump_tables[i];
8517 if (jump && jump->link_hdl == hdl) {
8518 /* Delete filters in the hardware in the child hash
8519 * table associated with this link
8520 */
8521 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8522 if (!test_bit(j, jump->child_loc_map))
8523 continue;
8524 spin_lock(&adapter->fdir_perfect_lock);
8525 err = ixgbe_update_ethtool_fdir_entry(adapter,
8526 NULL,
8527 j + 1);
8528 spin_unlock(&adapter->fdir_perfect_lock);
8529 clear_bit(j, jump->child_loc_map);
8530 }
8531 /* Remove resources for this link */
8532 kfree(jump->input);
8533 kfree(jump->mask);
8534 kfree(jump);
8535 adapter->jump_tables[i] = NULL;
8536 return err;
8537 }
8538 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008539
John Fastabendb82b17d2016-02-16 21:18:53 -08008540 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008541 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008542 spin_unlock(&adapter->fdir_perfect_lock);
8543 return err;
8544}
8545
John Fastabenddb956ae2016-02-16 21:19:19 -08008546static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
8547 __be16 protocol,
8548 struct tc_cls_u32_offload *cls)
8549{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008550 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8551
8552 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8553 return -EINVAL;
8554
John Fastabenddb956ae2016-02-16 21:19:19 -08008555 /* This ixgbe devices do not support hash tables at the moment
8556 * so abort when given hash tables.
8557 */
8558 if (cls->hnode.divisor > 0)
8559 return -EINVAL;
8560
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008561 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008562 return 0;
8563}
8564
8565static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8566 struct tc_cls_u32_offload *cls)
8567{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008568 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8569
8570 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8571 return -EINVAL;
8572
8573 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008574 return 0;
8575}
8576
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008577#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07008578struct upper_walk_data {
8579 struct ixgbe_adapter *adapter;
8580 u64 action;
8581 int ifindex;
8582 u8 queue;
8583};
8584
8585static int get_macvlan_queue(struct net_device *upper, void *_data)
8586{
8587 if (netif_is_macvlan(upper)) {
8588 struct macvlan_dev *dfwd = netdev_priv(upper);
8589 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
8590 struct upper_walk_data *data = _data;
8591 struct ixgbe_adapter *adapter = data->adapter;
8592 int ifindex = data->ifindex;
8593
8594 if (vadapter && vadapter->netdev->ifindex == ifindex) {
8595 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
8596 data->action = data->queue;
8597 return 1;
8598 }
8599 }
8600
8601 return 0;
8602}
8603
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008604static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
8605 u8 *queue, u64 *action)
8606{
8607 unsigned int num_vfs = adapter->num_vfs, vf;
David Ahern1cd127f2016-10-17 19:15:48 -07008608 struct upper_walk_data data;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008609 struct net_device *upper;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008610
8611 /* redirect to a SRIOV VF */
8612 for (vf = 0; vf < num_vfs; ++vf) {
8613 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
8614 if (upper->ifindex == ifindex) {
8615 if (adapter->num_rx_pools > 1)
8616 *queue = vf * 2;
8617 else
8618 *queue = vf * adapter->num_rx_queues_per_pool;
8619
8620 *action = vf + 1;
8621 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
8622 return 0;
8623 }
8624 }
8625
8626 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07008627 data.adapter = adapter;
8628 data.ifindex = ifindex;
8629 data.action = 0;
8630 data.queue = 0;
8631 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
8632 get_macvlan_queue, &data)) {
8633 *action = data.action;
8634 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008635
David Ahern1cd127f2016-10-17 19:15:48 -07008636 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008637 }
8638
8639 return -EINVAL;
8640}
8641
8642static int parse_tc_actions(struct ixgbe_adapter *adapter,
8643 struct tcf_exts *exts, u64 *action, u8 *queue)
8644{
8645 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07008646 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008647 int err;
8648
8649 if (tc_no_actions(exts))
8650 return -EINVAL;
8651
WANG Cong22dc13c2016-08-13 22:35:00 -07008652 tcf_exts_to_list(exts, &actions);
8653 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008654
8655 /* Drop action */
8656 if (is_tcf_gact_shot(a)) {
8657 *action = IXGBE_FDIR_DROP_QUEUE;
8658 *queue = IXGBE_FDIR_DROP_QUEUE;
8659 return 0;
8660 }
8661
8662 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03008663 if (is_tcf_mirred_egress_redirect(a)) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008664 int ifindex = tcf_mirred_ifindex(a);
8665
8666 err = handle_redirect_action(adapter, ifindex, queue,
8667 action);
8668 if (err == 0)
8669 return err;
8670 }
8671 }
8672
8673 return -EINVAL;
8674}
8675#else
8676static int parse_tc_actions(struct ixgbe_adapter *adapter,
8677 struct tcf_exts *exts, u64 *action, u8 *queue)
8678{
8679 return -EINVAL;
8680}
8681#endif /* CONFIG_NET_CLS_ACT */
8682
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008683static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
8684 union ixgbe_atr_input *mask,
8685 struct tc_cls_u32_offload *cls,
8686 struct ixgbe_mat_field *field_ptr,
8687 struct ixgbe_nexthdr *nexthdr)
8688{
8689 int i, j, off;
8690 __be32 val, m;
8691 bool found_entry = false, found_jump_field = false;
8692
8693 for (i = 0; i < cls->knode.sel->nkeys; i++) {
8694 off = cls->knode.sel->keys[i].off;
8695 val = cls->knode.sel->keys[i].val;
8696 m = cls->knode.sel->keys[i].mask;
8697
8698 for (j = 0; field_ptr[j].val; j++) {
8699 if (field_ptr[j].off == off) {
8700 field_ptr[j].val(input, mask, val, m);
8701 input->filter.formatted.flow_type |=
8702 field_ptr[j].type;
8703 found_entry = true;
8704 break;
8705 }
8706 }
8707 if (nexthdr) {
8708 if (nexthdr->off == cls->knode.sel->keys[i].off &&
8709 nexthdr->val == cls->knode.sel->keys[i].val &&
8710 nexthdr->mask == cls->knode.sel->keys[i].mask)
8711 found_jump_field = true;
8712 else
8713 continue;
8714 }
8715 }
8716
8717 if (nexthdr && !found_jump_field)
8718 return -EINVAL;
8719
8720 if (!found_entry)
8721 return 0;
8722
8723 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
8724 IXGBE_ATR_L4TYPE_MASK;
8725
8726 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
8727 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
8728
8729 return 0;
8730}
8731
John Fastabendb82b17d2016-02-16 21:18:53 -08008732static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
8733 __be16 protocol,
8734 struct tc_cls_u32_offload *cls)
8735{
8736 u32 loc = cls->knode.handle & 0xfffff;
8737 struct ixgbe_hw *hw = &adapter->hw;
8738 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008739 struct ixgbe_fdir_filter *input = NULL;
8740 union ixgbe_atr_input *mask = NULL;
8741 struct ixgbe_jump_table *jump = NULL;
8742 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008743 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008744 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08008745
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008746 uhtid = TC_U32_USERHTID(cls->knode.handle);
8747 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08008748
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008749 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08008750 * L2 headers. The canonical method to match L2 frames is to use
8751 * negative values. However this is error prone at best but really
8752 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008753 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08008754 * headers when needed.
8755 */
8756 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008757 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008758
8759 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
8760 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008761 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008762 }
8763
8764 /* cls u32 is a graph starting at root node 0x800. The driver tracks
8765 * links and also the fields used to advance the parser across each
8766 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
8767 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
8768 * To add support for new nodes update ixgbe_model.h parse structures
8769 * this function _should_ be generic try not to hardcode values here.
8770 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008771 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008772 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08008773 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008774 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008775 return err;
8776 if (!adapter->jump_tables[uhtid])
8777 return err;
8778 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08008779 }
8780
8781 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008782 return err;
8783
8784 /* At this point we know the field_ptr is valid and need to either
8785 * build cls_u32 link or attach filter. Because adding a link to
8786 * a handle that does not exist is invalid and the same for adding
8787 * rules to handles that don't exist.
8788 */
8789
8790 if (link_uhtid) {
8791 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
8792
8793 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
8794 return err;
8795
8796 if (!test_bit(link_uhtid - 1, &adapter->tables))
8797 return err;
8798
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008799 /* Multiple filters as links to the same hash table are not
8800 * supported. To add a new filter with the same next header
8801 * but different match/jump conditions, create a new hash table
8802 * and link to it.
8803 */
8804 if (adapter->jump_tables[link_uhtid] &&
8805 (adapter->jump_tables[link_uhtid])->link_hdl) {
8806 e_err(drv, "Link filter exists for link: %x\n",
8807 link_uhtid);
8808 return err;
8809 }
8810
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008811 for (i = 0; nexthdr[i].jump; i++) {
8812 if (nexthdr[i].o != cls->knode.sel->offoff ||
8813 nexthdr[i].s != cls->knode.sel->offshift ||
8814 nexthdr[i].m != cls->knode.sel->offmask)
8815 return err;
8816
8817 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
8818 if (!jump)
8819 return -ENOMEM;
8820 input = kzalloc(sizeof(*input), GFP_KERNEL);
8821 if (!input) {
8822 err = -ENOMEM;
8823 goto free_jump;
8824 }
8825 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
8826 if (!mask) {
8827 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008828 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008829 }
8830 jump->input = input;
8831 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008832 jump->link_hdl = cls->knode.handle;
8833
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008834 err = ixgbe_clsu32_build_input(input, mask, cls,
8835 field_ptr, &nexthdr[i]);
8836 if (!err) {
8837 jump->mat = nexthdr[i].jump;
8838 adapter->jump_tables[link_uhtid] = jump;
8839 break;
8840 }
8841 }
8842 return 0;
8843 }
John Fastabendb82b17d2016-02-16 21:18:53 -08008844
8845 input = kzalloc(sizeof(*input), GFP_KERNEL);
8846 if (!input)
8847 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008848 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
8849 if (!mask) {
8850 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008851 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08008852 }
8853
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008854 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
8855 if ((adapter->jump_tables[uhtid])->input)
8856 memcpy(input, (adapter->jump_tables[uhtid])->input,
8857 sizeof(*input));
8858 if ((adapter->jump_tables[uhtid])->mask)
8859 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
8860 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008861
8862 /* Lookup in all child hash tables if this location is already
8863 * filled with a filter
8864 */
8865 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8866 struct ixgbe_jump_table *link = adapter->jump_tables[i];
8867
8868 if (link && (test_bit(loc - 1, link->child_loc_map))) {
8869 e_err(drv, "Filter exists in location: %x\n",
8870 loc);
8871 err = -EINVAL;
8872 goto err_out;
8873 }
8874 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008875 }
8876 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
8877 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08008878 goto err_out;
8879
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008880 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
8881 &queue);
8882 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08008883 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08008884
John Fastabendb82b17d2016-02-16 21:18:53 -08008885 input->sw_idx = loc;
8886
8887 spin_lock(&adapter->fdir_perfect_lock);
8888
8889 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008890 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
8891 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008892 if (err)
8893 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008894 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008895 err = -EINVAL;
8896 goto err_out_w_lock;
8897 }
8898
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008899 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008900 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
8901 input->sw_idx, queue);
8902 if (!err)
8903 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
8904 spin_unlock(&adapter->fdir_perfect_lock);
8905
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008906 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
8907 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008908
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008909 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008910 return err;
8911err_out_w_lock:
8912 spin_unlock(&adapter->fdir_perfect_lock);
8913err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008914 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008915free_input:
8916 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008917free_jump:
8918 kfree(jump);
8919 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008920}
8921
Emil Tantilov6e2a60b2016-02-17 15:55:06 -08008922static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
8923 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08008924{
John Fastabendb82b17d2016-02-16 21:18:53 -08008925 struct ixgbe_adapter *adapter = netdev_priv(dev);
8926
8927 if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
8928 tc->type == TC_SETUP_CLSU32) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008929 switch (tc->cls_u32->command) {
8930 case TC_CLSU32_NEW_KNODE:
8931 case TC_CLSU32_REPLACE_KNODE:
8932 return ixgbe_configure_clsu32(adapter,
8933 proto, tc->cls_u32);
8934 case TC_CLSU32_DELETE_KNODE:
8935 return ixgbe_delete_clsu32(adapter, tc->cls_u32);
John Fastabenddb956ae2016-02-16 21:19:19 -08008936 case TC_CLSU32_NEW_HNODE:
8937 case TC_CLSU32_REPLACE_HNODE:
8938 return ixgbe_configure_clsu32_add_hnode(adapter, proto,
8939 tc->cls_u32);
8940 case TC_CLSU32_DELETE_HNODE:
8941 return ixgbe_configure_clsu32_del_hnode(adapter,
8942 tc->cls_u32);
John Fastabendb82b17d2016-02-16 21:18:53 -08008943 default:
8944 return -EINVAL;
8945 }
8946 }
8947
John Fastabend5eb4dce2016-02-29 11:26:13 -08008948 if (tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08008949 return -EINVAL;
8950
Amritha Nambiar56f36ac2017-03-15 10:39:25 -07008951 tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
8952
8953 return ixgbe_setup_tc(dev, tc->mqprio->num_tc);
John Fastabende4c67342016-02-16 21:16:15 -08008954}
8955
Greg Roseda36b642012-12-11 08:26:43 +00008956#ifdef CONFIG_PCI_IOV
8957void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
8958{
8959 struct net_device *netdev = adapter->netdev;
8960
8961 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00008962 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00008963 rtnl_unlock();
8964}
8965
8966#endif
Don Skidmore082757a2011-07-21 05:55:00 +00008967void ixgbe_do_reset(struct net_device *netdev)
8968{
8969 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8970
8971 if (netif_running(netdev))
8972 ixgbe_reinit_locked(adapter);
8973 else
8974 ixgbe_reset(adapter);
8975}
8976
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008977static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008978 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008979{
8980 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8981
Don Skidmore082757a2011-07-21 05:55:00 +00008982 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00008983 if (!(features & NETIF_F_RXCSUM))
8984 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00008985
Alexander Duyck567d2de2012-02-11 07:18:57 +00008986 /* Turn off LRO if not RSC capable */
8987 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
8988 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008989
Alexander Duyck567d2de2012-02-11 07:18:57 +00008990 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00008991}
8992
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008993static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008994 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008995{
8996 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00008997 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00008998 bool need_reset = false;
8999
Don Skidmore082757a2011-07-21 05:55:00 +00009000 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009001 if (!(features & NETIF_F_LRO)) {
9002 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00009003 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00009004 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9005 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9006 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9007 if (adapter->rx_itr_setting == 1 ||
9008 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9009 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9010 need_reset = true;
9011 } else if ((changed ^ features) & NETIF_F_LRO) {
9012 e_info(probe, "rx-usecs set too low, "
9013 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00009014 }
9015 }
9016
9017 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08009018 * Check if Flow Director n-tuple support or hw_tc support was
9019 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00009020 */
John Fastabendb82b17d2016-02-16 21:18:53 -08009021 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00009022 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00009023 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9024 need_reset = true;
9025
Alexander Duyck567d2de2012-02-11 07:18:57 +00009026 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9027 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08009028 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00009029 /* turn off perfect filters, enable ATR and reset */
9030 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9031 need_reset = true;
9032
9033 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9034
9035 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08009036 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9037 /* We cannot enable ATR if we have 2 or more tcs */
9038 (netdev_get_num_tc(netdev) > 1) ||
9039 /* We cannot enable ATR if RSS is disabled */
9040 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9041 /* A sample rate of 0 indicates ATR disabled */
9042 (!adapter->atr_sample_rate))
9043 ; /* do nothing not supported */
9044 else /* otherwise supported and set the flag */
9045 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00009046 }
9047
Ben Greear3f2d1c02012-03-08 08:28:41 +00009048 if (changed & NETIF_F_RXALL)
9049 need_reset = true;
9050
Alexander Duyck567d2de2012-02-11 07:18:57 +00009051 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07009052
Mark Rustad67359c32015-06-15 11:33:25 -07009053 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07009054 if (features & NETIF_F_RXCSUM) {
9055 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9056 } else {
9057 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9058
9059 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9060 }
9061 }
9062
9063 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9064 if (features & NETIF_F_RXCSUM) {
9065 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9066 } else {
9067 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9068
9069 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9070 }
Mark Rustad67359c32015-06-15 11:33:25 -07009071 }
Mark Rustad67359c32015-06-15 11:33:25 -07009072
Don Skidmore082757a2011-07-21 05:55:00 +00009073 if (need_reset)
9074 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009075 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9076 NETIF_F_HW_VLAN_CTAG_FILTER))
9077 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00009078
9079 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00009080}
9081
Don Skidmore3f207802014-12-23 07:40:34 +00009082/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009083 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009084 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009085 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009086 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009087static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9088 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009089{
9090 struct ixgbe_adapter *adapter = netdev_priv(dev);
9091 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07009092 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07009093 u32 port_shift = 0;
9094 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07009095
Alexander Duyckb3a49552016-06-16 12:22:19 -07009096 if (ti->sa_family != AF_INET)
9097 return;
9098
Emil Tantilova21d0822016-08-10 11:19:23 -07009099 switch (ti->type) {
9100 case UDP_TUNNEL_TYPE_VXLAN:
9101 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9102 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009103
Emil Tantilova21d0822016-08-10 11:19:23 -07009104 if (adapter->vxlan_port == port)
9105 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009106
Emil Tantilova21d0822016-08-10 11:19:23 -07009107 if (adapter->vxlan_port) {
9108 netdev_info(dev,
9109 "VXLAN port %d set, not adding port %d\n",
9110 ntohs(adapter->vxlan_port),
9111 ntohs(port));
9112 return;
9113 }
9114
9115 adapter->vxlan_port = port;
9116 break;
9117 case UDP_TUNNEL_TYPE_GENEVE:
9118 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9119 return;
9120
9121 if (adapter->geneve_port == port)
9122 return;
9123
9124 if (adapter->geneve_port) {
9125 netdev_info(dev,
9126 "GENEVE port %d set, not adding port %d\n",
9127 ntohs(adapter->geneve_port),
9128 ntohs(port));
9129 return;
9130 }
9131
9132 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9133 adapter->geneve_port = port;
9134 break;
9135 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009136 return;
9137 }
9138
Emil Tantilova21d0822016-08-10 11:19:23 -07009139 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9140 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00009141}
9142
9143/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009144 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009145 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009146 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009147 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009148static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9149 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009150{
9151 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07009152 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00009153
Emil Tantilova21d0822016-08-10 11:19:23 -07009154 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9155 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07009156 return;
9157
9158 if (ti->sa_family != AF_INET)
9159 return;
9160
Emil Tantilova21d0822016-08-10 11:19:23 -07009161 switch (ti->type) {
9162 case UDP_TUNNEL_TYPE_VXLAN:
9163 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9164 return;
Mark Rustad67359c32015-06-15 11:33:25 -07009165
Emil Tantilova21d0822016-08-10 11:19:23 -07009166 if (adapter->vxlan_port != ti->port) {
9167 netdev_info(dev, "VXLAN port %d not found\n",
9168 ntohs(ti->port));
9169 return;
9170 }
9171
9172 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9173 break;
9174 case UDP_TUNNEL_TYPE_GENEVE:
9175 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9176 return;
9177
9178 if (adapter->geneve_port != ti->port) {
9179 netdev_info(dev, "GENEVE port %d not found\n",
9180 ntohs(ti->port));
9181 return;
9182 }
9183
9184 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9185 break;
9186 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009187 return;
9188 }
9189
Emil Tantilova21d0822016-08-10 11:19:23 -07009190 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9191 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00009192}
9193
stephen hemmingeredc7d572012-10-01 12:32:33 +00009194static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009195 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009196 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009197 u16 flags)
9198{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009199 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00009200 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009201 struct ixgbe_adapter *adapter = netdev_priv(dev);
9202 u16 pool = VMDQ_P(0);
9203
9204 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009205 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009206 }
9207
Jiri Pirkof6f64242014-11-28 14:34:15 +01009208 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009209}
9210
Don Skidmore219efe92015-04-09 22:03:22 -07009211/**
9212 * ixgbe_configure_bridge_mode - set various bridge modes
9213 * @adapter - the private structure
9214 * @mode - requested bridge mode
9215 *
9216 * Configure some settings require for various bridge modes.
9217 **/
9218static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9219 __u16 mode)
9220{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009221 struct ixgbe_hw *hw = &adapter->hw;
9222 unsigned int p, num_pools;
9223 u32 vmdctl;
9224
Don Skidmore219efe92015-04-09 22:03:22 -07009225 switch (mode) {
9226 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009227 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009228 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009229
9230 /* must enable Rx switching replication to allow multicast
9231 * packet reception on all VFs, and to enable source address
9232 * pruning.
9233 */
9234 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9235 vmdctl |= IXGBE_VT_CTL_REPLEN;
9236 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9237
9238 /* enable Rx source address pruning. Note, this requires
9239 * replication to be enabled or else it does nothing.
9240 */
9241 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9242 for (p = 0; p < num_pools; p++) {
9243 if (hw->mac.ops.set_source_address_pruning)
9244 hw->mac.ops.set_source_address_pruning(hw,
9245 true,
9246 p);
9247 }
Don Skidmore219efe92015-04-09 22:03:22 -07009248 break;
9249 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009250 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009251 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9252 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009253
9254 /* disable Rx switching replication unless we have SR-IOV
9255 * virtual functions
9256 */
9257 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9258 if (!adapter->num_vfs)
9259 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9260 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9261
9262 /* disable Rx source address pruning, since we don't expect to
9263 * be receiving external loopback of our transmitted frames.
9264 */
9265 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9266 for (p = 0; p < num_pools; p++) {
9267 if (hw->mac.ops.set_source_address_pruning)
9268 hw->mac.ops.set_source_address_pruning(hw,
9269 false,
9270 p);
9271 }
Don Skidmore219efe92015-04-09 22:03:22 -07009272 break;
9273 default:
9274 return -EINVAL;
9275 }
9276
9277 adapter->bridge_mode = mode;
9278
9279 e_info(drv, "enabling bridge mode: %s\n",
9280 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9281
9282 return 0;
9283}
9284
John Fastabend815cccb2012-10-24 08:13:09 +00009285static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009286 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009287{
9288 struct ixgbe_adapter *adapter = netdev_priv(dev);
9289 struct nlattr *attr, *br_spec;
9290 int rem;
9291
9292 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9293 return -EOPNOTSUPP;
9294
9295 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009296 if (!br_spec)
9297 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009298
9299 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009300 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009301 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009302
9303 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9304 continue;
9305
Thomas Grafb7c1a312014-11-26 13:42:17 +01009306 if (nla_len(attr) < sizeof(mode))
9307 return -EINVAL;
9308
John Fastabend815cccb2012-10-24 08:13:09 +00009309 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009310 status = ixgbe_configure_bridge_mode(adapter, mode);
9311 if (status)
9312 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009313
9314 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009315 }
9316
9317 return 0;
9318}
9319
9320static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009321 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009322 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009323{
9324 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009325
9326 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9327 return 0;
9328
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009329 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009330 adapter->bridge_mode, 0, 0, nlflags,
9331 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009332}
9333
John Fastabend2a47fa42013-11-06 09:54:52 -08009334static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9335{
9336 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
9337 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009338 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08009339 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009340 int pool, err;
9341
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009342 /* Hardware has a limited number of available pools. Each VF, and the
9343 * PF require a pool. Check to ensure we don't attempt to use more
9344 * then the available number of pools.
9345 */
9346 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9347 return ERR_PTR(-EINVAL);
9348
John Fastabend219354d2013-11-08 00:50:32 -08009349#ifdef CONFIG_RPS
9350 if (vdev->num_rx_queues != vdev->num_tx_queues) {
9351 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
9352 vdev->name);
9353 return ERR_PTR(-EINVAL);
9354 }
9355#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08009356 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08009357 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08009358 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
9359 netdev_info(pdev,
9360 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
9361 pdev->name);
9362 return ERR_PTR(-EINVAL);
9363 }
9364
9365 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
9366 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
9367 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
9368 return ERR_PTR(-EBUSY);
9369
Maninder Singhbc52f952015-06-19 09:37:55 +05309370 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08009371 if (!fwd_adapter)
9372 return ERR_PTR(-ENOMEM);
9373
9374 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
9375 adapter->num_rx_pools++;
9376 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08009377 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08009378
9379 /* Enable VMDq flag so device will be set in VM mode */
9380 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08009381 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08009382 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08009383
9384 /* Force reinit of ring allocation with VMDQ enabled */
9385 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9386 if (err)
9387 goto fwd_add_err;
9388 fwd_adapter->pool = pool;
9389 fwd_adapter->real_adapter = adapter;
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009390
9391 if (netif_running(pdev)) {
9392 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
9393 if (err)
9394 goto fwd_add_err;
9395 netif_tx_start_all_queues(vdev);
9396 }
9397
John Fastabend2a47fa42013-11-06 09:54:52 -08009398 return fwd_adapter;
9399fwd_add_err:
9400 /* unwind counter and free adapter struct */
9401 netdev_info(pdev,
9402 "%s: dfwd hardware acceleration failed\n", vdev->name);
9403 clear_bit(pool, &adapter->fwd_bitmask);
9404 adapter->num_rx_pools--;
9405 kfree(fwd_adapter);
9406 return ERR_PTR(err);
9407}
9408
9409static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9410{
9411 struct ixgbe_fwd_adapter *fwd_adapter = priv;
9412 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08009413 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009414
9415 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
9416 adapter->num_rx_pools--;
9417
John Fastabend51f37732013-11-08 00:51:10 -08009418 limit = find_last_bit(&adapter->fwd_bitmask, 32);
9419 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009420 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
9421 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9422 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
9423 fwd_adapter->pool, adapter->num_rx_pools,
9424 fwd_adapter->rx_base_queue,
9425 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
9426 adapter->fwd_bitmask);
9427 kfree(fwd_adapter);
9428}
9429
Alexander Duyckb83e3012016-04-14 17:19:31 -04009430#define IXGBE_MAX_MAC_HDR_LEN 127
9431#define IXGBE_MAX_NETWORK_HDR_LEN 511
9432
Mark Rustadf467bc02015-06-15 11:33:20 -07009433static netdev_features_t
9434ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9435 netdev_features_t features)
9436{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009437 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009438
Alexander Duyckb83e3012016-04-14 17:19:31 -04009439 /* Make certain the headers can be described by a context descriptor */
9440 mac_hdr_len = skb_network_header(skb) - skb->data;
9441 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9442 return features & ~(NETIF_F_HW_CSUM |
9443 NETIF_F_SCTP_CRC |
9444 NETIF_F_HW_VLAN_CTAG_TX |
9445 NETIF_F_TSO |
9446 NETIF_F_TSO6);
9447
9448 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9449 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9450 return features & ~(NETIF_F_HW_CSUM |
9451 NETIF_F_SCTP_CRC |
9452 NETIF_F_TSO |
9453 NETIF_F_TSO6);
9454
9455 /* We can only support IPV4 TSO in tunnels if we can mangle the
9456 * inner IP ID field, so strip TSO if MANGLEID is not supported.
9457 */
9458 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
9459 features &= ~NETIF_F_TSO;
Mark Rustadf467bc02015-06-15 11:33:20 -07009460
9461 return features;
9462}
9463
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009464static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00009465 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009466 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08009467 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07009468 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00009469 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009470 .ndo_validate_addr = eth_validate_addr,
9471 .ndo_set_mac_address = ixgbe_set_mac,
9472 .ndo_change_mtu = ixgbe_change_mtu,
9473 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00009474 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009475 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
9476 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00009477 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00009478 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
9479 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04009480 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00009481 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03009482 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +00009483 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +00009484 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00009485 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -08009486 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009487#ifdef CONFIG_NET_POLL_CONTROLLER
9488 .ndo_poll_controller = ixgbe_netpoll,
9489#endif
Yi Zou332d4a72009-05-13 13:11:53 +00009490#ifdef IXGBE_FCOE
9491 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00009492 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00009493 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00009494 .ndo_fcoe_enable = ixgbe_fcoe_enable,
9495 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00009496 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00009497 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00009498#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00009499 .ndo_set_features = ixgbe_set_features,
9500 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009501 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00009502 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
9503 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08009504 .ndo_dfwd_add_station = ixgbe_fwd_add,
9505 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -07009506 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
9507 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -07009508 .ndo_features_check = ixgbe_features_check,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009509};
9510
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009511/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00009512 * ixgbe_enumerate_functions - Get the number of ports this device has
9513 * @adapter: adapter structure
9514 *
9515 * This function enumerates the phsyical functions co-located on a single slot,
9516 * in order to determine how many ports a device has. This is most useful in
9517 * determining the required GT/s of PCIe bandwidth necessary for optimal
9518 * performance.
9519 **/
9520static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
9521{
Jacob Kellercaafb952014-07-19 07:17:17 +00009522 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009523 int physfns = 0;
9524
Jacob Kellerf1f96572013-08-31 02:45:38 +00009525 /* Some cards can not use the generic count PCIe functions method,
9526 * because they are behind a parent switch, so we hardcode these with
9527 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00009528 */
Jacob Keller88189702014-07-19 07:17:16 +00009529 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00009530 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00009531
9532 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
9533 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00009534 if (entry->is_virtfn)
9535 continue;
9536
9537 /* When the devices on the bus don't all match our device ID,
9538 * we can't reliably determine the correct number of
9539 * functions. This can occur if a function has been direct
9540 * attached to a virtual machine using VT-d, for example. In
9541 * this case, simply return -1 to indicate this.
9542 */
9543 if ((entry->vendor != pdev->vendor) ||
9544 (entry->device != pdev->device))
9545 return -1;
9546
9547 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009548 }
9549
9550 return physfns;
9551}
9552
9553/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00009554 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -07009555 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +00009556 * @device_id: the device ID
9557 * @subdev_id: the subsystem device ID
9558 *
9559 * This function is used by probe and ethtool to determine
9560 * which devices have WoL support
9561 *
9562 **/
Emil Tantilov740234f2016-04-21 11:37:12 -07009563bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
9564 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +00009565{
9566 struct ixgbe_hw *hw = &adapter->hw;
9567 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009568
Emil Tantilov740234f2016-04-21 11:37:12 -07009569 /* WOL not supported on 82598 */
9570 if (hw->mac.type == ixgbe_mac_82598EB)
9571 return false;
9572
9573 /* check eeprom to see if WOL is enabled for X540 and newer */
9574 if (hw->mac.type >= ixgbe_mac_X540) {
9575 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
9576 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
9577 (hw->bus.func == 0)))
9578 return true;
9579 }
9580
9581 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +00009582 switch (device_id) {
9583 case IXGBE_DEV_ID_82599_SFP:
9584 /* Only these subdevices could supports WOL */
9585 switch (subdevice_id) {
9586 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009587 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
9588 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
9589 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009590 /* only support first port */
9591 if (hw->bus.func != 0)
9592 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00009593 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009594 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00009595 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00009596 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009597 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
9598 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
9599 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -07009600 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009601 }
9602 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009603 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -07009604 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +00009605 switch (subdevice_id) {
9606 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -07009607 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009608 }
9609 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009610 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
9611 /* All except this subdevice support WOL */
9612 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -07009613 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009614 break;
9615 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -07009616 return true;
9617 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009618 break;
9619 }
9620
Emil Tantilov740234f2016-04-21 11:37:12 -07009621 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009622}
9623
9624/**
Auke Kok9a799d72007-09-15 14:07:45 -07009625 * ixgbe_probe - Device Initialization Routine
9626 * @pdev: PCI device information struct
9627 * @ent: entry in ixgbe_pci_tbl
9628 *
9629 * Returns 0 on success, negative on failure
9630 *
9631 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
9632 * The OS initialization, configuring of the adapter private structure,
9633 * and a hardware reset occur.
9634 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00009635static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07009636{
9637 struct net_device *netdev;
9638 struct ixgbe_adapter *adapter = NULL;
9639 struct ixgbe_hw *hw;
9640 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +00009641 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009642 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00009643 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009644 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +00009645#ifdef IXGBE_FCOE
9646 u16 device_caps;
9647#endif
Don Skidmore289700db2010-12-03 03:32:58 +00009648 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07009649
Andy Gospodarekbded64a2010-07-21 06:40:31 +00009650 /* Catch broken hardware that put the wrong VF device ID in
9651 * the PCIe SR-IOV capability.
9652 */
9653 if (pdev->is_virtfn) {
9654 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
9655 pci_name(pdev), pdev->vendor, pdev->device);
9656 return -EINVAL;
9657 }
9658
gouji-new9ce77662009-05-06 10:44:45 +00009659 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009660 if (err)
9661 return err;
9662
Russell Kingf5f2eda2013-06-10 12:47:42 +01009663 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07009664 pci_using_dac = 1;
9665 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009666 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07009667 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009668 dev_err(&pdev->dev,
9669 "No usable DMA configuration, aborting\n");
9670 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07009671 }
9672 pci_using_dac = 0;
9673 }
9674
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02009675 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07009676 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00009677 dev_err(&pdev->dev,
9678 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07009679 goto err_pci_reg;
9680 }
9681
Frans Pop19d5afd2009-10-02 10:04:12 -07009682 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009683
Auke Kok9a799d72007-09-15 14:07:45 -07009684 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07009685 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009686
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009687 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00009688#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009689 /* 8 TC w/ 4 queues per TC */
9690 indices = 4 * MAX_TRAFFIC_CLASS;
9691#else
9692 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00009693#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009694 }
John Fastabende901acd2011-04-26 07:26:08 +00009695
John Fastabendc85a2612010-02-25 23:15:21 +00009696 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07009697 if (!netdev) {
9698 err = -ENOMEM;
9699 goto err_alloc_etherdev;
9700 }
9701
Auke Kok9a799d72007-09-15 14:07:45 -07009702 SET_NETDEV_DEV(netdev, &pdev->dev);
9703
Auke Kok9a799d72007-09-15 14:07:45 -07009704 adapter = netdev_priv(netdev);
9705
9706 adapter->netdev = netdev;
9707 adapter->pdev = pdev;
9708 hw = &adapter->hw;
9709 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00009710 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07009711
Jeff Kirsher05857982008-09-11 19:57:00 -07009712 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00009713 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08009714 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07009715 if (!hw->hw_addr) {
9716 err = -EIO;
9717 goto err_ioremap;
9718 }
9719
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009720 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009721 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009722 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +00009723 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -07009724
Auke Kok9a799d72007-09-15 14:07:45 -07009725 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -08009726 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009727 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009728 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -07009729 if (ii->link_ops)
9730 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009731
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009732 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -08009733 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009734 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +00009735 if (ixgbe_removed(hw->hw_addr)) {
9736 err = -EIO;
9737 goto err_ioremap;
9738 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009739 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07009740 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009741 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
9742
9743 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -08009744 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009745 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00009746 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
9747 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
9748 hw->phy.mdio.mmds = 0;
9749 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9750 hw->phy.mdio.dev = netdev;
9751 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
9752 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009753
Auke Kok9a799d72007-09-15 14:07:45 -07009754 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -07009755 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -07009756 if (err)
9757 goto err_sw_init;
9758
Don Skidmoredbd15b82016-03-09 16:45:00 -05009759 /* Make sure the SWFW semaphore is in a valid state */
9760 if (hw->mac.ops.init_swfw_sync)
9761 hw->mac.ops.init_swfw_sync(hw);
9762
Don Skidmoree86bff02010-02-11 04:14:08 +00009763 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08009764 switch (adapter->hw.mac.type) {
9765 case ixgbe_mac_82599EB:
9766 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00009767 case ixgbe_mac_X550:
9768 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07009769 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +00009770 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08009771 break;
9772 default:
9773 break;
9774 }
Don Skidmoree86bff02010-02-11 04:14:08 +00009775
Don Skidmorebf069c92009-05-07 10:39:54 +00009776 /*
9777 * If there is a fan on this device and it has failed log the
9778 * failure.
9779 */
9780 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
9781 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
9782 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00009783 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00009784 }
9785
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00009786 if (allow_unsupported_sfp)
9787 hw->allow_unsupported_sfp = allow_unsupported_sfp;
9788
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009789 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009790 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009791 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009792 hw->phy.reset_if_overtemp = false;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08009793 ixgbe_set_eee_capable(adapter);
Mark Rustad29a8dca2015-08-08 16:17:46 -07009794 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07009795 err = 0;
9796 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00009797 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
9798 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009799 goto err_sw_init;
9800 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009801 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009802 goto err_sw_init;
9803 }
9804
Alexander Duyck99d74482012-05-09 08:09:25 +00009805#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00009806 /* SR-IOV not supported on the 82598 */
9807 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
9808 goto skip_sriov;
9809 /* Mailbox */
9810 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -08009811 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -08009812 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ethan.zhao31ac9102014-01-16 19:41:05 -08009813 ixgbe_enable_sriov(adapter);
Greg Rose60a1a682012-12-11 08:26:33 +00009814skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009815
Alexander Duyck99d74482012-05-09 08:09:25 +00009816#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00009817 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +00009818 NETIF_F_TSO |
9819 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00009820 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -08009821 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -04009822 NETIF_F_HW_CSUM;
9823
9824#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
9825 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -07009826 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -07009827 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -04009828 NETIF_F_GSO_UDP_TUNNEL | \
9829 NETIF_F_GSO_UDP_TUNNEL_CSUM)
9830
9831 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
9832 netdev->features |= NETIF_F_GSO_PARTIAL |
9833 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -07009834
Alexander Duyck49763de2016-01-13 07:31:11 -08009835 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -08009836 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00009837
Alexander Duyck49763de2016-01-13 07:31:11 -08009838 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -04009839 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -07009840 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -04009841 NETIF_F_HW_VLAN_CTAG_RX |
9842 NETIF_F_HW_VLAN_CTAG_TX |
9843 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -08009844 NETIF_F_HW_L2FW_DOFFLOAD;
9845
9846 if (hw->mac.type >= ixgbe_mac_82599EB)
9847 netdev->hw_features |= NETIF_F_NTUPLE |
9848 NETIF_F_HW_TC;
9849
Alexander Duyckb83e3012016-04-14 17:19:31 -04009850 if (pci_using_dac)
9851 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -07009852
Alexander Duyck5eee87c2016-05-11 13:23:34 -07009853 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
9854 netdev->hw_enc_features |= netdev->vlan_features;
9855 netdev->mpls_features |= NETIF_F_HW_CSUM;
9856
Alexander Duyckb83e3012016-04-14 17:19:31 -04009857 /* set this bit last since it cannot be part of vlan_features */
9858 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
9859 NETIF_F_HW_VLAN_CTAG_RX |
9860 NETIF_F_HW_VLAN_CTAG_TX;
9861
Jiri Pirko01789342011-08-16 06:29:00 +00009862 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00009863 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00009864
Jarod Wilson91c527a2016-10-17 15:54:05 -04009865 /* MTU range: 68 - 9710 */
9866 netdev->min_mtu = ETH_MIN_MTU;
9867 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
9868
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08009869#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07009870 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
Stephen Hemminger3f40c742016-11-21 09:52:40 -08009871 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -08009872#endif
9873
Yi Zoueacd73f2009-05-13 13:11:06 +00009874#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00009875 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009876 unsigned int fcoe_l;
9877
Yi Zoueacd73f2009-05-13 13:11:06 +00009878 if (hw->mac.ops.get_device_caps) {
9879 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00009880 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
9881 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00009882 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009883
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009884
9885 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
9886 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009887
Alexander Duycka58915c2012-05-25 06:38:18 +00009888 netdev->features |= NETIF_F_FSO |
9889 NETIF_F_FCOE_CRC;
9890
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009891 netdev->vlan_features |= NETIF_F_FSO |
9892 NETIF_F_FCOE_CRC |
9893 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00009894 }
Yi Zoueacd73f2009-05-13 13:11:06 +00009895#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07009896
Don Skidmore082757a2011-07-21 05:55:00 +00009897 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
9898 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00009899 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00009900 netdev->features |= NETIF_F_LRO;
9901
Auke Kok9a799d72007-09-15 14:07:45 -07009902 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009903 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009904 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009905 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009906 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009907 }
9908
Sowmini Varadhanc7374b52016-01-12 19:32:30 -08009909 eth_platform_get_mac_address(&adapter->pdev->dev,
9910 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +00009911
Auke Kok9a799d72007-09-15 14:07:45 -07009912 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07009913
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00009914 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009915 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009916 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009917 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009918 }
9919
Tushar Dave56768042016-01-07 14:17:03 -08009920 /* Set hw->mac.addr to permanent MAC address */
9921 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07009922 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +00009923
Alexander Duyck70864002011-04-27 09:13:56 +00009924 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00009925 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009926
Mark Rustad58cf6632014-03-12 00:38:40 +00009927 if (ixgbe_removed(hw->hw_addr)) {
9928 err = -EIO;
9929 goto err_sw_init;
9930 }
Alexander Duyck70864002011-04-27 09:13:56 +00009931 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +00009932 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00009933 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009934
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009935 err = ixgbe_init_interrupt_scheme(adapter);
9936 if (err)
9937 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009938
Jacob Keller8e2813f2012-04-21 06:05:40 +00009939 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009940 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009941 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009942 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00009943 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009944 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00009945 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009946
PJ Waskiewicze8e26352009-02-27 15:45:05 +00009947 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
9948
Emil Tantilov15e52092011-09-29 05:01:29 +00009949 /* save off EEPROM version number */
9950 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
9951 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
9952
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009953 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +00009954 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00009955 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -04009956 else
9957 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009958
Jacob Kellere027d1a2013-07-31 06:53:31 +00009959 /* calculate the expected PCIe bandwidth required for optimal
9960 * performance. Note that some older parts will never have enough
9961 * bandwidth due to being older generation PCIe parts. We clamp these
9962 * parts to ensure no warning is displayed if it can't be fixed.
9963 */
9964 switch (hw->mac.type) {
9965 case ixgbe_mac_82598EB:
9966 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
9967 break;
9968 default:
9969 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
9970 break;
Auke Kok0c254d82008-02-11 09:25:56 -08009971 }
Jacob Kellercaafb952014-07-19 07:17:17 +00009972
9973 /* don't check link if we failed to enumerate functions */
9974 if (expected_gts > 0)
9975 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08009976
Mark Rustad339de302014-06-06 01:57:06 +00009977 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009978 if (err)
Mark Rustad339de302014-06-06 01:57:06 +00009979 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009980 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
9981 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
9982 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +00009983 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +00009984 else
9985 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
9986 hw->mac.type, hw->phy.type, part_str);
9987
9988 e_dev_info("%pM\n", netdev->dev_addr);
9989
Auke Kok9a799d72007-09-15 14:07:45 -07009990 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009991 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009992 if (err == IXGBE_ERR_EEPROM_VERSION) {
9993 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00009994 e_dev_warn("This device is a pre-production adapter/LOM. "
9995 "Please be aware there may be issues associated "
9996 "with your hardware. If you are experiencing "
9997 "problems please contact your Intel or hardware "
9998 "representative who provided you with this "
9999 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010000 }
Auke Kok9a799d72007-09-15 14:07:45 -070010001 strcpy(netdev->name, "eth%d");
10002 err = register_netdev(netdev);
10003 if (err)
10004 goto err_register;
10005
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010006 pci_set_drvdata(pdev, adapter);
10007
Emil Tantilovec74a472012-09-20 03:33:56 +000010008 /* power down the optics for 82599 SFP+ fiber */
10009 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +000010010 hw->mac.ops.disable_tx_laser(hw);
10011
Jesse Brandeburg54386462009-04-17 20:44:27 +000010012 /* carrier off reporting is important to ethtool even BEFORE open */
10013 netif_carrier_off(netdev);
10014
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010015#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +030010016 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010017 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010018 ixgbe_setup_dca(adapter);
10019 }
10020#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010021 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010022 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010023 for (i = 0; i < adapter->num_vfs; i++)
10024 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10025 }
10026
Jacob Keller2466dd92011-09-08 03:50:54 +000010027 /* firmware requires driver version to be 0xFFFFFFFF
10028 * since os does not support feature
10029 */
Emil Tantilov9612de92011-05-07 07:40:20 +000010030 if (hw->mac.ops.set_fw_drv_ver)
Tony Nguyencb8e0512016-10-26 16:25:18 -070010031 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10032 sizeof(ixgbe_driver_version) - 1,
10033 ixgbe_driver_version);
Emil Tantilov9612de92011-05-07 07:40:20 +000010034
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010035 /* add san mac addr to netdev */
10036 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010037
Neerav Parikhea818752012-01-04 20:23:40 +000010038 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010039
Don Skidmore12109822012-05-04 06:07:08 +000010040#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010041 if (ixgbe_sysfs_init(adapter))
10042 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +000010043#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010044
Catherine Sullivan00949162012-08-10 01:59:10 +000010045 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010046
Emil Tantilovd1a35ee2014-05-13 08:24:00 +000010047 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10048 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +000010049 hw->mac.ops.setup_link(hw,
10050 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10051 true);
10052
Auke Kok9a799d72007-09-15 14:07:45 -070010053 return 0;
10054
10055err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010056 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010057 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010058err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +000010059 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +000010060 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -080010061 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010062 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010063 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -070010064err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010065 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010066 free_netdev(netdev);
10067err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010068 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010069err_pci_reg:
10070err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010071 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010072 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010073 return err;
10074}
10075
10076/**
10077 * ixgbe_remove - Device Removal Routine
10078 * @pdev: PCI device information struct
10079 *
10080 * ixgbe_remove is called by the PCI subsystem to alert the driver
10081 * that it should release a PCI device. The could be caused by a
10082 * Hot-Plug event, or because the driver is going to be removed from
10083 * memory.
10084 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010085static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -070010086{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010087 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010088 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010089 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010090 int i;
Auke Kok9a799d72007-09-15 14:07:45 -070010091
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010092 /* if !adapter then we already cleaned up in probe */
10093 if (!adapter)
10094 return;
10095
10096 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +000010097 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010098
Mark Rustad09f40ae2014-01-14 18:53:11 -080010099 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010100 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -070010101
Jacob Keller3a6a4ed2012-05-01 05:24:58 +000010102
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010103#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010104 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10105 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10106 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -070010107 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10108 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010109 }
10110
10111#endif
Don Skidmore12109822012-05-04 06:07:08 +000010112#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010113 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +000010114#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010115
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010116 /* remove the added san mac */
10117 ixgbe_del_sanmac_netdev(netdev);
10118
Greg Roseda36b642012-12-11 08:26:43 +000010119#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -060010120 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +000010121#endif
Alex Williamson6b010e92015-07-29 14:38:21 -060010122 if (netdev->reg_state == NETREG_REGISTERED)
10123 unregister_netdev(netdev);
10124
Alexander Duyck7a921c92009-05-06 10:43:28 +000010125 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010126
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010127 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010128
Alexander Duyck2b1588c2012-03-17 02:39:16 +000010129#ifdef CONFIG_DCB
10130 kfree(adapter->ixgbe_ieee_pfc);
10131 kfree(adapter->ixgbe_ieee_ets);
10132
10133#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -080010134 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010135 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010136
Emil Tantilov849c4542010-06-03 16:53:41 +000010137 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010138
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010139 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
10140 if (adapter->jump_tables[i]) {
10141 kfree(adapter->jump_tables[i]->input);
10142 kfree(adapter->jump_tables[i]->mask);
10143 }
10144 kfree(adapter->jump_tables[i]);
10145 }
10146
Jacob Keller5d7daa32014-03-29 06:51:25 +000010147 kfree(adapter->mac_table);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010148 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010149 free_netdev(netdev);
10150
Frans Pop19d5afd2009-10-02 10:04:12 -070010151 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010152
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010153 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010154 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010155}
10156
10157/**
10158 * ixgbe_io_error_detected - called when PCI error is detected
10159 * @pdev: Pointer to PCI device
10160 * @state: The current pci connection state
10161 *
10162 * This function is called after a PCI bus error affecting
10163 * this device has been detected.
10164 */
10165static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +000010166 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -070010167{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010168 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10169 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010170
Greg Rose83c61fa2011-09-07 05:59:35 +000010171#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -080010172 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +000010173 struct pci_dev *bdev, *vfdev;
10174 u32 dw0, dw1, dw2, dw3;
10175 int vf, pos;
10176 u16 req_id, pf_func;
10177
10178 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
10179 adapter->num_vfs == 0)
10180 goto skip_bad_vf_detection;
10181
10182 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +080010183 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +000010184 bdev = bdev->bus->self;
10185
10186 if (!bdev)
10187 goto skip_bad_vf_detection;
10188
10189 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
10190 if (!pos)
10191 goto skip_bad_vf_detection;
10192
Mark Rustad14438462014-02-28 15:48:57 -080010193 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
10194 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
10195 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
10196 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
10197 if (ixgbe_removed(hw->hw_addr))
10198 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +000010199
10200 req_id = dw1 >> 16;
10201 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10202 if (!(req_id & 0x0080))
10203 goto skip_bad_vf_detection;
10204
10205 pf_func = req_id & 0x01;
10206 if ((pf_func & 1) == (pdev->devfn & 1)) {
10207 unsigned int device_id;
10208
10209 vf = (req_id & 0x7F) >> 1;
10210 e_dev_err("VF %d has caused a PCIe error\n", vf);
10211 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10212 "%8.8x\tdw3: %8.8x\n",
10213 dw0, dw1, dw2, dw3);
10214 switch (adapter->hw.mac.type) {
10215 case ixgbe_mac_82599EB:
10216 device_id = IXGBE_82599_VF_DEVICE_ID;
10217 break;
10218 case ixgbe_mac_X540:
10219 device_id = IXGBE_X540_VF_DEVICE_ID;
10220 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010221 case ixgbe_mac_X550:
10222 device_id = IXGBE_DEV_ID_X550_VF;
10223 break;
10224 case ixgbe_mac_X550EM_x:
10225 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10226 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010227 case ixgbe_mac_x550em_a:
10228 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10229 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010230 default:
10231 device_id = 0;
10232 break;
10233 }
10234
10235 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010236 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010237 while (vfdev) {
10238 if (vfdev->devfn == (req_id & 0xFF))
10239 break;
Jon Mason36e90312012-07-19 21:02:09 +000010240 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010241 device_id, vfdev);
10242 }
10243 /*
10244 * There's a slim chance the VF could have been hot plugged,
10245 * so if it is no longer present we don't need to issue the
10246 * VFLR. Just clean up the AER in that case.
10247 */
10248 if (vfdev) {
Emil Tantilov9079e412014-11-19 03:18:19 +000010249 ixgbe_issue_vf_flr(adapter, vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010250 /* Free device reference count */
10251 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010252 }
10253
10254 pci_cleanup_aer_uncorrect_error_status(pdev);
10255 }
10256
10257 /*
10258 * Even though the error may have occurred on the other port
10259 * we still need to increment the vf error reference count for
10260 * both ports because the I/O resume function will be called
10261 * for both of them.
10262 */
10263 adapter->vferr_refcount++;
10264
10265 return PCI_ERS_RESULT_RECOVERED;
10266
10267skip_bad_vf_detection:
10268#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010269 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10270 return PCI_ERS_RESULT_DISCONNECT;
10271
Mark Rustad41c62842014-03-12 00:38:35 +000010272 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010273 netif_device_detach(netdev);
10274
Mark Rustad41c62842014-03-12 00:38:35 +000010275 if (state == pci_channel_io_perm_failure) {
10276 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010277 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010278 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010279
Auke Kok9a799d72007-09-15 14:07:45 -070010280 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010281 ixgbe_close_suspend(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +000010282
10283 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10284 pci_disable_device(pdev);
10285 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010286
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010287 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010288 return PCI_ERS_RESULT_NEED_RESET;
10289}
10290
10291/**
10292 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10293 * @pdev: Pointer to PCI device
10294 *
10295 * Restart the card from scratch, as if from a cold-boot.
10296 */
10297static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10298{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010299 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010300 pci_ers_result_t result;
10301 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010302
gouji-new9ce77662009-05-06 10:44:45 +000010303 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010304 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010305 result = PCI_ERS_RESULT_DISCONNECT;
10306 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010307 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010308 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010309 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010310 pci_set_master(pdev);
10311 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010312 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010313
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010314 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010315
10316 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010317 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010318 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010319 }
Auke Kok9a799d72007-09-15 14:07:45 -070010320
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010321 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10322 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010323 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10324 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010325 /* non-fatal, continue */
10326 }
Auke Kok9a799d72007-09-15 14:07:45 -070010327
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010328 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010329}
10330
10331/**
10332 * ixgbe_io_resume - called when traffic can start flowing again.
10333 * @pdev: Pointer to PCI device
10334 *
10335 * This callback is called when the error recovery driver tells us that
10336 * its OK to resume normal operation.
10337 */
10338static void ixgbe_io_resume(struct pci_dev *pdev)
10339{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010340 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10341 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010342
Greg Rose83c61fa2011-09-07 05:59:35 +000010343#ifdef CONFIG_PCI_IOV
10344 if (adapter->vferr_refcount) {
10345 e_info(drv, "Resuming after VF err\n");
10346 adapter->vferr_refcount--;
10347 return;
10348 }
10349
10350#endif
Emil Tantilov126db132016-11-16 09:48:02 -080010351 rtnl_lock();
Alexander Duyckc7ccde02011-07-21 00:40:40 +000010352 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010353 ixgbe_open(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010354
10355 netif_device_attach(netdev);
Emil Tantilov126db132016-11-16 09:48:02 -080010356 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010357}
10358
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070010359static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070010360 .error_detected = ixgbe_io_error_detected,
10361 .slot_reset = ixgbe_io_slot_reset,
10362 .resume = ixgbe_io_resume,
10363};
10364
10365static struct pci_driver ixgbe_driver = {
10366 .name = ixgbe_driver_name,
10367 .id_table = ixgbe_pci_tbl,
10368 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010369 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070010370#ifdef CONFIG_PM
10371 .suspend = ixgbe_suspend,
10372 .resume = ixgbe_resume,
10373#endif
10374 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000010375 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070010376 .err_handler = &ixgbe_err_handler
10377};
10378
10379/**
10380 * ixgbe_init_module - Driver Registration Routine
10381 *
10382 * ixgbe_init_module is the first routine called when the driver is
10383 * loaded. All it does is register with the PCI subsystem.
10384 **/
10385static int __init ixgbe_init_module(void)
10386{
10387 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000010388 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000010389 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070010390
Mark Rustad780484d2015-10-21 17:21:10 -070010391 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
10392 if (!ixgbe_wq) {
10393 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
10394 return -ENOMEM;
10395 }
10396
Catherine Sullivan00949162012-08-10 01:59:10 +000010397 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000010398
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010399 ret = pci_register_driver(&ixgbe_driver);
10400 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000010401 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010402 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010403 return ret;
10404 }
10405
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010406#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010407 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010408#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010409
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010410 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070010411}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010412
Auke Kok9a799d72007-09-15 14:07:45 -070010413module_init(ixgbe_init_module);
10414
10415/**
10416 * ixgbe_exit_module - Driver Exit Cleanup Routine
10417 *
10418 * ixgbe_exit_module is called just before the driver is removed
10419 * from memory.
10420 **/
10421static void __exit ixgbe_exit_module(void)
10422{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010423#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010424 dca_unregister_notify(&dca_notifier);
10425#endif
Auke Kok9a799d72007-09-15 14:07:45 -070010426 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000010427
Catherine Sullivan00949162012-08-10 01:59:10 +000010428 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070010429 if (ixgbe_wq) {
10430 destroy_workqueue(ixgbe_wq);
10431 ixgbe_wq = NULL;
10432 }
Auke Kok9a799d72007-09-15 14:07:45 -070010433}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010434
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010435#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010436static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010437 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010438{
10439 int ret_val;
10440
10441 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010442 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010443
10444 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
10445}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010446
Alexander Duyckb4533682009-03-31 21:32:42 +000010447#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000010448
Auke Kok9a799d72007-09-15 14:07:45 -070010449module_exit(ixgbe_exit_module);
10450
10451/* ixgbe_main.c */