blob: 2436984481ccb5329e6b7d10ec8c5f48c8cd68be [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 Rustad10ef00f2016-04-01 12:18:51 -070075#define DRV_VERSION "4.4.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,
Auke Kok9a799d72007-09-15 14:07:45 -070089};
90
91/* ixgbe_pci_tbl - PCI Device ID Table
92 *
93 * Wildcard entries (PCI_ANY_ID) should come last
94 * Last entry must be all 0s
95 *
96 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
97 * Class, Class Mask, private data (not used) }
98 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020099static const struct pci_device_id ixgbe_pci_tbl[] = {
Alexander Duyck54239c62011-07-15 03:06:06 +0000100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Don Skidmore8f583322013-07-27 06:25:38 +0000126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Don Skidmore6a14ee02014-12-05 03:59:50 +0000130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
Mark Rustada711ad82016-03-21 11:21:31 -0700131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
Don Skidmore6a14ee02014-12-05 03:59:50 +0000132 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
133 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
Don Skidmorededa5622015-06-09 17:39:46 -0700134 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
Mark Rustad018d7142015-08-08 16:19:19 -0700135 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
Mark Rustadf572b2c2016-04-01 12:18:46 -0700136 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
137 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
Mark Rustad49425df2016-04-01 12:18:09 -0700138 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
Mark Rustad200157c2016-04-01 12:18:40 -0700139 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
140 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
Don Skidmore92ed8432016-08-17 20:34:40 -0400141 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
Mark Rustad2d40cd12016-04-01 12:18:35 -0700142 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
Auke Kok9a799d72007-09-15 14:07:45 -0700143 /* required last entry */
144 {0, }
145};
146MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
147
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400148#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800149static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000150 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800151static struct notifier_block dca_notifier = {
152 .notifier_call = ixgbe_notify_dca,
153 .next = NULL,
154 .priority = 0
155};
156#endif
157
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000158#ifdef CONFIG_PCI_IOV
159static unsigned int max_vfs;
160module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000161MODULE_PARM_DESC(max_vfs,
Jacob Keller170e8542013-11-09 04:52:32 -0800162 "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 +0000163#endif /* CONFIG_PCI_IOV */
164
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000165static unsigned int allow_unsupported_sfp;
166module_param(allow_unsupported_sfp, uint, 0);
167MODULE_PARM_DESC(allow_unsupported_sfp,
168 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
169
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000170#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
171static int debug = -1;
172module_param(debug, int, 0);
173MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
174
Auke Kok9a799d72007-09-15 14:07:45 -0700175MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
176MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
177MODULE_LICENSE("GPL");
178MODULE_VERSION(DRV_VERSION);
179
Mark Rustad780484d2015-10-21 17:21:10 -0700180static struct workqueue_struct *ixgbe_wq;
181
Mark Rustad14438462014-02-28 15:48:57 -0800182static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
183
Jacob Kellerb8e82002013-04-09 07:20:09 +0000184static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
185 u32 reg, u16 *value)
186{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000187 struct pci_dev *parent_dev;
188 struct pci_bus *parent_bus;
189
190 parent_bus = adapter->pdev->bus->parent;
191 if (!parent_bus)
192 return -1;
193
194 parent_dev = parent_bus->self;
195 if (!parent_dev)
196 return -1;
197
Yijing Wangc0798ed2013-09-04 17:30:08 +0000198 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000199 return -1;
200
Yijing Wangc0798ed2013-09-04 17:30:08 +0000201 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800202 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
203 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
204 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000205 return 0;
206}
207
208static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
209{
210 struct ixgbe_hw *hw = &adapter->hw;
211 u16 link_status = 0;
212 int err;
213
214 hw->bus.type = ixgbe_bus_type_pci_express;
215
216 /* Get the negotiated link width and speed from PCI config space of the
217 * parent, as this device is behind a switch
218 */
219 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
220
221 /* assume caller will handle error case */
222 if (err)
223 return err;
224
225 hw->bus.width = ixgbe_convert_bus_width(link_status);
226 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
227
228 return 0;
229}
230
Jacob Kellere027d1a2013-07-31 06:53:31 +0000231/**
232 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
233 * @hw: hw specific details
234 *
235 * This function is used by probe to determine whether a device's PCI-Express
236 * bandwidth details should be gathered from the parent bus instead of from the
237 * device. Used to ensure that various locations all have the correct device ID
238 * checks.
239 */
240static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
241{
242 switch (hw->device_id) {
243 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000244 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000245 return true;
246 default:
247 return false;
248 }
249}
250
251static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
252 int expected_gts)
253{
Don Skidmoref9328bc2015-06-18 13:24:06 -0400254 struct ixgbe_hw *hw = &adapter->hw;
Jacob Kellere027d1a2013-07-31 06:53:31 +0000255 int max_gts = 0;
256 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
257 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
258 struct pci_dev *pdev;
259
Don Skidmoref9328bc2015-06-18 13:24:06 -0400260 /* Some devices are not connected over PCIe and thus do not negotiate
261 * speed. These devices do not have valid bus info, and thus any report
262 * we generate may not be correct.
263 */
264 if (hw->bus.type == ixgbe_bus_type_internal)
265 return;
266
Jacob Keller56d13922015-06-10 11:44:45 -0700267 /* determine whether to use the parent device */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000268 if (ixgbe_pcie_from_parent(&adapter->hw))
269 pdev = adapter->pdev->bus->parent->self;
270 else
271 pdev = adapter->pdev;
272
273 if (pcie_get_minimum_link(pdev, &speed, &width) ||
274 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
275 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
276 return;
277 }
278
279 switch (speed) {
280 case PCIE_SPEED_2_5GT:
281 /* 8b/10b encoding reduces max throughput by 20% */
282 max_gts = 2 * width;
283 break;
284 case PCIE_SPEED_5_0GT:
285 /* 8b/10b encoding reduces max throughput by 20% */
286 max_gts = 4 * width;
287 break;
288 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000289 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000290 max_gts = 8 * width;
291 break;
292 default:
293 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
294 return;
295 }
296
297 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
298 max_gts);
299 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
300 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
301 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
302 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
303 "Unknown"),
304 width,
305 (speed == PCIE_SPEED_2_5GT ? "20%" :
306 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000307 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000308 "Unknown"));
309
310 if (max_gts < expected_gts) {
311 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
312 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
313 expected_gts);
314 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
315 }
316}
317
Alexander Duyck70864002011-04-27 09:13:56 +0000318static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
319{
320 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800321 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000322 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
Mark Rustad780484d2015-10-21 17:21:10 -0700323 queue_work(ixgbe_wq, &adapter->service_task);
Alexander Duyck70864002011-04-27 09:13:56 +0000324}
325
Mark Rustad2a1a0912014-01-14 18:53:15 -0800326static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
327{
328 struct ixgbe_adapter *adapter = hw->back;
329
330 if (!hw->hw_addr)
331 return;
332 hw->hw_addr = NULL;
333 e_dev_err("Adapter removed\n");
Mark Rustad58cf6632014-03-12 00:38:40 +0000334 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
335 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800336}
337
Mark Rustadf8e24722014-03-18 07:03:40 +0000338static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800339{
340 u32 value;
341
342 /* The following check not only optimizes a bit by not
343 * performing a read on the status register when the
344 * register just read was a status register read that
345 * returned IXGBE_FAILED_READ_REG. It also blocks any
346 * potential recursion.
347 */
348 if (reg == IXGBE_STATUS) {
349 ixgbe_remove_adapter(hw);
350 return;
351 }
352 value = ixgbe_read_reg(hw, IXGBE_STATUS);
353 if (value == IXGBE_FAILED_READ_REG)
354 ixgbe_remove_adapter(hw);
355}
356
Mark Rustadf8e24722014-03-18 07:03:40 +0000357/**
358 * ixgbe_read_reg - Read from device register
359 * @hw: hw specific details
360 * @reg: offset of register to read
361 *
362 * Returns : value read or IXGBE_FAILED_READ_REG if removed
363 *
364 * This function is used to read device registers. It checks for device
365 * removal by confirming any read that returns all ones by checking the
366 * status register value for all ones. This function avoids reading from
367 * the hardware if a removal was previously detected in which case it
368 * returns IXGBE_FAILED_READ_REG (all ones).
369 */
370u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
371{
372 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
373 u32 value;
374
375 if (ixgbe_removed(reg_addr))
376 return IXGBE_FAILED_READ_REG;
Mark Rustad2f2219b2016-04-07 10:43:50 -0700377 if (unlikely(hw->phy.nw_mng_if_sel &
378 IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) {
379 struct ixgbe_adapter *adapter;
380 int i;
381
382 for (i = 0; i < 200; ++i) {
383 value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
384 if (likely(!value))
385 goto writes_completed;
386 if (value == IXGBE_FAILED_READ_REG) {
387 ixgbe_remove_adapter(hw);
388 return IXGBE_FAILED_READ_REG;
389 }
390 udelay(5);
391 }
392
393 adapter = hw->back;
394 e_warn(hw, "register writes incomplete %08x\n", value);
395 }
396
397writes_completed:
Mark Rustadf8e24722014-03-18 07:03:40 +0000398 value = readl(reg_addr + reg);
399 if (unlikely(value == IXGBE_FAILED_READ_REG))
400 ixgbe_check_remove(hw, reg);
401 return value;
402}
403
Mark Rustad14438462014-02-28 15:48:57 -0800404static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
405{
406 u16 value;
407
408 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
409 if (value == IXGBE_FAILED_READ_CFG_WORD) {
410 ixgbe_remove_adapter(hw);
411 return true;
412 }
413 return false;
414}
415
416u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
417{
418 struct ixgbe_adapter *adapter = hw->back;
419 u16 value;
420
421 if (ixgbe_removed(hw->hw_addr))
422 return IXGBE_FAILED_READ_CFG_WORD;
423 pci_read_config_word(adapter->pdev, reg, &value);
424 if (value == IXGBE_FAILED_READ_CFG_WORD &&
425 ixgbe_check_cfg_remove(hw, adapter->pdev))
426 return IXGBE_FAILED_READ_CFG_WORD;
427 return value;
428}
429
430#ifdef CONFIG_PCI_IOV
431static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
432{
433 struct ixgbe_adapter *adapter = hw->back;
434 u32 value;
435
436 if (ixgbe_removed(hw->hw_addr))
437 return IXGBE_FAILED_READ_CFG_DWORD;
438 pci_read_config_dword(adapter->pdev, reg, &value);
439 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
440 ixgbe_check_cfg_remove(hw, adapter->pdev))
441 return IXGBE_FAILED_READ_CFG_DWORD;
442 return value;
443}
444#endif /* CONFIG_PCI_IOV */
445
Jacob Kellered192312014-02-22 01:23:53 +0000446void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
447{
448 struct ixgbe_adapter *adapter = hw->back;
449
450 if (ixgbe_removed(hw->hw_addr))
451 return;
452 pci_write_config_word(adapter->pdev, reg, value);
453}
454
Alexander Duyck70864002011-04-27 09:13:56 +0000455static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
456{
457 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
458
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000459 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100460 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000461 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
462}
463
Taku Izumidcd79ae2010-04-27 14:39:53 +0000464struct ixgbe_reg_info {
465 u32 ofs;
466 char *name;
467};
468
469static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
470
471 /* General Registers */
472 {IXGBE_CTRL, "CTRL"},
473 {IXGBE_STATUS, "STATUS"},
474 {IXGBE_CTRL_EXT, "CTRL_EXT"},
475
476 /* Interrupt Registers */
477 {IXGBE_EICR, "EICR"},
478
479 /* RX Registers */
480 {IXGBE_SRRCTL(0), "SRRCTL"},
481 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
482 {IXGBE_RDLEN(0), "RDLEN"},
483 {IXGBE_RDH(0), "RDH"},
484 {IXGBE_RDT(0), "RDT"},
485 {IXGBE_RXDCTL(0), "RXDCTL"},
486 {IXGBE_RDBAL(0), "RDBAL"},
487 {IXGBE_RDBAH(0), "RDBAH"},
488
489 /* TX Registers */
490 {IXGBE_TDBAL(0), "TDBAL"},
491 {IXGBE_TDBAH(0), "TDBAH"},
492 {IXGBE_TDLEN(0), "TDLEN"},
493 {IXGBE_TDH(0), "TDH"},
494 {IXGBE_TDT(0), "TDT"},
495 {IXGBE_TXDCTL(0), "TXDCTL"},
496
497 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000498 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000499};
500
501
502/*
503 * ixgbe_regdump - register printout routine
504 */
505static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
506{
507 int i = 0, j = 0;
508 char rname[16];
509 u32 regs[64];
510
511 switch (reginfo->ofs) {
512 case IXGBE_SRRCTL(0):
513 for (i = 0; i < 64; i++)
514 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
515 break;
516 case IXGBE_DCA_RXCTRL(0):
517 for (i = 0; i < 64; i++)
518 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
519 break;
520 case IXGBE_RDLEN(0):
521 for (i = 0; i < 64; i++)
522 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
523 break;
524 case IXGBE_RDH(0):
525 for (i = 0; i < 64; i++)
526 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
527 break;
528 case IXGBE_RDT(0):
529 for (i = 0; i < 64; i++)
530 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
531 break;
532 case IXGBE_RXDCTL(0):
533 for (i = 0; i < 64; i++)
534 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
535 break;
536 case IXGBE_RDBAL(0):
537 for (i = 0; i < 64; i++)
538 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
539 break;
540 case IXGBE_RDBAH(0):
541 for (i = 0; i < 64; i++)
542 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
543 break;
544 case IXGBE_TDBAL(0):
545 for (i = 0; i < 64; i++)
546 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
547 break;
548 case IXGBE_TDBAH(0):
549 for (i = 0; i < 64; i++)
550 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
551 break;
552 case IXGBE_TDLEN(0):
553 for (i = 0; i < 64; i++)
554 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
555 break;
556 case IXGBE_TDH(0):
557 for (i = 0; i < 64; i++)
558 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
559 break;
560 case IXGBE_TDT(0):
561 for (i = 0; i < 64; i++)
562 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
563 break;
564 case IXGBE_TXDCTL(0):
565 for (i = 0; i < 64; i++)
566 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
567 break;
568 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000569 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000570 IXGBE_READ_REG(hw, reginfo->ofs));
571 return;
572 }
573
574 for (i = 0; i < 8; i++) {
575 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000576 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000577 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000578 pr_cont(" %08x", regs[i*8+j]);
579 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000580 }
581
582}
583
584/*
585 * ixgbe_dump - Print registers, tx-rings and rx-rings
586 */
587static void ixgbe_dump(struct ixgbe_adapter *adapter)
588{
589 struct net_device *netdev = adapter->netdev;
590 struct ixgbe_hw *hw = &adapter->hw;
591 struct ixgbe_reg_info *reginfo;
592 int n = 0;
593 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000594 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000595 union ixgbe_adv_tx_desc *tx_desc;
596 struct my_u0 { u64 a; u64 b; } *u0;
597 struct ixgbe_ring *rx_ring;
598 union ixgbe_adv_rx_desc *rx_desc;
599 struct ixgbe_rx_buffer *rx_buffer_info;
600 u32 staterr;
601 int i = 0;
602
603 if (!netif_msg_hw(adapter))
604 return;
605
606 /* Print netdevice Info */
607 if (netdev) {
608 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000609 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000610 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000611 pr_info("%-15s %016lX %016lX %016lX\n",
612 netdev->name,
613 netdev->state,
Florian Westphal4d0e9652016-05-03 16:30:59 +0200614 dev_trans_start(netdev),
Joe Perchesc7689572010-09-07 21:35:17 +0000615 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000616 }
617
618 /* Print Registers */
619 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000620 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000621 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
622 reginfo->name; reginfo++) {
623 ixgbe_regdump(hw, reginfo);
624 }
625
626 /* Print TX Ring Summary */
627 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000628 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000629
630 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000631 pr_info(" %s %s %s %s\n",
632 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
633 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000634 for (n = 0; n < adapter->num_tx_queues; n++) {
635 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000636 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000637 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000638 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000639 (u64)dma_unmap_addr(tx_buffer, dma),
640 dma_unmap_len(tx_buffer, len),
641 tx_buffer->next_to_watch,
642 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000643 }
644
645 /* Print TX Rings */
646 if (!netif_msg_tx_done(adapter))
647 goto rx_ring_summary;
648
649 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
650
651 /* Transmit Descriptor Formats
652 *
Josh Hay39ac8682012-09-26 05:59:36 +0000653 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000654 * +--------------------------------------------------------------+
655 * 0 | Buffer Address [63:0] |
656 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000657 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000658 * +--------------------------------------------------------------+
659 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000660 *
661 * 82598 Advanced Transmit Descriptor (Write-Back Format)
662 * +--------------------------------------------------------------+
663 * 0 | RSV [63:0] |
664 * +--------------------------------------------------------------+
665 * 8 | RSV | STA | NXTSEQ |
666 * +--------------------------------------------------------------+
667 * 63 36 35 32 31 0
668 *
669 * 82599+ Advanced Transmit Descriptor
670 * +--------------------------------------------------------------+
671 * 0 | Buffer Address [63:0] |
672 * +--------------------------------------------------------------+
673 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
674 * +--------------------------------------------------------------+
675 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
676 *
677 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
678 * +--------------------------------------------------------------+
679 * 0 | RSV [63:0] |
680 * +--------------------------------------------------------------+
681 * 8 | RSV | STA | RSV |
682 * +--------------------------------------------------------------+
683 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000684 */
685
686 for (n = 0; n < adapter->num_tx_queues; n++) {
687 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000688 pr_info("------------------------------------\n");
689 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
690 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000691 pr_info("%s%s %s %s %s %s\n",
692 "T [desc] [address 63:0 ] ",
693 "[PlPOIdStDDt Ln] [bi->dma ] ",
694 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000695
696 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000697 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000698 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000699 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000700 if (dma_unmap_len(tx_buffer, len) > 0) {
701 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
702 i,
703 le64_to_cpu(u0->a),
704 le64_to_cpu(u0->b),
705 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000706 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000707 tx_buffer->next_to_watch,
708 (u64)tx_buffer->time_stamp,
709 tx_buffer->skb);
710 if (i == tx_ring->next_to_use &&
711 i == tx_ring->next_to_clean)
712 pr_cont(" NTC/U\n");
713 else if (i == tx_ring->next_to_use)
714 pr_cont(" NTU\n");
715 else if (i == tx_ring->next_to_clean)
716 pr_cont(" NTC\n");
717 else
718 pr_cont("\n");
719
720 if (netif_msg_pktdata(adapter) &&
721 tx_buffer->skb)
722 print_hex_dump(KERN_INFO, "",
723 DUMP_PREFIX_ADDRESS, 16, 1,
724 tx_buffer->skb->data,
725 dma_unmap_len(tx_buffer, len),
726 true);
727 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000728 }
729 }
730
731 /* Print RX Rings Summary */
732rx_ring_summary:
733 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000734 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000735 for (n = 0; n < adapter->num_rx_queues; n++) {
736 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000737 pr_info("%5d %5X %5X\n",
738 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000739 }
740
741 /* Print RX Rings */
742 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000743 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000744
745 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
746
Josh Hay39ac8682012-09-26 05:59:36 +0000747 /* Receive Descriptor Formats
748 *
749 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000750 * 63 1 0
751 * +-----------------------------------------------------+
752 * 0 | Packet Buffer Address [63:1] |A0/NSE|
753 * +----------------------------------------------+------+
754 * 8 | Header Buffer Address [63:1] | DD |
755 * +-----------------------------------------------------+
756 *
757 *
Josh Hay39ac8682012-09-26 05:59:36 +0000758 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000759 *
760 * 63 48 47 32 31 30 21 20 16 15 4 3 0
761 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000762 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
763 * | Packet | IP | | | | Type | Type |
764 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000765 * +------------------------------------------------------+
766 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
767 * +------------------------------------------------------+
768 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000769 *
770 * 82599+ Advanced Receive Descriptor (Read) Format
771 * 63 1 0
772 * +-----------------------------------------------------+
773 * 0 | Packet Buffer Address [63:1] |A0/NSE|
774 * +----------------------------------------------+------+
775 * 8 | Header Buffer Address [63:1] | DD |
776 * +-----------------------------------------------------+
777 *
778 *
779 * 82599+ Advanced Receive Descriptor (Write-Back) Format
780 *
781 * 63 48 47 32 31 30 21 20 17 16 4 3 0
782 * +------------------------------------------------------+
783 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
784 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
785 * |/ Flow Dir Flt ID | | | | | |
786 * +------------------------------------------------------+
787 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
788 * +------------------------------------------------------+
789 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000790 */
Josh Hay39ac8682012-09-26 05:59:36 +0000791
Taku Izumidcd79ae2010-04-27 14:39:53 +0000792 for (n = 0; n < adapter->num_rx_queues; n++) {
793 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000794 pr_info("------------------------------------\n");
795 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
796 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000797 pr_info("%s%s%s",
798 "R [desc] [ PktBuf A0] ",
799 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000800 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000801 pr_info("%s%s%s",
802 "RWB[desc] [PcsmIpSHl PtRs] ",
803 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000804 "<-- Adv Rx Write-Back format\n");
805
806 for (i = 0; i < rx_ring->count; i++) {
807 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000808 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000809 u0 = (struct my_u0 *)rx_desc;
810 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
811 if (staterr & IXGBE_RXD_STAT_DD) {
812 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000813 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000814 "%016llX ---------------- %p", i,
815 le64_to_cpu(u0->a),
816 le64_to_cpu(u0->b),
817 rx_buffer_info->skb);
818 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000819 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000820 "%016llX %016llX %p", i,
821 le64_to_cpu(u0->a),
822 le64_to_cpu(u0->b),
823 (u64)rx_buffer_info->dma,
824 rx_buffer_info->skb);
825
Emil Tantilov9c50c032012-07-26 01:21:24 +0000826 if (netif_msg_pktdata(adapter) &&
827 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000828 print_hex_dump(KERN_INFO, "",
829 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000830 page_address(rx_buffer_info->page) +
831 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000832 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000833 }
834 }
835
836 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000837 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000838 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000839 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000840 else
Joe Perchesc7689572010-09-07 21:35:17 +0000841 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000842
843 }
844 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000845}
846
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800847static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
848{
849 u32 ctrl_ext;
850
851 /* Let firmware take over control of h/w */
852 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
853 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000854 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800855}
856
857static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
858{
859 u32 ctrl_ext;
860
861 /* Let firmware know the driver has taken over */
862 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
863 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000864 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800865}
Auke Kok9a799d72007-09-15 14:07:45 -0700866
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000867/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000868 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
869 * @adapter: pointer to adapter struct
870 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
871 * @queue: queue to map the corresponding interrupt to
872 * @msix_vector: the vector to map to the corresponding queue
873 *
874 */
875static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000876 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700877{
878 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000879 struct ixgbe_hw *hw = &adapter->hw;
880 switch (hw->mac.type) {
881 case ixgbe_mac_82598EB:
882 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
883 if (direction == -1)
884 direction = 0;
885 index = (((direction * 64) + queue) >> 2) & 0x1F;
886 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
887 ivar &= ~(0xFF << (8 * (queue & 0x3)));
888 ivar |= (msix_vector << (8 * (queue & 0x3)));
889 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
890 break;
891 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800892 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000893 case ixgbe_mac_X550:
894 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700895 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000896 if (direction == -1) {
897 /* other causes */
898 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
899 index = ((queue & 1) * 8);
900 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
901 ivar &= ~(0xFF << index);
902 ivar |= (msix_vector << index);
903 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
904 break;
905 } else {
906 /* tx or rx causes */
907 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
908 index = ((16 * (queue & 1)) + (8 * direction));
909 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
910 ivar &= ~(0xFF << index);
911 ivar |= (msix_vector << index);
912 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
913 break;
914 }
915 default:
916 break;
917 }
Auke Kok9a799d72007-09-15 14:07:45 -0700918}
919
Alexander Duyckfe49f042009-06-04 16:00:09 +0000920static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000921 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000922{
923 u32 mask;
924
Alexander Duyckbd508172010-11-16 19:27:03 -0800925 switch (adapter->hw.mac.type) {
926 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000927 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
928 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800929 break;
930 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800931 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000932 case ixgbe_mac_X550:
933 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700934 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000935 mask = (qmask & 0xFFFFFFFF);
936 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
937 mask = (qmask >> 32);
938 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800939 break;
940 default:
941 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000942 }
943}
944
Alexander Duyck729739b2012-02-08 07:51:06 +0000945void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
946 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000947{
Alexander Duyck729739b2012-02-08 07:51:06 +0000948 if (tx_buffer->skb) {
949 dev_kfree_skb_any(tx_buffer->skb);
950 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000951 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000952 dma_unmap_addr(tx_buffer, dma),
953 dma_unmap_len(tx_buffer, len),
954 DMA_TO_DEVICE);
955 } else if (dma_unmap_len(tx_buffer, len)) {
956 dma_unmap_page(ring->dev,
957 dma_unmap_addr(tx_buffer, dma),
958 dma_unmap_len(tx_buffer, len),
959 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000960 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000961 tx_buffer->next_to_watch = NULL;
962 tx_buffer->skb = NULL;
963 dma_unmap_len_set(tx_buffer, len, 0);
964 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700965}
966
Alexander Duyck943561d2012-05-09 22:14:44 -0700967static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
968{
969 struct ixgbe_hw *hw = &adapter->hw;
970 struct ixgbe_hw_stats *hwstats = &adapter->stats;
971 int i;
972 u32 data;
973
974 if ((hw->fc.current_mode != ixgbe_fc_full) &&
975 (hw->fc.current_mode != ixgbe_fc_rx_pause))
976 return;
977
978 switch (hw->mac.type) {
979 case ixgbe_mac_82598EB:
980 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
981 break;
982 default:
983 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
984 }
985 hwstats->lxoffrxc += data;
986
987 /* refill credits (no tx hang) if we received xoff */
988 if (!data)
989 return;
990
991 for (i = 0; i < adapter->num_tx_queues; i++)
992 clear_bit(__IXGBE_HANG_CHECK_ARMED,
993 &adapter->tx_ring[i]->state);
994}
995
John Fastabendc84d3242010-11-16 19:27:12 -0800996static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700997{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700998 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800999 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -08001000 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001001 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001002 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -07001003 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001004
Alexander Duyck943561d2012-05-09 22:14:44 -07001005 if (adapter->ixgbe_ieee_pfc)
1006 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -08001007
Alexander Duyck943561d2012-05-09 22:14:44 -07001008 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
1009 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -08001010 return;
Alexander Duyck943561d2012-05-09 22:14:44 -07001011 }
John Fastabendc84d3242010-11-16 19:27:12 -08001012
1013 /* update stats for each tc, only valid with PFC enabled */
1014 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001015 u32 pxoffrxc;
1016
John Fastabendc84d3242010-11-16 19:27:12 -08001017 switch (hw->mac.type) {
1018 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001019 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001020 break;
1021 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001022 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001023 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001024 hwstats->pxoffrxc[i] += pxoffrxc;
1025 /* Get the TC for given UP */
1026 tc = netdev_get_prio_tc_map(adapter->netdev, i);
1027 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -07001028 }
1029
John Fastabendc84d3242010-11-16 19:27:12 -08001030 /* disarm tx queues that have received xoff frames */
1031 for (i = 0; i < adapter->num_tx_queues; i++) {
1032 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -08001033
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001034 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001035 if (xoff[tc])
1036 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1037 }
1038}
1039
1040static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1041{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001042 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001043}
1044
1045static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1046{
John Fastabend2a47fa42013-11-06 09:54:52 -08001047 struct ixgbe_adapter *adapter;
1048 struct ixgbe_hw *hw;
1049 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001050
John Fastabend2a47fa42013-11-06 09:54:52 -08001051 if (ring->l2_accel_priv)
1052 adapter = ring->l2_accel_priv->real_adapter;
1053 else
1054 adapter = netdev_priv(ring->netdev);
1055
1056 hw = &adapter->hw;
1057 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1058 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001059
1060 if (head != tail)
1061 return (head < tail) ?
1062 tail - head : (tail + ring->count - head);
1063
1064 return 0;
1065}
1066
1067static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1068{
1069 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1070 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1071 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001072
1073 clear_check_for_tx_hang(tx_ring);
1074
1075 /*
1076 * Check for a hung queue, but be thorough. This verifies
1077 * that a transmit has been completed since the previous
1078 * check AND there is at least one packet pending. The
1079 * ARMED bit is set to indicate a potential hang. The
1080 * bit is cleared if a pause frame is received to remove
1081 * false hang detection due to PFC or 802.3x frames. By
1082 * requiring this to fail twice we avoid races with
1083 * pfc clearing the ARMED bit and conditions where we
1084 * run the check_tx_hang logic with a transmit completion
1085 * pending but without time to complete it yet.
1086 */
Mark Rustade90dd262014-07-22 06:51:08 +00001087 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001088 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001089 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1090 &tx_ring->state);
1091 /* update completed stats and continue */
1092 tx_ring->tx_stats.tx_done_old = tx_done;
1093 /* reset the countdown */
1094 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001095
Mark Rustade90dd262014-07-22 06:51:08 +00001096 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001097}
1098
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001099/**
1100 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1101 * @adapter: driver private struct
1102 **/
1103static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1104{
1105
1106 /* Do the reset outside of interrupt context */
1107 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
Emil Tantilov57ca2a42016-07-29 14:46:31 -07001108 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Jacob Keller12ff3f32012-12-01 07:57:17 +00001109 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001110 ixgbe_service_event_schedule(adapter);
1111 }
1112}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001113
Auke Kok9a799d72007-09-15 14:07:45 -07001114/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001115 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1116 **/
1117static int ixgbe_tx_maxrate(struct net_device *netdev,
1118 int queue_index, u32 maxrate)
1119{
1120 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1121 struct ixgbe_hw *hw = &adapter->hw;
1122 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1123
1124 if (!maxrate)
1125 return 0;
1126
1127 /* Calculate the rate factor values to set */
1128 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1129 bcnrc_val /= maxrate;
1130
1131 /* clear everything but the rate factor */
1132 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1133 IXGBE_RTTBCNRC_RF_DEC_MASK;
1134
1135 /* enable the rate scheduler */
1136 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1137
1138 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1139 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1140
1141 return 0;
1142}
1143
1144/**
Auke Kok9a799d72007-09-15 14:07:45 -07001145 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001146 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001147 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001148 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001149 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001150static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001151 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001152{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001153 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001154 struct ixgbe_tx_buffer *tx_buffer;
1155 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001156 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001157 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001158 unsigned int i = tx_ring->next_to_clean;
1159
1160 if (test_bit(__IXGBE_DOWN, &adapter->state))
1161 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001162
Alexander Duyckd3d00232011-07-15 02:31:25 +00001163 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001164 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001165 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001166
Alexander Duyck729739b2012-02-08 07:51:06 +00001167 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001168 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001169
Alexander Duyckd3d00232011-07-15 02:31:25 +00001170 /* if next_to_watch is not set then there is no work pending */
1171 if (!eop_desc)
1172 break;
1173
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001174 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001175 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001176
Alexander Duyckd3d00232011-07-15 02:31:25 +00001177 /* if DD is not set pending work has not been completed */
1178 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1179 break;
1180
Alexander Duyckd3d00232011-07-15 02:31:25 +00001181 /* clear next_to_watch to prevent false hangs */
1182 tx_buffer->next_to_watch = NULL;
1183
Alexander Duyck091a6242012-02-08 07:51:01 +00001184 /* update the statistics for this packet */
1185 total_bytes += tx_buffer->bytecount;
1186 total_packets += tx_buffer->gso_segs;
1187
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001188 /* free the skb */
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001189 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001190
Alexander Duyck729739b2012-02-08 07:51:06 +00001191 /* unmap skb header data */
1192 dma_unmap_single(tx_ring->dev,
1193 dma_unmap_addr(tx_buffer, dma),
1194 dma_unmap_len(tx_buffer, len),
1195 DMA_TO_DEVICE);
1196
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001197 /* clear tx_buffer data */
1198 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +00001199 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001200
Alexander Duyck729739b2012-02-08 07:51:06 +00001201 /* unmap remaining buffers */
1202 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001203 tx_buffer++;
1204 tx_desc++;
1205 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001206 if (unlikely(!i)) {
1207 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001208 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001209 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001210 }
1211
Alexander Duyck729739b2012-02-08 07:51:06 +00001212 /* unmap any remaining paged data */
1213 if (dma_unmap_len(tx_buffer, len)) {
1214 dma_unmap_page(tx_ring->dev,
1215 dma_unmap_addr(tx_buffer, dma),
1216 dma_unmap_len(tx_buffer, len),
1217 DMA_TO_DEVICE);
1218 dma_unmap_len_set(tx_buffer, len, 0);
1219 }
1220 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001221
Alexander Duyck729739b2012-02-08 07:51:06 +00001222 /* move us one more past the eop_desc for start of next pkt */
1223 tx_buffer++;
1224 tx_desc++;
1225 i++;
1226 if (unlikely(!i)) {
1227 i -= tx_ring->count;
1228 tx_buffer = tx_ring->tx_buffer_info;
1229 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1230 }
1231
1232 /* issue prefetch for next Tx descriptor */
1233 prefetch(tx_desc);
1234
1235 /* update budget accounting */
1236 budget--;
1237 } while (likely(budget));
1238
1239 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001240 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001241 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001242 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001243 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001244 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001245 q_vector->tx.total_bytes += total_bytes;
1246 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001247
John Fastabendc84d3242010-11-16 19:27:12 -08001248 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001249 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001250 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001251 e_err(drv, "Detected Tx Unit Hang\n"
1252 " Tx Queue <%d>\n"
1253 " TDH, TDT <%x>, <%x>\n"
1254 " next_to_use <%x>\n"
1255 " next_to_clean <%x>\n"
1256 "tx_buffer_info[next_to_clean]\n"
1257 " time_stamp <%lx>\n"
1258 " jiffies <%lx>\n",
1259 tx_ring->queue_index,
1260 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1261 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001262 tx_ring->next_to_use, i,
1263 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001264
1265 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1266
1267 e_info(probe,
1268 "tx hang %d detected on queue %d, resetting adapter\n",
1269 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1270
1271 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001272 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001273
1274 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001275 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001276 }
Auke Kok9a799d72007-09-15 14:07:45 -07001277
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001278 netdev_tx_completed_queue(txring_txq(tx_ring),
1279 total_packets, total_bytes);
1280
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001281#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001282 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001283 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001284 /* Make sure that anybody stopping the queue after this
1285 * sees the new next_to_clean.
1286 */
1287 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001288 if (__netif_subqueue_stopped(tx_ring->netdev,
1289 tx_ring->queue_index)
1290 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1291 netif_wake_subqueue(tx_ring->netdev,
1292 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001293 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001294 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001295 }
Auke Kok9a799d72007-09-15 14:07:45 -07001296
Alexander Duyck59224552011-08-31 00:01:06 +00001297 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001298}
1299
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001300#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001301static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001302 struct ixgbe_ring *tx_ring,
1303 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001304{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001305 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001306 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001307 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001308
Mark Rustad9de76052015-08-08 16:27:41 -07001309 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1310 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1311
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001312 switch (hw->mac.type) {
1313 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001314 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001315 break;
1316 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001317 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001318 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1319 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1320 break;
1321 default:
1322 /* for unknown hardware do not write register */
1323 return;
1324 }
1325
1326 /*
1327 * We can enable relaxed ordering for reads, but not writes when
1328 * DCA is enabled. This is due to a known issue in some chipsets
1329 * which will cause the DCA tag to be cleared.
1330 */
1331 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1332 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1333 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1334
1335 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1336}
1337
1338static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1339 struct ixgbe_ring *rx_ring,
1340 int cpu)
1341{
1342 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001343 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001344 u8 reg_idx = rx_ring->reg_idx;
1345
Mark Rustad9de76052015-08-08 16:27:41 -07001346 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1347 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001348
1349 switch (hw->mac.type) {
1350 case ixgbe_mac_82599EB:
1351 case ixgbe_mac_X540:
1352 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001353 break;
1354 default:
1355 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001356 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001357
1358 /*
1359 * We can enable relaxed ordering for reads, but not writes when
1360 * DCA is enabled. This is due to a known issue in some chipsets
1361 * which will cause the DCA tag to be cleared.
1362 */
1363 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Mark Rustad9de76052015-08-08 16:27:41 -07001364 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001365 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1366
1367 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001368}
1369
1370static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1371{
1372 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001373 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001374 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001375
1376 if (q_vector->cpu == cpu)
1377 goto out_no_update;
1378
Alexander Duycka5579282012-02-08 07:50:04 +00001379 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001380 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001381
Alexander Duycka5579282012-02-08 07:50:04 +00001382 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001383 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001384
1385 q_vector->cpu = cpu;
1386out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001387 put_cpu();
1388}
1389
1390static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1391{
1392 int i;
1393
Alexander Duycke35ec122009-05-21 13:07:12 +00001394 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001395 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1396 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1397 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1398 else
1399 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1400 IXGBE_DCA_CTRL_DCA_DISABLE);
Alexander Duycke35ec122009-05-21 13:07:12 +00001401
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001402 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001403 adapter->q_vector[i]->cpu = -1;
1404 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001405 }
1406}
1407
1408static int __ixgbe_notify_dca(struct device *dev, void *data)
1409{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001410 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001411 unsigned long event = *(unsigned long *)data;
1412
Don Skidmore2a72c312011-07-20 02:27:05 +00001413 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001414 return 0;
1415
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001416 switch (event) {
1417 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001418 /* if we're already enabled, don't do it again */
1419 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1420 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001421 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001422 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001423 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1424 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001425 break;
1426 }
1427 /* Fall Through since DCA is disabled. */
1428 case DCA_PROVIDER_REMOVE:
1429 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1430 dca_remove_requester(dev);
1431 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001432 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1433 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001434 }
1435 break;
1436 }
1437
Denis V. Lunev652f0932008-03-27 14:39:17 +03001438 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001439}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001440
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001441#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b2015-04-29 10:57:39 +08001442
1443#define IXGBE_RSS_L4_TYPES_MASK \
1444 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1445 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1446 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1447 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1448
Alexander Duyck8a0da212012-01-31 02:59:49 +00001449static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1450 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001451 struct sk_buff *skb)
1452{
Fan Du7edda4b2015-04-29 10:57:39 +08001453 u16 rss_type;
1454
1455 if (!(ring->netdev->features & NETIF_F_RXHASH))
1456 return;
1457
1458 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1459 IXGBE_RXDADV_RSSTYPE_MASK;
1460
1461 if (!rss_type)
1462 return;
1463
1464 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1465 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1466 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001467}
1468
Alexander Duyckf8003262012-03-03 02:35:52 +00001469#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001470/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001471 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001472 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001473 * @rx_desc: advanced rx descriptor
1474 *
1475 * Returns : true if it is FCoE pkt
1476 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001477static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001478 union ixgbe_adv_rx_desc *rx_desc)
1479{
1480 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1481
Alexander Duyck57efd442012-06-25 21:54:46 +00001482 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001483 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1484 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1485 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1486}
1487
Alexander Duyckf8003262012-03-03 02:35:52 +00001488#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001489/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001490 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001491 * @ring: structure containing ring specific data
1492 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001493 * @skb: skb currently being received and modified
1494 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001495static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001496 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001497 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001498{
Don Skidmore3f207802014-12-23 07:40:34 +00001499 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore3f207802014-12-23 07:40:34 +00001500 bool encap_pkt = false;
1501
Alexander Duyck8a0da212012-01-31 02:59:49 +00001502 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001503
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001504 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001505 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001506 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001507
Emil Tantilova21d0822016-08-10 11:19:23 -07001508 /* check for VXLAN and Geneve packets */
1509 if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
Don Skidmore3f207802014-12-23 07:40:34 +00001510 encap_pkt = true;
1511 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001512 }
1513
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001514 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001515 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1516 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001517 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001518 return;
1519 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001520
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001521 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001522 return;
1523
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001524 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001525 /*
1526 * 82599 errata, UDP frames with a 0 checksum can be marked as
1527 * checksum errors.
1528 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001529 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1530 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001531 return;
1532
Alexander Duyck8a0da212012-01-31 02:59:49 +00001533 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001534 return;
1535 }
1536
Auke Kok9a799d72007-09-15 14:07:45 -07001537 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001538 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001539 if (encap_pkt) {
1540 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1541 return;
1542
1543 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
Mark Rustadd4692512015-12-04 11:26:43 -08001544 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001545 return;
1546 }
1547 /* If we checked the outer header let the stack know */
1548 skb->csum_level = 1;
1549 }
Auke Kok9a799d72007-09-15 14:07:45 -07001550}
1551
Alexander Duyckf990b792012-01-31 02:59:34 +00001552static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1553 struct ixgbe_rx_buffer *bi)
1554{
1555 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001556 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001557
Alexander Duyckf8003262012-03-03 02:35:52 +00001558 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001559 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001560 return true;
1561
Alexander Duyckf8003262012-03-03 02:35:52 +00001562 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001563 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1564 if (unlikely(!page)) {
1565 rx_ring->rx_stats.alloc_rx_page_failed++;
1566 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001567 }
1568
Alexander Duyckf8003262012-03-03 02:35:52 +00001569 /* map page for use */
1570 dma = dma_map_page(rx_ring->dev, page, 0,
1571 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001572
Alexander Duyckf8003262012-03-03 02:35:52 +00001573 /*
1574 * if mapping failed free memory back to system since
1575 * there isn't much point in holding memory we can't use
1576 */
1577 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001578 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001579
Alexander Duyckf990b792012-01-31 02:59:34 +00001580 rx_ring->rx_stats.alloc_rx_page_failed++;
1581 return false;
1582 }
1583
Alexander Duyckf8003262012-03-03 02:35:52 +00001584 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001585 bi->page = page;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001586 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001587
Alexander Duyckf990b792012-01-31 02:59:34 +00001588 return true;
1589}
1590
Auke Kok9a799d72007-09-15 14:07:45 -07001591/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001592 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001593 * @rx_ring: ring to place buffers on
1594 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001595 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001596void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001597{
Auke Kok9a799d72007-09-15 14:07:45 -07001598 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001599 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001600 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001601
Alexander Duyckf8003262012-03-03 02:35:52 +00001602 /* nothing to do */
1603 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001604 return;
1605
Alexander Duycke4f74022012-01-31 02:59:44 +00001606 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001607 bi = &rx_ring->rx_buffer_info[i];
1608 i -= rx_ring->count;
1609
Alexander Duyckf8003262012-03-03 02:35:52 +00001610 do {
1611 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001612 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001613
Alexander Duyckf8003262012-03-03 02:35:52 +00001614 /*
1615 * Refresh the desc even if buffer_addrs didn't change
1616 * because each write-back erases this info.
1617 */
1618 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001619
Alexander Duyckf990b792012-01-31 02:59:34 +00001620 rx_desc++;
1621 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001622 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001623 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001624 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001625 bi = rx_ring->rx_buffer_info;
1626 i -= rx_ring->count;
1627 }
1628
Alexander Duyck18cb6522014-11-14 00:56:29 +00001629 /* clear the status bits for the next_to_use descriptor */
1630 rx_desc->wb.upper.status_error = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001631
1632 cleaned_count--;
1633 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001634
Alexander Duyckf990b792012-01-31 02:59:34 +00001635 i += rx_ring->count;
1636
Alexander Duyckad435ec2014-11-14 00:56:35 +00001637 if (rx_ring->next_to_use != i) {
1638 rx_ring->next_to_use = i;
1639
1640 /* update next to alloc since we have filled the ring */
1641 rx_ring->next_to_alloc = i;
1642
1643 /* Force memory writes to complete before letting h/w
1644 * know there are new descriptors to fetch. (Only
1645 * applicable for weak-ordered memory model archs,
1646 * such as IA-64).
1647 */
1648 wmb();
1649 writel(i, rx_ring->tail);
1650 }
Auke Kok9a799d72007-09-15 14:07:45 -07001651}
1652
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001653static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1654 struct sk_buff *skb)
1655{
Alexander Duyckf8003262012-03-03 02:35:52 +00001656 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001657
1658 /* set gso_size to avoid messing up TCP MSS */
1659 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1660 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001661 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001662}
1663
1664static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1665 struct sk_buff *skb)
1666{
1667 /* if append_cnt is 0 then frame is not RSC */
1668 if (!IXGBE_CB(skb)->append_cnt)
1669 return;
1670
1671 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1672 rx_ring->rx_stats.rsc_flush++;
1673
1674 ixgbe_set_rsc_gso_size(rx_ring, skb);
1675
1676 /* gso_size is computed using append_cnt so always clear it last */
1677 IXGBE_CB(skb)->append_cnt = 0;
1678}
1679
Alexander Duyck8a0da212012-01-31 02:59:49 +00001680/**
1681 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1682 * @rx_ring: rx descriptor ring packet is being transacted on
1683 * @rx_desc: pointer to the EOP Rx descriptor
1684 * @skb: pointer to current skb being populated
1685 *
1686 * This function checks the ring, descriptor, and packet information in
1687 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1688 * other fields within the skb.
1689 **/
1690static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1691 union ixgbe_adv_rx_desc *rx_desc,
1692 struct sk_buff *skb)
1693{
John Fastabend43e95f12012-05-15 06:12:17 +00001694 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001695 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001696
Alexander Duyck8a0da212012-01-31 02:59:49 +00001697 ixgbe_update_rsc_stats(rx_ring, skb);
1698
1699 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1700
1701 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1702
Mark Rustada9763f32015-10-27 09:58:07 -07001703 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1704 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001705
Patrick McHardyf6469682013-04-19 02:04:27 +00001706 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001707 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001708 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001709 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001710 }
1711
1712 skb_record_rx_queue(skb, rx_ring->queue_index);
1713
John Fastabend43e95f12012-05-15 06:12:17 +00001714 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001715}
1716
1717static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1718 struct sk_buff *skb)
1719{
Eric Dumazet93f93a42015-11-18 06:30:59 -08001720 skb_mark_napi_id(skb, &q_vector->napi);
Jacob Kellerb4640032013-10-01 04:33:54 -07001721 if (ixgbe_qv_busy_polling(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001722 netif_receive_skb(skb);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001723 else
Alexander Duyck856f6062015-02-25 17:45:54 +00001724 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001725}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001726
Alexander Duyckf8003262012-03-03 02:35:52 +00001727/**
1728 * ixgbe_is_non_eop - process handling of non-EOP buffers
1729 * @rx_ring: Rx ring being processed
1730 * @rx_desc: Rx descriptor for current buffer
1731 * @skb: Current socket buffer containing buffer in progress
1732 *
1733 * This function updates next to clean. If the buffer is an EOP buffer
1734 * this function exits returning false, otherwise it will place the
1735 * sk_buff in the next buffer to be chained and return true indicating
1736 * that this is in fact a non-EOP buffer.
1737 **/
1738static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1739 union ixgbe_adv_rx_desc *rx_desc,
1740 struct sk_buff *skb)
1741{
1742 u32 ntc = rx_ring->next_to_clean + 1;
1743
1744 /* fetch, update, and store next to clean */
1745 ntc = (ntc < rx_ring->count) ? ntc : 0;
1746 rx_ring->next_to_clean = ntc;
1747
1748 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1749
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001750 /* update RSC append count if present */
1751 if (ring_is_rsc_enabled(rx_ring)) {
1752 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1753 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1754
1755 if (unlikely(rsc_enabled)) {
1756 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1757
1758 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1759 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1760
1761 /* update ntc based on RSC value */
1762 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1763 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1764 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1765 }
1766 }
1767
1768 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001769 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1770 return false;
1771
Alexander Duyckf8003262012-03-03 02:35:52 +00001772 /* place skb in next buffer to be received */
1773 rx_ring->rx_buffer_info[ntc].skb = skb;
1774 rx_ring->rx_stats.non_eop_descs++;
1775
1776 return true;
1777}
1778
1779/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001780 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1781 * @rx_ring: rx descriptor ring packet is being transacted on
1782 * @skb: pointer to current skb being adjusted
1783 *
1784 * This function is an ixgbe specific version of __pskb_pull_tail. The
1785 * main difference between this version and the original function is that
1786 * this function can make several assumptions about the state of things
1787 * that allow for significant optimizations versus the standard function.
1788 * As a result we can do things like drop a frag and maintain an accurate
1789 * truesize for the skb.
1790 */
1791static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1792 struct sk_buff *skb)
1793{
1794 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1795 unsigned char *va;
1796 unsigned int pull_len;
1797
1798 /*
1799 * it is valid to use page_address instead of kmap since we are
1800 * working with pages allocated out of the lomem pool per
1801 * alloc_page(GFP_ATOMIC)
1802 */
1803 va = skb_frag_address(frag);
1804
1805 /*
1806 * we need the header to contain the greater of either ETH_HLEN or
1807 * 60 bytes if the skb->len is less than 60 for skb_pad.
1808 */
Alexander Duyck8496e332014-09-05 19:22:18 -04001809 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001810
1811 /* align pull length to size of long to optimize memcpy performance */
1812 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1813
1814 /* update all of the pointers */
1815 skb_frag_size_sub(frag, pull_len);
1816 frag->page_offset += pull_len;
1817 skb->data_len -= pull_len;
1818 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001819}
1820
1821/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001822 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1823 * @rx_ring: rx descriptor ring packet is being transacted on
1824 * @skb: pointer to current skb being updated
1825 *
1826 * This function provides a basic DMA sync up for the first fragment of an
1827 * skb. The reason for doing this is that the first fragment cannot be
1828 * unmapped until we have reached the end of packet descriptor for a buffer
1829 * chain.
1830 */
1831static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1832 struct sk_buff *skb)
1833{
1834 /* if the page was released unmap it, else just sync our portion */
1835 if (unlikely(IXGBE_CB(skb)->page_released)) {
1836 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1837 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1838 IXGBE_CB(skb)->page_released = false;
1839 } else {
1840 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1841
1842 dma_sync_single_range_for_cpu(rx_ring->dev,
1843 IXGBE_CB(skb)->dma,
1844 frag->page_offset,
1845 ixgbe_rx_bufsz(rx_ring),
1846 DMA_FROM_DEVICE);
1847 }
1848 IXGBE_CB(skb)->dma = 0;
1849}
1850
1851/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001852 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1853 * @rx_ring: rx descriptor ring packet is being transacted on
1854 * @rx_desc: pointer to the EOP Rx descriptor
1855 * @skb: pointer to current skb being fixed
1856 *
1857 * Check for corrupted packet headers caused by senders on the local L2
1858 * embedded NIC switch not setting up their Tx Descriptors right. These
1859 * should be very rare.
1860 *
1861 * Also address the case where we are pulling data in on pages only
1862 * and as such no data is present in the skb header.
1863 *
1864 * In addition if skb is not at least 60 bytes we need to pad it so that
1865 * it is large enough to qualify as a valid Ethernet frame.
1866 *
1867 * Returns true if an error was encountered and skb was freed.
1868 **/
1869static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1870 union ixgbe_adv_rx_desc *rx_desc,
1871 struct sk_buff *skb)
1872{
Alexander Duyckf8003262012-03-03 02:35:52 +00001873 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001874
1875 /* verify that the packet does not have any known errors */
1876 if (unlikely(ixgbe_test_staterr(rx_desc,
1877 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1878 !(netdev->features & NETIF_F_RXALL))) {
1879 dev_kfree_skb_any(skb);
1880 return true;
1881 }
1882
Alexander Duyck19861ce2012-07-20 08:08:33 +00001883 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001884 if (skb_is_nonlinear(skb))
1885 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001886
Alexander Duyck57efd442012-06-25 21:54:46 +00001887#ifdef IXGBE_FCOE
1888 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1889 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1890 return false;
1891
1892#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001893 /* if eth_skb_pad returns an error the skb was freed */
1894 if (eth_skb_pad(skb))
1895 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001896
1897 return false;
1898}
1899
1900/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001901 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1902 * @rx_ring: rx descriptor ring to store buffers on
1903 * @old_buff: donor buffer to have page reused
1904 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001905 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001906 **/
1907static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1908 struct ixgbe_rx_buffer *old_buff)
1909{
1910 struct ixgbe_rx_buffer *new_buff;
1911 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001912
1913 new_buff = &rx_ring->rx_buffer_info[nta];
1914
1915 /* update, and store next to alloc */
1916 nta++;
1917 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1918
1919 /* transfer page from old buffer to new buffer */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001920 *new_buff = *old_buff;
Alexander Duyckf8003262012-03-03 02:35:52 +00001921
1922 /* sync the buffer for use by the device */
1923 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001924 new_buff->page_offset,
1925 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001926 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001927}
1928
Alexander Duyck18cb6522014-11-14 00:56:29 +00001929static inline bool ixgbe_page_is_reserved(struct page *page)
1930{
Michal Hocko2f064f32015-08-21 14:11:51 -07001931 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001932}
1933
Alexander Duyckf8003262012-03-03 02:35:52 +00001934/**
1935 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1936 * @rx_ring: rx descriptor ring to transact packets on
1937 * @rx_buffer: buffer containing page to add
1938 * @rx_desc: descriptor containing length of buffer written by hardware
1939 * @skb: sk_buff to place the data into
1940 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001941 * This function will add the data contained in rx_buffer->page to the skb.
1942 * This is done either through a direct copy if the data in the buffer is
1943 * less than the skb header size, otherwise it will just attach the page as
1944 * a frag to the skb.
1945 *
1946 * The function will then update the page offset if necessary and return
1947 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001948 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001949static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001950 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001951 union ixgbe_adv_rx_desc *rx_desc,
1952 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001953{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001954 struct page *page = rx_buffer->page;
1955 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001956#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001957 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001958#else
1959 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1960 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1961 ixgbe_rx_bufsz(rx_ring);
1962#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001963
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001964 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1965 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1966
1967 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1968
Alexander Duyck18cb6522014-11-14 00:56:29 +00001969 /* page is not reserved, we can reuse buffer as-is */
1970 if (likely(!ixgbe_page_is_reserved(page)))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001971 return true;
1972
1973 /* this page cannot be reused so discard it */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001974 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001975 return false;
1976 }
1977
Alexander Duyck0549ae22012-07-20 08:08:18 +00001978 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1979 rx_buffer->page_offset, size, truesize);
1980
Alexander Duyck09816fb2012-07-20 08:08:23 +00001981 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001982 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001983 return false;
1984
1985#if (PAGE_SIZE < 8192)
1986 /* if we are only owner of page we can reuse it */
1987 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001988 return false;
1989
1990 /* flip page offset to other buffer */
1991 rx_buffer->page_offset ^= truesize;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001992#else
1993 /* move offset up to the next cache line */
1994 rx_buffer->page_offset += truesize;
1995
1996 if (rx_buffer->page_offset > last_offset)
1997 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001998#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001999
Alexander Duyck18cb6522014-11-14 00:56:29 +00002000 /* Even if we own the page, we are not allowed to use atomic_set()
2001 * This would break get_page_unless_zero() users.
2002 */
Joonsoo Kimfe896d12016-03-17 14:19:26 -07002003 page_ref_inc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00002004
Alexander Duyck0549ae22012-07-20 08:08:18 +00002005 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00002006}
2007
Alexander Duyck18806c92012-07-20 08:08:44 +00002008static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
2009 union ixgbe_adv_rx_desc *rx_desc)
2010{
2011 struct ixgbe_rx_buffer *rx_buffer;
2012 struct sk_buff *skb;
2013 struct page *page;
2014
2015 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
2016 page = rx_buffer->page;
2017 prefetchw(page);
2018
2019 skb = rx_buffer->skb;
2020
2021 if (likely(!skb)) {
2022 void *page_addr = page_address(page) +
2023 rx_buffer->page_offset;
2024
2025 /* prefetch first cache line of first page */
2026 prefetch(page_addr);
2027#if L1_CACHE_BYTES < 128
2028 prefetch(page_addr + L1_CACHE_BYTES);
2029#endif
2030
2031 /* allocate a skb to store the frags */
Alexander Duyck67fd8932014-12-09 19:40:56 -08002032 skb = napi_alloc_skb(&rx_ring->q_vector->napi,
2033 IXGBE_RX_HDR_SIZE);
Alexander Duyck18806c92012-07-20 08:08:44 +00002034 if (unlikely(!skb)) {
2035 rx_ring->rx_stats.alloc_rx_buff_failed++;
2036 return NULL;
2037 }
2038
2039 /*
2040 * we will be copying header into skb->data in
2041 * pskb_may_pull so it is in our interest to prefetch
2042 * it now to avoid a possible cache miss
2043 */
2044 prefetchw(skb->data);
2045
2046 /*
2047 * Delay unmapping of the first packet. It carries the
2048 * header information, HW may still access the header
2049 * after the writeback. Only unmap it when EOP is
2050 * reached
2051 */
2052 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
2053 goto dma_sync;
2054
2055 IXGBE_CB(skb)->dma = rx_buffer->dma;
2056 } else {
2057 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2058 ixgbe_dma_sync_frag(rx_ring, skb);
2059
2060dma_sync:
2061 /* we are reusing so sync this buffer for CPU use */
2062 dma_sync_single_range_for_cpu(rx_ring->dev,
2063 rx_buffer->dma,
2064 rx_buffer->page_offset,
2065 ixgbe_rx_bufsz(rx_ring),
2066 DMA_FROM_DEVICE);
Alexander Duyck18cb6522014-11-14 00:56:29 +00002067
2068 rx_buffer->skb = NULL;
Alexander Duyck18806c92012-07-20 08:08:44 +00002069 }
2070
2071 /* pull page into skb */
2072 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
2073 /* hand second half of page back to the ring */
2074 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
2075 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
2076 /* the page has been released from the ring */
2077 IXGBE_CB(skb)->page_released = true;
2078 } else {
2079 /* we are not reusing the buffer so unmap it */
2080 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
2081 ixgbe_rx_pg_size(rx_ring),
2082 DMA_FROM_DEVICE);
2083 }
2084
2085 /* clear contents of buffer_info */
Alexander Duyck18806c92012-07-20 08:08:44 +00002086 rx_buffer->page = NULL;
2087
2088 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002089}
2090
2091/**
2092 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2093 * @q_vector: structure containing interrupt and ring information
2094 * @rx_ring: rx descriptor ring to transact packets on
2095 * @budget: Total limit on number of packets to process
2096 *
2097 * This function provides a "bounce buffer" approach to Rx interrupt
2098 * processing. The advantage to this is that on systems that have
2099 * expensive overhead for IOMMU access this provides a means of avoiding
2100 * it by maintaining the mapping of the page to the syste.
2101 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002102 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002103 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002104static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002105 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002106 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002107{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002108 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00002109#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00002110 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00002111 int ddp_bytes;
2112 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002113#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002114 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002115
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002116 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002117 union ixgbe_adv_rx_desc *rx_desc;
2118 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002119
Alexander Duyckf8003262012-03-03 02:35:52 +00002120 /* return some buffers to hardware, one at a time is too slow */
2121 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2122 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2123 cleaned_count = 0;
2124 }
Auke Kok9a799d72007-09-15 14:07:45 -07002125
Alexander Duyck18806c92012-07-20 08:08:44 +00002126 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07002127
Alexander Duyck124b74c2014-12-11 15:02:28 -08002128 if (!rx_desc->wb.upper.status_error)
Alexander Duyckf8003262012-03-03 02:35:52 +00002129 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002130
Alexander Duyck124b74c2014-12-11 15:02:28 -08002131 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002132 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002133 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002134 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002135 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002136
Alexander Duyck18806c92012-07-20 08:08:44 +00002137 /* retrieve a buffer from the ring */
2138 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00002139
Alexander Duyck18806c92012-07-20 08:08:44 +00002140 /* exit if we failed to retrieve a buffer */
2141 if (!skb)
2142 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002143
Auke Kok9a799d72007-09-15 14:07:45 -07002144 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002145
Alexander Duyckf8003262012-03-03 02:35:52 +00002146 /* place incomplete frames back on ring for completion */
2147 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2148 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002149
Alexander Duyckf8003262012-03-03 02:35:52 +00002150 /* verify the packet layout is correct */
2151 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2152 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002153
2154 /* probably a little skewed due to removing CRC */
2155 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002156
Alexander Duyck8a0da212012-01-31 02:59:49 +00002157 /* populate checksum, timestamp, VLAN, and protocol */
2158 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2159
Yi Zou332d4a72009-05-13 13:11:53 +00002160#ifdef IXGBE_FCOE
2161 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002162 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002163 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002164 /* include DDPed FCoE data */
2165 if (ddp_bytes > 0) {
2166 if (!mss) {
2167 mss = rx_ring->netdev->mtu -
2168 sizeof(struct fcoe_hdr) -
2169 sizeof(struct fc_frame_header) -
2170 sizeof(struct fcoe_crc_eof);
2171 if (mss > 512)
2172 mss &= ~511;
2173 }
2174 total_rx_bytes += ddp_bytes;
2175 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2176 mss);
2177 }
David S. Miller823dcd22011-08-20 10:39:12 -07002178 if (!ddp_bytes) {
2179 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002180 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002181 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002182 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002183
Yi Zou332d4a72009-05-13 13:11:53 +00002184#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002185 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002186
Alexander Duyckf8003262012-03-03 02:35:52 +00002187 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002188 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002189 }
Auke Kok9a799d72007-09-15 14:07:45 -07002190
Alexander Duyckc267fc12010-11-16 19:27:00 -08002191 u64_stats_update_begin(&rx_ring->syncp);
2192 rx_ring->stats.packets += total_rx_packets;
2193 rx_ring->stats.bytes += total_rx_bytes;
2194 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002195 q_vector->rx.total_packets += total_rx_packets;
2196 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002197
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002198 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002199}
2200
Cong Wange0d10952013-08-01 11:10:25 +08002201#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002202/* must be called with local_bh_disable()d */
2203static int ixgbe_low_latency_recv(struct napi_struct *napi)
2204{
2205 struct ixgbe_q_vector *q_vector =
2206 container_of(napi, struct ixgbe_q_vector, napi);
2207 struct ixgbe_adapter *adapter = q_vector->adapter;
2208 struct ixgbe_ring *ring;
2209 int found = 0;
2210
2211 if (test_bit(__IXGBE_DOWN, &adapter->state))
2212 return LL_FLUSH_FAILED;
2213
2214 if (!ixgbe_qv_lock_poll(q_vector))
2215 return LL_FLUSH_BUSY;
2216
2217 ixgbe_for_each_ring(ring, q_vector->rx) {
2218 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
Jacob Kellerb4640032013-10-01 04:33:54 -07002219#ifdef BP_EXTENDED_STATS
Eliezer Tamir7e15b902013-06-10 11:40:31 +03002220 if (found)
2221 ring->stats.cleaned += found;
2222 else
2223 ring->stats.misses++;
2224#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002225 if (found)
2226 break;
2227 }
2228
2229 ixgbe_qv_unlock_poll(q_vector);
2230
2231 return found;
2232}
Cong Wange0d10952013-08-01 11:10:25 +08002233#endif /* CONFIG_NET_RX_BUSY_POLL */
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002234
Auke Kok9a799d72007-09-15 14:07:45 -07002235/**
2236 * ixgbe_configure_msix - Configure MSI-X hardware
2237 * @adapter: board private structure
2238 *
2239 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2240 * interrupts.
2241 **/
2242static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2243{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002245 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002246 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002247
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002248 /* Populate MSIX to EITR Select */
2249 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002250 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002251 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2252 }
2253
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002254 /*
2255 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002256 * corresponding register.
2257 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002258 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002259 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002260 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002261
Alexander Duycka5579282012-02-08 07:50:04 +00002262 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002263 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002264
Alexander Duycka5579282012-02-08 07:50:04 +00002265 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002266 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002267
Alexander Duyckfe49f042009-06-04 16:00:09 +00002268 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002269 }
2270
Alexander Duyckbd508172010-11-16 19:27:03 -08002271 switch (adapter->hw.mac.type) {
2272 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002273 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002274 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002275 break;
2276 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002277 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002278 case ixgbe_mac_X550:
2279 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002280 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002281 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002282 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002283 default:
2284 break;
2285 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002286 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002287
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002288 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002289 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002290 mask &= ~(IXGBE_EIMS_OTHER |
2291 IXGBE_EIMS_MAILBOX |
2292 IXGBE_EIMS_LSC);
2293
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002294 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002295}
2296
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002297enum latency_range {
2298 lowest_latency = 0,
2299 low_latency = 1,
2300 bulk_latency = 2,
2301 latency_invalid = 255
2302};
2303
2304/**
2305 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002306 * @q_vector: structure containing interrupt and ring information
2307 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002308 *
2309 * Stores a new ITR value based on packets and byte
2310 * counts during the last interrupt. The advantage of per interrupt
2311 * computation is faster updates and more accurate ITR for the current
2312 * traffic pattern. Constants in this function were computed
2313 * based on theoretical maximum wire speed and thresholds were set based
2314 * on testing data as well as attempting to minimize response time
2315 * while increasing bulk throughput.
2316 * this functionality is controlled by the InterruptThrottleRate module
2317 * parameter (see ixgbe_param.c)
2318 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002319static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2320 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002321{
Alexander Duyckbd198052011-06-11 01:45:08 +00002322 int bytes = ring_container->total_bytes;
2323 int packets = ring_container->total_packets;
2324 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002325 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002326 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002327
2328 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002329 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002330
2331 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002332 * 0-10MB/s lowest (100000 ints/s)
2333 * 10-20MB/s low (20000 ints/s)
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002334 * 20-1249MB/s bulk (12000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002335 */
2336 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002337 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002338 if (timepassed_us == 0)
2339 return;
2340
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002341 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2342
2343 switch (itr_setting) {
2344 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002345 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002346 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002347 break;
2348 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002349 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002350 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002351 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002352 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002353 break;
2354 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002355 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002356 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002357 break;
2358 }
2359
Alexander Duyckbd198052011-06-11 01:45:08 +00002360 /* clear work counters since we have the values we need */
2361 ring_container->total_bytes = 0;
2362 ring_container->total_packets = 0;
2363
2364 /* write updated itr to ring container */
2365 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002366}
2367
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002368/**
2369 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002370 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002371 *
2372 * This function is made to be called by ethtool and by the driver
2373 * when it needs to update EITR registers at runtime. Hardware
2374 * specific quirks/differences are taken care of here.
2375 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002376void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002377{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002378 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002379 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002380 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002381 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002382
Alexander Duyckbd508172010-11-16 19:27:03 -08002383 switch (adapter->hw.mac.type) {
2384 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002385 /* must write high and low 16 bits to reset counter */
2386 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002387 break;
2388 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002389 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002390 case ixgbe_mac_X550:
2391 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002392 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002393 /*
2394 * set the WDIS bit to not clear the timer bits and cause an
2395 * immediate assertion of the interrupt
2396 */
2397 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002398 break;
2399 default:
2400 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002401 }
2402 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2403}
2404
Alexander Duyckbd198052011-06-11 01:45:08 +00002405static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002406{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002407 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002408 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002409
Alexander Duyckbd198052011-06-11 01:45:08 +00002410 ixgbe_update_itr(q_vector, &q_vector->tx);
2411 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002412
Alexander Duyck08c88332011-06-11 01:45:03 +00002413 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002414
2415 switch (current_itr) {
2416 /* counts and packets in update_itr are dependent on these numbers */
2417 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002418 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002419 break;
2420 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002421 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002422 break;
2423 case bulk_latency:
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002424 new_itr = IXGBE_12K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002425 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002426 default:
2427 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002428 }
2429
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002430 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002431 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002432 new_itr = (10 * new_itr * q_vector->itr) /
2433 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002434
Alexander Duyckbd198052011-06-11 01:45:08 +00002435 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002436 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002437
2438 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002439 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002440}
2441
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002442/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002443 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002444 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002445 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002446static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002447{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002448 struct ixgbe_hw *hw = &adapter->hw;
2449 u32 eicr = adapter->interrupt_event;
2450
Alexander Duyckf0f97782011-04-22 04:08:09 +00002451 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002452 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002453
Alexander Duyckf0f97782011-04-22 04:08:09 +00002454 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2455 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2456 return;
2457
2458 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2459
Joe Perches7ca647b2010-09-07 21:35:40 +00002460 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002461 case IXGBE_DEV_ID_82599_T3_LOM:
2462 /*
2463 * Since the warning interrupt is for both ports
2464 * we don't have to check if:
2465 * - This interrupt wasn't for our port.
2466 * - We may have missed the interrupt so always have to
2467 * check if we got a LSC
2468 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002469 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002470 !(eicr & IXGBE_EICR_LSC))
2471 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002472
Alexander Duyckf0f97782011-04-22 04:08:09 +00002473 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002474 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002475 bool link_up = false;
2476
Josh Hay3d292262012-12-15 03:28:19 +00002477 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002478
Alexander Duyckf0f97782011-04-22 04:08:09 +00002479 if (link_up)
2480 return;
2481 }
2482
2483 /* Check if this is not due to overtemp */
2484 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2485 return;
2486
2487 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002488 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002489 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2490 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002491 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002492 return;
2493 break;
2494 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002495 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002496
2497 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002498}
2499
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002500static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2501{
2502 struct ixgbe_hw *hw = &adapter->hw;
2503
2504 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002505 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002506 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002507 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002508 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002509 }
2510}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002511
Jacob Keller4f51bf72011-08-20 04:49:45 +00002512static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2513{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002514 struct ixgbe_hw *hw = &adapter->hw;
2515
Jacob Keller4f51bf72011-08-20 04:49:45 +00002516 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2517 return;
2518
2519 switch (adapter->hw.mac.type) {
2520 case ixgbe_mac_82599EB:
2521 /*
2522 * Need to check link state so complete overtemp check
2523 * on service task
2524 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002525 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2526 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002527 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2528 adapter->interrupt_event = eicr;
2529 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2530 ixgbe_service_event_schedule(adapter);
2531 return;
2532 }
2533 return;
2534 case ixgbe_mac_X540:
2535 if (!(eicr & IXGBE_EICR_TS))
2536 return;
2537 break;
2538 default:
2539 return;
2540 }
2541
Don Skidmoref44e7512015-06-09 16:36:23 -07002542 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002543}
2544
Don Skidmore45788d22015-06-09 16:59:04 -07002545static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2546{
2547 switch (hw->mac.type) {
2548 case ixgbe_mac_82598EB:
2549 if (hw->phy.type == ixgbe_phy_nl)
2550 return true;
2551 return false;
2552 case ixgbe_mac_82599EB:
2553 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002554 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002555 switch (hw->mac.ops.get_media_type(hw)) {
2556 case ixgbe_media_type_fiber:
2557 case ixgbe_media_type_fiber_qsfp:
2558 return true;
2559 default:
2560 return false;
2561 }
2562 default:
2563 return false;
2564 }
2565}
2566
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002567static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2568{
2569 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002570 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002571
Don Skidmore4ccc6502015-09-02 13:47:54 -07002572 if (!ixgbe_is_sfp(hw))
2573 return;
2574
2575 /* Later MAC's use different SDP */
2576 if (hw->mac.type >= ixgbe_mac_X540)
2577 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2578
2579 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002580 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002581 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002582 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2583 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002584 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002585 ixgbe_service_event_schedule(adapter);
2586 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002587 }
2588
Don Skidmore4ccc6502015-09-02 13:47:54 -07002589 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2590 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002591 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002592 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002593 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2594 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2595 ixgbe_service_event_schedule(adapter);
2596 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002597 }
2598}
2599
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002600static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2601{
2602 struct ixgbe_hw *hw = &adapter->hw;
2603
2604 adapter->lsc_int++;
2605 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2606 adapter->link_check_timeout = jiffies;
2607 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2608 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002609 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002610 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002611 }
2612}
2613
Alexander Duyckfe49f042009-06-04 16:00:09 +00002614static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2615 u64 qmask)
2616{
2617 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002618 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002619
Alexander Duyckbd508172010-11-16 19:27:03 -08002620 switch (hw->mac.type) {
2621 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002622 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002623 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2624 break;
2625 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002626 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002627 case ixgbe_mac_X550:
2628 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002629 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002630 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002631 if (mask)
2632 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002633 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002634 if (mask)
2635 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2636 break;
2637 default:
2638 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002639 }
2640 /* skip the flush */
2641}
2642
2643static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002644 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002645{
2646 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002647 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002648
Alexander Duyckbd508172010-11-16 19:27:03 -08002649 switch (hw->mac.type) {
2650 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002651 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002652 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2653 break;
2654 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002655 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002656 case ixgbe_mac_X550:
2657 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002658 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002659 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002660 if (mask)
2661 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002662 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002663 if (mask)
2664 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2665 break;
2666 default:
2667 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002668 }
2669 /* skip the flush */
2670}
2671
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002672/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002673 * ixgbe_irq_enable - Enable default interrupt generation settings
2674 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002675 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002676static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2677 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002678{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002679 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002680 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002681
Alexander Duyck2c4af692011-07-15 07:29:55 +00002682 /* don't reenable LSC while waiting for link */
2683 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2684 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002685
Alexander Duyck2c4af692011-07-15 07:29:55 +00002686 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002687 switch (adapter->hw.mac.type) {
2688 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002689 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002690 break;
2691 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002692 case ixgbe_mac_X550:
2693 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002694 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002695 mask |= IXGBE_EIMS_TS;
2696 break;
2697 default:
2698 break;
2699 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002700 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002701 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002702 switch (adapter->hw.mac.type) {
2703 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002704 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2705 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002706 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00002707 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002708 case ixgbe_mac_X550:
2709 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002710 case ixgbe_mac_x550em_a:
2711 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07002712 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07002713 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07002714 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07002715 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
2716 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00002717 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002718 mask |= IXGBE_EIMS_MAILBOX;
2719 break;
2720 default:
2721 break;
2722 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002723
Alexander Duyck2c4af692011-07-15 07:29:55 +00002724 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2725 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2726 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002727
Alexander Duyck2c4af692011-07-15 07:29:55 +00002728 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2729 if (queues)
2730 ixgbe_irq_enable_queues(adapter, ~0);
2731 if (flush)
2732 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002733}
2734
Alexander Duyck2c4af692011-07-15 07:29:55 +00002735static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002736{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002737 struct ixgbe_adapter *adapter = data;
2738 struct ixgbe_hw *hw = &adapter->hw;
2739 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002740
Alexander Duyck2c4af692011-07-15 07:29:55 +00002741 /*
2742 * Workaround for Silicon errata. Use clear-by-write instead
2743 * of clear-by-read. Reading with EICS will return the
2744 * interrupt causes without clearing, which later be done
2745 * with the write to EICR.
2746 */
2747 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002748
2749 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08002750 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00002751 * the bits are high when ixgbe_msix_other is called. There is a race
2752 * condition otherwise which results in possible performance loss
2753 * especially if the ixgbe_msix_other interrupt is triggering
2754 * consistently (as it would when PPS is turned on for the X540 device)
2755 */
2756 eicr &= 0xFFFF0000;
2757
Alexander Duyck2c4af692011-07-15 07:29:55 +00002758 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002759
Alexander Duyck2c4af692011-07-15 07:29:55 +00002760 if (eicr & IXGBE_EICR_LSC)
2761 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002762
Alexander Duyck2c4af692011-07-15 07:29:55 +00002763 if (eicr & IXGBE_EICR_MAILBOX)
2764 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002765
Alexander Duyck2c4af692011-07-15 07:29:55 +00002766 switch (hw->mac.type) {
2767 case ixgbe_mac_82599EB:
2768 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002769 case ixgbe_mac_X550:
2770 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002771 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07002772 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
2773 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
2774 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
2775 ixgbe_service_event_schedule(adapter);
2776 IXGBE_WRITE_REG(hw, IXGBE_EICR,
2777 IXGBE_EICR_GPI_SDP0_X540);
2778 }
Don Skidmored773ce22014-02-25 17:58:53 -08002779 if (eicr & IXGBE_EICR_ECC) {
2780 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07002781 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08002782 ixgbe_service_event_schedule(adapter);
2783 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2784 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002785 /* Handle Flow Director Full threshold interrupt */
2786 if (eicr & IXGBE_EICR_FLOW_DIR) {
2787 int reinit_count = 0;
2788 int i;
2789 for (i = 0; i < adapter->num_tx_queues; i++) {
2790 struct ixgbe_ring *ring = adapter->tx_ring[i];
2791 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2792 &ring->state))
2793 reinit_count++;
2794 }
2795 if (reinit_count) {
2796 /* no more flow director interrupts until after init */
2797 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2798 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2799 ixgbe_service_event_schedule(adapter);
2800 }
2801 }
2802 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002803 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002804 break;
2805 default:
2806 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002807 }
2808
Alexander Duyck2c4af692011-07-15 07:29:55 +00002809 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002810
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002811 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07002812 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002813
Alexander Duyck2c4af692011-07-15 07:29:55 +00002814 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002815 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002816 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002817
Alexander Duyck2c4af692011-07-15 07:29:55 +00002818 return IRQ_HANDLED;
2819}
2820
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002821static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002822{
2823 struct ixgbe_q_vector *q_vector = data;
2824
Auke Kok9a799d72007-09-15 14:07:45 -07002825 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002826
2827 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07002828 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002829
2830 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002831}
2832
Auke Kok9a799d72007-09-15 14:07:45 -07002833/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002834 * ixgbe_poll - NAPI Rx polling callback
2835 * @napi: structure for representing this polling device
2836 * @budget: how many packets driver is allowed to clean
2837 *
2838 * This function is used for legacy and MSI, NAPI mode
2839 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002840int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002841{
2842 struct ixgbe_q_vector *q_vector =
2843 container_of(napi, struct ixgbe_q_vector, napi);
2844 struct ixgbe_adapter *adapter = q_vector->adapter;
2845 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002846 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00002847 bool clean_complete = true;
2848
2849#ifdef CONFIG_IXGBE_DCA
2850 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2851 ixgbe_update_dca(q_vector);
2852#endif
2853
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002854 ixgbe_for_each_ring(ring, q_vector->tx) {
2855 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
2856 clean_complete = false;
2857 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002858
Alexander Duyck5d6002b2015-09-22 14:35:41 -07002859 /* Exit if we are called by netpoll or busy polling is active */
2860 if ((budget <= 0) || !ixgbe_qv_lock_napi(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002861 return budget;
2862
Alexander Duyckeb01b972012-02-08 07:51:27 +00002863 /* attempt to distribute budget to each queue fairly, but don't allow
2864 * the budget to go below 1 because we'll exit polling */
2865 if (q_vector->rx.count > 1)
2866 per_ring_budget = max(budget/q_vector->rx.count, 1);
2867 else
2868 per_ring_budget = budget;
2869
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002870 ixgbe_for_each_ring(ring, q_vector->rx) {
2871 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
2872 per_ring_budget);
2873
2874 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08002875 if (cleaned >= per_ring_budget)
2876 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002877 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00002878
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002879 ixgbe_qv_unlock_napi(q_vector);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002880 /* If all work not completed, return budget and keep polling */
2881 if (!clean_complete)
2882 return budget;
2883
2884 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07002885 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002886 if (adapter->rx_itr_setting & 1)
2887 ixgbe_set_itr(q_vector);
2888 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002889 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00002890
Paolo Abeni4b732cd2016-06-15 15:37:59 +02002891 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002892}
2893
2894/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002895 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2896 * @adapter: board private structure
2897 *
2898 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2899 * interrupts from the kernel.
2900 **/
2901static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2902{
2903 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002904 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002905 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002906
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002907 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002908 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002909 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002910
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002911 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002912 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002913 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002914 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002915 } else if (q_vector->rx.ring) {
2916 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2917 "%s-%s-%d", netdev->name, "rx", ri++);
2918 } else if (q_vector->tx.ring) {
2919 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2920 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002921 } else {
2922 /* skip this unused q_vector */
2923 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002924 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002925 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2926 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002927 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002928 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002929 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002930 goto free_queue_irqs;
2931 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002932 /* If Flow Director is enabled, set interrupt affinity */
2933 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2934 /* assign the mask for this irq */
2935 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002936 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002937 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002938 }
2939
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002940 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002941 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002942 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002943 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002944 goto free_queue_irqs;
2945 }
2946
2947 return 0;
2948
2949free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002950 while (vector) {
2951 vector--;
2952 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2953 NULL);
2954 free_irq(adapter->msix_entries[vector].vector,
2955 adapter->q_vector[vector]);
2956 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002957 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2958 pci_disable_msix(adapter->pdev);
2959 kfree(adapter->msix_entries);
2960 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002961 return err;
2962}
2963
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002964/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002965 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002966 * @irq: interrupt number
2967 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002968 **/
2969static irqreturn_t ixgbe_intr(int irq, void *data)
2970{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002971 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002972 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002973 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002974 u32 eicr;
2975
Don Skidmore54037502009-02-21 15:42:56 -08002976 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002977 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002978 * before the read of EICR.
2979 */
2980 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2981
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002982 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002983 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002984 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002985 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002986 /*
2987 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002988 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002989 * have disabled interrupts due to EIAM
2990 * finish the workaround of silicon errata on 82598. Unmask
2991 * the interrupt that we masked before the EICR read.
2992 */
2993 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2994 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002995 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002996 }
Auke Kok9a799d72007-09-15 14:07:45 -07002997
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002998 if (eicr & IXGBE_EICR_LSC)
2999 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003000
Alexander Duyckbd508172010-11-16 19:27:03 -08003001 switch (hw->mac.type) {
3002 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003003 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003004 /* Fall through */
3005 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003006 case ixgbe_mac_X550:
3007 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003008 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003009 if (eicr & IXGBE_EICR_ECC) {
3010 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003011 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003012 ixgbe_service_event_schedule(adapter);
3013 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3014 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003015 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003016 break;
3017 default:
3018 break;
3019 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003020
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003021 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003022 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003023 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003024
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003025 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003026 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003027
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003028 /*
3029 * re-enable link(maybe) and non-queue interrupts, no flush.
3030 * ixgbe_poll will re-enable the queue interrupts
3031 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003032 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3033 ixgbe_irq_enable(adapter, false, false);
3034
Auke Kok9a799d72007-09-15 14:07:45 -07003035 return IRQ_HANDLED;
3036}
3037
3038/**
3039 * ixgbe_request_irq - initialize interrupts
3040 * @adapter: board private structure
3041 *
3042 * Attempts to configure interrupts using the best available
3043 * capabilities of the hardware and kernel.
3044 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003045static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003046{
3047 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003048 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003049
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003050 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003051 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003052 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003053 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003054 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003055 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003056 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003057 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003058
Alexander Duyckde88eee2012-02-08 07:49:59 +00003059 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003060 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003061
Auke Kok9a799d72007-09-15 14:07:45 -07003062 return err;
3063}
3064
3065static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3066{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003067 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003068
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003069 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003070 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003071 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003072 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003073
Mark Rustad1fa71252016-09-28 15:36:38 -07003074 if (!adapter->msix_entries)
3075 return;
3076
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003077 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3078 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3079 struct msix_entry *entry = &adapter->msix_entries[vector];
3080
3081 /* free only the irqs that were actually requested */
3082 if (!q_vector->rx.ring && !q_vector->tx.ring)
3083 continue;
3084
3085 /* clear the affinity_mask in the IRQ descriptor */
3086 irq_set_affinity_hint(entry->vector, NULL);
3087
3088 free_irq(entry->vector, q_vector);
3089 }
3090
Babu Moger90c6f872016-06-18 17:40:47 -07003091 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003092}
3093
3094/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003095 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3096 * @adapter: board private structure
3097 **/
3098static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3099{
Alexander Duyckbd508172010-11-16 19:27:03 -08003100 switch (adapter->hw.mac.type) {
3101 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003102 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003103 break;
3104 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003105 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003106 case ixgbe_mac_X550:
3107 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003108 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003109 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3110 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003111 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003112 break;
3113 default:
3114 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003115 }
3116 IXGBE_WRITE_FLUSH(&adapter->hw);
3117 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003118 int vector;
3119
3120 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3121 synchronize_irq(adapter->msix_entries[vector].vector);
3122
3123 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003124 } else {
3125 synchronize_irq(adapter->pdev->irq);
3126 }
3127}
3128
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003129/**
Auke Kok9a799d72007-09-15 14:07:45 -07003130 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3131 *
3132 **/
3133static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3134{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003135 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003136
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003137 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003138
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003139 ixgbe_set_ivar(adapter, 0, 0, 0);
3140 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003141
Emil Tantilov396e7992010-07-01 20:05:12 +00003142 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003143}
3144
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003145/**
3146 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3147 * @adapter: board private structure
3148 * @ring: structure containing ring specific data
3149 *
3150 * Configure the Tx descriptor ring after a reset.
3151 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003152void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3153 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003154{
3155 struct ixgbe_hw *hw = &adapter->hw;
3156 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003157 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003158 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003159 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003160
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003161 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003162 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003163 IXGBE_WRITE_FLUSH(hw);
3164
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003165 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003166 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003167 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3168 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3169 ring->count * sizeof(union ixgbe_adv_tx_desc));
3170 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3171 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003172 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003173
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003174 /*
3175 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003176 * higher than 1 when:
3177 * - ITR is 0 as it could cause false TX hangs
3178 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003179 *
3180 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3181 * to or less than the number of on chip descriptors, which is
3182 * currently 40.
3183 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003184 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003185 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003186 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003187 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003188
Alexander Duycke954b372012-02-08 07:49:38 +00003189 /*
3190 * Setting PTHRESH to 32 both improves performance
3191 * and avoids a TX hang with DFP enabled
3192 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003193 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003194 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003195
3196 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003197 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003198 ring->atr_sample_rate = adapter->atr_sample_rate;
3199 ring->atr_count = 0;
3200 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3201 } else {
3202 ring->atr_sample_rate = 0;
3203 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003204
Alexander Duyckfd786b72013-01-12 06:33:31 +00003205 /* initialize XPS */
3206 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3207 struct ixgbe_q_vector *q_vector = ring->q_vector;
3208
3209 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003210 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003211 &q_vector->affinity_mask,
3212 ring->queue_index);
3213 }
3214
John Fastabendc84d3242010-11-16 19:27:12 -08003215 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3216
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003217 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003218 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3219
3220 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3221 if (hw->mac.type == ixgbe_mac_82598EB &&
3222 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3223 return;
3224
3225 /* poll to verify queue is enabled */
3226 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003227 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003228 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3229 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3230 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003231 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003232}
3233
Alexander Duyck120ff942010-08-19 13:34:50 +00003234static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3235{
3236 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003237 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003238 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003239
3240 if (hw->mac.type == ixgbe_mac_82598EB)
3241 return;
3242
3243 /* disable the arbiter while setting MTQC */
3244 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3245 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3246 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3247
3248 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003249 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3250 mtqc = IXGBE_MTQC_VT_ENA;
3251 if (tcs > 4)
3252 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3253 else if (tcs > 1)
3254 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003255 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3256 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003257 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003258 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003259 mtqc |= IXGBE_MTQC_64VF;
3260 } else {
3261 if (tcs > 4)
3262 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3263 else if (tcs > 1)
3264 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3265 else
3266 mtqc = IXGBE_MTQC_64Q_1PB;
3267 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003268
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003269 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003270
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003271 /* Enable Security TX Buffer IFG for multiple pb */
3272 if (tcs) {
3273 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3274 sectx |= IXGBE_SECTX_DCB;
3275 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003276 }
3277
3278 /* re-enable the arbiter */
3279 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3280 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3281}
3282
Auke Kok9a799d72007-09-15 14:07:45 -07003283/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003284 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003285 * @adapter: board private structure
3286 *
3287 * Configure the Tx unit of the MAC after a reset.
3288 **/
3289static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3290{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003291 struct ixgbe_hw *hw = &adapter->hw;
3292 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003293 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003294
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003295 ixgbe_setup_mtqc(adapter);
3296
3297 if (hw->mac.type != ixgbe_mac_82598EB) {
3298 /* DMATXCTL.EN must be before Tx queues are enabled */
3299 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3300 dmatxctl |= IXGBE_DMATXCTL_TE;
3301 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3302 }
3303
Auke Kok9a799d72007-09-15 14:07:45 -07003304 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003305 for (i = 0; i < adapter->num_tx_queues; i++)
3306 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003307}
3308
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003309static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3310 struct ixgbe_ring *ring)
3311{
3312 struct ixgbe_hw *hw = &adapter->hw;
3313 u8 reg_idx = ring->reg_idx;
3314 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3315
3316 srrctl |= IXGBE_SRRCTL_DROP_EN;
3317
3318 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3319}
3320
3321static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3322 struct ixgbe_ring *ring)
3323{
3324 struct ixgbe_hw *hw = &adapter->hw;
3325 u8 reg_idx = ring->reg_idx;
3326 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3327
3328 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3329
3330 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3331}
3332
3333#ifdef CONFIG_IXGBE_DCB
3334void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3335#else
3336static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3337#endif
3338{
3339 int i;
3340 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3341
3342 if (adapter->ixgbe_ieee_pfc)
3343 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3344
3345 /*
3346 * We should set the drop enable bit if:
3347 * SR-IOV is enabled
3348 * or
3349 * Number of Rx queues > 1 and flow control is disabled
3350 *
3351 * This allows us to avoid head of line blocking for security
3352 * and performance reasons.
3353 */
3354 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3355 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3356 for (i = 0; i < adapter->num_rx_queues; i++)
3357 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3358 } else {
3359 for (i = 0; i < adapter->num_rx_queues; i++)
3360 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3361 }
3362}
3363
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003364#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003365
Yi Zoua6616b42009-08-06 13:05:23 +00003366static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003367 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003368{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003369 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003370 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003371 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003372
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003373 if (hw->mac.type == ixgbe_mac_82598EB) {
3374 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3375
3376 /*
3377 * if VMDq is not active we must program one srrctl register
3378 * per RSS queue since we have enabled RDRXCTL.MVMEN
3379 */
3380 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003381 }
3382
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003383 /* configure header buffer length, needed for RSC */
3384 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003385
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003386 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00003387 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003388
3389 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003390 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003391
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003392 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003393}
3394
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003395/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003396 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003397 * @adapter: device handle
3398 *
3399 * - 82598/82599/X540: 128
3400 * - X550(non-SRIOV mode): 512
3401 * - X550(SRIOV mode): 64
3402 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003403u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003404{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003405 if (adapter->hw.mac.type < ixgbe_mac_X550)
3406 return 128;
3407 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3408 return 64;
3409 else
3410 return 512;
3411}
3412
3413/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003414 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003415 * @adapter: device handle
3416 *
3417 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3418 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003419void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003420{
3421 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003422 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003423 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003424 u32 indices_multi;
3425 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003426
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003427 /* Fill out the redirection table as follows:
3428 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3429 * indices.
3430 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3431 * - X550: 8 bit wide entries containing 6 bit RSS index
3432 */
3433 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3434 indices_multi = 0x11;
3435 else
3436 indices_multi = 0x1;
3437
3438 /* Write redirection table to HW */
3439 for (i = 0; i < reta_entries; i++) {
3440 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3441 if ((i & 3) == 3) {
3442 if (i < 128)
3443 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3444 else
3445 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3446 reta);
3447 reta = 0;
3448 }
3449 }
3450}
3451
3452/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003453 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003454 * @adapter: device handle
3455 *
3456 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3457 */
3458static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3459{
3460 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3461 struct ixgbe_hw *hw = &adapter->hw;
3462 u32 vfreta = 0;
3463 unsigned int pf_pool = adapter->num_vfs;
3464
3465 /* Write redirection table to HW */
3466 for (i = 0; i < reta_entries; i++) {
3467 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3468 if ((i & 3) == 3) {
3469 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3470 vfreta);
3471 vfreta = 0;
3472 }
3473 }
3474}
3475
3476static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3477{
3478 struct ixgbe_hw *hw = &adapter->hw;
3479 u32 i, j;
3480 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3481 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3482
Alexander Duycke24fcf22016-09-07 20:28:24 -07003483 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003484 * make full use of any rings they may have. We will use the
3485 * PSRTYPE register to control how many rings we use within the PF.
3486 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003487 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3488 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003489
Alexander Duyck05abb122010-08-19 13:35:41 +00003490 /* Fill out hash function seeds */
3491 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003492 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003493
Alexander Duyck05abb122010-08-19 13:35:41 +00003494 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003495 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3496
Don Skidmore0f9b2322014-11-18 09:35:08 +00003497 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003498 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003499 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003500
3501 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003502 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003503
3504 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003505}
3506
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003507static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003508{
3509 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003510 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3511 unsigned int pf_pool = adapter->num_vfs;
3512 int i, j;
3513
3514 /* Fill out hash function seeds */
3515 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003516 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
3517 adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003518
3519 /* Fill out the redirection table */
3520 for (i = 0, j = 0; i < 64; i++, j++) {
3521 if (j == rss_i)
3522 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003523
3524 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003525 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003526
3527 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003528}
3529
3530static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3531{
3532 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003533 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003534 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003535
3536 /* Disable indicating checksum in descriptor, enables RSS hash */
3537 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3538 rxcsum |= IXGBE_RXCSUM_PCSD;
3539 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3540
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003541 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003542 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003543 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003544 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003545 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003546
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003547 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3548 if (tcs > 4)
3549 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3550 else if (tcs > 1)
3551 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003552 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3553 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003554 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3555 else
3556 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3557 } else {
3558 if (tcs > 4)
3559 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3560 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003561 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3562 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003563 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003564 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003565 }
3566
Alexander Duyck05abb122010-08-19 13:35:41 +00003567 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003568 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3569 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3570 IXGBE_MRQC_RSS_FIELD_IPV6 |
3571 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003572
Alexander Duyckef6afc02012-02-08 07:51:53 +00003573 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003574 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003575 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003576 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003577
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003578 netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003579 if ((hw->mac.type >= ixgbe_mac_X550) &&
3580 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3581 unsigned int pf_pool = adapter->num_vfs;
3582
3583 /* Enable VF RSS mode */
3584 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3585 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3586
3587 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003588 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003589 vfmrqc = IXGBE_MRQC_RSSEN;
3590 vfmrqc |= rss_field;
3591 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3592 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003593 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003594 mrqc |= rss_field;
3595 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3596 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003597}
3598
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003599/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003600 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3601 * @adapter: address of board private structure
3602 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003603 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003604static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003605 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003606{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003607 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003608 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003609 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003610
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003611 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003612 return;
3613
Alexander Duyck73670962010-08-19 13:38:34 +00003614 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003615 rscctrl |= IXGBE_RSCCTL_RSCEN;
3616 /*
3617 * we must limit the number of descriptors so that the
3618 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003619 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003620 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003621 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003622 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003623}
3624
Alexander Duyck9e10e042010-08-19 13:40:06 +00003625#define IXGBE_MAX_RX_DESC_POLL 10
3626static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3627 struct ixgbe_ring *ring)
3628{
3629 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003630 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3631 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003632 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003633
Mark Rustadb0483c82014-01-14 18:53:17 -08003634 if (ixgbe_removed(hw->hw_addr))
3635 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003636 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3637 if (hw->mac.type == ixgbe_mac_82598EB &&
3638 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3639 return;
3640
3641 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003642 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003643 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3644 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3645
3646 if (!wait_loop) {
3647 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3648 "the polling period\n", reg_idx);
3649 }
3650}
3651
Yi Zou2d39d572011-01-06 14:29:56 +00003652void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3653 struct ixgbe_ring *ring)
3654{
3655 struct ixgbe_hw *hw = &adapter->hw;
3656 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3657 u32 rxdctl;
3658 u8 reg_idx = ring->reg_idx;
3659
Mark Rustadb0483c82014-01-14 18:53:17 -08003660 if (ixgbe_removed(hw->hw_addr))
3661 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003662 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3663 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3664
3665 /* write value back with RXDCTL.ENABLE bit cleared */
3666 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3667
3668 if (hw->mac.type == ixgbe_mac_82598EB &&
3669 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3670 return;
3671
3672 /* the hardware may take up to 100us to really disable the rx queue */
3673 do {
3674 udelay(10);
3675 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3676 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3677
3678 if (!wait_loop) {
3679 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3680 "the polling period\n", reg_idx);
3681 }
3682}
3683
Alexander Duyck84418e32010-08-19 13:40:54 +00003684void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3685 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003686{
3687 struct ixgbe_hw *hw = &adapter->hw;
3688 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003689 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003690 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003691
Alexander Duyck9e10e042010-08-19 13:40:06 +00003692 /* disable queue to avoid issues while updating state */
3693 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003694 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003695
Alexander Duyckacd37172010-08-19 13:36:05 +00003696 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3697 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3698 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3699 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08003700 /* Force flushing of IXGBE_RDLEN to prevent MDD */
3701 IXGBE_WRITE_FLUSH(hw);
3702
Alexander Duyckacd37172010-08-19 13:36:05 +00003703 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3704 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003705 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003706
3707 ixgbe_configure_srrctl(adapter, ring);
3708 ixgbe_configure_rscctl(adapter, ring);
3709
3710 if (hw->mac.type == ixgbe_mac_82598EB) {
3711 /*
3712 * enable cache line friendly hardware writes:
3713 * PTHRESH=32 descriptors (half the internal cache),
3714 * this also removes ugly rx_no_buffer_count increment
3715 * HTHRESH=4 descriptors (to minimize latency on fetch)
3716 * WTHRESH=8 burst writeback up to two cache lines
3717 */
3718 rxdctl &= ~0x3FFFFF;
3719 rxdctl |= 0x080420;
3720 }
3721
3722 /* enable receive descriptor ring */
3723 rxdctl |= IXGBE_RXDCTL_ENABLE;
3724 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3725
3726 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003727 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003728}
3729
Alexander Duyck48654522010-08-19 13:36:27 +00003730static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3731{
3732 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003733 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003734 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003735
3736 /* PSRTYPE must be initialized in non 82598 adapters */
3737 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003738 IXGBE_PSRTYPE_UDPHDR |
3739 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003740 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003741 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003742
3743 if (hw->mac.type == ixgbe_mac_82598EB)
3744 return;
3745
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003746 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003747 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003748 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003749 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003750
John Fastabend2a47fa42013-11-06 09:54:52 -08003751 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3752 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003753}
3754
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003755static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3756{
3757 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003758 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003759 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003760 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003761
3762 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3763 return;
3764
3765 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003766 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3767 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003768 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003769 vmdctl |= IXGBE_VT_CTL_REPLEN;
3770 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003771
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003772 vf_shift = VMDQ_P(0) % 32;
3773 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003774
3775 /* Enable only the PF's pool for Tx/Rx */
Emil Tantilov11f2b492016-05-04 15:01:27 -07003776 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00003777 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
Emil Tantilov11f2b492016-05-04 15:01:27 -07003778 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00003779 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07003780 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00003781 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003782
3783 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003784 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003785
Alexander Duyck16369562015-11-02 17:10:13 -08003786 /* clear VLAN promisc flag so VFTA will be updated if necessary */
3787 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
3788
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003789 /*
3790 * Set up VF register offsets for selected VT Mode,
3791 * i.e. 32 or 64 VFs for SR-IOV
3792 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003793 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3794 case IXGBE_82599_VMDQ_8Q_MASK:
3795 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3796 break;
3797 case IXGBE_82599_VMDQ_4Q_MASK:
3798 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3799 break;
3800 default:
3801 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3802 break;
3803 }
3804
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003805 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3806
Greg Rosede4c7f62011-09-29 05:57:33 +00003807 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07003808 /* configure spoof checking */
3809 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
3810 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03003811
3812 /* Enable/Disable RSS query feature */
3813 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
3814 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00003815 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003816}
3817
Alexander Duyck477de6e2010-08-19 13:38:11 +00003818static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003819{
Auke Kok9a799d72007-09-15 14:07:45 -07003820 struct ixgbe_hw *hw = &adapter->hw;
3821 struct net_device *netdev = adapter->netdev;
3822 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003823 struct ixgbe_ring *rx_ring;
3824 int i;
3825 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003826
Alexander Duyck477de6e2010-08-19 13:38:11 +00003827#ifdef IXGBE_FCOE
3828 /* adjust max frame to be able to do baby jumbo for FCoE */
3829 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3830 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3831 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3832
3833#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003834
3835 /* adjust max frame to be at least the size of a standard frame */
3836 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3837 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3838
Alexander Duyck477de6e2010-08-19 13:38:11 +00003839 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3840 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3841 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3842 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3843
3844 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003845 }
3846
Auke Kok9a799d72007-09-15 14:07:45 -07003847 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003848 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3849 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003850 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3851
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003852 /*
3853 * Setup the HW Rx Head and Tail Descriptor Pointers and
3854 * the Base and Length of the Rx Descriptor Ring
3855 */
Auke Kok9a799d72007-09-15 14:07:45 -07003856 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003857 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003858 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3859 set_ring_rsc_enabled(rx_ring);
3860 else
3861 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003862 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003863}
3864
Alexander Duyck73670962010-08-19 13:38:34 +00003865static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3866{
3867 struct ixgbe_hw *hw = &adapter->hw;
3868 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3869
3870 switch (hw->mac.type) {
3871 case ixgbe_mac_82598EB:
3872 /*
3873 * For VMDq support of different descriptor types or
3874 * buffer sizes through the use of multiple SRRCTL
3875 * registers, RDRXCTL.MVMEN must be set to 1
3876 *
3877 * also, the manual doesn't mention it clearly but DCA hints
3878 * will only use queue 0's tags unless this bit is set. Side
3879 * effects of setting this bit are only that SRRCTL must be
3880 * fully programmed [0..15]
3881 */
3882 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3883 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07003884 case ixgbe_mac_X550:
3885 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003886 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07003887 if (adapter->num_vfs)
3888 rdrxctl |= IXGBE_RDRXCTL_PSP;
3889 /* fall through for older HW */
Alexander Duyck73670962010-08-19 13:38:34 +00003890 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003891 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003892 /* Disable RSC for ACK packets */
3893 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3894 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3895 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3896 /* hardware requires some bits to be set by default */
3897 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3898 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3899 break;
3900 default:
3901 /* We should do nothing since we don't know this hardware */
3902 return;
3903 }
3904
3905 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3906}
3907
Alexander Duyck477de6e2010-08-19 13:38:11 +00003908/**
3909 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3910 * @adapter: board private structure
3911 *
3912 * Configure the Rx unit of the MAC after a reset.
3913 **/
3914static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3915{
3916 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003917 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003918 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003919
3920 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07003921 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003922
3923 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003924 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003925
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003926 /* RSC Setup */
3927 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
3928 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
3929 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
3930 rfctl |= IXGBE_RFCTL_RSC_DIS;
Emil Tantilova21d0822016-08-10 11:19:23 -07003931
3932 /* disable NFS filtering */
3933 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003934 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
3935
Alexander Duyck9e10e042010-08-19 13:40:06 +00003936 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003937 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003938
Alexander Duyck477de6e2010-08-19 13:38:11 +00003939 /* set_rx_buffer_len must be called before ring initialization */
3940 ixgbe_set_rx_buffer_len(adapter);
3941
3942 /*
3943 * Setup the HW Rx Head and Tail Descriptor Pointers and
3944 * the Base and Length of the Rx Descriptor Ring
3945 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003946 for (i = 0; i < adapter->num_rx_queues; i++)
3947 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003948
Don Skidmore1f9ac572015-03-13 13:54:30 -07003949 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003950 /* disable drop enable for 82598 parts */
3951 if (hw->mac.type == ixgbe_mac_82598EB)
3952 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3953
3954 /* enable all receives */
3955 rxctrl |= IXGBE_RXCTRL_RXEN;
3956 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003957}
3958
Patrick McHardy80d5c362013-04-19 02:04:28 +00003959static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3960 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003961{
3962 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003963 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003964
3965 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08003966 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
3967 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
3968
Jesse Grossf62bbb52010-10-20 13:56:10 +00003969 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003970
3971 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003972}
3973
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08003974static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
3975{
3976 u32 vlvf;
3977 int idx;
3978
3979 /* short cut the special case */
3980 if (vlan == 0)
3981 return 0;
3982
3983 /* Search for the vlan id in the VLVF entries */
3984 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
3985 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
3986 if ((vlvf & VLAN_VID_MASK) == vlan)
3987 break;
3988 }
3989
3990 return idx;
3991}
3992
3993void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
3994{
3995 struct ixgbe_hw *hw = &adapter->hw;
3996 u32 bits, word;
3997 int idx;
3998
3999 idx = ixgbe_find_vlvf_entry(hw, vid);
4000 if (!idx)
4001 return;
4002
4003 /* See if any other pools are set for this VLAN filter
4004 * entry other than the PF.
4005 */
4006 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004007 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004008 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4009
4010 /* Disable the filter so this falls into the default pool. */
4011 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4012 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4013 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4014 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4015 }
4016}
4017
Patrick McHardy80d5c362013-04-19 02:04:28 +00004018static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4019 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004020{
4021 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004022 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004023
Auke Kok9a799d72007-09-15 14:07:45 -07004024 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004025 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004026 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4027
Jesse Grossf62bbb52010-10-20 13:56:10 +00004028 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004029
4030 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004031}
4032
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004033/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004034 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4035 * @adapter: driver data
4036 */
4037static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4038{
4039 struct ixgbe_hw *hw = &adapter->hw;
4040 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004041 int i, j;
4042
4043 switch (hw->mac.type) {
4044 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004045 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4046 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004047 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4048 break;
4049 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004050 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004051 case ixgbe_mac_X550:
4052 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004053 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004054 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004055 struct ixgbe_ring *ring = adapter->rx_ring[i];
4056
4057 if (ring->l2_accel_priv)
4058 continue;
4059 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004060 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4061 vlnctrl &= ~IXGBE_RXDCTL_VME;
4062 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4063 }
4064 break;
4065 default:
4066 break;
4067 }
4068}
4069
4070/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004071 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004072 * @adapter: driver data
4073 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004074static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004075{
4076 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004077 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004078 int i, j;
4079
4080 switch (hw->mac.type) {
4081 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004082 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4083 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004084 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4085 break;
4086 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004087 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004088 case ixgbe_mac_X550:
4089 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004090 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004091 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004092 struct ixgbe_ring *ring = adapter->rx_ring[i];
4093
4094 if (ring->l2_accel_priv)
4095 continue;
4096 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004097 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4098 vlnctrl |= IXGBE_RXDCTL_VME;
4099 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4100 }
4101 break;
4102 default:
4103 break;
4104 }
4105}
4106
Alexander Duyck16369562015-11-02 17:10:13 -08004107static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4108{
4109 struct ixgbe_hw *hw = &adapter->hw;
4110 u32 vlnctrl, i;
4111
Alexander Duyckf60439b2016-08-11 14:51:56 -07004112 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4113
Emil Tantilov691e4122016-08-22 16:17:46 -07004114 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4115 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4116 vlnctrl |= IXGBE_VLNCTRL_VFE;
4117 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4118 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004119 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004120 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4121 return;
4122 }
4123
Emil Tantilov691e4122016-08-22 16:17:46 -07004124 /* Nothing to do for 82598 */
4125 if (hw->mac.type == ixgbe_mac_82598EB)
4126 return;
4127
Alexander Duyck16369562015-11-02 17:10:13 -08004128 /* We are already in VLAN promisc, nothing to do */
4129 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4130 return;
4131
4132 /* Set flag so we don't redo unnecessary work */
4133 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4134
4135 /* Add PF to all active pools */
4136 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4137 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4138 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4139
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004140 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004141 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4142 }
4143
4144 /* Set all bits in the VLAN filter table array */
4145 for (i = hw->mac.vft_size; i--;)
4146 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4147}
4148
4149#define VFTA_BLOCK_SIZE 8
4150static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4151{
4152 struct ixgbe_hw *hw = &adapter->hw;
4153 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4154 u32 vid_start = vfta_offset * 32;
4155 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4156 u32 i, vid, word, bits;
4157
4158 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4159 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4160
4161 /* pull VLAN ID from VLVF */
4162 vid = vlvf & VLAN_VID_MASK;
4163
4164 /* only concern outselves with a certain range */
4165 if (vid < vid_start || vid >= vid_end)
4166 continue;
4167
4168 if (vlvf) {
4169 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004170 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004171
4172 /* if PF is part of this then continue */
4173 if (test_bit(vid, adapter->active_vlans))
4174 continue;
4175 }
4176
4177 /* remove PF from the pool */
4178 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004179 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004180 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4181 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4182 }
4183
4184 /* extract values from active_vlans and write back to VFTA */
4185 for (i = VFTA_BLOCK_SIZE; i--;) {
4186 vid = (vfta_offset + i) * 32;
4187 word = vid / BITS_PER_LONG;
4188 bits = vid % BITS_PER_LONG;
4189
4190 vfta[i] |= adapter->active_vlans[word] >> bits;
4191
4192 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4193 }
4194}
4195
4196static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4197{
4198 struct ixgbe_hw *hw = &adapter->hw;
4199 u32 vlnctrl, i;
4200
Alexander Duyckf60439b2016-08-11 14:51:56 -07004201 /* Set VLAN filtering to enabled */
4202 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4203 vlnctrl |= IXGBE_VLNCTRL_VFE;
4204 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4205
Emil Tantilov691e4122016-08-22 16:17:46 -07004206 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4207 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004208 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004209
4210 /* We are not in VLAN promisc, nothing to do */
4211 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4212 return;
4213
4214 /* Set flag so we don't redo unnecessary work */
4215 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4216
4217 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4218 ixgbe_scrub_vfta(adapter, i);
4219}
4220
Auke Kok9a799d72007-09-15 14:07:45 -07004221static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4222{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004223 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004224
Patrick McHardy80d5c362013-04-19 02:04:28 +00004225 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004226
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004227 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004228 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004229}
4230
4231/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004232 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4233 * @netdev: network interface device structure
4234 *
4235 * Writes multicast address list to the MTA hash table.
4236 * Returns: -ENOMEM on failure
4237 * 0 on no addresses written
4238 * X on writing X addresses to MTA
4239 **/
4240static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4241{
4242 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4243 struct ixgbe_hw *hw = &adapter->hw;
4244
4245 if (!netif_running(netdev))
4246 return 0;
4247
4248 if (hw->mac.ops.update_mc_addr_list)
4249 hw->mac.ops.update_mc_addr_list(hw, netdev);
4250 else
4251 return -ENOMEM;
4252
4253#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004254 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004255#endif
4256
4257 return netdev_mc_count(netdev);
4258}
4259
Jacob Keller5d7daa32014-03-29 06:51:25 +00004260#ifdef CONFIG_PCI_IOV
4261void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4262{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004263 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004264 struct ixgbe_hw *hw = &adapter->hw;
4265 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004266
4267 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4268 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4269
4270 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4271 hw->mac.ops.set_rar(hw, i,
4272 mac_table->addr,
4273 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004274 IXGBE_RAH_AV);
4275 else
4276 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004277 }
4278}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004279
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004280#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004281static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4282{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004283 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004284 struct ixgbe_hw *hw = &adapter->hw;
4285 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004286
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004287 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4288 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4289 continue;
4290
4291 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4292
4293 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4294 hw->mac.ops.set_rar(hw, i,
4295 mac_table->addr,
4296 mac_table->pool,
4297 IXGBE_RAH_AV);
4298 else
4299 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004300 }
4301}
4302
4303static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4304{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004305 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004306 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004307 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004308
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004309 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4310 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4311 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004312 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004313
Jacob Keller5d7daa32014-03-29 06:51:25 +00004314 ixgbe_sync_mac_table(adapter);
4315}
4316
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004317static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004318{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004319 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004320 struct ixgbe_hw *hw = &adapter->hw;
4321 int i, count = 0;
4322
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004323 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4324 /* do not count default RAR as available */
4325 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4326 continue;
4327
4328 /* only count unused and addresses that belong to us */
4329 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4330 if (mac_table->pool != pool)
4331 continue;
4332 }
4333
4334 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004335 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004336
Jacob Keller5d7daa32014-03-29 06:51:25 +00004337 return count;
4338}
4339
4340/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004341static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004342{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004343 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004344 struct ixgbe_hw *hw = &adapter->hw;
4345
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004346 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4347 mac_table->pool = VMDQ_P(0);
4348
4349 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4350
4351 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004352 IXGBE_RAH_AV);
4353}
4354
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004355int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4356 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004357{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004358 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004359 struct ixgbe_hw *hw = &adapter->hw;
4360 int i;
4361
4362 if (is_zero_ether_addr(addr))
4363 return -EINVAL;
4364
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004365 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4366 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004367 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004368
4369 ether_addr_copy(mac_table->addr, addr);
4370 mac_table->pool = pool;
4371
4372 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4373 IXGBE_MAC_STATE_IN_USE;
4374
Jacob Keller5d7daa32014-03-29 06:51:25 +00004375 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004376
Jacob Keller5d7daa32014-03-29 06:51:25 +00004377 return i;
4378 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004379
Jacob Keller5d7daa32014-03-29 06:51:25 +00004380 return -ENOMEM;
4381}
4382
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004383int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4384 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004385{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004386 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004387 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004388 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004389
4390 if (is_zero_ether_addr(addr))
4391 return -EINVAL;
4392
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004393 /* search table for addr, if found clear IN_USE flag and sync */
4394 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4395 /* we can only delete an entry if it is in use */
4396 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4397 continue;
4398 /* we only care about entries that belong to the given pool */
4399 if (mac_table->pool != pool)
4400 continue;
4401 /* we only care about a specific MAC address */
4402 if (!ether_addr_equal(addr, mac_table->addr))
4403 continue;
4404
4405 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4406 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4407
4408 ixgbe_sync_mac_table(adapter);
4409
4410 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004411 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004412
Jacob Keller5d7daa32014-03-29 06:51:25 +00004413 return -ENOMEM;
4414}
Jacob Kellerb335e752014-03-25 07:45:27 +00004415/**
Alexander Duyck28500622010-06-15 09:25:48 +00004416 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4417 * @netdev: network interface device structure
4418 *
4419 * Writes unicast address list to the RAR table.
4420 * Returns: -ENOMEM on failure/insufficient address space
4421 * 0 on no addresses written
4422 * X on writing X addresses to the RAR table
4423 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004424static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004425{
4426 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004427 int count = 0;
4428
4429 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004430 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004431 return -ENOMEM;
4432
John Fastabend95447462012-05-31 12:42:26 +00004433 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004434 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004435 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004436 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4437 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004438 count++;
4439 }
4440 }
Alexander Duyck28500622010-06-15 09:25:48 +00004441 return count;
4442}
4443
Alexander Duyck0f079d22015-10-22 16:26:36 -07004444static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4445{
4446 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4447 int ret;
4448
4449 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4450
4451 return min_t(int, ret, 0);
4452}
4453
4454static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4455{
4456 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4457
4458 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4459
4460 return 0;
4461}
4462
Alexander Duyck28500622010-06-15 09:25:48 +00004463/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004464 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004465 * @netdev: network interface device structure
4466 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004467 * The set_rx_method entry point is called whenever the unicast/multicast
4468 * address list or the network interface flags are updated. This routine is
4469 * responsible for configuring the hardware for proper unicast, multicast and
4470 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004471 **/
Greg Rose7f870472010-01-09 02:25:29 +00004472void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004473{
4474 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4475 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004476 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004477 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004478 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004479
4480 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004481 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4482
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004483 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004484 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004485 fctrl |= IXGBE_FCTRL_BAM;
4486 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4487 fctrl |= IXGBE_FCTRL_PMCF;
4488
Alexander Duyck28500622010-06-15 09:25:48 +00004489 /* clear the bits we are changing the status of */
4490 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004491 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004492 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004493 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004494 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004495 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004496 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004497 if (netdev->flags & IFF_ALLMULTI) {
4498 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004499 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004500 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004501 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004502 }
4503
4504 /*
4505 * Write addresses to available RAR registers, if there is not
4506 * sufficient space to store all the addresses then enable
4507 * unicast promiscuous mode
4508 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004509 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004510 fctrl |= IXGBE_FCTRL_UPE;
4511 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004512 }
4513
Emil Tantilovcf789592013-10-26 08:13:20 +00004514 /* Write addresses to the MTA, if the attempt fails
4515 * then we should just turn on promiscuous mode so
4516 * that we can at least receive multicast traffic
4517 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004518 count = ixgbe_write_mc_addr_list(netdev);
4519 if (count < 0) {
4520 fctrl |= IXGBE_FCTRL_MPE;
4521 vmolr |= IXGBE_VMOLR_MPE;
4522 } else if (count) {
4523 vmolr |= IXGBE_VMOLR_ROMPE;
4524 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004525
4526 if (hw->mac.type != ixgbe_mac_82598EB) {
4527 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004528 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4529 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004530 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004531 }
4532
Ben Greear3f2d1c02012-03-08 08:28:41 +00004533 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004534 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004535 /* UPE and MPE will be handled by normal PROMISC logic
4536 * in e1000e_set_rx_mode */
4537 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4538 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4539 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4540
4541 fctrl &= ~(IXGBE_FCTRL_DPF);
4542 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4543 }
4544
Auke Kok9a799d72007-09-15 14:07:45 -07004545 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004546
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004547 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004548 ixgbe_vlan_strip_enable(adapter);
4549 else
4550 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004551
4552 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4553 ixgbe_vlan_promisc_disable(adapter);
4554 else
4555 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004556}
4557
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004558static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4559{
4560 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004561
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004562 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
4563 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004564 napi_enable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004565 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004566}
4567
4568static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4569{
4570 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004571
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004572 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004573 napi_disable(&adapter->q_vector[q_idx]->napi);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004574 while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) {
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004575 pr_info("QV %d locked\n", q_idx);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004576 usleep_range(1000, 20000);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004577 }
4578 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004579}
4580
Emil Tantilova21d0822016-08-10 11:19:23 -07004581static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07004582{
Emil Tantilova21d0822016-08-10 11:19:23 -07004583 struct ixgbe_hw *hw = &adapter->hw;
4584 u32 vxlanctrl;
4585
4586 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
4587 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
4588 return;
4589
4590 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask;
4591 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
4592
4593 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07004594 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07004595
4596 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
4597 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07004598}
4599
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004600#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004601/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004602 * ixgbe_configure_dcb - Configure DCB hardware
4603 * @adapter: ixgbe adapter struct
4604 *
4605 * This is called by the driver on open to configure the DCB hardware.
4606 * This is also called by the gennetlink interface when reconfiguring
4607 * the DCB state.
4608 */
4609static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4610{
4611 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00004612 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004613
Alexander Duyck67ebd792010-08-19 13:34:04 +00004614 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4615 if (hw->mac.type == ixgbe_mac_82598EB)
4616 netif_set_gso_max_size(adapter->netdev, 65536);
4617 return;
4618 }
4619
4620 if (hw->mac.type == ixgbe_mac_82598EB)
4621 netif_set_gso_max_size(adapter->netdev, 32768);
4622
John Fastabendb1208182011-10-15 05:00:10 +00004623#ifdef IXGBE_FCOE
4624 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4625 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4626#endif
4627
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004628 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004629 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004630 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4631 DCB_TX_CONFIG);
4632 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4633 DCB_RX_CONFIG);
4634 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004635 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4636 ixgbe_dcb_hw_ets(&adapter->hw,
4637 adapter->ixgbe_ieee_ets,
4638 max_frame);
4639 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4640 adapter->ixgbe_ieee_pfc->pfc_en,
4641 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004642 }
John Fastabend8187cd42011-02-23 05:58:08 +00004643
4644 /* Enable RSS Hash per TC */
4645 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004646 u32 msb = 0;
4647 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004648
Alexander Duyckd411a932012-06-30 00:14:01 +00004649 while (rss_i) {
4650 msb++;
4651 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004652 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004653
Alexander Duyck4ae63732012-06-22 06:46:33 +00004654 /* write msb to all 8 TCs in one write */
4655 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004656 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004657}
John Fastabend9da712d2011-08-23 03:14:22 +00004658#endif
4659
4660/* Additional bittime to account for IXGBE framing */
4661#define IXGBE_ETH_FRAMING 20
4662
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004663/**
John Fastabend9da712d2011-08-23 03:14:22 +00004664 * ixgbe_hpbthresh - calculate high water mark for flow control
4665 *
4666 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004667 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004668 */
4669static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4670{
4671 struct ixgbe_hw *hw = &adapter->hw;
4672 struct net_device *dev = adapter->netdev;
4673 int link, tc, kb, marker;
4674 u32 dv_id, rx_pba;
4675
4676 /* Calculate max LAN frame size */
4677 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4678
4679#ifdef IXGBE_FCOE
4680 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004681 if ((dev->features & NETIF_F_FCOE_MTU) &&
4682 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4683 (pb == ixgbe_fcoe_get_tc(adapter)))
4684 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004685#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004686
John Fastabend9da712d2011-08-23 03:14:22 +00004687 /* Calculate delay value for device */
4688 switch (hw->mac.type) {
4689 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004690 case ixgbe_mac_X550:
4691 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004692 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004693 dv_id = IXGBE_DV_X540(link, tc);
4694 break;
4695 default:
4696 dv_id = IXGBE_DV(link, tc);
4697 break;
4698 }
4699
4700 /* Loopback switch introduces additional latency */
4701 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4702 dv_id += IXGBE_B2BT(tc);
4703
4704 /* Delay value is calculated in bit times convert to KB */
4705 kb = IXGBE_BT2KB(dv_id);
4706 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4707
4708 marker = rx_pba - kb;
4709
4710 /* It is possible that the packet buffer is not large enough
4711 * to provide required headroom. In this case throw an error
4712 * to user and a do the best we can.
4713 */
4714 if (marker < 0) {
4715 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4716 "headroom to support flow control."
4717 "Decrease MTU or number of traffic classes\n", pb);
4718 marker = tc + 1;
4719 }
4720
4721 return marker;
4722}
4723
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004724/**
John Fastabend9da712d2011-08-23 03:14:22 +00004725 * ixgbe_lpbthresh - calculate low water mark for for flow control
4726 *
4727 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004728 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004729 */
Jacob Kellere5776622014-04-05 02:35:52 +00004730static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00004731{
4732 struct ixgbe_hw *hw = &adapter->hw;
4733 struct net_device *dev = adapter->netdev;
4734 int tc;
4735 u32 dv_id;
4736
4737 /* Calculate max LAN frame size */
4738 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4739
Jacob Kellere5776622014-04-05 02:35:52 +00004740#ifdef IXGBE_FCOE
4741 /* FCoE traffic class uses FCOE jumbo frames */
4742 if ((dev->features & NETIF_F_FCOE_MTU) &&
4743 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4744 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4745 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4746#endif
4747
John Fastabend9da712d2011-08-23 03:14:22 +00004748 /* Calculate delay value for device */
4749 switch (hw->mac.type) {
4750 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004751 case ixgbe_mac_X550:
4752 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004753 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004754 dv_id = IXGBE_LOW_DV_X540(tc);
4755 break;
4756 default:
4757 dv_id = IXGBE_LOW_DV(tc);
4758 break;
4759 }
4760
4761 /* Delay value is calculated in bit times convert to KB */
4762 return IXGBE_BT2KB(dv_id);
4763}
4764
4765/*
4766 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4767 */
4768static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4769{
4770 struct ixgbe_hw *hw = &adapter->hw;
4771 int num_tc = netdev_get_num_tc(adapter->netdev);
4772 int i;
4773
4774 if (!num_tc)
4775 num_tc = 1;
4776
John Fastabend9da712d2011-08-23 03:14:22 +00004777 for (i = 0; i < num_tc; i++) {
4778 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00004779 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00004780
4781 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00004782 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4783 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004784 }
Jacob Kellere5776622014-04-05 02:35:52 +00004785
4786 for (; i < MAX_TRAFFIC_CLASS; i++)
4787 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004788}
John Fastabend80605c652011-05-02 12:34:10 +00004789
4790static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4791{
John Fastabend80605c652011-05-02 12:34:10 +00004792 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004793 int hdrm;
4794 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004795
4796 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4797 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004798 hdrm = 32 << adapter->fdir_pballoc;
4799 else
4800 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004801
Alexander Duyckf7e10272011-07-21 00:40:35 +00004802 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004803 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004804}
4805
Alexander Duycke4911d52011-05-11 07:18:52 +00004806static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4807{
4808 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004809 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004810 struct ixgbe_fdir_filter *filter;
4811
4812 spin_lock(&adapter->fdir_perfect_lock);
4813
4814 if (!hlist_empty(&adapter->fdir_filter_list))
4815 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4816
Sasha Levinb67bfe02013-02-27 17:06:00 -08004817 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004818 &adapter->fdir_filter_list, fdir_node) {
4819 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004820 &filter->filter,
4821 filter->sw_idx,
4822 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4823 IXGBE_FDIR_DROP_QUEUE :
4824 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004825 }
4826
4827 spin_unlock(&adapter->fdir_perfect_lock);
4828}
4829
John Fastabend2a47fa42013-11-06 09:54:52 -08004830static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4831 struct ixgbe_adapter *adapter)
4832{
4833 struct ixgbe_hw *hw = &adapter->hw;
4834 u32 vmolr;
4835
4836 /* No unicast promiscuous support for VMDQ devices. */
4837 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4838 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4839
4840 /* clear the affected bit */
4841 vmolr &= ~IXGBE_VMOLR_MPE;
4842
4843 if (dev->flags & IFF_ALLMULTI) {
4844 vmolr |= IXGBE_VMOLR_MPE;
4845 } else {
4846 vmolr |= IXGBE_VMOLR_ROMPE;
4847 hw->mac.ops.update_mc_addr_list(hw, dev);
4848 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00004849 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08004850 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4851}
4852
John Fastabend2a47fa42013-11-06 09:54:52 -08004853static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4854{
4855 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004856 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004857 struct ixgbe_hw *hw = &adapter->hw;
4858 u16 pool = vadapter->pool;
4859 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4860 IXGBE_PSRTYPE_UDPHDR |
4861 IXGBE_PSRTYPE_IPV4HDR |
4862 IXGBE_PSRTYPE_L2HDR |
4863 IXGBE_PSRTYPE_IPV6HDR;
4864
4865 if (hw->mac.type == ixgbe_mac_82598EB)
4866 return;
4867
4868 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004869 psrtype |= 2u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004870 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004871 psrtype |= 1u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08004872
4873 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4874}
4875
4876/**
4877 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4878 * @rx_ring: ring to free buffers from
4879 **/
4880static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4881{
4882 struct device *dev = rx_ring->dev;
4883 unsigned long size;
4884 u16 i;
4885
4886 /* ring already cleared, nothing to do */
4887 if (!rx_ring->rx_buffer_info)
4888 return;
4889
4890 /* Free all the Rx ring sk_buffs */
4891 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyck18cb6522014-11-14 00:56:29 +00004892 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08004893
John Fastabend2a47fa42013-11-06 09:54:52 -08004894 if (rx_buffer->skb) {
4895 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00004896 if (IXGBE_CB(skb)->page_released)
John Fastabend2a47fa42013-11-06 09:54:52 -08004897 dma_unmap_page(dev,
4898 IXGBE_CB(skb)->dma,
4899 ixgbe_rx_bufsz(rx_ring),
4900 DMA_FROM_DEVICE);
John Fastabend2a47fa42013-11-06 09:54:52 -08004901 dev_kfree_skb(skb);
Junwei Zhang4d2fcfb2014-10-22 15:29:03 +00004902 rx_buffer->skb = NULL;
John Fastabend2a47fa42013-11-06 09:54:52 -08004903 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00004904
4905 if (!rx_buffer->page)
4906 continue;
4907
4908 dma_unmap_page(dev, rx_buffer->dma,
4909 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
4910 __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring));
4911
John Fastabend2a47fa42013-11-06 09:54:52 -08004912 rx_buffer->page = NULL;
4913 }
4914
4915 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4916 memset(rx_ring->rx_buffer_info, 0, size);
4917
4918 /* Zero out the descriptor ring */
4919 memset(rx_ring->desc, 0, rx_ring->size);
4920
4921 rx_ring->next_to_alloc = 0;
4922 rx_ring->next_to_clean = 0;
4923 rx_ring->next_to_use = 0;
4924}
4925
4926static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
4927 struct ixgbe_ring *rx_ring)
4928{
4929 struct ixgbe_adapter *adapter = vadapter->real_adapter;
4930 int index = rx_ring->queue_index + vadapter->rx_base_queue;
4931
4932 /* shutdown specific queue receive and wait for dma to settle */
4933 ixgbe_disable_rx_queue(adapter, rx_ring);
4934 usleep_range(10000, 20000);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004935 ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
John Fastabend2a47fa42013-11-06 09:54:52 -08004936 ixgbe_clean_rx_ring(rx_ring);
4937 rx_ring->l2_accel_priv = NULL;
4938}
4939
John Fastabendae72c8d2013-11-09 07:11:26 +00004940static int ixgbe_fwd_ring_down(struct net_device *vdev,
4941 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08004942{
4943 struct ixgbe_adapter *adapter = accel->real_adapter;
4944 unsigned int rxbase = accel->rx_base_queue;
4945 unsigned int txbase = accel->tx_base_queue;
4946 int i;
4947
4948 netif_tx_stop_all_queues(vdev);
4949
4950 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4951 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4952 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
4953 }
4954
4955 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4956 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
4957 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
4958 }
4959
4960
4961 return 0;
4962}
4963
4964static int ixgbe_fwd_ring_up(struct net_device *vdev,
4965 struct ixgbe_fwd_adapter *accel)
4966{
4967 struct ixgbe_adapter *adapter = accel->real_adapter;
4968 unsigned int rxbase, txbase, queues;
4969 int i, baseq, err = 0;
4970
4971 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
4972 return 0;
4973
4974 baseq = accel->pool * adapter->num_rx_queues_per_pool;
4975 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4976 accel->pool, adapter->num_rx_pools,
4977 baseq, baseq + adapter->num_rx_queues_per_pool,
4978 adapter->fwd_bitmask);
4979
4980 accel->netdev = vdev;
4981 accel->rx_base_queue = rxbase = baseq;
4982 accel->tx_base_queue = txbase = baseq;
4983
4984 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
4985 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4986
4987 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4988 adapter->rx_ring[rxbase + i]->netdev = vdev;
4989 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
4990 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
4991 }
4992
4993 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4994 adapter->tx_ring[txbase + i]->netdev = vdev;
4995 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
4996 }
4997
4998 queues = min_t(unsigned int,
4999 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
5000 err = netif_set_real_num_tx_queues(vdev, queues);
5001 if (err)
5002 goto fwd_queue_err;
5003
John Fastabend2a47fa42013-11-06 09:54:52 -08005004 err = netif_set_real_num_rx_queues(vdev, queues);
5005 if (err)
5006 goto fwd_queue_err;
5007
5008 if (is_valid_ether_addr(vdev->dev_addr))
5009 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
5010
5011 ixgbe_fwd_psrtype(accel);
5012 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
5013 return err;
5014fwd_queue_err:
5015 ixgbe_fwd_ring_down(vdev, accel);
5016 return err;
5017}
5018
David Ahern1cd127f2016-10-17 19:15:48 -07005019static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
5020{
5021 if (netif_is_macvlan(upper)) {
5022 struct macvlan_dev *dfwd = netdev_priv(upper);
5023 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5024
5025 if (dfwd->fwd_priv)
5026 ixgbe_fwd_ring_up(upper, vadapter);
5027 }
5028
5029 return 0;
5030}
5031
John Fastabend2a47fa42013-11-06 09:54:52 -08005032static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5033{
David Ahern1cd127f2016-10-17 19:15:48 -07005034 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5035 ixgbe_upper_dev_walk, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005036}
5037
Auke Kok9a799d72007-09-15 14:07:45 -07005038static void ixgbe_configure(struct ixgbe_adapter *adapter)
5039{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005040 struct ixgbe_hw *hw = &adapter->hw;
5041
John Fastabend80605c652011-05-02 12:34:10 +00005042 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005043#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005044 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005045#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005046 /*
5047 * We must restore virtualization before VLANs or else
5048 * the VLVF registers will not be populated
5049 */
5050 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005051
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005052 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005053 ixgbe_restore_vlan(adapter);
5054
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005055 switch (hw->mac.type) {
5056 case ixgbe_mac_82599EB:
5057 case ixgbe_mac_X540:
5058 hw->mac.ops.disable_rx_buff(hw);
5059 break;
5060 default:
5061 break;
5062 }
5063
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005064 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005065 ixgbe_init_fdir_signature_82599(&adapter->hw,
5066 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005067 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5068 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5069 adapter->fdir_pballoc);
5070 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005071 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005072
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005073 switch (hw->mac.type) {
5074 case ixgbe_mac_82599EB:
5075 case ixgbe_mac_X540:
5076 hw->mac.ops.enable_rx_buff(hw);
5077 break;
5078 default:
5079 break;
5080 }
5081
Mark Rustad9de76052015-08-08 16:27:41 -07005082#ifdef CONFIG_IXGBE_DCA
5083 /* configure DCA */
5084 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5085 ixgbe_setup_dca(adapter);
5086#endif /* CONFIG_IXGBE_DCA */
5087
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005088#ifdef IXGBE_FCOE
5089 /* configure FCoE L2 filters, redirection table, and Rx control */
5090 ixgbe_configure_fcoe(adapter);
5091
5092#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005093 ixgbe_configure_tx(adapter);
5094 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005095 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005096}
5097
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005098/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005099 * ixgbe_sfp_link_config - set up SFP+ link
5100 * @adapter: pointer to private adapter struct
5101 **/
5102static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5103{
Alexander Duyck70864002011-04-27 09:13:56 +00005104 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005105 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005106 * is that an SFP was inserted/removed after the reset
5107 * but before SFP detection was enabled. As such the best
5108 * solution is to just start searching as soon as we start
5109 */
5110 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5111 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005112
Alexander Duyck70864002011-04-27 09:13:56 +00005113 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005114 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005115}
5116
5117/**
5118 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005119 * @hw: pointer to private hardware struct
5120 *
5121 * Returns 0 on success, negative on failure
5122 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005123static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005124{
Josh Hay3d292262012-12-15 03:28:19 +00005125 u32 speed;
5126 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005127 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005128
5129 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005130 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005131
5132 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005133 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005134
Josh Hay3d292262012-12-15 03:28:19 +00005135 speed = hw->phy.autoneg_advertised;
5136 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5137 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5138 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005139 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005140 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005141
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005142 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005143 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005144
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005145 return ret;
5146}
5147
Alexander Duycka34bcff2010-08-19 13:39:20 +00005148static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005149{
Auke Kok9a799d72007-09-15 14:07:45 -07005150 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005151 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005152
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005153 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005154 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5155 IXGBE_GPIE_OCD;
5156 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005157 /*
5158 * use EIAM to auto-mask when MSI-X interrupt is asserted
5159 * this saves a register write for every interrupt
5160 */
5161 switch (hw->mac.type) {
5162 case ixgbe_mac_82598EB:
5163 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5164 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005165 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005166 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005167 case ixgbe_mac_X550:
5168 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005169 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005170 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005171 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5172 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5173 break;
5174 }
5175 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005176 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5177 * specifically only auto mask tx and rx interrupts */
5178 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005179 }
5180
Alexander Duycka34bcff2010-08-19 13:39:20 +00005181 /* XXX: to interrupt immediately for EICS writes, enable this */
5182 /* gpie |= IXGBE_GPIE_EIMEN; */
5183
5184 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5185 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005186
5187 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5188 case IXGBE_82599_VMDQ_8Q_MASK:
5189 gpie |= IXGBE_GPIE_VTMODE_16;
5190 break;
5191 case IXGBE_82599_VMDQ_4Q_MASK:
5192 gpie |= IXGBE_GPIE_VTMODE_32;
5193 break;
5194 default:
5195 gpie |= IXGBE_GPIE_VTMODE_64;
5196 break;
5197 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005198 }
5199
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005200 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005201 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5202 switch (adapter->hw.mac.type) {
5203 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005204 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005205 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005206 default:
5207 break;
5208 }
5209 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005210
Alexander Duycka34bcff2010-08-19 13:39:20 +00005211 /* Enable fan failure interrupt */
5212 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005213 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005214
Don Skidmorea023bbd2015-06-24 16:38:53 -04005215 switch (hw->mac.type) {
5216 case ixgbe_mac_82599EB:
5217 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5218 break;
5219 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005220 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005221 gpie |= IXGBE_SDP0_GPIEN_X540;
5222 break;
5223 default:
5224 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005225 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005226
5227 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5228}
5229
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005230static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005231{
5232 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005233 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005234 u32 ctrl_ext;
5235
5236 ixgbe_get_hw_control(adapter);
5237 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005238
Auke Kok9a799d72007-09-15 14:07:45 -07005239 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5240 ixgbe_configure_msix(adapter);
5241 else
5242 ixgbe_configure_msi_and_legacy(adapter);
5243
Emil Tantilovec74a472012-09-20 03:33:56 +00005244 /* enable the optics for 82599 SFP+ fiber */
5245 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005246 hw->mac.ops.enable_tx_laser(hw);
5247
Don Skidmore961fac82015-06-09 16:09:47 -07005248 if (hw->phy.ops.set_phy_power)
5249 hw->phy.ops.set_phy_power(hw, true);
5250
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005251 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005252 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005253 ixgbe_napi_enable_all(adapter);
5254
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005255 if (ixgbe_is_sfp(hw)) {
5256 ixgbe_sfp_link_config(adapter);
5257 } else {
5258 err = ixgbe_non_sfp_link_config(hw);
5259 if (err)
5260 e_err(probe, "link_config FAILED %d\n", err);
5261 }
5262
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005263 /* clear any pending interrupts, may auto mask */
5264 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005265 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005266
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005267 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005268 * If this adapter has a fan, check to see if we had a failure
5269 * before we enabled the interrupt.
5270 */
5271 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5272 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5273 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005274 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005275 }
5276
Auke Kok9a799d72007-09-15 14:07:45 -07005277 /* bring the link up in the watchdog, this could race with our first
5278 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005279 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5280 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005281 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005282
5283 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5284 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5285 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5286 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005287}
5288
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005289void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5290{
5291 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005292 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005293 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005294
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005295 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005296 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005297 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005298 /*
5299 * If SR-IOV enabled then wait a bit before bringing the adapter
5300 * back up to give the VFs time to respond to the reset. The
5301 * two second wait is based upon the watchdog timer cycle in
5302 * the VF driver.
5303 */
5304 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5305 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005306 ixgbe_up(adapter);
5307 clear_bit(__IXGBE_RESETTING, &adapter->state);
5308}
5309
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005310void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005311{
5312 /* hardware has been reset, we need to reload some things */
5313 ixgbe_configure(adapter);
5314
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005315 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005316}
5317
5318void ixgbe_reset(struct ixgbe_adapter *adapter)
5319{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005320 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005321 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005322 int err;
5323
Mark Rustadb0483c82014-01-14 18:53:17 -08005324 if (ixgbe_removed(hw->hw_addr))
5325 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005326 /* lock SFP init bit to prevent race conditions with the watchdog */
5327 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5328 usleep_range(1000, 2000);
5329
5330 /* clear all SFP and link config related flags while holding SFP_INIT */
5331 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5332 IXGBE_FLAG2_SFP_NEEDS_RESET);
5333 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5334
Don Skidmore8ca783a2009-05-26 20:40:47 -07005335 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005336 switch (err) {
5337 case 0:
5338 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005339 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005340 break;
5341 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005342 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005343 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005344 case IXGBE_ERR_EEPROM_VERSION:
5345 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005346 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005347 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005348 "your hardware. If you are experiencing problems "
5349 "please contact your Intel or hardware "
5350 "representative who provided you with this "
5351 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005352 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005353 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005354 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005355 }
Auke Kok9a799d72007-09-15 14:07:45 -07005356
Alexander Duyck70864002011-04-27 09:13:56 +00005357 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005358
5359 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005360 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005361 __dev_uc_unsync(netdev, NULL);
5362
5363 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005364 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005365
5366 /* update SAN MAC vmdq pool selection */
5367 if (hw->mac.san_mac_rar_index)
5368 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005369
Jacob Keller8fecf672013-06-21 08:14:32 +00005370 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005371 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005372
5373 if (hw->phy.ops.set_phy_power) {
5374 if (!netif_running(adapter->netdev) && !adapter->wol)
5375 hw->phy.ops.set_phy_power(hw, false);
5376 else
5377 hw->phy.ops.set_phy_power(hw, true);
5378 }
Auke Kok9a799d72007-09-15 14:07:45 -07005379}
5380
Auke Kok9a799d72007-09-15 14:07:45 -07005381/**
Auke Kok9a799d72007-09-15 14:07:45 -07005382 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005383 * @tx_ring: ring to be cleaned
5384 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005385static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005386{
5387 struct ixgbe_tx_buffer *tx_buffer_info;
5388 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005389 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07005390
Alexander Duyck84418e32010-08-19 13:40:54 +00005391 /* ring already cleared, nothing to do */
5392 if (!tx_ring->tx_buffer_info)
5393 return;
Auke Kok9a799d72007-09-15 14:07:45 -07005394
Alexander Duyck84418e32010-08-19 13:40:54 +00005395 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07005396 for (i = 0; i < tx_ring->count; i++) {
5397 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005398 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07005399 }
5400
John Fastabenddad8a3b2012-04-23 12:22:39 +00005401 netdev_tx_reset_queue(txring_txq(tx_ring));
5402
Auke Kok9a799d72007-09-15 14:07:45 -07005403 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5404 memset(tx_ring->tx_buffer_info, 0, size);
5405
5406 /* Zero out the descriptor ring */
5407 memset(tx_ring->desc, 0, tx_ring->size);
5408
5409 tx_ring->next_to_use = 0;
5410 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005411}
5412
5413/**
Auke Kok9a799d72007-09-15 14:07:45 -07005414 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5415 * @adapter: board private structure
5416 **/
5417static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5418{
5419 int i;
5420
5421 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005422 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005423}
5424
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005425/**
5426 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5427 * @adapter: board private structure
5428 **/
5429static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5430{
5431 int i;
5432
5433 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005434 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005435}
5436
Alexander Duycke4911d52011-05-11 07:18:52 +00005437static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5438{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005439 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005440 struct ixgbe_fdir_filter *filter;
5441
5442 spin_lock(&adapter->fdir_perfect_lock);
5443
Sasha Levinb67bfe02013-02-27 17:06:00 -08005444 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005445 &adapter->fdir_filter_list, fdir_node) {
5446 hlist_del(&filter->fdir_node);
5447 kfree(filter);
5448 }
5449 adapter->fdir_filter_count = 0;
5450
5451 spin_unlock(&adapter->fdir_perfect_lock);
5452}
5453
David Ahern1cd127f2016-10-17 19:15:48 -07005454static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
5455{
5456 if (netif_is_macvlan(upper)) {
5457 struct macvlan_dev *vlan = netdev_priv(upper);
5458
5459 if (vlan->fwd_priv) {
5460 netif_tx_stop_all_queues(upper);
5461 netif_carrier_off(upper);
5462 netif_tx_disable(upper);
5463 }
5464 }
5465
5466 return 0;
5467}
5468
Auke Kok9a799d72007-09-15 14:07:45 -07005469void ixgbe_down(struct ixgbe_adapter *adapter)
5470{
5471 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005472 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005473 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005474
5475 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005476 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5477 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005478
5479 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005480 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005481
Yi Zou2d39d572011-01-06 14:29:56 +00005482 /* disable all enabled rx queues */
5483 for (i = 0; i < adapter->num_rx_queues; i++)
5484 /* this call also flushes the previous write */
5485 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5486
Don Skidmore032b4322011-03-18 09:32:53 +00005487 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005488
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005489 netif_tx_stop_all_queues(netdev);
5490
Alexander Duyck70864002011-04-27 09:13:56 +00005491 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005492 netif_carrier_off(netdev);
5493 netif_tx_disable(netdev);
5494
John Fastabend2a47fa42013-11-06 09:54:52 -08005495 /* disable any upper devices */
David Ahern1cd127f2016-10-17 19:15:48 -07005496 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5497 ixgbe_disable_macvlan, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005498
John Fastabendc0dfb902010-04-27 02:13:39 +00005499 ixgbe_irq_disable(adapter);
5500
5501 ixgbe_napi_disable_all(adapter);
5502
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005503 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5504 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005505 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5506
5507 del_timer_sync(&adapter->service_timer);
5508
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005509 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005510 /* Clear EITR Select mapping */
5511 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5512
5513 /* Mark all the VFs as inactive */
5514 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005515 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005516
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005517 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005518 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005519
Auke Kok9a799d72007-09-15 14:07:45 -07005520 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005521 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005522 }
5523
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005524 /* disable transmits in the hardware now that interrupts are off */
5525 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005526 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005527 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005528 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005529
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005530 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005531 switch (hw->mac.type) {
5532 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005533 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005534 case ixgbe_mac_X550:
5535 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005536 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005537 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005538 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5539 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005540 break;
5541 default:
5542 break;
5543 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005544
Paul Larson6f4a0e42008-06-24 17:00:56 -07005545 if (!pci_channel_offline(adapter->pdev))
5546 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005547
Emil Tantilovec74a472012-09-20 03:33:56 +00005548 /* power down the optics for 82599 SFP+ fiber */
5549 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005550 hw->mac.ops.disable_tx_laser(hw);
5551
Auke Kok9a799d72007-09-15 14:07:45 -07005552 ixgbe_clean_all_tx_rings(adapter);
5553 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005554}
5555
Auke Kok9a799d72007-09-15 14:07:45 -07005556/**
Auke Kok9a799d72007-09-15 14:07:45 -07005557 * ixgbe_tx_timeout - Respond to a Tx Hang
5558 * @netdev: network interface device structure
5559 **/
5560static void ixgbe_tx_timeout(struct net_device *netdev)
5561{
5562 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5563
5564 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005565 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005566}
5567
Usha Ketineni88290092016-04-26 05:00:26 -07005568#ifdef CONFIG_IXGBE_DCB
5569static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
5570{
5571 struct ixgbe_hw *hw = &adapter->hw;
5572 struct tc_configuration *tc;
5573 int j;
5574
5575 switch (hw->mac.type) {
5576 case ixgbe_mac_82598EB:
5577 case ixgbe_mac_82599EB:
5578 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5579 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5580 break;
5581 case ixgbe_mac_X540:
5582 case ixgbe_mac_X550:
5583 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5584 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5585 break;
5586 case ixgbe_mac_X550EM_x:
5587 case ixgbe_mac_x550em_a:
5588 default:
5589 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
5590 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
5591 break;
5592 }
5593
5594 /* Configure DCB traffic classes */
5595 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5596 tc = &adapter->dcb_cfg.tc_config[j];
5597 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5598 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5599 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5600 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5601 tc->dcb_pfc = pfc_disabled;
5602 }
5603
5604 /* Initialize default user to priority mapping, UPx->TC0 */
5605 tc = &adapter->dcb_cfg.tc_config[0];
5606 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5607 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5608
5609 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5610 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5611 adapter->dcb_cfg.pfc_mode_enable = false;
5612 adapter->dcb_set_bitmap = 0x00;
5613 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
5614 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5615 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5616 sizeof(adapter->temp_dcb_cfg));
5617}
5618#endif
5619
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005620/**
Auke Kok9a799d72007-09-15 14:07:45 -07005621 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5622 * @adapter: board private structure to initialize
5623 *
5624 * ixgbe_sw_init initializes the Adapter private data structure.
5625 * Fields are initialized based on PCI device information and
5626 * OS network device settings (MTU size).
5627 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07005628static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
5629 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07005630{
5631 struct ixgbe_hw *hw = &adapter->hw;
5632 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005633 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005634 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005635 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005636
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005637 /* PCI config space info */
5638
5639 hw->vendor_id = pdev->vendor;
5640 hw->device_id = pdev->device;
5641 hw->revision_id = pdev->revision;
5642 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5643 hw->subsystem_device_id = pdev->subsystem_device;
5644
Emil Tantilov55570b62016-10-12 12:34:25 -07005645 /* get_invariants needs the device IDs */
5646 ii->get_invariants(hw);
5647
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005648 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00005649 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005650 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005651 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005652 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5653 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005654 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5655 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005656 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5657#ifdef CONFIG_IXGBE_DCA
5658 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5659#endif
Usha Ketineni88290092016-04-26 05:00:26 -07005660#ifdef CONFIG_IXGBE_DCB
5661 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
5662 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
5663#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005664#ifdef IXGBE_FCOE
5665 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5666 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5667#ifdef CONFIG_IXGBE_DCB
5668 /* Default traffic class to use for FCoE */
5669 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5670#endif /* CONFIG_IXGBE_DCB */
5671#endif /* IXGBE_FCOE */
5672
John Fastabendb82b17d2016-02-16 21:18:53 -08005673 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005674 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
5675 GFP_KERNEL);
5676 if (!adapter->jump_tables[0])
5677 return -ENOMEM;
5678 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
5679
5680 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
5681 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08005682
Jacob Keller5d7daa32014-03-29 06:51:25 +00005683 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5684 hw->mac.num_rar_entries,
5685 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08005686 if (!adapter->mac_table)
5687 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005688
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005689 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005690 switch (hw->mac.type) {
5691 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005692 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005693
Don Skidmorebf069c92009-05-07 10:39:54 +00005694 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5695 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005696
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005697 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005698 adapter->ring_feature[RING_F_FDIR].limit = 0;
5699 adapter->atr_sample_rate = 0;
5700 adapter->fdir_pballoc = 0;
5701#ifdef IXGBE_FCOE
5702 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5703 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5704#ifdef CONFIG_IXGBE_DCB
5705 adapter->fcoe.up = 0;
5706#endif /* IXGBE_DCB */
5707#endif /* IXGBE_FCOE */
5708 break;
5709 case ixgbe_mac_82599EB:
5710 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5711 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005712 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005713 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005714 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005715 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5716 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005717 break;
Mark Rustad49425df2016-04-01 12:18:09 -07005718 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07005719 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
5720 /* fall through */
5721 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07005722#ifdef CONFIG_IXGBE_DCB
5723 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
5724#endif
5725#ifdef IXGBE_FCOE
5726 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5727#ifdef CONFIG_IXGBE_DCB
5728 adapter->fcoe.up = 0;
5729#endif /* IXGBE_DCB */
5730#endif /* IXGBE_FCOE */
5731 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005732 case ixgbe_mac_X550:
5733#ifdef CONFIG_IXGBE_DCA
5734 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
5735#endif
Mark Rustad67359c32015-06-15 11:33:25 -07005736 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005737 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08005738 default:
5739 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005740 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005741
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005742#ifdef IXGBE_FCOE
5743 /* FCoE support exists, always init the FCoE lock */
5744 spin_lock_init(&adapter->fcoe.lock);
5745
5746#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005747 /* n-tuple support exists, always init our spinlock */
5748 spin_lock_init(&adapter->fdir_perfect_lock);
5749
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005750#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07005751 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005752#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005753
5754 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005755 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005756 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005757 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005758 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5759 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005760 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005761
Alexander Duyck99d74482012-05-09 08:09:25 +00005762#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005763 if (max_vfs > 0)
5764 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 +00005765
Jacob Keller170e8542013-11-09 04:52:32 -08005766 /* assign number of SR-IOV VFs */
5767 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005768 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Jacob Keller170e8542013-11-09 04:52:32 -08005769 adapter->num_vfs = 0;
5770 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5771 } else {
5772 adapter->num_vfs = max_vfs;
5773 }
5774 }
5775#endif /* CONFIG_PCI_IOV */
5776
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005777 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005778 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005779 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005780
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005781 /* set default ring sizes */
5782 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5783 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5784
Alexander Duyckbd198052011-06-11 01:45:08 +00005785 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005786 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005787
Auke Kok9a799d72007-09-15 14:07:45 -07005788 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005789 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005790 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005791 return -EIO;
5792 }
5793
John Fastabend2a47fa42013-11-06 09:54:52 -08005794 /* PF holds first pool slot */
5795 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005796 set_bit(__IXGBE_DOWN, &adapter->state);
5797
5798 return 0;
5799}
5800
5801/**
5802 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005803 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005804 *
5805 * Return 0 on success, negative on failure
5806 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005807int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005808{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005809 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005810 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005811 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005812 int size;
5813
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005814 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005815
5816 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005817 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005818
Mark Rustadca8dfe22014-07-24 06:19:24 +00005819 tx_ring->tx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005820 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005821 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005822 if (!tx_ring->tx_buffer_info)
5823 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005824
John Stultz827da442013-10-07 15:51:58 -07005825 u64_stats_init(&tx_ring->syncp);
5826
Auke Kok9a799d72007-09-15 14:07:45 -07005827 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005828 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005829 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005830
Mark Rustadca8dfe22014-07-24 06:19:24 +00005831 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005832 tx_ring->desc = dma_alloc_coherent(dev,
5833 tx_ring->size,
5834 &tx_ring->dma,
5835 GFP_KERNEL);
5836 set_dev_node(dev, orig_node);
5837 if (!tx_ring->desc)
5838 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5839 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005840 if (!tx_ring->desc)
5841 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005842
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005843 tx_ring->next_to_use = 0;
5844 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005845 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005846
5847err:
5848 vfree(tx_ring->tx_buffer_info);
5849 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005850 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005851 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005852}
5853
5854/**
Alexander Duyck69888672008-09-11 20:05:39 -07005855 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5856 * @adapter: board private structure
5857 *
5858 * If this function returns with an error, then it's possible one or
5859 * more of the rings is populated (while the rest are not). It is the
5860 * callers duty to clean those orphaned rings.
5861 *
5862 * Return 0 on success, negative on failure
5863 **/
5864static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5865{
5866 int i, err = 0;
5867
5868 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005869 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005870 if (!err)
5871 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005872
Emil Tantilov396e7992010-07-01 20:05:12 +00005873 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005874 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07005875 }
5876
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005877 return 0;
5878err_setup_tx:
5879 /* rewind the index freeing the rings as we go */
5880 while (i--)
5881 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005882 return err;
5883}
5884
5885/**
Auke Kok9a799d72007-09-15 14:07:45 -07005886 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005887 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005888 *
5889 * Returns 0 on success, negative on failure
5890 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005891int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005892{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005893 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005894 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005895 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005896 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005897
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005898 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005899
5900 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005901 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005902
Mark Rustadca8dfe22014-07-24 06:19:24 +00005903 rx_ring->rx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005904 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005905 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005906 if (!rx_ring->rx_buffer_info)
5907 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005908
John Stultz827da442013-10-07 15:51:58 -07005909 u64_stats_init(&rx_ring->syncp);
5910
Auke Kok9a799d72007-09-15 14:07:45 -07005911 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005912 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5913 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005914
Mark Rustadca8dfe22014-07-24 06:19:24 +00005915 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005916 rx_ring->desc = dma_alloc_coherent(dev,
5917 rx_ring->size,
5918 &rx_ring->dma,
5919 GFP_KERNEL);
5920 set_dev_node(dev, orig_node);
5921 if (!rx_ring->desc)
5922 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5923 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005924 if (!rx_ring->desc)
5925 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005926
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005927 rx_ring->next_to_clean = 0;
5928 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005929
5930 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005931err:
5932 vfree(rx_ring->rx_buffer_info);
5933 rx_ring->rx_buffer_info = NULL;
5934 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005935 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005936}
5937
5938/**
Alexander Duyck69888672008-09-11 20:05:39 -07005939 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5940 * @adapter: board private structure
5941 *
5942 * If this function returns with an error, then it's possible one or
5943 * more of the rings is populated (while the rest are not). It is the
5944 * callers duty to clean those orphaned rings.
5945 *
5946 * Return 0 on success, negative on failure
5947 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005948static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5949{
5950 int i, err = 0;
5951
5952 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005953 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005954 if (!err)
5955 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005956
Emil Tantilov396e7992010-07-01 20:05:12 +00005957 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005958 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07005959 }
5960
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005961#ifdef IXGBE_FCOE
5962 err = ixgbe_setup_fcoe_ddp_resources(adapter);
5963 if (!err)
5964#endif
5965 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005966err_setup_rx:
5967 /* rewind the index freeing the rings as we go */
5968 while (i--)
5969 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005970 return err;
5971}
5972
5973/**
Auke Kok9a799d72007-09-15 14:07:45 -07005974 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005975 * @tx_ring: Tx descriptor ring for a specific queue
5976 *
5977 * Free all transmit software resources
5978 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005979void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005980{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005981 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005982
5983 vfree(tx_ring->tx_buffer_info);
5984 tx_ring->tx_buffer_info = NULL;
5985
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005986 /* if not set, then don't free */
5987 if (!tx_ring->desc)
5988 return;
5989
5990 dma_free_coherent(tx_ring->dev, tx_ring->size,
5991 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005992
5993 tx_ring->desc = NULL;
5994}
5995
5996/**
5997 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5998 * @adapter: board private structure
5999 *
6000 * Free all transmit software resources
6001 **/
6002static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6003{
6004 int i;
6005
6006 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006007 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006008 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006009}
6010
6011/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006012 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006013 * @rx_ring: ring to clean the resources from
6014 *
6015 * Free all receive software resources
6016 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006017void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006018{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006019 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006020
6021 vfree(rx_ring->rx_buffer_info);
6022 rx_ring->rx_buffer_info = NULL;
6023
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006024 /* if not set, then don't free */
6025 if (!rx_ring->desc)
6026 return;
6027
6028 dma_free_coherent(rx_ring->dev, rx_ring->size,
6029 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006030
6031 rx_ring->desc = NULL;
6032}
6033
6034/**
6035 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6036 * @adapter: board private structure
6037 *
6038 * Free all receive software resources
6039 **/
6040static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6041{
6042 int i;
6043
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006044#ifdef IXGBE_FCOE
6045 ixgbe_free_fcoe_ddp_resources(adapter);
6046
6047#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006048 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006049 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006050 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006051}
6052
6053/**
Auke Kok9a799d72007-09-15 14:07:45 -07006054 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6055 * @netdev: network interface device structure
6056 * @new_mtu: new value for maximum frame size
6057 *
6058 * Returns 0 on success, negative on failure
6059 **/
6060static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6061{
6062 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck655309e2012-02-08 07:50:35 +00006063
6064 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006065 * For 82599EB we cannot allow legacy VFs to enable their receive
6066 * paths when MTU greater than 1500 is configured. So display a
6067 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006068 */
6069 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6070 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Jarod Wilson91c527a2016-10-17 15:54:05 -04006071 (new_mtu > ETH_DATA_LEN))
Alexander Duyck872844d2012-08-15 02:10:43 +00006072 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006073
Emil Tantilov396e7992010-07-01 20:05:12 +00006074 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006075
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006076 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006077 netdev->mtu = new_mtu;
6078
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006079 if (netif_running(netdev))
6080 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006081
6082 return 0;
6083}
6084
6085/**
6086 * ixgbe_open - Called when a network interface is made active
6087 * @netdev: network interface device structure
6088 *
6089 * Returns 0 on success, negative value on failure
6090 *
6091 * The open entry point is called when a network interface is made
6092 * active by the system (IFF_UP). At this point all resources needed
6093 * for transmit and receive operations are allocated, the interrupt
6094 * handler is registered with the OS, the watchdog timer is started,
6095 * and the stack is notified that the interface is ready.
6096 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006097int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006098{
6099 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006100 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006101 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006102
Auke Kok4bebfaa2008-02-11 09:26:01 -08006103 /* disallow open during test */
6104 if (test_bit(__IXGBE_TESTING, &adapter->state))
6105 return -EBUSY;
6106
Jesse Brandeburg54386462009-04-17 20:44:27 +00006107 netif_carrier_off(netdev);
6108
Auke Kok9a799d72007-09-15 14:07:45 -07006109 /* allocate transmit descriptors */
6110 err = ixgbe_setup_all_tx_resources(adapter);
6111 if (err)
6112 goto err_setup_tx;
6113
Auke Kok9a799d72007-09-15 14:07:45 -07006114 /* allocate receive descriptors */
6115 err = ixgbe_setup_all_rx_resources(adapter);
6116 if (err)
6117 goto err_setup_rx;
6118
6119 ixgbe_configure(adapter);
6120
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006121 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006122 if (err)
6123 goto err_req_irq;
6124
Alexander Duyckac802f52012-07-12 05:52:53 +00006125 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08006126 if (adapter->num_rx_pools > 1)
6127 queues = adapter->num_rx_queues_per_pool;
6128 else
6129 queues = adapter->num_tx_queues;
6130
6131 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006132 if (err)
6133 goto err_set_queues;
6134
John Fastabend2a47fa42013-11-06 09:54:52 -08006135 if (adapter->num_rx_pools > 1 &&
6136 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
6137 queues = IXGBE_MAX_L2A_QUEUES;
6138 else
6139 queues = adapter->num_rx_queues;
6140 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006141 if (err)
6142 goto err_set_queues;
6143
Jacob Keller1a71ab22012-08-25 03:54:19 +00006144 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006145
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006146 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006147
Emil Tantilova21d0822016-08-10 11:19:23 -07006148 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
Alexander Duyckb3a49552016-06-16 12:22:19 -07006149 udp_tunnel_get_rx_info(netdev);
Mark Rustad67359c32015-06-15 11:33:25 -07006150
Auke Kok9a799d72007-09-15 14:07:45 -07006151 return 0;
6152
Alexander Duyckac802f52012-07-12 05:52:53 +00006153err_set_queues:
6154 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006155err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006156 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006157 if (hw->phy.ops.set_phy_power && !adapter->wol)
6158 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006159err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006160 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006161err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006162 ixgbe_reset(adapter);
6163
6164 return err;
6165}
6166
Jacob Kellera0cccce2014-05-16 05:12:29 +00006167static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6168{
6169 ixgbe_ptp_suspend(adapter);
6170
Don Skidmore6ac74392015-06-17 17:34:31 -04006171 if (adapter->hw.phy.ops.enter_lplu) {
6172 adapter->hw.phy.reset_disable = true;
6173 ixgbe_down(adapter);
6174 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6175 adapter->hw.phy.reset_disable = false;
6176 } else {
6177 ixgbe_down(adapter);
6178 }
6179
Jacob Kellera0cccce2014-05-16 05:12:29 +00006180 ixgbe_free_irq(adapter);
6181
6182 ixgbe_free_all_tx_resources(adapter);
6183 ixgbe_free_all_rx_resources(adapter);
6184}
6185
Auke Kok9a799d72007-09-15 14:07:45 -07006186/**
6187 * ixgbe_close - Disables a network interface
6188 * @netdev: network interface device structure
6189 *
6190 * Returns 0, this is not allowed to fail
6191 *
6192 * The close entry point is called when an interface is de-activated
6193 * by the OS. The hardware is still under the drivers control, but
6194 * needs to be disabled. A global MAC reset is issued to stop the
6195 * hardware, and all transmit and receive resources are freed.
6196 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006197int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006198{
6199 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006200
Jacob Keller1a71ab22012-08-25 03:54:19 +00006201 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006202
Jacob Kellera0cccce2014-05-16 05:12:29 +00006203 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006204
Alexander Duycke4911d52011-05-11 07:18:52 +00006205 ixgbe_fdir_filter_exit(adapter);
6206
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006207 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006208
6209 return 0;
6210}
6211
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006212#ifdef CONFIG_PM
6213static int ixgbe_resume(struct pci_dev *pdev)
6214{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006215 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6216 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006217 u32 err;
6218
Mark Rustad0391bbe2014-02-28 15:48:55 -08006219 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006220 pci_set_power_state(pdev, PCI_D0);
6221 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006222 /*
6223 * pci_restore_state clears dev->state_saved so call
6224 * pci_save_state to restore it.
6225 */
6226 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006227
6228 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006229 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006230 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006231 return err;
6232 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006233 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006234 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006235 pci_set_master(pdev);
6236
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006237 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006238
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006239 ixgbe_reset(adapter);
6240
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006241 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6242
Alexander Duyckac802f52012-07-12 05:52:53 +00006243 rtnl_lock();
6244 err = ixgbe_init_interrupt_scheme(adapter);
6245 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006246 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006247
6248 rtnl_unlock();
6249
6250 if (err)
6251 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006252
6253 netif_device_attach(netdev);
6254
6255 return 0;
6256}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006257#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006258
6259static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006260{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006261 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6262 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006263 struct ixgbe_hw *hw = &adapter->hw;
6264 u32 ctrl, fctrl;
6265 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006266#ifdef CONFIG_PM
6267 int retval = 0;
6268#endif
6269
6270 netif_device_detach(netdev);
6271
akepner499ab5c2013-03-13 14:54:58 +00006272 rtnl_lock();
Jacob Kellera0cccce2014-05-16 05:12:29 +00006273 if (netif_running(netdev))
6274 ixgbe_close_suspend(adapter);
akepner499ab5c2013-03-13 14:54:58 +00006275 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006276
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006277 ixgbe_clear_interrupt_scheme(adapter);
6278
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006279#ifdef CONFIG_PM
6280 retval = pci_save_state(pdev);
6281 if (retval)
6282 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006283
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006284#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006285 if (hw->mac.ops.stop_link_on_d3)
6286 hw->mac.ops.stop_link_on_d3(hw);
6287
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006288 if (wufc) {
6289 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006290
Emil Tantilovec74a472012-09-20 03:33:56 +00006291 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6292 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006293 hw->mac.ops.enable_tx_laser(hw);
6294
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006295 /* turn on all-multi mode if wake on multicast is enabled */
6296 if (wufc & IXGBE_WUFC_MC) {
6297 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6298 fctrl |= IXGBE_FCTRL_MPE;
6299 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
6300 }
6301
6302 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6303 ctrl |= IXGBE_CTRL_GIO_DIS;
6304 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6305
6306 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6307 } else {
6308 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6309 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6310 }
6311
Alexander Duyckbd508172010-11-16 19:27:03 -08006312 switch (hw->mac.type) {
6313 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006314 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006315 break;
6316 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006317 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006318 case ixgbe_mac_X550:
6319 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006320 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006321 pci_wake_from_d3(pdev, !!wufc);
6322 break;
6323 default:
6324 break;
6325 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006326
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006327 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006328 if (hw->phy.ops.set_phy_power && !*enable_wake)
6329 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006330
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006331 ixgbe_release_hw_control(adapter);
6332
Mark Rustad41c62842014-03-12 00:38:35 +00006333 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6334 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006335
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006336 return 0;
6337}
6338
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006339#ifdef CONFIG_PM
6340static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6341{
6342 int retval;
6343 bool wake;
6344
6345 retval = __ixgbe_shutdown(pdev, &wake);
6346 if (retval)
6347 return retval;
6348
6349 if (wake) {
6350 pci_prepare_to_sleep(pdev);
6351 } else {
6352 pci_wake_from_d3(pdev, false);
6353 pci_set_power_state(pdev, PCI_D3hot);
6354 }
6355
6356 return 0;
6357}
6358#endif /* CONFIG_PM */
6359
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006360static void ixgbe_shutdown(struct pci_dev *pdev)
6361{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006362 bool wake;
6363
6364 __ixgbe_shutdown(pdev, &wake);
6365
6366 if (system_state == SYSTEM_POWER_OFF) {
6367 pci_wake_from_d3(pdev, wake);
6368 pci_set_power_state(pdev, PCI_D3hot);
6369 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006370}
6371
6372/**
Auke Kok9a799d72007-09-15 14:07:45 -07006373 * ixgbe_update_stats - Update the board statistics counters.
6374 * @adapter: board private structure
6375 **/
6376void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6377{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006378 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006379 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006380 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006381 u64 total_mpc = 0;
6382 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006383 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6384 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006385 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006386
Don Skidmored08935c2010-06-11 13:20:29 +00006387 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6388 test_bit(__IXGBE_RESETTING, &adapter->state))
6389 return;
6390
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006391 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006392 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006393 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006394 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006395 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6396 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006397 }
6398 adapter->rsc_total_count = rsc_count;
6399 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006400 }
6401
Alexander Duyck5b7da512010-11-16 19:26:50 -08006402 for (i = 0; i < adapter->num_rx_queues; i++) {
6403 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6404 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
6405 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6406 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006407 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006408 bytes += rx_ring->stats.bytes;
6409 packets += rx_ring->stats.packets;
6410 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006411 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006412 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6413 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006414 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006415 netdev->stats.rx_bytes = bytes;
6416 netdev->stats.rx_packets = packets;
6417
6418 bytes = 0;
6419 packets = 0;
6420 /* gather some stats to the adapter struct that are per queue */
6421 for (i = 0; i < adapter->num_tx_queues; i++) {
6422 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6423 restart_queue += tx_ring->tx_stats.restart_queue;
6424 tx_busy += tx_ring->tx_stats.tx_busy;
6425 bytes += tx_ring->stats.bytes;
6426 packets += tx_ring->stats.packets;
6427 }
6428 adapter->restart_queue = restart_queue;
6429 adapter->tx_busy = tx_busy;
6430 netdev->stats.tx_bytes = bytes;
6431 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006432
Joe Perches7ca647b2010-09-07 21:35:40 +00006433 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006434
6435 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006436 for (i = 0; i < 8; i++) {
6437 /* for packet buffers not used, the register should read 0 */
6438 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6439 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006440 hwstats->mpc[i] += mpc;
6441 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006442 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6443 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006444 switch (hw->mac.type) {
6445 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006446 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6447 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6448 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006449 hwstats->pxonrxc[i] +=
6450 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006451 break;
6452 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006453 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006454 case ixgbe_mac_X550:
6455 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006456 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006457 hwstats->pxonrxc[i] +=
6458 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006459 break;
6460 default:
6461 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006462 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006463 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006464
6465 /*16 register reads */
6466 for (i = 0; i < 16; i++) {
6467 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6468 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6469 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006470 (hw->mac.type == ixgbe_mac_X540) ||
6471 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006472 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6473 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006474 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6475 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6476 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6477 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6478 }
6479 }
6480
Joe Perches7ca647b2010-09-07 21:35:40 +00006481 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006482 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006483 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006484
John Fastabendc84d3242010-11-16 19:27:12 -08006485 ixgbe_update_xoff_received(adapter);
6486
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006487 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006488 switch (hw->mac.type) {
6489 case ixgbe_mac_82598EB:
6490 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006491 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6492 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6493 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6494 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006495 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006496 case ixgbe_mac_X550:
6497 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006498 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006499 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006500 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6501 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6502 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6503 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6504 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006505 for (i = 0; i < 16; i++)
6506 adapter->hw_rx_no_dma_resources +=
6507 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006508 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006509 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006510 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006511 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006512 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006513 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006514 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006515 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6516 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006517#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006518 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6519 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6520 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6521 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6522 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6523 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006524 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006525 if (adapter->fcoe.ddp_pool) {
6526 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6527 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6528 unsigned int cpu;
6529 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006530 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006531 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6532 noddp += ddp_pool->noddp;
6533 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006534 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006535 hwstats->fcoe_noddp = noddp;
6536 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006537 }
Yi Zou6d455222009-05-13 13:12:16 +00006538#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006539 break;
6540 default:
6541 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006542 }
Auke Kok9a799d72007-09-15 14:07:45 -07006543 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006544 hwstats->bprc += bprc;
6545 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006546 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006547 hwstats->mprc -= bprc;
6548 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6549 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6550 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6551 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6552 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6553 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6554 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6555 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006556 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006557 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006558 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006559 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006560 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6561 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006562 /*
6563 * 82598 errata - tx of flow control packets is included in tx counters
6564 */
6565 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006566 hwstats->gptc -= xon_off_tot;
6567 hwstats->mptc -= xon_off_tot;
6568 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6569 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6570 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6571 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6572 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6573 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6574 hwstats->ptc64 -= xon_off_tot;
6575 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6576 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6577 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6578 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6579 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6580 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006581
6582 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006583 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006584
6585 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006586 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006587 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006588 netdev->stats.rx_length_errors = hwstats->rlec;
6589 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006590 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006591}
6592
6593/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006594 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006595 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006596 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006597static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006598{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006599 struct ixgbe_hw *hw = &adapter->hw;
6600 int i;
6601
Alexander Duyckd034acf2011-04-27 09:25:34 +00006602 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6603 return;
6604
6605 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6606
6607 /* if interface is down do nothing */
6608 if (test_bit(__IXGBE_DOWN, &adapter->state))
6609 return;
6610
6611 /* do nothing if we are not using signature filters */
6612 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6613 return;
6614
6615 adapter->fdir_overflow++;
6616
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006617 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6618 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006619 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00006620 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006621 /* re-enable flow director interrupts */
6622 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006623 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006624 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006625 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006626 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006627}
6628
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006629/**
6630 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006631 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006632 *
6633 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006634 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006635 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006636 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006637 */
6638static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6639{
Auke Kok9a799d72007-09-15 14:07:45 -07006640 struct ixgbe_hw *hw = &adapter->hw;
6641 u64 eics = 0;
6642 int i;
6643
Mark Rustad09f40ae2014-01-14 18:53:11 -08006644 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006645 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006646 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006647 test_bit(__IXGBE_RESETTING, &adapter->state))
6648 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006649
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006650 /* Force detection of hung controller */
6651 if (netif_carrier_ok(adapter->netdev)) {
6652 for (i = 0; i < adapter->num_tx_queues; i++)
6653 set_check_for_tx_hang(adapter->tx_ring[i]);
6654 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006655
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006656 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006657 /*
6658 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006659 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006660 * would set *both* EIMS and EICS for any bit in EIAM
6661 */
6662 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6663 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006664 } else {
6665 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006666 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006667 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006668 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07006669 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006670 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006671 }
6672
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006673 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006674 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00006675}
6676
6677/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006678 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006679 * @adapter: pointer to the device adapter structure
6680 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006681 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006682static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006683{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006684 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006685 u32 link_speed = adapter->link_speed;
6686 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006687 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006688
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006689 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6690 return;
6691
6692 if (hw->mac.ops.check_link) {
6693 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006694 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006695 /* always assume link is up, if no check link function */
6696 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6697 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006698 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006699
6700 if (adapter->ixgbe_ieee_pfc)
6701 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6702
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006703 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006704 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006705 ixgbe_set_rx_drop_en(adapter);
6706 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006707
6708 if (link_up ||
6709 time_after(jiffies, (adapter->link_check_timeout +
6710 IXGBE_TRY_LINK_TIMEOUT))) {
6711 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6712 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6713 IXGBE_WRITE_FLUSH(hw);
6714 }
6715
6716 adapter->link_up = link_up;
6717 adapter->link_speed = link_speed;
6718}
6719
Alexander Duyck107d3012012-10-02 00:17:03 +00006720static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6721{
6722#ifdef CONFIG_IXGBE_DCB
6723 struct net_device *netdev = adapter->netdev;
6724 struct dcb_app app = {
6725 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6726 .protocol = 0,
6727 };
6728 u8 up = 0;
6729
6730 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6731 up = dcb_ieee_getapp_mask(netdev, &app);
6732
6733 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6734#endif
6735}
6736
David Ahern1cd127f2016-10-17 19:15:48 -07006737static int ixgbe_enable_macvlan(struct net_device *upper, void *data)
6738{
6739 if (netif_is_macvlan(upper)) {
6740 struct macvlan_dev *vlan = netdev_priv(upper);
6741
6742 if (vlan->fwd_priv)
6743 netif_tx_wake_all_queues(upper);
6744 }
6745
6746 return 0;
6747}
6748
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006749/**
6750 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6751 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006752 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006753 **/
6754static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6755{
6756 struct net_device *netdev = adapter->netdev;
6757 struct ixgbe_hw *hw = &adapter->hw;
6758 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07006759 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006760 bool flow_rx, flow_tx;
6761
6762 /* only continue if link was previously down */
6763 if (netif_carrier_ok(netdev))
6764 return;
6765
6766 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6767
6768 switch (hw->mac.type) {
6769 case ixgbe_mac_82598EB: {
6770 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6771 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6772 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6773 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6774 }
6775 break;
6776 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006777 case ixgbe_mac_X550:
6778 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006779 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006780 case ixgbe_mac_82599EB: {
6781 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6782 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6783 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6784 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6785 }
6786 break;
6787 default:
6788 flow_tx = false;
6789 flow_rx = false;
6790 break;
6791 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006792
Jacob Keller6cb562d2012-12-05 07:24:41 +00006793 adapter->last_rx_ptp_check = jiffies;
6794
Jacob Keller8fecf672013-06-21 08:14:32 +00006795 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006796 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006797
Mark Rustad454adb02015-07-10 14:19:22 -07006798 switch (link_speed) {
6799 case IXGBE_LINK_SPEED_10GB_FULL:
6800 speed_str = "10 Gbps";
6801 break;
6802 case IXGBE_LINK_SPEED_2_5GB_FULL:
6803 speed_str = "2.5 Gbps";
6804 break;
6805 case IXGBE_LINK_SPEED_1GB_FULL:
6806 speed_str = "1 Gbps";
6807 break;
6808 case IXGBE_LINK_SPEED_100_FULL:
6809 speed_str = "100 Mbps";
6810 break;
6811 default:
6812 speed_str = "unknown speed";
6813 break;
6814 }
6815 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006816 ((flow_rx && flow_tx) ? "RX/TX" :
6817 (flow_rx ? "RX" :
6818 (flow_tx ? "TX" : "None"))));
6819
6820 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006821 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006822
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006823 /* enable transmits */
6824 netif_tx_wake_all_queues(adapter->netdev);
6825
6826 /* enable any upper devices */
6827 rtnl_lock();
David Ahern1cd127f2016-10-17 19:15:48 -07006828 netdev_walk_all_upper_dev_rcu(adapter->netdev,
6829 ixgbe_enable_macvlan, NULL);
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006830 rtnl_unlock();
6831
Alexander Duyck107d3012012-10-02 00:17:03 +00006832 /* update the default user priority for VFs */
6833 ixgbe_update_default_up(adapter);
6834
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006835 /* ping all the active vfs to let them know link has changed */
6836 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006837}
6838
6839/**
6840 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6841 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006842 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006843 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00006844static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006845{
6846 struct net_device *netdev = adapter->netdev;
6847 struct ixgbe_hw *hw = &adapter->hw;
6848
6849 adapter->link_up = false;
6850 adapter->link_speed = 0;
6851
6852 /* only continue if link was up previously */
6853 if (!netif_carrier_ok(netdev))
6854 return;
6855
6856 /* poll for SFP+ cable when link is down */
6857 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6858 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6859
Jacob Keller8fecf672013-06-21 08:14:32 +00006860 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006861 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006862
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006863 e_info(drv, "NIC Link is Down\n");
6864 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006865
6866 /* ping all the active vfs to let them know link has changed */
6867 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006868}
6869
Emil Tantilov07923c12014-08-12 07:12:08 +00006870static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
6871{
6872 int i;
6873
6874 for (i = 0; i < adapter->num_tx_queues; i++) {
6875 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6876
6877 if (tx_ring->next_to_use != tx_ring->next_to_clean)
6878 return true;
6879 }
6880
6881 return false;
6882}
6883
6884static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
6885{
6886 struct ixgbe_hw *hw = &adapter->hw;
6887 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
6888 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
6889
6890 int i, j;
6891
6892 if (!adapter->num_vfs)
6893 return false;
6894
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006895 /* resetting the PF is only needed for MAC before X550 */
6896 if (hw->mac.type >= ixgbe_mac_X550)
6897 return false;
6898
Emil Tantilov07923c12014-08-12 07:12:08 +00006899 for (i = 0; i < adapter->num_vfs; i++) {
6900 for (j = 0; j < q_per_pool; j++) {
6901 u32 h, t;
6902
6903 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
6904 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
6905
6906 if (h != t)
6907 return true;
6908 }
6909 }
6910
6911 return false;
6912}
6913
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006914/**
6915 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006916 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006917 **/
6918static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6919{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006920 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00006921 if (ixgbe_ring_tx_pending(adapter) ||
6922 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006923 /* We've lost link, so the controller stops DMA,
6924 * but we've got queued Tx work that's never going
6925 * to get done, so reset controller to flush Tx.
6926 * (Do the reset outside of interrupt context).
6927 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00006928 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07006929 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006930 }
6931 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006932}
6933
Emil Tantilov9079e412014-11-19 03:18:19 +00006934#ifdef CONFIG_PCI_IOV
6935static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
6936 struct pci_dev *vfdev)
6937{
6938 if (!pci_wait_for_pending_transaction(vfdev))
6939 e_dev_warn("Issuing VFLR with pending transactions\n");
6940
6941 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
6942 pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
6943
6944 msleep(100);
6945}
6946
6947static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6948{
6949 struct ixgbe_hw *hw = &adapter->hw;
6950 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07006951 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00006952 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00006953
6954 if (!(netif_carrier_ok(adapter->netdev)))
6955 return;
6956
6957 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6958 if (gpc) /* If incrementing then no need for the check below */
6959 return;
6960 /* Check to see if a bad DMA write target from an errant or
6961 * malicious VF has caused a PCIe error. If so then we can
6962 * issue a VFLR to the offending VF(s) and then resume without
6963 * requesting a full slot reset.
6964 */
6965
6966 if (!pdev)
6967 return;
6968
Emil Tantilov9079e412014-11-19 03:18:19 +00006969 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07006970 for (vf = 0; vf < adapter->num_vfs; ++vf) {
6971 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
6972 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00006973
Mark Rustad988d1302015-10-30 15:29:34 -07006974 if (!vfdev)
6975 continue;
6976 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
6977 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
6978 status_reg & PCI_STATUS_REC_MASTER_ABORT)
6979 ixgbe_issue_vf_flr(adapter, vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00006980 }
6981}
6982
Greg Rosea985b6c32010-11-18 03:02:52 +00006983static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6984{
6985 u32 ssvpc;
6986
Greg Rose0584d992012-08-08 00:00:58 +00006987 /* Do not perform spoof check for 82598 or if not in IOV mode */
6988 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
6989 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00006990 return;
6991
6992 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6993
6994 /*
6995 * ssvpc register is cleared on read, if zero then no
6996 * spoofed packets in the last interval.
6997 */
6998 if (!ssvpc)
6999 return;
7000
Emil Tantilovd6ea0752012-08-08 06:28:37 +00007001 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00007002}
Emil Tantilov9079e412014-11-19 03:18:19 +00007003#else
7004static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7005{
7006}
7007
7008static void
7009ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7010{
7011}
7012#endif /* CONFIG_PCI_IOV */
7013
Greg Rosea985b6c32010-11-18 03:02:52 +00007014
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007015/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007016 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007017 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007018 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007019static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007020{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007021 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007022 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007023 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007024 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007025 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007026
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007027 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007028
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007029 if (adapter->link_up)
7030 ixgbe_watchdog_link_is_up(adapter);
7031 else
7032 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007033
Emil Tantilov9079e412014-11-19 03:18:19 +00007034 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007035 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007036 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007037
7038 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007039}
7040
Alexander Duyck70864002011-04-27 09:13:56 +00007041/**
7042 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007043 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007044 **/
7045static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7046{
7047 struct ixgbe_hw *hw = &adapter->hw;
7048 s32 err;
7049
7050 /* not searching for SFP so there is nothing to do here */
7051 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7052 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7053 return;
7054
Mark Rustad58e7cd22015-08-08 16:18:48 -07007055 if (adapter->sfp_poll_time &&
7056 time_after(adapter->sfp_poll_time, jiffies))
7057 return; /* If not yet time to poll for SFP */
7058
Alexander Duyck70864002011-04-27 09:13:56 +00007059 /* someone else is in init, wait until next service event */
7060 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7061 return;
7062
Mark Rustad58e7cd22015-08-08 16:18:48 -07007063 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7064
Alexander Duyck70864002011-04-27 09:13:56 +00007065 err = hw->phy.ops.identify_sfp(hw);
7066 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7067 goto sfp_out;
7068
7069 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7070 /* If no cable is present, then we need to reset
7071 * the next time we find a good cable. */
7072 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7073 }
7074
7075 /* exit on error */
7076 if (err)
7077 goto sfp_out;
7078
7079 /* exit if reset not needed */
7080 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7081 goto sfp_out;
7082
7083 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7084
7085 /*
7086 * A module may be identified correctly, but the EEPROM may not have
7087 * support for that module. setup_sfp() will fail in that case, so
7088 * we should not allow that module to load.
7089 */
7090 if (hw->mac.type == ixgbe_mac_82598EB)
7091 err = hw->phy.ops.reset(hw);
7092 else
7093 err = hw->mac.ops.setup_sfp(hw);
7094
7095 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7096 goto sfp_out;
7097
7098 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7099 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7100
7101sfp_out:
7102 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7103
7104 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7105 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7106 e_dev_err("failed to initialize because an unsupported "
7107 "SFP+ module type was detected.\n");
7108 e_dev_err("Reload the driver after installing a "
7109 "supported module.\n");
7110 unregister_netdev(adapter->netdev);
7111 }
7112}
7113
7114/**
7115 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007116 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007117 **/
7118static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7119{
7120 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00007121 u32 speed;
7122 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007123
7124 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7125 return;
7126
7127 /* someone else is in init, wait until next service event */
7128 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7129 return;
7130
7131 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7132
Josh Hay3d292262012-12-15 03:28:19 +00007133 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00007134 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00007135 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007136
7137 /* setup the highest link when no autoneg */
7138 if (!autoneg) {
7139 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
7140 speed = IXGBE_LINK_SPEED_10GB_FULL;
7141 }
7142 }
7143
Alexander Duyck70864002011-04-27 09:13:56 +00007144 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007145 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007146
7147 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7148 adapter->link_check_timeout = jiffies;
7149 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7150}
7151
7152/**
7153 * ixgbe_service_timer - Timer Call-back
7154 * @data: pointer to adapter cast into an unsigned long
7155 **/
7156static void ixgbe_service_timer(unsigned long data)
7157{
7158 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
7159 unsigned long next_event_offset;
7160
7161 /* poll faster when waiting for link */
7162 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7163 next_event_offset = HZ / 10;
7164 else
7165 next_event_offset = HZ * 2;
7166
7167 /* Reset the timer */
7168 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7169
Emil Tantilov9079e412014-11-19 03:18:19 +00007170 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007171}
7172
Don Skidmore597f22d2015-06-09 16:52:02 -07007173static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7174{
7175 struct ixgbe_hw *hw = &adapter->hw;
7176 u32 status;
7177
7178 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7179 return;
7180
7181 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7182
7183 if (!hw->phy.ops.handle_lasi)
7184 return;
7185
7186 status = hw->phy.ops.handle_lasi(&adapter->hw);
7187 if (status != IXGBE_ERR_OVERTEMP)
7188 return;
7189
7190 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7191}
7192
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007193static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7194{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007195 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007196 return;
7197
Mark Rustad09f40ae2014-01-14 18:53:11 -08007198 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007199 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007200 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007201 test_bit(__IXGBE_RESETTING, &adapter->state))
7202 return;
7203
7204 ixgbe_dump(adapter);
7205 netdev_err(adapter->netdev, "Reset adapter\n");
7206 adapter->tx_timeout_count++;
7207
John Fastabend8f4c5c92014-01-16 02:30:05 -08007208 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007209 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007210 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007211}
7212
Alexander Duyck70864002011-04-27 09:13:56 +00007213/**
7214 * ixgbe_service_task - manages and runs subtasks
7215 * @work: pointer to work_struct containing our data
7216 **/
7217static void ixgbe_service_task(struct work_struct *work)
7218{
7219 struct ixgbe_adapter *adapter = container_of(work,
7220 struct ixgbe_adapter,
7221 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007222 if (ixgbe_removed(adapter->hw.hw_addr)) {
7223 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7224 rtnl_lock();
7225 ixgbe_down(adapter);
7226 rtnl_unlock();
7227 }
7228 ixgbe_service_event_complete(adapter);
7229 return;
7230 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007231 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007232 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007233 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007234 udp_tunnel_get_rx_info(adapter->netdev);
7235 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007236 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007237 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007238 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007239 ixgbe_sfp_detection_subtask(adapter);
7240 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007241 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007242 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007243 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007244 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007245
Jacob Keller8fecf672013-06-21 08:14:32 +00007246 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007247 ixgbe_ptp_overflow_check(adapter);
7248 ixgbe_ptp_rx_hang(adapter);
7249 }
Alexander Duyck70864002011-04-27 09:13:56 +00007250
7251 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007252}
7253
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007254static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7255 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007256 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007257{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007258 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007259 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007260 union {
7261 struct iphdr *v4;
7262 struct ipv6hdr *v6;
7263 unsigned char *hdr;
7264 } ip;
7265 union {
7266 struct tcphdr *tcp;
7267 unsigned char *hdr;
7268 } l4;
7269 u32 paylen, l4_offset;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007270 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007271
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007272 if (skb->ip_summed != CHECKSUM_PARTIAL)
7273 return 0;
7274
Alexander Duyck897ab152011-05-27 05:31:47 +00007275 if (!skb_is_gso(skb))
7276 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007277
Francois Romieu2049e1f2014-03-30 03:14:27 +00007278 err = skb_cow_head(skb, 0);
7279 if (err < 0)
7280 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007281
Alexander Duyckb83e3012016-04-14 17:19:31 -04007282 ip.hdr = skb_network_header(skb);
7283 l4.hdr = skb_checksum_start(skb);
7284
Alexander Duyck897ab152011-05-27 05:31:47 +00007285 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7286 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7287
Alexander Duyckb83e3012016-04-14 17:19:31 -04007288 /* initialize outer IP header fields */
7289 if (ip.v4->version == 4) {
7290 /* IP header will have to cancel out any data that
7291 * is not a part of the outer IP header
7292 */
7293 ip.v4->check = csum_fold(csum_add(lco_csum(skb),
7294 csum_unfold(l4.tcp->check)));
Alexander Duyck897ab152011-05-27 05:31:47 +00007295 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007296
7297 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007298 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7299 IXGBE_TX_FLAGS_CSUM |
7300 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007301 } else {
7302 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007303 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7304 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007305 }
7306
Alexander Duyckb83e3012016-04-14 17:19:31 -04007307 /* determine offset of inner transport header */
7308 l4_offset = l4.hdr - skb->data;
7309
7310 /* compute length of segmentation header */
7311 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7312
7313 /* remove payload length from inner checksum */
7314 paylen = skb->len - l4_offset;
7315 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007316
Alexander Duyck091a6242012-02-08 07:51:01 +00007317 /* update gso size and bytecount with header size */
7318 first->gso_segs = skb_shinfo(skb)->gso_segs;
7319 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7320
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007321 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007322 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007323 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007324
7325 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007326 vlan_macip_lens = l4.hdr - ip.hdr;
7327 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007328 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007329
7330 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007331 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007332
7333 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007334}
7335
Alexander Duyck49763de2016-01-13 07:31:11 -08007336static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7337{
7338 unsigned int offset = 0;
7339
7340 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7341
7342 return offset == skb_checksum_start_offset(skb);
7343}
7344
Alexander Duyck244e27a2012-02-08 07:51:11 +00007345static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7346 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007347{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007348 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007349 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007350 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007351
Alexander Duyck897ab152011-05-27 05:31:47 +00007352 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007353csum_failed:
7354 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7355 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007356 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007357 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007358 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007359
Alexander Duyck49763de2016-01-13 07:31:11 -08007360 switch (skb->csum_offset) {
7361 case offsetof(struct tcphdr, check):
7362 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7363 /* fall through */
7364 case offsetof(struct udphdr, check):
7365 break;
7366 case offsetof(struct sctphdr, checksum):
7367 /* validate that this is actually an SCTP request */
7368 if (((first->protocol == htons(ETH_P_IP)) &&
7369 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7370 ((first->protocol == htons(ETH_P_IPV6)) &&
7371 ixgbe_ipv6_csum_is_sctp(skb))) {
7372 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7373 break;
7374 }
7375 /* fall through */
7376 default:
7377 skb_checksum_help(skb);
7378 goto csum_failed;
7379 }
7380
7381 /* update TX checksum flag */
7382 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7383 vlan_macip_lens = skb_checksum_start_offset(skb) -
7384 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007385no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007386 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007387 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007388 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007389
Alexander Duyck49763de2016-01-13 07:31:11 -08007390 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007391}
7392
Alexander Duyck472148c2012-11-07 02:34:28 +00007393#define IXGBE_SET_FLAG(_input, _flag, _result) \
7394 ((_flag <= _result) ? \
7395 ((u32)(_input & _flag) * (_result / _flag)) : \
7396 ((u32)(_input & _flag) / (_flag / _result)))
7397
7398static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007399{
7400 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007401 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7402 IXGBE_ADVTXD_DCMD_DEXT |
7403 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007404
7405 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007406 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7407 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007408
Alexander Duyckd3d00232011-07-15 02:31:25 +00007409 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007410 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7411 IXGBE_ADVTXD_DCMD_TSE);
7412
7413 /* set timestamp bit if present */
7414 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7415 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007416
Alexander Duyck62748b72012-07-20 08:09:01 +00007417 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007418 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007419
Alexander Duyckd3d00232011-07-15 02:31:25 +00007420 return cmd_type;
7421}
7422
Alexander Duyck729739b2012-02-08 07:51:06 +00007423static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7424 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007425{
Alexander Duyck472148c2012-11-07 02:34:28 +00007426 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007427
7428 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007429 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7430 IXGBE_TX_FLAGS_CSUM,
7431 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007432
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007433 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007434 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7435 IXGBE_TX_FLAGS_IPV4,
7436 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007437
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007438 /*
7439 * Check Context must be set if Tx switch is enabled, which it
7440 * always is for case where virtual functions are running
7441 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007442 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7443 IXGBE_TX_FLAGS_CC,
7444 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007445
Alexander Duyck472148c2012-11-07 02:34:28 +00007446 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007447}
7448
Daniel Borkmann2367a172014-08-26 19:34:18 +02007449static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7450{
7451 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7452
7453 /* Herbert's original patch had:
7454 * smp_mb__after_netif_stop_queue();
7455 * but since that doesn't exist yet, just open code it.
7456 */
7457 smp_mb();
7458
7459 /* We need to check again in a case another CPU has just
7460 * made room available.
7461 */
7462 if (likely(ixgbe_desc_unused(tx_ring) < size))
7463 return -EBUSY;
7464
7465 /* A reprieve! - use start_queue because it doesn't call schedule */
7466 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7467 ++tx_ring->tx_stats.restart_queue;
7468 return 0;
7469}
7470
7471static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7472{
7473 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7474 return 0;
7475
7476 return __ixgbe_maybe_stop_tx(tx_ring, size);
7477}
7478
Alexander Duyckd3d00232011-07-15 02:31:25 +00007479#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7480 IXGBE_TXD_CMD_RS)
7481
7482static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007483 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007484 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007485{
Alexander Duyck729739b2012-02-08 07:51:06 +00007486 struct sk_buff *skb = first->skb;
7487 struct ixgbe_tx_buffer *tx_buffer;
7488 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007489 struct skb_frag_struct *frag;
7490 dma_addr_t dma;
7491 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007492 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007493 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007494 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007495
Alexander Duyck729739b2012-02-08 07:51:06 +00007496 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7497
Alexander Duyckec718252012-10-30 06:01:55 +00007498 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7499
7500 size = skb_headlen(skb);
7501 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007502
Alexander Duyckd3d00232011-07-15 02:31:25 +00007503#ifdef IXGBE_FCOE
7504 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007505 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007506 size -= sizeof(struct fcoe_crc_eof) - data_len;
7507 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007508 } else {
7509 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007510 }
Auke Kok9a799d72007-09-15 14:07:45 -07007511 }
7512
Alexander Duyckd3d00232011-07-15 02:31:25 +00007513#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007514 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007515
Alexander Duyckec718252012-10-30 06:01:55 +00007516 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007517
Alexander Duyckec718252012-10-30 06:01:55 +00007518 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7519 if (dma_mapping_error(tx_ring->dev, dma))
7520 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007521
Alexander Duyckec718252012-10-30 06:01:55 +00007522 /* record length, and DMA address */
7523 dma_unmap_len_set(tx_buffer, len, size);
7524 dma_unmap_addr_set(tx_buffer, dma, dma);
7525
7526 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7527
Alexander Duyck729739b2012-02-08 07:51:06 +00007528 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007529 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007530 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007531
Alexander Duyckd3d00232011-07-15 02:31:25 +00007532 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007533 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007534 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007535 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007536 i = 0;
7537 }
Alexander Duyckec718252012-10-30 06:01:55 +00007538 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007539
7540 dma += IXGBE_MAX_DATA_PER_TXD;
7541 size -= IXGBE_MAX_DATA_PER_TXD;
7542
7543 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007544 }
7545
Alexander Duyck729739b2012-02-08 07:51:06 +00007546 if (likely(!data_len))
7547 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007548
Alexander Duyck472148c2012-11-07 02:34:28 +00007549 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007550
Alexander Duyck729739b2012-02-08 07:51:06 +00007551 i++;
7552 tx_desc++;
7553 if (i == tx_ring->count) {
7554 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7555 i = 0;
7556 }
Alexander Duyckec718252012-10-30 06:01:55 +00007557 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007558
Alexander Duyckd3d00232011-07-15 02:31:25 +00007559#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007560 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007561#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007562 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007563#endif
7564 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007565
Alexander Duyck729739b2012-02-08 07:51:06 +00007566 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7567 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007568
Alexander Duyck729739b2012-02-08 07:51:06 +00007569 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007570 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007571
Alexander Duyck729739b2012-02-08 07:51:06 +00007572 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007573 cmd_type |= size | IXGBE_TXD_CMD;
7574 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007575
Alexander Duyck091a6242012-02-08 07:51:01 +00007576 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007577
Alexander Duyckd3d00232011-07-15 02:31:25 +00007578 /* set the timestamp */
7579 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007580
7581 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007582 * Force memory writes to complete before letting h/w know there
7583 * are new descriptors to fetch. (Only applicable for weak-ordered
7584 * memory model archs, such as IA-64).
7585 *
7586 * We also need this memory barrier to make certain all of the
7587 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007588 */
7589 wmb();
7590
Alexander Duyckd3d00232011-07-15 02:31:25 +00007591 /* set next_to_watch value indicating a packet is present */
7592 first->next_to_watch = tx_desc;
7593
Alexander Duyck729739b2012-02-08 07:51:06 +00007594 i++;
7595 if (i == tx_ring->count)
7596 i = 0;
7597
7598 tx_ring->next_to_use = i;
7599
Daniel Borkmann2367a172014-08-26 19:34:18 +02007600 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7601
7602 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00007603 writel(i, tx_ring->tail);
7604
7605 /* we need this if more than one processor can write to our tail
7606 * at a time, it synchronizes IO on IA64/Altix systems
7607 */
7608 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02007609 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02007610
Alexander Duyckd3d00232011-07-15 02:31:25 +00007611 return;
7612dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00007613 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00007614
7615 /* clear dma mappings for failed tx_buffer_info map */
7616 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007617 tx_buffer = &tx_ring->tx_buffer_info[i];
7618 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
7619 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007620 break;
7621 if (i == 0)
7622 i = tx_ring->count;
7623 i--;
7624 }
7625
Alexander Duyckd3d00232011-07-15 02:31:25 +00007626 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07007627}
7628
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007629static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007630 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007631{
Alexander Duyck69830522011-01-06 14:29:58 +00007632 struct ixgbe_q_vector *q_vector = ring->q_vector;
7633 union ixgbe_atr_hash_dword input = { .dword = 0 };
7634 union ixgbe_atr_hash_dword common = { .dword = 0 };
7635 union {
7636 unsigned char *network;
7637 struct iphdr *ipv4;
7638 struct ipv6hdr *ipv6;
7639 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007640 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08007641 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07007642 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00007643 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08007644 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007645
Alexander Duyck69830522011-01-06 14:29:58 +00007646 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7647 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00007648 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007649
Alexander Duyck69830522011-01-06 14:29:58 +00007650 /* do nothing if sampling is disabled */
7651 if (!ring->atr_sample_rate)
7652 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007653
Alexander Duyck69830522011-01-06 14:29:58 +00007654 ring->atr_count++;
7655
Alexander Duycke2873d42016-01-25 19:39:40 -08007656 /* currently only IPv4/IPv6 with TCP is supported */
7657 if ((first->protocol != htons(ETH_P_IP)) &&
7658 (first->protocol != htons(ETH_P_IPV6)))
7659 return;
7660
Alexander Duyck69830522011-01-06 14:29:58 +00007661 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07007662 skb = first->skb;
7663 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007664 if (unlikely(hdr.network <= skb->data))
7665 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08007666 if (skb->encapsulation &&
7667 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07007668 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07007669 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00007670
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007671 if (unlikely(skb_tail_pointer(skb) < hdr.network +
7672 VXLAN_HEADROOM))
7673 return;
7674
Alexander Duyck9f12df92016-01-25 19:36:29 -08007675 /* verify the port is recognized as VXLAN */
7676 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08007677 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08007678 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07007679
7680 if (adapter->geneve_port &&
7681 udp_hdr(skb)->dest == adapter->geneve_port)
7682 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08007683 }
7684
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007685 /* Make sure we have at least [minimum IPv4 header + TCP]
7686 * or [IPv6 header] bytes
7687 */
7688 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
7689 return;
7690
Mark Rustade19dcde2015-12-09 14:55:37 -08007691 /* Currently only IPv4/IPv6 with TCP is supported */
7692 switch (hdr.ipv4->version) {
7693 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08007694 /* access ihl as u8 to avoid unaligned access on ia64 */
7695 hlen = (hdr.network[0] & 0x0F) << 2;
7696 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08007697 break;
7698 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08007699 hlen = hdr.network - skb->data;
7700 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
7701 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08007702 break;
7703 default:
7704 return;
Mark Rustad67359c32015-06-15 11:33:25 -07007705 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007706
Alexander Duycke2873d42016-01-25 19:39:40 -08007707 if (l4_proto != IPPROTO_TCP)
7708 return;
7709
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07007710 if (unlikely(skb_tail_pointer(skb) < hdr.network +
7711 hlen + sizeof(struct tcphdr)))
7712 return;
7713
Alexander Duycke2873d42016-01-25 19:39:40 -08007714 th = (struct tcphdr *)(hdr.network + hlen);
7715
7716 /* skip this packet since the socket is closing */
7717 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00007718 return;
7719
7720 /* sample on all syn packets or once every atr sample count */
7721 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
7722 return;
7723
7724 /* reset sample count */
7725 ring->atr_count = 0;
7726
Alexander Duyck244e27a2012-02-08 07:51:11 +00007727 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00007728
7729 /*
7730 * src and dst are inverted, think how the receiver sees them
7731 *
7732 * The input is broken into two sections, a non-compressed section
7733 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7734 * is XORed together and stored in the compressed dword.
7735 */
7736 input.formatted.vlan_id = vlan_id;
7737
7738 /*
7739 * since src port and flex bytes occupy the same word XOR them together
7740 * and write the value to source port portion of compressed dword
7741 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007742 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00007743 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00007744 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00007745 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00007746 common.port.dst ^= th->source;
7747
Mark Rustade19dcde2015-12-09 14:55:37 -08007748 switch (hdr.ipv4->version) {
7749 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00007750 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7751 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08007752 break;
7753 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00007754 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7755 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7756 hdr.ipv6->saddr.s6_addr32[1] ^
7757 hdr.ipv6->saddr.s6_addr32[2] ^
7758 hdr.ipv6->saddr.s6_addr32[3] ^
7759 hdr.ipv6->daddr.s6_addr32[0] ^
7760 hdr.ipv6->daddr.s6_addr32[1] ^
7761 hdr.ipv6->daddr.s6_addr32[2] ^
7762 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08007763 break;
7764 default:
7765 break;
Alexander Duyck69830522011-01-06 14:29:58 +00007766 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007767
Alexander Duyck9f12df92016-01-25 19:36:29 -08007768 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07007769 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07007770
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007771 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007772 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7773 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007774}
7775
Jason Wangf663dd92014-01-10 16:18:26 +08007776static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01007777 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007778{
Jason Wangf663dd92014-01-10 16:18:26 +08007779 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7780#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00007781 struct ixgbe_adapter *adapter;
7782 struct ixgbe_ring_feature *f;
7783 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08007784#endif
7785
7786 if (fwd_adapter)
7787 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7788
7789#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00007790
Alexander Duyck97488bd2013-01-12 06:33:37 +00007791 /*
7792 * only execute the code below if protocol is FCoE
7793 * or FIP and we have FCoE enabled on the adapter
7794 */
7795 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00007796 case htons(ETH_P_FCOE):
7797 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00007798 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00007799
Alexander Duyck97488bd2013-01-12 06:33:37 +00007800 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7801 break;
7802 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01007803 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007804 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007805
Alexander Duyck97488bd2013-01-12 06:33:37 +00007806 f = &adapter->ring_feature[RING_F_FCOE];
7807
7808 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7809 smp_processor_id();
7810
7811 while (txq >= f->indices)
7812 txq -= f->indices;
7813
7814 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08007815#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01007816 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08007817#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007818}
7819
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007820netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007821 struct ixgbe_adapter *adapter,
7822 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007823{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007824 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007825 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007826 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007827 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00007828 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007829 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007830 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007831
Alexander Duycka535c302011-05-27 05:31:52 +00007832 /*
7833 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007834 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007835 * + 2 desc gap to keep tail from touching head,
7836 * + 1 desc for context descriptor,
7837 * otherwise try next time
7838 */
Alexander Duycka535c302011-05-27 05:31:52 +00007839 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7840 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00007841
Alexander Duycka535c302011-05-27 05:31:52 +00007842 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7843 tx_ring->tx_stats.tx_busy++;
7844 return NETDEV_TX_BUSY;
7845 }
7846
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007847 /* record the location of the first descriptor for this packet */
7848 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7849 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00007850 first->bytecount = skb->len;
7851 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007852
Alexander Duyck66f32a82011-06-29 05:43:22 +00007853 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01007854 if (skb_vlan_tag_present(skb)) {
7855 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007856 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7857 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007858 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007859 struct vlan_hdr *vhdr, _vhdr;
7860 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7861 if (!vhdr)
7862 goto out_drop;
7863
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007864 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7865 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007866 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007867 }
Toshiaki Makita02136682015-01-29 20:37:09 +09007868 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00007869
Mark Rustadd5234932014-08-09 07:02:09 +00007870 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
7871 adapter->ptp_clock &&
7872 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
7873 &adapter->state)) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007874 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
7875 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00007876
7877 /* schedule check for Tx timestamp */
7878 adapter->ptp_tx_skb = skb_get(skb);
7879 adapter->ptp_tx_start = jiffies;
7880 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007881 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007882
Jakub Kicinskiff29a862014-03-15 14:55:16 +00007883 skb_tx_timestamp(skb);
7884
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007885#ifdef CONFIG_PCI_IOV
7886 /*
7887 * Use the l2switch_enable flag - would be false if the DMA
7888 * Tx switch had been disabled.
7889 */
7890 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00007891 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007892
7893#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007894 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007895 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007896 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7897 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007898 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007899 tx_flags |= (skb->priority & 0x7) <<
7900 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007901 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7902 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007903
7904 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00007905 goto out_drop;
7906 vhdr = (struct vlan_ethhdr *)skb->data;
7907 vhdr->h_vlan_TCI = htons(tx_flags >>
7908 IXGBE_TX_FLAGS_VLAN_SHIFT);
7909 } else {
7910 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7911 }
7912 }
Alexander Duycka535c302011-05-27 05:31:52 +00007913
Alexander Duyck244e27a2012-02-08 07:51:11 +00007914 /* record initial flags and protocol */
7915 first->tx_flags = tx_flags;
7916 first->protocol = protocol;
7917
Yi Zoueacd73f2009-05-13 13:11:06 +00007918#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007919 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007920 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00007921 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00007922 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00007923 if (tso < 0)
7924 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07007925
Alexander Duyck66f32a82011-06-29 05:43:22 +00007926 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007927 }
Auke Kok9a799d72007-09-15 14:07:45 -07007928
Auke Kok9a799d72007-09-15 14:07:45 -07007929#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007930 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007931 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007932 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007933 else if (!tso)
7934 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007935
7936 /* add the ATR filter if ATR is on */
7937 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00007938 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007939
7940#ifdef IXGBE_FCOE
7941xmit_fcoe:
7942#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007943 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007944
Auke Kok9a799d72007-09-15 14:07:45 -07007945 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007946
7947out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007948 dev_kfree_skb_any(first->skb);
7949 first->skb = NULL;
7950
Alexander Duyck897ab152011-05-27 05:31:47 +00007951 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007952}
7953
John Fastabend2a47fa42013-11-06 09:54:52 -08007954static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
7955 struct net_device *netdev,
7956 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007957{
7958 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007959 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07007960
Alexander Duycka50c29d2012-02-08 07:50:40 +00007961 /*
7962 * The minimum packet size for olinfo paylen is 17 so pad the skb
7963 * in order to meet this minimum size requirement.
7964 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08007965 if (skb_put_padto(skb, 17))
7966 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00007967
John Fastabend2a47fa42013-11-06 09:54:52 -08007968 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
7969
Auke Kok9a799d72007-09-15 14:07:45 -07007970 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7971}
7972
John Fastabend2a47fa42013-11-06 09:54:52 -08007973static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7974 struct net_device *netdev)
7975{
7976 return __ixgbe_xmit_frame(skb, netdev, NULL);
7977}
7978
Auke Kok9a799d72007-09-15 14:07:45 -07007979/**
7980 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7981 * @netdev: network interface device structure
7982 * @p: pointer to an address structure
7983 *
7984 * Returns 0 on success, negative on failure
7985 **/
7986static int ixgbe_set_mac(struct net_device *netdev, void *p)
7987{
7988 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7989 struct ixgbe_hw *hw = &adapter->hw;
7990 struct sockaddr *addr = p;
7991
7992 if (!is_valid_ether_addr(addr->sa_data))
7993 return -EADDRNOTAVAIL;
7994
7995 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007996 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007997
Alexander Duyckc9f53e62015-10-22 16:26:30 -07007998 ixgbe_mac_set_default_filter(adapter);
7999
8000 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008001}
8002
Ben Hutchings6b73e102009-04-29 08:08:58 +00008003static int
8004ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8005{
8006 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8007 struct ixgbe_hw *hw = &adapter->hw;
8008 u16 value;
8009 int rc;
8010
8011 if (prtad != hw->phy.mdio.prtad)
8012 return -EINVAL;
8013 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8014 if (!rc)
8015 rc = value;
8016 return rc;
8017}
8018
8019static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8020 u16 addr, u16 value)
8021{
8022 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8023 struct ixgbe_hw *hw = &adapter->hw;
8024
8025 if (prtad != hw->phy.mdio.prtad)
8026 return -EINVAL;
8027 return hw->phy.ops.write_reg(hw, addr, devad, value);
8028}
8029
8030static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8031{
8032 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8033
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008034 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008035 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008036 return ixgbe_ptp_set_ts_config(adapter, req);
8037 case SIOCGHWTSTAMP:
8038 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008039 default:
8040 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8041 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008042}
8043
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008044/**
8045 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008046 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008047 * @netdev: network interface device structure
8048 *
8049 * Returns non-zero on failure
8050 **/
8051static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8052{
8053 int err = 0;
8054 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008055 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008056
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008057 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008058 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008059 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008060 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008061
8062 /* update SAN MAC vmdq pool selection */
8063 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008064 }
8065 return err;
8066}
8067
8068/**
8069 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008070 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008071 * @netdev: network interface device structure
8072 *
8073 * Returns non-zero on failure
8074 **/
8075static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8076{
8077 int err = 0;
8078 struct ixgbe_adapter *adapter = netdev_priv(dev);
8079 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8080
8081 if (is_valid_ether_addr(mac->san_addr)) {
8082 rtnl_lock();
8083 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8084 rtnl_unlock();
8085 }
8086 return err;
8087}
8088
Auke Kok9a799d72007-09-15 14:07:45 -07008089#ifdef CONFIG_NET_POLL_CONTROLLER
8090/*
8091 * Polling 'interrupt' - used by things like netconsole to send skbs
8092 * without having to re-enable interrupts. It's not called while
8093 * the interrupt routine is executing.
8094 */
8095static void ixgbe_netpoll(struct net_device *netdev)
8096{
8097 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008098 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008099
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008100 /* if interface is down do nothing */
8101 if (test_bit(__IXGBE_DOWN, &adapter->state))
8102 return;
8103
Alexander Duyck856f6062015-02-25 17:45:54 +00008104 /* loop through and schedule all active queues */
8105 for (i = 0; i < adapter->num_q_vectors; i++)
8106 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008107}
Auke Kok9a799d72007-09-15 14:07:45 -07008108
Alexander Duyck581330b2012-02-08 07:51:47 +00008109#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00008110static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
8111 struct rtnl_link_stats64 *stats)
8112{
8113 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8114 int i;
8115
Eric Dumazet1a515022010-11-16 19:26:42 -08008116 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008117 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08008118 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008119 u64 bytes, packets;
8120 unsigned int start;
8121
Eric Dumazet1a515022010-11-16 19:26:42 -08008122 if (ring) {
8123 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008124 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008125 packets = ring->stats.packets;
8126 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008127 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008128 stats->rx_packets += packets;
8129 stats->rx_bytes += bytes;
8130 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008131 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008132
8133 for (i = 0; i < adapter->num_tx_queues; i++) {
8134 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
8135 u64 bytes, packets;
8136 unsigned int start;
8137
8138 if (ring) {
8139 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008140 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008141 packets = ring->stats.packets;
8142 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008143 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008144 stats->tx_packets += packets;
8145 stats->tx_bytes += bytes;
8146 }
8147 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008148 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008149 /* following stats updated by ixgbe_watchdog_task() */
8150 stats->multicast = netdev->stats.multicast;
8151 stats->rx_errors = netdev->stats.rx_errors;
8152 stats->rx_length_errors = netdev->stats.rx_length_errors;
8153 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8154 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
8155 return stats;
8156}
8157
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008158#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008159/**
8160 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8161 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008162 * @tc: number of traffic classes currently enabled
8163 *
8164 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8165 * 802.1Q priority maps to a packet buffer that exists.
8166 */
8167static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8168{
8169 struct ixgbe_hw *hw = &adapter->hw;
8170 u32 reg, rsave;
8171 int i;
8172
8173 /* 82598 have a static priority to TC mapping that can not
8174 * be changed so no validation is needed.
8175 */
8176 if (hw->mac.type == ixgbe_mac_82598EB)
8177 return;
8178
8179 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8180 rsave = reg;
8181
8182 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8183 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8184
8185 /* If up2tc is out of bounds default to zero */
8186 if (up2tc > tc)
8187 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8188 }
8189
8190 if (reg != rsave)
8191 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8192
8193 return;
8194}
8195
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008196/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008197 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8198 * @adapter: Pointer to adapter struct
8199 *
8200 * Populate the netdev user priority to tc map
8201 */
8202static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8203{
8204 struct net_device *dev = adapter->netdev;
8205 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8206 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8207 u8 prio;
8208
8209 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8210 u8 tc = 0;
8211
8212 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8213 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8214 else if (ets)
8215 tc = ets->prio_tc[prio];
8216
8217 netdev_set_prio_tc_map(dev, prio, tc);
8218 }
8219}
8220
Alexander Duyckcca73c52013-01-12 06:33:44 +00008221#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008222/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008223 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008224 *
8225 * @netdev: net device to configure
8226 * @tc: number of traffic classes to enable
8227 */
8228int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8229{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008230 struct ixgbe_adapter *adapter = netdev_priv(dev);
8231 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08008232 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008233
John Fastabend8b1c0b22011-05-03 02:26:48 +00008234 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008235 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8236 return -EINVAL;
8237
8238 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008239 return -EINVAL;
8240
John Fastabend2a47fa42013-11-06 09:54:52 -08008241 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
8242 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
8243 return -EBUSY;
8244
John Fastabend8b1c0b22011-05-03 02:26:48 +00008245 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008246 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008247 * hardware is not flexible enough to do this dynamically.
8248 */
8249 if (netif_running(dev))
8250 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008251 else
8252 ixgbe_reset(adapter);
8253
John Fastabend8b1c0b22011-05-03 02:26:48 +00008254 ixgbe_clear_interrupt_scheme(adapter);
8255
Alexander Duyckcca73c52013-01-12 06:33:44 +00008256#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008257 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008258 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008259 ixgbe_set_prio_tc_map(adapter);
8260
John Fastabende7589ea2011-07-18 22:38:36 +00008261 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008262
Alexander Duyck943561d2012-05-09 22:14:44 -07008263 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8264 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008265 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008266 }
John Fastabende7589ea2011-07-18 22:38:36 +00008267 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008268 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008269
Alexander Duyck943561d2012-05-09 22:14:44 -07008270 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8271 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008272
8273 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008274
8275 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8276 adapter->dcb_cfg.pfc_mode_enable = false;
8277 }
8278
John Fastabend8b1c0b22011-05-03 02:26:48 +00008279 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008280
8281#endif /* CONFIG_IXGBE_DCB */
8282 ixgbe_init_interrupt_scheme(adapter);
8283
John Fastabend8b1c0b22011-05-03 02:26:48 +00008284 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008285 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008286
8287 return 0;
8288}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008289
John Fastabendb82b17d2016-02-16 21:18:53 -08008290static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8291 struct tc_cls_u32_offload *cls)
8292{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008293 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008294 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008295 u32 loc = cls->knode.handle & 0xfffff;
8296 int err = 0, i, j;
8297 struct ixgbe_jump_table *jump = NULL;
8298
8299 if (loc > IXGBE_MAX_HW_ENTRIES)
8300 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008301
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008302 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8303 return -EINVAL;
8304
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008305 /* Clear this filter in the link data it is associated with */
8306 if (uhtid != 0x800) {
8307 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008308 if (!jump)
8309 return -EINVAL;
8310 if (!test_bit(loc - 1, jump->child_loc_map))
8311 return -EINVAL;
8312 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008313 }
8314
8315 /* Check if the filter being deleted is a link */
8316 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8317 jump = adapter->jump_tables[i];
8318 if (jump && jump->link_hdl == hdl) {
8319 /* Delete filters in the hardware in the child hash
8320 * table associated with this link
8321 */
8322 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8323 if (!test_bit(j, jump->child_loc_map))
8324 continue;
8325 spin_lock(&adapter->fdir_perfect_lock);
8326 err = ixgbe_update_ethtool_fdir_entry(adapter,
8327 NULL,
8328 j + 1);
8329 spin_unlock(&adapter->fdir_perfect_lock);
8330 clear_bit(j, jump->child_loc_map);
8331 }
8332 /* Remove resources for this link */
8333 kfree(jump->input);
8334 kfree(jump->mask);
8335 kfree(jump);
8336 adapter->jump_tables[i] = NULL;
8337 return err;
8338 }
8339 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008340
John Fastabendb82b17d2016-02-16 21:18:53 -08008341 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008342 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008343 spin_unlock(&adapter->fdir_perfect_lock);
8344 return err;
8345}
8346
John Fastabenddb956ae2016-02-16 21:19:19 -08008347static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
8348 __be16 protocol,
8349 struct tc_cls_u32_offload *cls)
8350{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008351 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8352
8353 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8354 return -EINVAL;
8355
John Fastabenddb956ae2016-02-16 21:19:19 -08008356 /* This ixgbe devices do not support hash tables at the moment
8357 * so abort when given hash tables.
8358 */
8359 if (cls->hnode.divisor > 0)
8360 return -EINVAL;
8361
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008362 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008363 return 0;
8364}
8365
8366static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8367 struct tc_cls_u32_offload *cls)
8368{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008369 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8370
8371 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8372 return -EINVAL;
8373
8374 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008375 return 0;
8376}
8377
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008378#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07008379struct upper_walk_data {
8380 struct ixgbe_adapter *adapter;
8381 u64 action;
8382 int ifindex;
8383 u8 queue;
8384};
8385
8386static int get_macvlan_queue(struct net_device *upper, void *_data)
8387{
8388 if (netif_is_macvlan(upper)) {
8389 struct macvlan_dev *dfwd = netdev_priv(upper);
8390 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
8391 struct upper_walk_data *data = _data;
8392 struct ixgbe_adapter *adapter = data->adapter;
8393 int ifindex = data->ifindex;
8394
8395 if (vadapter && vadapter->netdev->ifindex == ifindex) {
8396 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
8397 data->action = data->queue;
8398 return 1;
8399 }
8400 }
8401
8402 return 0;
8403}
8404
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008405static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
8406 u8 *queue, u64 *action)
8407{
8408 unsigned int num_vfs = adapter->num_vfs, vf;
David Ahern1cd127f2016-10-17 19:15:48 -07008409 struct upper_walk_data data;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008410 struct net_device *upper;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008411
8412 /* redirect to a SRIOV VF */
8413 for (vf = 0; vf < num_vfs; ++vf) {
8414 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
8415 if (upper->ifindex == ifindex) {
8416 if (adapter->num_rx_pools > 1)
8417 *queue = vf * 2;
8418 else
8419 *queue = vf * adapter->num_rx_queues_per_pool;
8420
8421 *action = vf + 1;
8422 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
8423 return 0;
8424 }
8425 }
8426
8427 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07008428 data.adapter = adapter;
8429 data.ifindex = ifindex;
8430 data.action = 0;
8431 data.queue = 0;
8432 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
8433 get_macvlan_queue, &data)) {
8434 *action = data.action;
8435 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008436
David Ahern1cd127f2016-10-17 19:15:48 -07008437 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008438 }
8439
8440 return -EINVAL;
8441}
8442
8443static int parse_tc_actions(struct ixgbe_adapter *adapter,
8444 struct tcf_exts *exts, u64 *action, u8 *queue)
8445{
8446 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07008447 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008448 int err;
8449
8450 if (tc_no_actions(exts))
8451 return -EINVAL;
8452
WANG Cong22dc13c2016-08-13 22:35:00 -07008453 tcf_exts_to_list(exts, &actions);
8454 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008455
8456 /* Drop action */
8457 if (is_tcf_gact_shot(a)) {
8458 *action = IXGBE_FDIR_DROP_QUEUE;
8459 *queue = IXGBE_FDIR_DROP_QUEUE;
8460 return 0;
8461 }
8462
8463 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03008464 if (is_tcf_mirred_egress_redirect(a)) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008465 int ifindex = tcf_mirred_ifindex(a);
8466
8467 err = handle_redirect_action(adapter, ifindex, queue,
8468 action);
8469 if (err == 0)
8470 return err;
8471 }
8472 }
8473
8474 return -EINVAL;
8475}
8476#else
8477static int parse_tc_actions(struct ixgbe_adapter *adapter,
8478 struct tcf_exts *exts, u64 *action, u8 *queue)
8479{
8480 return -EINVAL;
8481}
8482#endif /* CONFIG_NET_CLS_ACT */
8483
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008484static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
8485 union ixgbe_atr_input *mask,
8486 struct tc_cls_u32_offload *cls,
8487 struct ixgbe_mat_field *field_ptr,
8488 struct ixgbe_nexthdr *nexthdr)
8489{
8490 int i, j, off;
8491 __be32 val, m;
8492 bool found_entry = false, found_jump_field = false;
8493
8494 for (i = 0; i < cls->knode.sel->nkeys; i++) {
8495 off = cls->knode.sel->keys[i].off;
8496 val = cls->knode.sel->keys[i].val;
8497 m = cls->knode.sel->keys[i].mask;
8498
8499 for (j = 0; field_ptr[j].val; j++) {
8500 if (field_ptr[j].off == off) {
8501 field_ptr[j].val(input, mask, val, m);
8502 input->filter.formatted.flow_type |=
8503 field_ptr[j].type;
8504 found_entry = true;
8505 break;
8506 }
8507 }
8508 if (nexthdr) {
8509 if (nexthdr->off == cls->knode.sel->keys[i].off &&
8510 nexthdr->val == cls->knode.sel->keys[i].val &&
8511 nexthdr->mask == cls->knode.sel->keys[i].mask)
8512 found_jump_field = true;
8513 else
8514 continue;
8515 }
8516 }
8517
8518 if (nexthdr && !found_jump_field)
8519 return -EINVAL;
8520
8521 if (!found_entry)
8522 return 0;
8523
8524 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
8525 IXGBE_ATR_L4TYPE_MASK;
8526
8527 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
8528 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
8529
8530 return 0;
8531}
8532
John Fastabendb82b17d2016-02-16 21:18:53 -08008533static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
8534 __be16 protocol,
8535 struct tc_cls_u32_offload *cls)
8536{
8537 u32 loc = cls->knode.handle & 0xfffff;
8538 struct ixgbe_hw *hw = &adapter->hw;
8539 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008540 struct ixgbe_fdir_filter *input = NULL;
8541 union ixgbe_atr_input *mask = NULL;
8542 struct ixgbe_jump_table *jump = NULL;
8543 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008544 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008545 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08008546
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008547 uhtid = TC_U32_USERHTID(cls->knode.handle);
8548 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08008549
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008550 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08008551 * L2 headers. The canonical method to match L2 frames is to use
8552 * negative values. However this is error prone at best but really
8553 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008554 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08008555 * headers when needed.
8556 */
8557 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008558 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008559
8560 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
8561 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008562 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008563 }
8564
8565 /* cls u32 is a graph starting at root node 0x800. The driver tracks
8566 * links and also the fields used to advance the parser across each
8567 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
8568 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
8569 * To add support for new nodes update ixgbe_model.h parse structures
8570 * this function _should_ be generic try not to hardcode values here.
8571 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008572 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008573 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08008574 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008575 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008576 return err;
8577 if (!adapter->jump_tables[uhtid])
8578 return err;
8579 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08008580 }
8581
8582 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008583 return err;
8584
8585 /* At this point we know the field_ptr is valid and need to either
8586 * build cls_u32 link or attach filter. Because adding a link to
8587 * a handle that does not exist is invalid and the same for adding
8588 * rules to handles that don't exist.
8589 */
8590
8591 if (link_uhtid) {
8592 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
8593
8594 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
8595 return err;
8596
8597 if (!test_bit(link_uhtid - 1, &adapter->tables))
8598 return err;
8599
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008600 /* Multiple filters as links to the same hash table are not
8601 * supported. To add a new filter with the same next header
8602 * but different match/jump conditions, create a new hash table
8603 * and link to it.
8604 */
8605 if (adapter->jump_tables[link_uhtid] &&
8606 (adapter->jump_tables[link_uhtid])->link_hdl) {
8607 e_err(drv, "Link filter exists for link: %x\n",
8608 link_uhtid);
8609 return err;
8610 }
8611
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008612 for (i = 0; nexthdr[i].jump; i++) {
8613 if (nexthdr[i].o != cls->knode.sel->offoff ||
8614 nexthdr[i].s != cls->knode.sel->offshift ||
8615 nexthdr[i].m != cls->knode.sel->offmask)
8616 return err;
8617
8618 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
8619 if (!jump)
8620 return -ENOMEM;
8621 input = kzalloc(sizeof(*input), GFP_KERNEL);
8622 if (!input) {
8623 err = -ENOMEM;
8624 goto free_jump;
8625 }
8626 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
8627 if (!mask) {
8628 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008629 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008630 }
8631 jump->input = input;
8632 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008633 jump->link_hdl = cls->knode.handle;
8634
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008635 err = ixgbe_clsu32_build_input(input, mask, cls,
8636 field_ptr, &nexthdr[i]);
8637 if (!err) {
8638 jump->mat = nexthdr[i].jump;
8639 adapter->jump_tables[link_uhtid] = jump;
8640 break;
8641 }
8642 }
8643 return 0;
8644 }
John Fastabendb82b17d2016-02-16 21:18:53 -08008645
8646 input = kzalloc(sizeof(*input), GFP_KERNEL);
8647 if (!input)
8648 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008649 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
8650 if (!mask) {
8651 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008652 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08008653 }
8654
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008655 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
8656 if ((adapter->jump_tables[uhtid])->input)
8657 memcpy(input, (adapter->jump_tables[uhtid])->input,
8658 sizeof(*input));
8659 if ((adapter->jump_tables[uhtid])->mask)
8660 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
8661 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008662
8663 /* Lookup in all child hash tables if this location is already
8664 * filled with a filter
8665 */
8666 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8667 struct ixgbe_jump_table *link = adapter->jump_tables[i];
8668
8669 if (link && (test_bit(loc - 1, link->child_loc_map))) {
8670 e_err(drv, "Filter exists in location: %x\n",
8671 loc);
8672 err = -EINVAL;
8673 goto err_out;
8674 }
8675 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008676 }
8677 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
8678 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08008679 goto err_out;
8680
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008681 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
8682 &queue);
8683 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08008684 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08008685
John Fastabendb82b17d2016-02-16 21:18:53 -08008686 input->sw_idx = loc;
8687
8688 spin_lock(&adapter->fdir_perfect_lock);
8689
8690 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008691 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
8692 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008693 if (err)
8694 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008695 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008696 err = -EINVAL;
8697 goto err_out_w_lock;
8698 }
8699
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008700 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008701 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
8702 input->sw_idx, queue);
8703 if (!err)
8704 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
8705 spin_unlock(&adapter->fdir_perfect_lock);
8706
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008707 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
8708 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008709
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008710 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08008711 return err;
8712err_out_w_lock:
8713 spin_unlock(&adapter->fdir_perfect_lock);
8714err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008715 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008716free_input:
8717 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008718free_jump:
8719 kfree(jump);
8720 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08008721}
8722
Emil Tantilov6e2a60b2016-02-17 15:55:06 -08008723static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
8724 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08008725{
John Fastabendb82b17d2016-02-16 21:18:53 -08008726 struct ixgbe_adapter *adapter = netdev_priv(dev);
8727
8728 if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
8729 tc->type == TC_SETUP_CLSU32) {
John Fastabendb82b17d2016-02-16 21:18:53 -08008730 switch (tc->cls_u32->command) {
8731 case TC_CLSU32_NEW_KNODE:
8732 case TC_CLSU32_REPLACE_KNODE:
8733 return ixgbe_configure_clsu32(adapter,
8734 proto, tc->cls_u32);
8735 case TC_CLSU32_DELETE_KNODE:
8736 return ixgbe_delete_clsu32(adapter, tc->cls_u32);
John Fastabenddb956ae2016-02-16 21:19:19 -08008737 case TC_CLSU32_NEW_HNODE:
8738 case TC_CLSU32_REPLACE_HNODE:
8739 return ixgbe_configure_clsu32_add_hnode(adapter, proto,
8740 tc->cls_u32);
8741 case TC_CLSU32_DELETE_HNODE:
8742 return ixgbe_configure_clsu32_del_hnode(adapter,
8743 tc->cls_u32);
John Fastabendb82b17d2016-02-16 21:18:53 -08008744 default:
8745 return -EINVAL;
8746 }
8747 }
8748
John Fastabend5eb4dce2016-02-29 11:26:13 -08008749 if (tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08008750 return -EINVAL;
8751
John Fastabend16e5cc62016-02-16 21:16:43 -08008752 return ixgbe_setup_tc(dev, tc->tc);
John Fastabende4c67342016-02-16 21:16:15 -08008753}
8754
Greg Roseda36b642012-12-11 08:26:43 +00008755#ifdef CONFIG_PCI_IOV
8756void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
8757{
8758 struct net_device *netdev = adapter->netdev;
8759
8760 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00008761 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00008762 rtnl_unlock();
8763}
8764
8765#endif
Don Skidmore082757a2011-07-21 05:55:00 +00008766void ixgbe_do_reset(struct net_device *netdev)
8767{
8768 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8769
8770 if (netif_running(netdev))
8771 ixgbe_reinit_locked(adapter);
8772 else
8773 ixgbe_reset(adapter);
8774}
8775
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008776static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008777 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008778{
8779 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8780
Don Skidmore082757a2011-07-21 05:55:00 +00008781 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00008782 if (!(features & NETIF_F_RXCSUM))
8783 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00008784
Alexander Duyck567d2de2012-02-11 07:18:57 +00008785 /* Turn off LRO if not RSC capable */
8786 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
8787 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008788
Alexander Duyck567d2de2012-02-11 07:18:57 +00008789 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00008790}
8791
Michał Mirosławc8f44af2011-11-15 15:29:55 +00008792static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00008793 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00008794{
8795 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00008796 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00008797 bool need_reset = false;
8798
Don Skidmore082757a2011-07-21 05:55:00 +00008799 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00008800 if (!(features & NETIF_F_LRO)) {
8801 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00008802 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00008803 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
8804 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
8805 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
8806 if (adapter->rx_itr_setting == 1 ||
8807 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
8808 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
8809 need_reset = true;
8810 } else if ((changed ^ features) & NETIF_F_LRO) {
8811 e_info(probe, "rx-usecs set too low, "
8812 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00008813 }
8814 }
8815
8816 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08008817 * Check if Flow Director n-tuple support or hw_tc support was
8818 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00008819 */
John Fastabendb82b17d2016-02-16 21:18:53 -08008820 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00008821 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00008822 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
8823 need_reset = true;
8824
Alexander Duyck567d2de2012-02-11 07:18:57 +00008825 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
8826 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08008827 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00008828 /* turn off perfect filters, enable ATR and reset */
8829 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
8830 need_reset = true;
8831
8832 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
8833
8834 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08008835 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
8836 /* We cannot enable ATR if we have 2 or more tcs */
8837 (netdev_get_num_tc(netdev) > 1) ||
8838 /* We cannot enable ATR if RSS is disabled */
8839 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
8840 /* A sample rate of 0 indicates ATR disabled */
8841 (!adapter->atr_sample_rate))
8842 ; /* do nothing not supported */
8843 else /* otherwise supported and set the flag */
8844 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00008845 }
8846
Ben Greear3f2d1c02012-03-08 08:28:41 +00008847 if (changed & NETIF_F_RXALL)
8848 need_reset = true;
8849
Alexander Duyck567d2de2012-02-11 07:18:57 +00008850 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07008851
Mark Rustad67359c32015-06-15 11:33:25 -07008852 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07008853 if (features & NETIF_F_RXCSUM) {
8854 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
8855 } else {
8856 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
8857
8858 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
8859 }
8860 }
8861
8862 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
8863 if (features & NETIF_F_RXCSUM) {
8864 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
8865 } else {
8866 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
8867
8868 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
8869 }
Mark Rustad67359c32015-06-15 11:33:25 -07008870 }
Mark Rustad67359c32015-06-15 11:33:25 -07008871
Don Skidmore082757a2011-07-21 05:55:00 +00008872 if (need_reset)
8873 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08008874 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
8875 NETIF_F_HW_VLAN_CTAG_FILTER))
8876 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00008877
8878 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00008879}
8880
Don Skidmore3f207802014-12-23 07:40:34 +00008881/**
Emil Tantilova21d0822016-08-10 11:19:23 -07008882 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00008883 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02008884 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00008885 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07008886static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
8887 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00008888{
8889 struct ixgbe_adapter *adapter = netdev_priv(dev);
8890 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07008891 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07008892 u32 port_shift = 0;
8893 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07008894
Alexander Duyckb3a49552016-06-16 12:22:19 -07008895 if (ti->sa_family != AF_INET)
8896 return;
8897
Emil Tantilova21d0822016-08-10 11:19:23 -07008898 switch (ti->type) {
8899 case UDP_TUNNEL_TYPE_VXLAN:
8900 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
8901 return;
Don Skidmore3f207802014-12-23 07:40:34 +00008902
Emil Tantilova21d0822016-08-10 11:19:23 -07008903 if (adapter->vxlan_port == port)
8904 return;
Don Skidmore3f207802014-12-23 07:40:34 +00008905
Emil Tantilova21d0822016-08-10 11:19:23 -07008906 if (adapter->vxlan_port) {
8907 netdev_info(dev,
8908 "VXLAN port %d set, not adding port %d\n",
8909 ntohs(adapter->vxlan_port),
8910 ntohs(port));
8911 return;
8912 }
8913
8914 adapter->vxlan_port = port;
8915 break;
8916 case UDP_TUNNEL_TYPE_GENEVE:
8917 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
8918 return;
8919
8920 if (adapter->geneve_port == port)
8921 return;
8922
8923 if (adapter->geneve_port) {
8924 netdev_info(dev,
8925 "GENEVE port %d set, not adding port %d\n",
8926 ntohs(adapter->geneve_port),
8927 ntohs(port));
8928 return;
8929 }
8930
8931 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
8932 adapter->geneve_port = port;
8933 break;
8934 default:
Don Skidmore3f207802014-12-23 07:40:34 +00008935 return;
8936 }
8937
Emil Tantilova21d0822016-08-10 11:19:23 -07008938 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
8939 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00008940}
8941
8942/**
Emil Tantilova21d0822016-08-10 11:19:23 -07008943 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00008944 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02008945 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00008946 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07008947static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
8948 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00008949{
8950 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07008951 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00008952
Emil Tantilova21d0822016-08-10 11:19:23 -07008953 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
8954 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07008955 return;
8956
8957 if (ti->sa_family != AF_INET)
8958 return;
8959
Emil Tantilova21d0822016-08-10 11:19:23 -07008960 switch (ti->type) {
8961 case UDP_TUNNEL_TYPE_VXLAN:
8962 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
8963 return;
Mark Rustad67359c32015-06-15 11:33:25 -07008964
Emil Tantilova21d0822016-08-10 11:19:23 -07008965 if (adapter->vxlan_port != ti->port) {
8966 netdev_info(dev, "VXLAN port %d not found\n",
8967 ntohs(ti->port));
8968 return;
8969 }
8970
8971 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
8972 break;
8973 case UDP_TUNNEL_TYPE_GENEVE:
8974 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
8975 return;
8976
8977 if (adapter->geneve_port != ti->port) {
8978 netdev_info(dev, "GENEVE port %d not found\n",
8979 ntohs(ti->port));
8980 return;
8981 }
8982
8983 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
8984 break;
8985 default:
Don Skidmore3f207802014-12-23 07:40:34 +00008986 return;
8987 }
8988
Emil Tantilova21d0822016-08-10 11:19:23 -07008989 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
8990 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00008991}
8992
stephen hemmingeredc7d572012-10-01 12:32:33 +00008993static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008994 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01008995 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008996 u16 flags)
8997{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00008998 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00008999 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009000 struct ixgbe_adapter *adapter = netdev_priv(dev);
9001 u16 pool = VMDQ_P(0);
9002
9003 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009004 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009005 }
9006
Jiri Pirkof6f64242014-11-28 14:34:15 +01009007 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009008}
9009
Don Skidmore219efe92015-04-09 22:03:22 -07009010/**
9011 * ixgbe_configure_bridge_mode - set various bridge modes
9012 * @adapter - the private structure
9013 * @mode - requested bridge mode
9014 *
9015 * Configure some settings require for various bridge modes.
9016 **/
9017static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9018 __u16 mode)
9019{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009020 struct ixgbe_hw *hw = &adapter->hw;
9021 unsigned int p, num_pools;
9022 u32 vmdctl;
9023
Don Skidmore219efe92015-04-09 22:03:22 -07009024 switch (mode) {
9025 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009026 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009027 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009028
9029 /* must enable Rx switching replication to allow multicast
9030 * packet reception on all VFs, and to enable source address
9031 * pruning.
9032 */
9033 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9034 vmdctl |= IXGBE_VT_CTL_REPLEN;
9035 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9036
9037 /* enable Rx source address pruning. Note, this requires
9038 * replication to be enabled or else it does nothing.
9039 */
9040 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9041 for (p = 0; p < num_pools; p++) {
9042 if (hw->mac.ops.set_source_address_pruning)
9043 hw->mac.ops.set_source_address_pruning(hw,
9044 true,
9045 p);
9046 }
Don Skidmore219efe92015-04-09 22:03:22 -07009047 break;
9048 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009049 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009050 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9051 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009052
9053 /* disable Rx switching replication unless we have SR-IOV
9054 * virtual functions
9055 */
9056 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9057 if (!adapter->num_vfs)
9058 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9059 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9060
9061 /* disable Rx source address pruning, since we don't expect to
9062 * be receiving external loopback of our transmitted frames.
9063 */
9064 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9065 for (p = 0; p < num_pools; p++) {
9066 if (hw->mac.ops.set_source_address_pruning)
9067 hw->mac.ops.set_source_address_pruning(hw,
9068 false,
9069 p);
9070 }
Don Skidmore219efe92015-04-09 22:03:22 -07009071 break;
9072 default:
9073 return -EINVAL;
9074 }
9075
9076 adapter->bridge_mode = mode;
9077
9078 e_info(drv, "enabling bridge mode: %s\n",
9079 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9080
9081 return 0;
9082}
9083
John Fastabend815cccb2012-10-24 08:13:09 +00009084static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009085 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009086{
9087 struct ixgbe_adapter *adapter = netdev_priv(dev);
9088 struct nlattr *attr, *br_spec;
9089 int rem;
9090
9091 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9092 return -EOPNOTSUPP;
9093
9094 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009095 if (!br_spec)
9096 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009097
9098 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009099 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009100 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009101
9102 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9103 continue;
9104
Thomas Grafb7c1a312014-11-26 13:42:17 +01009105 if (nla_len(attr) < sizeof(mode))
9106 return -EINVAL;
9107
John Fastabend815cccb2012-10-24 08:13:09 +00009108 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009109 status = ixgbe_configure_bridge_mode(adapter, mode);
9110 if (status)
9111 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009112
9113 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009114 }
9115
9116 return 0;
9117}
9118
9119static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009120 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009121 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009122{
9123 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009124
9125 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9126 return 0;
9127
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009128 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009129 adapter->bridge_mode, 0, 0, nlflags,
9130 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009131}
9132
John Fastabend2a47fa42013-11-06 09:54:52 -08009133static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9134{
9135 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
9136 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009137 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08009138 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009139 int pool, err;
9140
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009141 /* Hardware has a limited number of available pools. Each VF, and the
9142 * PF require a pool. Check to ensure we don't attempt to use more
9143 * then the available number of pools.
9144 */
9145 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9146 return ERR_PTR(-EINVAL);
9147
John Fastabend219354d2013-11-08 00:50:32 -08009148#ifdef CONFIG_RPS
9149 if (vdev->num_rx_queues != vdev->num_tx_queues) {
9150 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
9151 vdev->name);
9152 return ERR_PTR(-EINVAL);
9153 }
9154#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08009155 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08009156 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08009157 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
9158 netdev_info(pdev,
9159 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
9160 pdev->name);
9161 return ERR_PTR(-EINVAL);
9162 }
9163
9164 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
9165 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
9166 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
9167 return ERR_PTR(-EBUSY);
9168
Maninder Singhbc52f952015-06-19 09:37:55 +05309169 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08009170 if (!fwd_adapter)
9171 return ERR_PTR(-ENOMEM);
9172
9173 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
9174 adapter->num_rx_pools++;
9175 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08009176 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08009177
9178 /* Enable VMDq flag so device will be set in VM mode */
9179 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08009180 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08009181 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08009182
9183 /* Force reinit of ring allocation with VMDQ enabled */
9184 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9185 if (err)
9186 goto fwd_add_err;
9187 fwd_adapter->pool = pool;
9188 fwd_adapter->real_adapter = adapter;
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009189
9190 if (netif_running(pdev)) {
9191 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
9192 if (err)
9193 goto fwd_add_err;
9194 netif_tx_start_all_queues(vdev);
9195 }
9196
John Fastabend2a47fa42013-11-06 09:54:52 -08009197 return fwd_adapter;
9198fwd_add_err:
9199 /* unwind counter and free adapter struct */
9200 netdev_info(pdev,
9201 "%s: dfwd hardware acceleration failed\n", vdev->name);
9202 clear_bit(pool, &adapter->fwd_bitmask);
9203 adapter->num_rx_pools--;
9204 kfree(fwd_adapter);
9205 return ERR_PTR(err);
9206}
9207
9208static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9209{
9210 struct ixgbe_fwd_adapter *fwd_adapter = priv;
9211 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08009212 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009213
9214 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
9215 adapter->num_rx_pools--;
9216
John Fastabend51f37732013-11-08 00:51:10 -08009217 limit = find_last_bit(&adapter->fwd_bitmask, 32);
9218 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009219 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
9220 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9221 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
9222 fwd_adapter->pool, adapter->num_rx_pools,
9223 fwd_adapter->rx_base_queue,
9224 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
9225 adapter->fwd_bitmask);
9226 kfree(fwd_adapter);
9227}
9228
Alexander Duyckb83e3012016-04-14 17:19:31 -04009229#define IXGBE_MAX_MAC_HDR_LEN 127
9230#define IXGBE_MAX_NETWORK_HDR_LEN 511
9231
Mark Rustadf467bc02015-06-15 11:33:20 -07009232static netdev_features_t
9233ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9234 netdev_features_t features)
9235{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009236 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009237
Alexander Duyckb83e3012016-04-14 17:19:31 -04009238 /* Make certain the headers can be described by a context descriptor */
9239 mac_hdr_len = skb_network_header(skb) - skb->data;
9240 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9241 return features & ~(NETIF_F_HW_CSUM |
9242 NETIF_F_SCTP_CRC |
9243 NETIF_F_HW_VLAN_CTAG_TX |
9244 NETIF_F_TSO |
9245 NETIF_F_TSO6);
9246
9247 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9248 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9249 return features & ~(NETIF_F_HW_CSUM |
9250 NETIF_F_SCTP_CRC |
9251 NETIF_F_TSO |
9252 NETIF_F_TSO6);
9253
9254 /* We can only support IPV4 TSO in tunnels if we can mangle the
9255 * inner IP ID field, so strip TSO if MANGLEID is not supported.
9256 */
9257 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
9258 features &= ~NETIF_F_TSO;
Mark Rustadf467bc02015-06-15 11:33:20 -07009259
9260 return features;
9261}
9262
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009263static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00009264 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009265 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08009266 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07009267 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00009268 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009269 .ndo_validate_addr = eth_validate_addr,
9270 .ndo_set_mac_address = ixgbe_set_mac,
9271 .ndo_change_mtu = ixgbe_change_mtu,
9272 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00009273 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009274 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
9275 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00009276 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00009277 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
9278 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04009279 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00009280 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03009281 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +00009282 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +00009283 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00009284 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -08009285 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009286#ifdef CONFIG_NET_POLL_CONTROLLER
9287 .ndo_poll_controller = ixgbe_netpoll,
9288#endif
Cong Wange0d10952013-08-01 11:10:25 +08009289#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03009290 .ndo_busy_poll = ixgbe_low_latency_recv,
Eliezer Tamir5a85e732013-06-10 11:40:20 +03009291#endif
Yi Zou332d4a72009-05-13 13:11:53 +00009292#ifdef IXGBE_FCOE
9293 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00009294 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00009295 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00009296 .ndo_fcoe_enable = ixgbe_fcoe_enable,
9297 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00009298 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00009299 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00009300#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00009301 .ndo_set_features = ixgbe_set_features,
9302 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009303 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00009304 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
9305 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08009306 .ndo_dfwd_add_station = ixgbe_fwd_add,
9307 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -07009308 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
9309 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -07009310 .ndo_features_check = ixgbe_features_check,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009311};
9312
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009313/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00009314 * ixgbe_enumerate_functions - Get the number of ports this device has
9315 * @adapter: adapter structure
9316 *
9317 * This function enumerates the phsyical functions co-located on a single slot,
9318 * in order to determine how many ports a device has. This is most useful in
9319 * determining the required GT/s of PCIe bandwidth necessary for optimal
9320 * performance.
9321 **/
9322static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
9323{
Jacob Kellercaafb952014-07-19 07:17:17 +00009324 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009325 int physfns = 0;
9326
Jacob Kellerf1f96572013-08-31 02:45:38 +00009327 /* Some cards can not use the generic count PCIe functions method,
9328 * because they are behind a parent switch, so we hardcode these with
9329 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00009330 */
Jacob Keller88189702014-07-19 07:17:16 +00009331 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00009332 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00009333
9334 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
9335 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00009336 if (entry->is_virtfn)
9337 continue;
9338
9339 /* When the devices on the bus don't all match our device ID,
9340 * we can't reliably determine the correct number of
9341 * functions. This can occur if a function has been direct
9342 * attached to a virtual machine using VT-d, for example. In
9343 * this case, simply return -1 to indicate this.
9344 */
9345 if ((entry->vendor != pdev->vendor) ||
9346 (entry->device != pdev->device))
9347 return -1;
9348
9349 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009350 }
9351
9352 return physfns;
9353}
9354
9355/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00009356 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -07009357 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +00009358 * @device_id: the device ID
9359 * @subdev_id: the subsystem device ID
9360 *
9361 * This function is used by probe and ethtool to determine
9362 * which devices have WoL support
9363 *
9364 **/
Emil Tantilov740234f2016-04-21 11:37:12 -07009365bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
9366 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +00009367{
9368 struct ixgbe_hw *hw = &adapter->hw;
9369 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009370
Emil Tantilov740234f2016-04-21 11:37:12 -07009371 /* WOL not supported on 82598 */
9372 if (hw->mac.type == ixgbe_mac_82598EB)
9373 return false;
9374
9375 /* check eeprom to see if WOL is enabled for X540 and newer */
9376 if (hw->mac.type >= ixgbe_mac_X540) {
9377 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
9378 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
9379 (hw->bus.func == 0)))
9380 return true;
9381 }
9382
9383 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +00009384 switch (device_id) {
9385 case IXGBE_DEV_ID_82599_SFP:
9386 /* Only these subdevices could supports WOL */
9387 switch (subdevice_id) {
9388 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009389 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
9390 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
9391 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009392 /* only support first port */
9393 if (hw->bus.func != 0)
9394 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00009395 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009396 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00009397 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00009398 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009399 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
9400 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
9401 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -07009402 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009403 }
9404 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009405 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -07009406 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +00009407 switch (subdevice_id) {
9408 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -07009409 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009410 }
9411 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009412 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
9413 /* All except this subdevice support WOL */
9414 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -07009415 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009416 break;
9417 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -07009418 return true;
9419 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009420 break;
9421 }
9422
Emil Tantilov740234f2016-04-21 11:37:12 -07009423 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009424}
9425
9426/**
Auke Kok9a799d72007-09-15 14:07:45 -07009427 * ixgbe_probe - Device Initialization Routine
9428 * @pdev: PCI device information struct
9429 * @ent: entry in ixgbe_pci_tbl
9430 *
9431 * Returns 0 on success, negative on failure
9432 *
9433 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
9434 * The OS initialization, configuring of the adapter private structure,
9435 * and a hardware reset occur.
9436 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00009437static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07009438{
9439 struct net_device *netdev;
9440 struct ixgbe_adapter *adapter = NULL;
9441 struct ixgbe_hw *hw;
9442 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +00009443 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009444 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00009445 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009446 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +00009447#ifdef IXGBE_FCOE
9448 u16 device_caps;
9449#endif
Don Skidmore289700db2010-12-03 03:32:58 +00009450 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07009451
Andy Gospodarekbded64a2010-07-21 06:40:31 +00009452 /* Catch broken hardware that put the wrong VF device ID in
9453 * the PCIe SR-IOV capability.
9454 */
9455 if (pdev->is_virtfn) {
9456 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
9457 pci_name(pdev), pdev->vendor, pdev->device);
9458 return -EINVAL;
9459 }
9460
gouji-new9ce77662009-05-06 10:44:45 +00009461 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009462 if (err)
9463 return err;
9464
Russell Kingf5f2eda2013-06-10 12:47:42 +01009465 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07009466 pci_using_dac = 1;
9467 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009468 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07009469 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01009470 dev_err(&pdev->dev,
9471 "No usable DMA configuration, aborting\n");
9472 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07009473 }
9474 pci_using_dac = 0;
9475 }
9476
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02009477 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07009478 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00009479 dev_err(&pdev->dev,
9480 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07009481 goto err_pci_reg;
9482 }
9483
Frans Pop19d5afd2009-10-02 10:04:12 -07009484 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009485
Auke Kok9a799d72007-09-15 14:07:45 -07009486 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07009487 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009488
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009489 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00009490#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009491 /* 8 TC w/ 4 queues per TC */
9492 indices = 4 * MAX_TRAFFIC_CLASS;
9493#else
9494 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00009495#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009496 }
John Fastabende901acd2011-04-26 07:26:08 +00009497
John Fastabendc85a2612010-02-25 23:15:21 +00009498 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07009499 if (!netdev) {
9500 err = -ENOMEM;
9501 goto err_alloc_etherdev;
9502 }
9503
Auke Kok9a799d72007-09-15 14:07:45 -07009504 SET_NETDEV_DEV(netdev, &pdev->dev);
9505
Auke Kok9a799d72007-09-15 14:07:45 -07009506 adapter = netdev_priv(netdev);
9507
9508 adapter->netdev = netdev;
9509 adapter->pdev = pdev;
9510 hw = &adapter->hw;
9511 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00009512 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07009513
Jeff Kirsher05857982008-09-11 19:57:00 -07009514 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00009515 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08009516 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07009517 if (!hw->hw_addr) {
9518 err = -EIO;
9519 goto err_ioremap;
9520 }
9521
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009522 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009523 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009524 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +00009525 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -07009526
Auke Kok9a799d72007-09-15 14:07:45 -07009527 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -08009528 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009529 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009530 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -07009531 if (ii->link_ops)
9532 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07009533
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009534 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -08009535 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -07009536 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +00009537 if (ixgbe_removed(hw->hw_addr)) {
9538 err = -EIO;
9539 goto err_ioremap;
9540 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009541 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07009542 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009543 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
9544
9545 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -08009546 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009547 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00009548 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
9549 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
9550 hw->phy.mdio.mmds = 0;
9551 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9552 hw->phy.mdio.dev = netdev;
9553 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
9554 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08009555
Auke Kok9a799d72007-09-15 14:07:45 -07009556 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -07009557 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -07009558 if (err)
9559 goto err_sw_init;
9560
Don Skidmoredbd15b82016-03-09 16:45:00 -05009561 /* Make sure the SWFW semaphore is in a valid state */
9562 if (hw->mac.ops.init_swfw_sync)
9563 hw->mac.ops.init_swfw_sync(hw);
9564
Don Skidmoree86bff02010-02-11 04:14:08 +00009565 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08009566 switch (adapter->hw.mac.type) {
9567 case ixgbe_mac_82599EB:
9568 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00009569 case ixgbe_mac_X550:
9570 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07009571 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +00009572 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08009573 break;
9574 default:
9575 break;
9576 }
Don Skidmoree86bff02010-02-11 04:14:08 +00009577
Don Skidmorebf069c92009-05-07 10:39:54 +00009578 /*
9579 * If there is a fan on this device and it has failed log the
9580 * failure.
9581 */
9582 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
9583 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
9584 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00009585 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00009586 }
9587
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00009588 if (allow_unsupported_sfp)
9589 hw->allow_unsupported_sfp = allow_unsupported_sfp;
9590
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009591 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009592 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009593 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07009594 hw->phy.reset_if_overtemp = false;
Mark Rustad29a8dca2015-08-08 16:17:46 -07009595 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07009596 err = 0;
9597 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00009598 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
9599 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009600 goto err_sw_init;
9601 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009602 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009603 goto err_sw_init;
9604 }
9605
Alexander Duyck99d74482012-05-09 08:09:25 +00009606#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00009607 /* SR-IOV not supported on the 82598 */
9608 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
9609 goto skip_sriov;
9610 /* Mailbox */
9611 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -08009612 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -08009613 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ethan.zhao31ac9102014-01-16 19:41:05 -08009614 ixgbe_enable_sriov(adapter);
Greg Rose60a1a682012-12-11 08:26:33 +00009615skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009616
Alexander Duyck99d74482012-05-09 08:09:25 +00009617#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00009618 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +00009619 NETIF_F_TSO |
9620 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00009621 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -08009622 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -04009623 NETIF_F_HW_CSUM;
9624
9625#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
9626 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -07009627 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -07009628 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -04009629 NETIF_F_GSO_UDP_TUNNEL | \
9630 NETIF_F_GSO_UDP_TUNNEL_CSUM)
9631
9632 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
9633 netdev->features |= NETIF_F_GSO_PARTIAL |
9634 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -07009635
Alexander Duyck49763de2016-01-13 07:31:11 -08009636 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -08009637 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00009638
Alexander Duyck49763de2016-01-13 07:31:11 -08009639 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -04009640 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -07009641 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -04009642 NETIF_F_HW_VLAN_CTAG_RX |
9643 NETIF_F_HW_VLAN_CTAG_TX |
9644 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -08009645 NETIF_F_HW_L2FW_DOFFLOAD;
9646
9647 if (hw->mac.type >= ixgbe_mac_82599EB)
9648 netdev->hw_features |= NETIF_F_NTUPLE |
9649 NETIF_F_HW_TC;
9650
Alexander Duyckb83e3012016-04-14 17:19:31 -04009651 if (pci_using_dac)
9652 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -07009653
Alexander Duyck5eee87c2016-05-11 13:23:34 -07009654 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
9655 netdev->hw_enc_features |= netdev->vlan_features;
9656 netdev->mpls_features |= NETIF_F_HW_CSUM;
9657
Alexander Duyckb83e3012016-04-14 17:19:31 -04009658 /* set this bit last since it cannot be part of vlan_features */
9659 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
9660 NETIF_F_HW_VLAN_CTAG_RX |
9661 NETIF_F_HW_VLAN_CTAG_TX;
9662
Jiri Pirko01789342011-08-16 06:29:00 +00009663 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00009664 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00009665
Jarod Wilson91c527a2016-10-17 15:54:05 -04009666 /* MTU range: 68 - 9710 */
9667 netdev->min_mtu = ETH_MIN_MTU;
9668 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
9669
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08009670#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07009671 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
9672 netdev->dcbnl_ops = &dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -08009673#endif
9674
Yi Zoueacd73f2009-05-13 13:11:06 +00009675#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00009676 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009677 unsigned int fcoe_l;
9678
Yi Zoueacd73f2009-05-13 13:11:06 +00009679 if (hw->mac.ops.get_device_caps) {
9680 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00009681 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
9682 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00009683 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009684
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009685
9686 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
9687 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009688
Alexander Duycka58915c2012-05-25 06:38:18 +00009689 netdev->features |= NETIF_F_FSO |
9690 NETIF_F_FCOE_CRC;
9691
Alexander Duyck7c8ae652012-05-05 05:32:47 +00009692 netdev->vlan_features |= NETIF_F_FSO |
9693 NETIF_F_FCOE_CRC |
9694 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00009695 }
Yi Zoueacd73f2009-05-13 13:11:06 +00009696#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07009697
Don Skidmore082757a2011-07-21 05:55:00 +00009698 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
9699 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00009700 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00009701 netdev->features |= NETIF_F_LRO;
9702
Auke Kok9a799d72007-09-15 14:07:45 -07009703 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009704 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009705 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009706 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009707 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009708 }
9709
Sowmini Varadhanc7374b52016-01-12 19:32:30 -08009710 eth_platform_get_mac_address(&adapter->pdev->dev,
9711 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +00009712
Auke Kok9a799d72007-09-15 14:07:45 -07009713 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07009714
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00009715 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009716 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07009717 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00009718 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009719 }
9720
Tushar Dave56768042016-01-07 14:17:03 -08009721 /* Set hw->mac.addr to permanent MAC address */
9722 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07009723 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +00009724
Alexander Duyck70864002011-04-27 09:13:56 +00009725 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00009726 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009727
Mark Rustad58cf6632014-03-12 00:38:40 +00009728 if (ixgbe_removed(hw->hw_addr)) {
9729 err = -EIO;
9730 goto err_sw_init;
9731 }
Alexander Duyck70864002011-04-27 09:13:56 +00009732 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +00009733 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00009734 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009735
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009736 err = ixgbe_init_interrupt_scheme(adapter);
9737 if (err)
9738 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07009739
Jacob Keller8e2813f2012-04-21 06:05:40 +00009740 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009741 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009742 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009743 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00009744 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00009745 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00009746 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00009747
PJ Waskiewicze8e26352009-02-27 15:45:05 +00009748 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
9749
Emil Tantilov15e52092011-09-29 05:01:29 +00009750 /* save off EEPROM version number */
9751 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
9752 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
9753
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009754 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +00009755 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00009756 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -04009757 else
9758 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00009759
Jacob Kellere027d1a2013-07-31 06:53:31 +00009760 /* calculate the expected PCIe bandwidth required for optimal
9761 * performance. Note that some older parts will never have enough
9762 * bandwidth due to being older generation PCIe parts. We clamp these
9763 * parts to ensure no warning is displayed if it can't be fixed.
9764 */
9765 switch (hw->mac.type) {
9766 case ixgbe_mac_82598EB:
9767 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
9768 break;
9769 default:
9770 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
9771 break;
Auke Kok0c254d82008-02-11 09:25:56 -08009772 }
Jacob Kellercaafb952014-07-19 07:17:17 +00009773
9774 /* don't check link if we failed to enumerate functions */
9775 if (expected_gts > 0)
9776 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08009777
Mark Rustad339de302014-06-06 01:57:06 +00009778 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009779 if (err)
Mark Rustad339de302014-06-06 01:57:06 +00009780 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00009781 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
9782 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
9783 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +00009784 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +00009785 else
9786 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
9787 hw->mac.type, hw->phy.type, part_str);
9788
9789 e_dev_info("%pM\n", netdev->dev_addr);
9790
Auke Kok9a799d72007-09-15 14:07:45 -07009791 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009792 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009793 if (err == IXGBE_ERR_EEPROM_VERSION) {
9794 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00009795 e_dev_warn("This device is a pre-production adapter/LOM. "
9796 "Please be aware there may be issues associated "
9797 "with your hardware. If you are experiencing "
9798 "problems please contact your Intel or hardware "
9799 "representative who provided you with this "
9800 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00009801 }
Auke Kok9a799d72007-09-15 14:07:45 -07009802 strcpy(netdev->name, "eth%d");
9803 err = register_netdev(netdev);
9804 if (err)
9805 goto err_register;
9806
Emil Tantilov0fb6a552014-12-04 03:03:38 +00009807 pci_set_drvdata(pdev, adapter);
9808
Emil Tantilovec74a472012-09-20 03:33:56 +00009809 /* power down the optics for 82599 SFP+ fiber */
9810 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00009811 hw->mac.ops.disable_tx_laser(hw);
9812
Jesse Brandeburg54386462009-04-17 20:44:27 +00009813 /* carrier off reporting is important to ethtool even BEFORE open */
9814 netif_carrier_off(netdev);
9815
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009816#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03009817 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009818 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009819 ixgbe_setup_dca(adapter);
9820 }
9821#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009822 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00009823 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00009824 for (i = 0; i < adapter->num_vfs; i++)
9825 ixgbe_vf_configuration(pdev, (i | 0x10000000));
9826 }
9827
Jacob Keller2466dd92011-09-08 03:50:54 +00009828 /* firmware requires driver version to be 0xFFFFFFFF
9829 * since os does not support feature
9830 */
Emil Tantilov9612de92011-05-07 07:40:20 +00009831 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00009832 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
9833 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00009834
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00009835 /* add san mac addr to netdev */
9836 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009837
Neerav Parikhea818752012-01-04 20:23:40 +00009838 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009839
Don Skidmore12109822012-05-04 06:07:08 +00009840#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009841 if (ixgbe_sysfs_init(adapter))
9842 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00009843#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009844
Catherine Sullivan00949162012-08-10 01:59:10 +00009845 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00009846
Emil Tantilovd1a35ee2014-05-13 08:24:00 +00009847 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
9848 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +00009849 hw->mac.ops.setup_link(hw,
9850 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
9851 true);
9852
Auke Kok9a799d72007-09-15 14:07:45 -07009853 return 0;
9854
9855err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08009856 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00009857 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009858err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00009859 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00009860 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -08009861 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009862 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +00009863 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -07009864err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009865 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009866 free_netdev(netdev);
9867err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02009868 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009869err_pci_reg:
9870err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009871 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00009872 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009873 return err;
9874}
9875
9876/**
9877 * ixgbe_remove - Device Removal Routine
9878 * @pdev: PCI device information struct
9879 *
9880 * ixgbe_remove is called by the PCI subsystem to alert the driver
9881 * that it should release a PCI device. The could be caused by a
9882 * Hot-Plug event, or because the driver is going to be removed from
9883 * memory.
9884 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05009885static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07009886{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009887 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +00009888 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009889 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009890 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07009891
Emil Tantilov0fb6a552014-12-04 03:03:38 +00009892 /* if !adapter then we already cleaned up in probe */
9893 if (!adapter)
9894 return;
9895
9896 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +00009897 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00009898
Mark Rustad09f40ae2014-01-14 18:53:11 -08009899 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00009900 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07009901
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00009902
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009903#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009904 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
9905 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
9906 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -07009907 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
9908 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009909 }
9910
9911#endif
Don Skidmore12109822012-05-04 06:07:08 +00009912#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009913 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00009914#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00009915
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00009916 /* remove the added san mac */
9917 ixgbe_del_sanmac_netdev(netdev);
9918
Greg Roseda36b642012-12-11 08:26:43 +00009919#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -06009920 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +00009921#endif
Alex Williamson6b010e92015-07-29 14:38:21 -06009922 if (netdev->reg_state == NETREG_REGISTERED)
9923 unregister_netdev(netdev);
9924
Alexander Duyck7a921c92009-05-06 10:43:28 +00009925 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08009926
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009927 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009928
Alexander Duyck2b1588c2012-03-17 02:39:16 +00009929#ifdef CONFIG_DCB
9930 kfree(adapter->ixgbe_ieee_pfc);
9931 kfree(adapter->ixgbe_ieee_ets);
9932
9933#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -08009934 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +02009935 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009936
Emil Tantilov849c4542010-06-03 16:53:41 +00009937 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08009938
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009939 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
9940 if (adapter->jump_tables[i]) {
9941 kfree(adapter->jump_tables[i]->input);
9942 kfree(adapter->jump_tables[i]->mask);
9943 }
9944 kfree(adapter->jump_tables[i]);
9945 }
9946
Jacob Keller5d7daa32014-03-29 06:51:25 +00009947 kfree(adapter->mac_table);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009948 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07009949 free_netdev(netdev);
9950
Frans Pop19d5afd2009-10-02 10:04:12 -07009951 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009952
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009953 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00009954 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009955}
9956
9957/**
9958 * ixgbe_io_error_detected - called when PCI error is detected
9959 * @pdev: Pointer to PCI device
9960 * @state: The current pci connection state
9961 *
9962 * This function is called after a PCI bus error affecting
9963 * this device has been detected.
9964 */
9965static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00009966 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07009967{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009968 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
9969 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07009970
Greg Rose83c61fa2011-09-07 05:59:35 +00009971#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -08009972 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +00009973 struct pci_dev *bdev, *vfdev;
9974 u32 dw0, dw1, dw2, dw3;
9975 int vf, pos;
9976 u16 req_id, pf_func;
9977
9978 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
9979 adapter->num_vfs == 0)
9980 goto skip_bad_vf_detection;
9981
9982 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08009983 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00009984 bdev = bdev->bus->self;
9985
9986 if (!bdev)
9987 goto skip_bad_vf_detection;
9988
9989 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
9990 if (!pos)
9991 goto skip_bad_vf_detection;
9992
Mark Rustad14438462014-02-28 15:48:57 -08009993 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
9994 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
9995 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
9996 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
9997 if (ixgbe_removed(hw->hw_addr))
9998 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +00009999
10000 req_id = dw1 >> 16;
10001 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10002 if (!(req_id & 0x0080))
10003 goto skip_bad_vf_detection;
10004
10005 pf_func = req_id & 0x01;
10006 if ((pf_func & 1) == (pdev->devfn & 1)) {
10007 unsigned int device_id;
10008
10009 vf = (req_id & 0x7F) >> 1;
10010 e_dev_err("VF %d has caused a PCIe error\n", vf);
10011 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10012 "%8.8x\tdw3: %8.8x\n",
10013 dw0, dw1, dw2, dw3);
10014 switch (adapter->hw.mac.type) {
10015 case ixgbe_mac_82599EB:
10016 device_id = IXGBE_82599_VF_DEVICE_ID;
10017 break;
10018 case ixgbe_mac_X540:
10019 device_id = IXGBE_X540_VF_DEVICE_ID;
10020 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010021 case ixgbe_mac_X550:
10022 device_id = IXGBE_DEV_ID_X550_VF;
10023 break;
10024 case ixgbe_mac_X550EM_x:
10025 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10026 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010027 case ixgbe_mac_x550em_a:
10028 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10029 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010030 default:
10031 device_id = 0;
10032 break;
10033 }
10034
10035 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010036 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010037 while (vfdev) {
10038 if (vfdev->devfn == (req_id & 0xFF))
10039 break;
Jon Mason36e90312012-07-19 21:02:09 +000010040 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010041 device_id, vfdev);
10042 }
10043 /*
10044 * There's a slim chance the VF could have been hot plugged,
10045 * so if it is no longer present we don't need to issue the
10046 * VFLR. Just clean up the AER in that case.
10047 */
10048 if (vfdev) {
Emil Tantilov9079e412014-11-19 03:18:19 +000010049 ixgbe_issue_vf_flr(adapter, vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010050 /* Free device reference count */
10051 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010052 }
10053
10054 pci_cleanup_aer_uncorrect_error_status(pdev);
10055 }
10056
10057 /*
10058 * Even though the error may have occurred on the other port
10059 * we still need to increment the vf error reference count for
10060 * both ports because the I/O resume function will be called
10061 * for both of them.
10062 */
10063 adapter->vferr_refcount++;
10064
10065 return PCI_ERS_RESULT_RECOVERED;
10066
10067skip_bad_vf_detection:
10068#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010069 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10070 return PCI_ERS_RESULT_DISCONNECT;
10071
Mark Rustad41c62842014-03-12 00:38:35 +000010072 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010073 netif_device_detach(netdev);
10074
Mark Rustad41c62842014-03-12 00:38:35 +000010075 if (state == pci_channel_io_perm_failure) {
10076 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010077 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010078 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010079
Auke Kok9a799d72007-09-15 14:07:45 -070010080 if (netif_running(netdev))
10081 ixgbe_down(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +000010082
10083 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10084 pci_disable_device(pdev);
10085 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010086
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010087 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010088 return PCI_ERS_RESULT_NEED_RESET;
10089}
10090
10091/**
10092 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10093 * @pdev: Pointer to PCI device
10094 *
10095 * Restart the card from scratch, as if from a cold-boot.
10096 */
10097static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10098{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010099 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010100 pci_ers_result_t result;
10101 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010102
gouji-new9ce77662009-05-06 10:44:45 +000010103 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010104 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010105 result = PCI_ERS_RESULT_DISCONNECT;
10106 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010107 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010108 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010109 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010110 pci_set_master(pdev);
10111 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010112 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010113
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010114 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010115
10116 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010117 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010118 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010119 }
Auke Kok9a799d72007-09-15 14:07:45 -070010120
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010121 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10122 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010123 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10124 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010125 /* non-fatal, continue */
10126 }
Auke Kok9a799d72007-09-15 14:07:45 -070010127
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010128 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010129}
10130
10131/**
10132 * ixgbe_io_resume - called when traffic can start flowing again.
10133 * @pdev: Pointer to PCI device
10134 *
10135 * This callback is called when the error recovery driver tells us that
10136 * its OK to resume normal operation.
10137 */
10138static void ixgbe_io_resume(struct pci_dev *pdev)
10139{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010140 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10141 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010142
Greg Rose83c61fa2011-09-07 05:59:35 +000010143#ifdef CONFIG_PCI_IOV
10144 if (adapter->vferr_refcount) {
10145 e_info(drv, "Resuming after VF err\n");
10146 adapter->vferr_refcount--;
10147 return;
10148 }
10149
10150#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +000010151 if (netif_running(netdev))
10152 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010153
10154 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010155}
10156
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070010157static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070010158 .error_detected = ixgbe_io_error_detected,
10159 .slot_reset = ixgbe_io_slot_reset,
10160 .resume = ixgbe_io_resume,
10161};
10162
10163static struct pci_driver ixgbe_driver = {
10164 .name = ixgbe_driver_name,
10165 .id_table = ixgbe_pci_tbl,
10166 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010167 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070010168#ifdef CONFIG_PM
10169 .suspend = ixgbe_suspend,
10170 .resume = ixgbe_resume,
10171#endif
10172 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000010173 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070010174 .err_handler = &ixgbe_err_handler
10175};
10176
10177/**
10178 * ixgbe_init_module - Driver Registration Routine
10179 *
10180 * ixgbe_init_module is the first routine called when the driver is
10181 * loaded. All it does is register with the PCI subsystem.
10182 **/
10183static int __init ixgbe_init_module(void)
10184{
10185 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000010186 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000010187 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070010188
Mark Rustad780484d2015-10-21 17:21:10 -070010189 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
10190 if (!ixgbe_wq) {
10191 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
10192 return -ENOMEM;
10193 }
10194
Catherine Sullivan00949162012-08-10 01:59:10 +000010195 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000010196
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010197 ret = pci_register_driver(&ixgbe_driver);
10198 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000010199 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010200 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010201 return ret;
10202 }
10203
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010204#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010205 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010206#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010207
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010208 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070010209}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010210
Auke Kok9a799d72007-09-15 14:07:45 -070010211module_init(ixgbe_init_module);
10212
10213/**
10214 * ixgbe_exit_module - Driver Exit Cleanup Routine
10215 *
10216 * ixgbe_exit_module is called just before the driver is removed
10217 * from memory.
10218 **/
10219static void __exit ixgbe_exit_module(void)
10220{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010221#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010222 dca_unregister_notify(&dca_notifier);
10223#endif
Auke Kok9a799d72007-09-15 14:07:45 -070010224 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000010225
Catherine Sullivan00949162012-08-10 01:59:10 +000010226 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070010227 if (ixgbe_wq) {
10228 destroy_workqueue(ixgbe_wq);
10229 ixgbe_wq = NULL;
10230 }
Auke Kok9a799d72007-09-15 14:07:45 -070010231}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010232
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010233#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010234static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010235 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010236{
10237 int ret_val;
10238
10239 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010240 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010241
10242 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
10243}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010244
Alexander Duyckb4533682009-03-31 21:32:42 +000010245#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000010246
Auke Kok9a799d72007-09-15 14:07:45 -070010247module_exit(ixgbe_exit_module);
10248
10249/* ixgbe_main.c */