blob: 7906234c51642d60b4d79cfa4dfc48ade9ae353c [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Mark Rustad0391bbe2014-02-28 15:48:55 -08004 Copyright(c) 1999 - 2014 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Jacob Kellerb89aae72014-02-22 01:23:50 +000023 Linux NICS <linux.nics@intel.com>
Auke Kok9a799d72007-09-15 14:07:45 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include <linux/types.h>
30#include <linux/module.h>
31#include <linux/pci.h>
32#include <linux/netdevice.h>
33#include <linux/vmalloc.h>
34#include <linux/string.h>
35#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000036#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070037#include <linux/ip.h>
38#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000039#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000040#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070041#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070043#include <net/checksum.h>
44#include <net/ip6_checksum.h>
Martin K Petersenc762dff2014-11-15 14:24:51 +000045#include <linux/etherdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000047#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070048#include <linux/if_vlan.h>
John Fastabend2a47fa42013-11-06 09:54:52 -080049#include <linux/if_macvlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000050#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040051#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000052#include <scsi/fc/fc_fcoe.h>
Don Skidmore3f207802014-12-23 07:40:34 +000053#include <net/vxlan.h>
Auke Kok9a799d72007-09-15 14:07:45 -070054
Martin K Petersenc762dff2014-11-15 14:24:51 +000055#ifdef CONFIG_OF
56#include <linux/of_net.h>
57#endif
58
59#ifdef CONFIG_SPARC
60#include <asm/idprom.h>
61#include <asm/prom.h>
62#endif
63
Auke Kok9a799d72007-09-15 14:07:45 -070064#include "ixgbe.h"
65#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000066#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000067#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070068
69char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070070static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000071 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000072#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000073char ixgbe_default_device_descr[] =
74 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000075#else
76static char ixgbe_default_device_descr[] =
77 "Intel(R) 10 Gigabit Network Connection";
78#endif
Don Skidmore9be4a9b2014-11-29 05:22:58 +000079#define DRV_VERSION "4.0.1-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070080const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000081static const char ixgbe_copyright[] =
Mark Rustad0391bbe2014-02-28 15:48:55 -080082 "Copyright (c) 1999-2014 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070083
Don Skidmoref44e7512015-06-09 16:36:23 -070084static 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";
85
Auke Kok9a799d72007-09-15 14:07:45 -070086static const struct ixgbe_info *ixgbe_info_tbl[] = {
Don Skidmore6a14ee02014-12-05 03:59:50 +000087 [board_82598] = &ixgbe_82598_info,
88 [board_82599] = &ixgbe_82599_info,
89 [board_X540] = &ixgbe_X540_info,
90 [board_X550] = &ixgbe_X550_info,
91 [board_X550EM_x] = &ixgbe_X550EM_x_info,
Auke Kok9a799d72007-09-15 14:07:45 -070092};
93
94/* ixgbe_pci_tbl - PCI Device ID Table
95 *
96 * Wildcard entries (PCI_ANY_ID) should come last
97 * Last entry must be all 0s
98 *
99 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
100 * Class, Class Mask, private data (not used) }
101 */
Benoit Taine9baa3c32014-08-08 15:56:03 +0200102static const struct pci_device_id ixgbe_pci_tbl[] = {
Alexander Duyck54239c62011-07-15 03:06:06 +0000103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Don Skidmore8f583322013-07-27 06:25:38 +0000129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000132 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Don Skidmore6a14ee02014-12-05 03:59:50 +0000133 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
134 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
135 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
Don Skidmorededa5622015-06-09 17:39:46 -0700136 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
Auke Kok9a799d72007-09-15 14:07:45 -0700137 /* required last entry */
138 {0, }
139};
140MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
141
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400142#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800143static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000144 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800145static struct notifier_block dca_notifier = {
146 .notifier_call = ixgbe_notify_dca,
147 .next = NULL,
148 .priority = 0
149};
150#endif
151
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000152#ifdef CONFIG_PCI_IOV
153static unsigned int max_vfs;
154module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000155MODULE_PARM_DESC(max_vfs,
Jacob Keller170e8542013-11-09 04:52:32 -0800156 "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 +0000157#endif /* CONFIG_PCI_IOV */
158
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000159static unsigned int allow_unsupported_sfp;
160module_param(allow_unsupported_sfp, uint, 0);
161MODULE_PARM_DESC(allow_unsupported_sfp,
162 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
163
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000164#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
165static int debug = -1;
166module_param(debug, int, 0);
167MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
168
Auke Kok9a799d72007-09-15 14:07:45 -0700169MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
170MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
171MODULE_LICENSE("GPL");
172MODULE_VERSION(DRV_VERSION);
173
Mark Rustad14438462014-02-28 15:48:57 -0800174static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
175
Jacob Kellerb8e82002013-04-09 07:20:09 +0000176static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
177 u32 reg, u16 *value)
178{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000179 struct pci_dev *parent_dev;
180 struct pci_bus *parent_bus;
181
182 parent_bus = adapter->pdev->bus->parent;
183 if (!parent_bus)
184 return -1;
185
186 parent_dev = parent_bus->self;
187 if (!parent_dev)
188 return -1;
189
Yijing Wangc0798ed2013-09-04 17:30:08 +0000190 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000191 return -1;
192
Yijing Wangc0798ed2013-09-04 17:30:08 +0000193 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800194 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
195 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
196 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000197 return 0;
198}
199
200static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
201{
202 struct ixgbe_hw *hw = &adapter->hw;
203 u16 link_status = 0;
204 int err;
205
206 hw->bus.type = ixgbe_bus_type_pci_express;
207
208 /* Get the negotiated link width and speed from PCI config space of the
209 * parent, as this device is behind a switch
210 */
211 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
212
213 /* assume caller will handle error case */
214 if (err)
215 return err;
216
217 hw->bus.width = ixgbe_convert_bus_width(link_status);
218 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
219
220 return 0;
221}
222
Jacob Kellere027d1a2013-07-31 06:53:31 +0000223/**
224 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
225 * @hw: hw specific details
226 *
227 * This function is used by probe to determine whether a device's PCI-Express
228 * bandwidth details should be gathered from the parent bus instead of from the
229 * device. Used to ensure that various locations all have the correct device ID
230 * checks.
231 */
232static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
233{
234 switch (hw->device_id) {
235 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000236 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000237 return true;
238 default:
239 return false;
240 }
241}
242
243static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
244 int expected_gts)
245{
246 int max_gts = 0;
247 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
248 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
249 struct pci_dev *pdev;
250
Jacob Keller56d13922015-06-10 11:44:45 -0700251 /* determine whether to use the parent device */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000252 if (ixgbe_pcie_from_parent(&adapter->hw))
253 pdev = adapter->pdev->bus->parent->self;
254 else
255 pdev = adapter->pdev;
256
257 if (pcie_get_minimum_link(pdev, &speed, &width) ||
258 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
259 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
260 return;
261 }
262
263 switch (speed) {
264 case PCIE_SPEED_2_5GT:
265 /* 8b/10b encoding reduces max throughput by 20% */
266 max_gts = 2 * width;
267 break;
268 case PCIE_SPEED_5_0GT:
269 /* 8b/10b encoding reduces max throughput by 20% */
270 max_gts = 4 * width;
271 break;
272 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000273 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000274 max_gts = 8 * width;
275 break;
276 default:
277 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
278 return;
279 }
280
281 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
282 max_gts);
283 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
284 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
285 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
286 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
287 "Unknown"),
288 width,
289 (speed == PCIE_SPEED_2_5GT ? "20%" :
290 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000291 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000292 "Unknown"));
293
294 if (max_gts < expected_gts) {
295 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
296 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
297 expected_gts);
298 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
299 }
300}
301
Alexander Duyck70864002011-04-27 09:13:56 +0000302static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
303{
304 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800305 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000306 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
307 schedule_work(&adapter->service_task);
308}
309
Mark Rustad2a1a0912014-01-14 18:53:15 -0800310static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
311{
312 struct ixgbe_adapter *adapter = hw->back;
313
314 if (!hw->hw_addr)
315 return;
316 hw->hw_addr = NULL;
317 e_dev_err("Adapter removed\n");
Mark Rustad58cf6632014-03-12 00:38:40 +0000318 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
319 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800320}
321
Mark Rustadf8e24722014-03-18 07:03:40 +0000322static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800323{
324 u32 value;
325
326 /* The following check not only optimizes a bit by not
327 * performing a read on the status register when the
328 * register just read was a status register read that
329 * returned IXGBE_FAILED_READ_REG. It also blocks any
330 * potential recursion.
331 */
332 if (reg == IXGBE_STATUS) {
333 ixgbe_remove_adapter(hw);
334 return;
335 }
336 value = ixgbe_read_reg(hw, IXGBE_STATUS);
337 if (value == IXGBE_FAILED_READ_REG)
338 ixgbe_remove_adapter(hw);
339}
340
Mark Rustadf8e24722014-03-18 07:03:40 +0000341/**
342 * ixgbe_read_reg - Read from device register
343 * @hw: hw specific details
344 * @reg: offset of register to read
345 *
346 * Returns : value read or IXGBE_FAILED_READ_REG if removed
347 *
348 * This function is used to read device registers. It checks for device
349 * removal by confirming any read that returns all ones by checking the
350 * status register value for all ones. This function avoids reading from
351 * the hardware if a removal was previously detected in which case it
352 * returns IXGBE_FAILED_READ_REG (all ones).
353 */
354u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
355{
356 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
357 u32 value;
358
359 if (ixgbe_removed(reg_addr))
360 return IXGBE_FAILED_READ_REG;
361 value = readl(reg_addr + reg);
362 if (unlikely(value == IXGBE_FAILED_READ_REG))
363 ixgbe_check_remove(hw, reg);
364 return value;
365}
366
Mark Rustad14438462014-02-28 15:48:57 -0800367static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
368{
369 u16 value;
370
371 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
372 if (value == IXGBE_FAILED_READ_CFG_WORD) {
373 ixgbe_remove_adapter(hw);
374 return true;
375 }
376 return false;
377}
378
379u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
380{
381 struct ixgbe_adapter *adapter = hw->back;
382 u16 value;
383
384 if (ixgbe_removed(hw->hw_addr))
385 return IXGBE_FAILED_READ_CFG_WORD;
386 pci_read_config_word(adapter->pdev, reg, &value);
387 if (value == IXGBE_FAILED_READ_CFG_WORD &&
388 ixgbe_check_cfg_remove(hw, adapter->pdev))
389 return IXGBE_FAILED_READ_CFG_WORD;
390 return value;
391}
392
393#ifdef CONFIG_PCI_IOV
394static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
395{
396 struct ixgbe_adapter *adapter = hw->back;
397 u32 value;
398
399 if (ixgbe_removed(hw->hw_addr))
400 return IXGBE_FAILED_READ_CFG_DWORD;
401 pci_read_config_dword(adapter->pdev, reg, &value);
402 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
403 ixgbe_check_cfg_remove(hw, adapter->pdev))
404 return IXGBE_FAILED_READ_CFG_DWORD;
405 return value;
406}
407#endif /* CONFIG_PCI_IOV */
408
Jacob Kellered192312014-02-22 01:23:53 +0000409void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
410{
411 struct ixgbe_adapter *adapter = hw->back;
412
413 if (ixgbe_removed(hw->hw_addr))
414 return;
415 pci_write_config_word(adapter->pdev, reg, value);
416}
417
Alexander Duyck70864002011-04-27 09:13:56 +0000418static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
419{
420 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
421
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000422 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100423 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000424 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
425}
426
Taku Izumidcd79ae2010-04-27 14:39:53 +0000427struct ixgbe_reg_info {
428 u32 ofs;
429 char *name;
430};
431
432static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
433
434 /* General Registers */
435 {IXGBE_CTRL, "CTRL"},
436 {IXGBE_STATUS, "STATUS"},
437 {IXGBE_CTRL_EXT, "CTRL_EXT"},
438
439 /* Interrupt Registers */
440 {IXGBE_EICR, "EICR"},
441
442 /* RX Registers */
443 {IXGBE_SRRCTL(0), "SRRCTL"},
444 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
445 {IXGBE_RDLEN(0), "RDLEN"},
446 {IXGBE_RDH(0), "RDH"},
447 {IXGBE_RDT(0), "RDT"},
448 {IXGBE_RXDCTL(0), "RXDCTL"},
449 {IXGBE_RDBAL(0), "RDBAL"},
450 {IXGBE_RDBAH(0), "RDBAH"},
451
452 /* TX Registers */
453 {IXGBE_TDBAL(0), "TDBAL"},
454 {IXGBE_TDBAH(0), "TDBAH"},
455 {IXGBE_TDLEN(0), "TDLEN"},
456 {IXGBE_TDH(0), "TDH"},
457 {IXGBE_TDT(0), "TDT"},
458 {IXGBE_TXDCTL(0), "TXDCTL"},
459
460 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000461 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000462};
463
464
465/*
466 * ixgbe_regdump - register printout routine
467 */
468static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
469{
470 int i = 0, j = 0;
471 char rname[16];
472 u32 regs[64];
473
474 switch (reginfo->ofs) {
475 case IXGBE_SRRCTL(0):
476 for (i = 0; i < 64; i++)
477 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
478 break;
479 case IXGBE_DCA_RXCTRL(0):
480 for (i = 0; i < 64; i++)
481 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
482 break;
483 case IXGBE_RDLEN(0):
484 for (i = 0; i < 64; i++)
485 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
486 break;
487 case IXGBE_RDH(0):
488 for (i = 0; i < 64; i++)
489 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
490 break;
491 case IXGBE_RDT(0):
492 for (i = 0; i < 64; i++)
493 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
494 break;
495 case IXGBE_RXDCTL(0):
496 for (i = 0; i < 64; i++)
497 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
498 break;
499 case IXGBE_RDBAL(0):
500 for (i = 0; i < 64; i++)
501 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
502 break;
503 case IXGBE_RDBAH(0):
504 for (i = 0; i < 64; i++)
505 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
506 break;
507 case IXGBE_TDBAL(0):
508 for (i = 0; i < 64; i++)
509 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
510 break;
511 case IXGBE_TDBAH(0):
512 for (i = 0; i < 64; i++)
513 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
514 break;
515 case IXGBE_TDLEN(0):
516 for (i = 0; i < 64; i++)
517 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
518 break;
519 case IXGBE_TDH(0):
520 for (i = 0; i < 64; i++)
521 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
522 break;
523 case IXGBE_TDT(0):
524 for (i = 0; i < 64; i++)
525 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
526 break;
527 case IXGBE_TXDCTL(0):
528 for (i = 0; i < 64; i++)
529 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
530 break;
531 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000532 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000533 IXGBE_READ_REG(hw, reginfo->ofs));
534 return;
535 }
536
537 for (i = 0; i < 8; i++) {
538 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000539 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000540 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000541 pr_cont(" %08x", regs[i*8+j]);
542 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000543 }
544
545}
546
547/*
548 * ixgbe_dump - Print registers, tx-rings and rx-rings
549 */
550static void ixgbe_dump(struct ixgbe_adapter *adapter)
551{
552 struct net_device *netdev = adapter->netdev;
553 struct ixgbe_hw *hw = &adapter->hw;
554 struct ixgbe_reg_info *reginfo;
555 int n = 0;
556 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000557 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000558 union ixgbe_adv_tx_desc *tx_desc;
559 struct my_u0 { u64 a; u64 b; } *u0;
560 struct ixgbe_ring *rx_ring;
561 union ixgbe_adv_rx_desc *rx_desc;
562 struct ixgbe_rx_buffer *rx_buffer_info;
563 u32 staterr;
564 int i = 0;
565
566 if (!netif_msg_hw(adapter))
567 return;
568
569 /* Print netdevice Info */
570 if (netdev) {
571 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000572 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000573 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000574 pr_info("%-15s %016lX %016lX %016lX\n",
575 netdev->name,
576 netdev->state,
577 netdev->trans_start,
578 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000579 }
580
581 /* Print Registers */
582 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000583 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000584 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
585 reginfo->name; reginfo++) {
586 ixgbe_regdump(hw, reginfo);
587 }
588
589 /* Print TX Ring Summary */
590 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000591 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000592
593 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000594 pr_info(" %s %s %s %s\n",
595 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
596 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000597 for (n = 0; n < adapter->num_tx_queues; n++) {
598 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000599 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000600 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000601 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000602 (u64)dma_unmap_addr(tx_buffer, dma),
603 dma_unmap_len(tx_buffer, len),
604 tx_buffer->next_to_watch,
605 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000606 }
607
608 /* Print TX Rings */
609 if (!netif_msg_tx_done(adapter))
610 goto rx_ring_summary;
611
612 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
613
614 /* Transmit Descriptor Formats
615 *
Josh Hay39ac8682012-09-26 05:59:36 +0000616 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000617 * +--------------------------------------------------------------+
618 * 0 | Buffer Address [63:0] |
619 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000620 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000621 * +--------------------------------------------------------------+
622 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000623 *
624 * 82598 Advanced Transmit Descriptor (Write-Back Format)
625 * +--------------------------------------------------------------+
626 * 0 | RSV [63:0] |
627 * +--------------------------------------------------------------+
628 * 8 | RSV | STA | NXTSEQ |
629 * +--------------------------------------------------------------+
630 * 63 36 35 32 31 0
631 *
632 * 82599+ Advanced Transmit Descriptor
633 * +--------------------------------------------------------------+
634 * 0 | Buffer Address [63:0] |
635 * +--------------------------------------------------------------+
636 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
637 * +--------------------------------------------------------------+
638 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
639 *
640 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
641 * +--------------------------------------------------------------+
642 * 0 | RSV [63:0] |
643 * +--------------------------------------------------------------+
644 * 8 | RSV | STA | RSV |
645 * +--------------------------------------------------------------+
646 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000647 */
648
649 for (n = 0; n < adapter->num_tx_queues; n++) {
650 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000651 pr_info("------------------------------------\n");
652 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
653 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000654 pr_info("%s%s %s %s %s %s\n",
655 "T [desc] [address 63:0 ] ",
656 "[PlPOIdStDDt Ln] [bi->dma ] ",
657 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000658
659 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000660 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000661 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000662 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000663 if (dma_unmap_len(tx_buffer, len) > 0) {
664 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
665 i,
666 le64_to_cpu(u0->a),
667 le64_to_cpu(u0->b),
668 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000669 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000670 tx_buffer->next_to_watch,
671 (u64)tx_buffer->time_stamp,
672 tx_buffer->skb);
673 if (i == tx_ring->next_to_use &&
674 i == tx_ring->next_to_clean)
675 pr_cont(" NTC/U\n");
676 else if (i == tx_ring->next_to_use)
677 pr_cont(" NTU\n");
678 else if (i == tx_ring->next_to_clean)
679 pr_cont(" NTC\n");
680 else
681 pr_cont("\n");
682
683 if (netif_msg_pktdata(adapter) &&
684 tx_buffer->skb)
685 print_hex_dump(KERN_INFO, "",
686 DUMP_PREFIX_ADDRESS, 16, 1,
687 tx_buffer->skb->data,
688 dma_unmap_len(tx_buffer, len),
689 true);
690 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000691 }
692 }
693
694 /* Print RX Rings Summary */
695rx_ring_summary:
696 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000697 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000698 for (n = 0; n < adapter->num_rx_queues; n++) {
699 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000700 pr_info("%5d %5X %5X\n",
701 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000702 }
703
704 /* Print RX Rings */
705 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000706 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000707
708 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
709
Josh Hay39ac8682012-09-26 05:59:36 +0000710 /* Receive Descriptor Formats
711 *
712 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000713 * 63 1 0
714 * +-----------------------------------------------------+
715 * 0 | Packet Buffer Address [63:1] |A0/NSE|
716 * +----------------------------------------------+------+
717 * 8 | Header Buffer Address [63:1] | DD |
718 * +-----------------------------------------------------+
719 *
720 *
Josh Hay39ac8682012-09-26 05:59:36 +0000721 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000722 *
723 * 63 48 47 32 31 30 21 20 16 15 4 3 0
724 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000725 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
726 * | Packet | IP | | | | Type | Type |
727 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000728 * +------------------------------------------------------+
729 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
730 * +------------------------------------------------------+
731 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000732 *
733 * 82599+ Advanced Receive Descriptor (Read) Format
734 * 63 1 0
735 * +-----------------------------------------------------+
736 * 0 | Packet Buffer Address [63:1] |A0/NSE|
737 * +----------------------------------------------+------+
738 * 8 | Header Buffer Address [63:1] | DD |
739 * +-----------------------------------------------------+
740 *
741 *
742 * 82599+ Advanced Receive Descriptor (Write-Back) Format
743 *
744 * 63 48 47 32 31 30 21 20 17 16 4 3 0
745 * +------------------------------------------------------+
746 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
747 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
748 * |/ Flow Dir Flt ID | | | | | |
749 * +------------------------------------------------------+
750 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
751 * +------------------------------------------------------+
752 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000753 */
Josh Hay39ac8682012-09-26 05:59:36 +0000754
Taku Izumidcd79ae2010-04-27 14:39:53 +0000755 for (n = 0; n < adapter->num_rx_queues; n++) {
756 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000757 pr_info("------------------------------------\n");
758 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
759 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000760 pr_info("%s%s%s",
761 "R [desc] [ PktBuf A0] ",
762 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000763 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000764 pr_info("%s%s%s",
765 "RWB[desc] [PcsmIpSHl PtRs] ",
766 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000767 "<-- Adv Rx Write-Back format\n");
768
769 for (i = 0; i < rx_ring->count; i++) {
770 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000771 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000772 u0 = (struct my_u0 *)rx_desc;
773 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
774 if (staterr & IXGBE_RXD_STAT_DD) {
775 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000776 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000777 "%016llX ---------------- %p", i,
778 le64_to_cpu(u0->a),
779 le64_to_cpu(u0->b),
780 rx_buffer_info->skb);
781 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000782 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000783 "%016llX %016llX %p", i,
784 le64_to_cpu(u0->a),
785 le64_to_cpu(u0->b),
786 (u64)rx_buffer_info->dma,
787 rx_buffer_info->skb);
788
Emil Tantilov9c50c032012-07-26 01:21:24 +0000789 if (netif_msg_pktdata(adapter) &&
790 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000791 print_hex_dump(KERN_INFO, "",
792 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000793 page_address(rx_buffer_info->page) +
794 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000795 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000796 }
797 }
798
799 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000800 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000801 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000802 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000803 else
Joe Perchesc7689572010-09-07 21:35:17 +0000804 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000805
806 }
807 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000808}
809
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800810static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
811{
812 u32 ctrl_ext;
813
814 /* Let firmware take over control of h/w */
815 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
816 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000817 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800818}
819
820static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
821{
822 u32 ctrl_ext;
823
824 /* Let firmware know the driver has taken over */
825 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
826 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000827 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800828}
Auke Kok9a799d72007-09-15 14:07:45 -0700829
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000830/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000831 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
832 * @adapter: pointer to adapter struct
833 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
834 * @queue: queue to map the corresponding interrupt to
835 * @msix_vector: the vector to map to the corresponding queue
836 *
837 */
838static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000839 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700840{
841 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000842 struct ixgbe_hw *hw = &adapter->hw;
843 switch (hw->mac.type) {
844 case ixgbe_mac_82598EB:
845 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
846 if (direction == -1)
847 direction = 0;
848 index = (((direction * 64) + queue) >> 2) & 0x1F;
849 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
850 ivar &= ~(0xFF << (8 * (queue & 0x3)));
851 ivar |= (msix_vector << (8 * (queue & 0x3)));
852 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
853 break;
854 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800855 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000856 case ixgbe_mac_X550:
857 case ixgbe_mac_X550EM_x:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000858 if (direction == -1) {
859 /* other causes */
860 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
861 index = ((queue & 1) * 8);
862 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
863 ivar &= ~(0xFF << index);
864 ivar |= (msix_vector << index);
865 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
866 break;
867 } else {
868 /* tx or rx causes */
869 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
870 index = ((16 * (queue & 1)) + (8 * direction));
871 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
872 ivar &= ~(0xFF << index);
873 ivar |= (msix_vector << index);
874 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
875 break;
876 }
877 default:
878 break;
879 }
Auke Kok9a799d72007-09-15 14:07:45 -0700880}
881
Alexander Duyckfe49f042009-06-04 16:00:09 +0000882static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000883 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000884{
885 u32 mask;
886
Alexander Duyckbd508172010-11-16 19:27:03 -0800887 switch (adapter->hw.mac.type) {
888 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000889 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
890 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800891 break;
892 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800893 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000894 case ixgbe_mac_X550:
895 case ixgbe_mac_X550EM_x:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000896 mask = (qmask & 0xFFFFFFFF);
897 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
898 mask = (qmask >> 32);
899 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800900 break;
901 default:
902 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000903 }
904}
905
Alexander Duyck729739b2012-02-08 07:51:06 +0000906void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
907 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000908{
Alexander Duyck729739b2012-02-08 07:51:06 +0000909 if (tx_buffer->skb) {
910 dev_kfree_skb_any(tx_buffer->skb);
911 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000912 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000913 dma_unmap_addr(tx_buffer, dma),
914 dma_unmap_len(tx_buffer, len),
915 DMA_TO_DEVICE);
916 } else if (dma_unmap_len(tx_buffer, len)) {
917 dma_unmap_page(ring->dev,
918 dma_unmap_addr(tx_buffer, dma),
919 dma_unmap_len(tx_buffer, len),
920 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000921 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000922 tx_buffer->next_to_watch = NULL;
923 tx_buffer->skb = NULL;
924 dma_unmap_len_set(tx_buffer, len, 0);
925 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700926}
927
Alexander Duyck943561d2012-05-09 22:14:44 -0700928static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
929{
930 struct ixgbe_hw *hw = &adapter->hw;
931 struct ixgbe_hw_stats *hwstats = &adapter->stats;
932 int i;
933 u32 data;
934
935 if ((hw->fc.current_mode != ixgbe_fc_full) &&
936 (hw->fc.current_mode != ixgbe_fc_rx_pause))
937 return;
938
939 switch (hw->mac.type) {
940 case ixgbe_mac_82598EB:
941 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
942 break;
943 default:
944 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
945 }
946 hwstats->lxoffrxc += data;
947
948 /* refill credits (no tx hang) if we received xoff */
949 if (!data)
950 return;
951
952 for (i = 0; i < adapter->num_tx_queues; i++)
953 clear_bit(__IXGBE_HANG_CHECK_ARMED,
954 &adapter->tx_ring[i]->state);
955}
956
John Fastabendc84d3242010-11-16 19:27:12 -0800957static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700958{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700959 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800960 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800961 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000962 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800963 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700964 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700965
Alexander Duyck943561d2012-05-09 22:14:44 -0700966 if (adapter->ixgbe_ieee_pfc)
967 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800968
Alexander Duyck943561d2012-05-09 22:14:44 -0700969 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
970 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800971 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700972 }
John Fastabendc84d3242010-11-16 19:27:12 -0800973
974 /* update stats for each tc, only valid with PFC enabled */
975 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000976 u32 pxoffrxc;
977
John Fastabendc84d3242010-11-16 19:27:12 -0800978 switch (hw->mac.type) {
979 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000980 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800981 break;
982 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000983 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800984 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000985 hwstats->pxoffrxc[i] += pxoffrxc;
986 /* Get the TC for given UP */
987 tc = netdev_get_prio_tc_map(adapter->netdev, i);
988 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -0700989 }
990
John Fastabendc84d3242010-11-16 19:27:12 -0800991 /* disarm tx queues that have received xoff frames */
992 for (i = 0; i < adapter->num_tx_queues; i++) {
993 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -0800994
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000995 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800996 if (xoff[tc])
997 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
998 }
999}
1000
1001static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1002{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001003 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001004}
1005
1006static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1007{
John Fastabend2a47fa42013-11-06 09:54:52 -08001008 struct ixgbe_adapter *adapter;
1009 struct ixgbe_hw *hw;
1010 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001011
John Fastabend2a47fa42013-11-06 09:54:52 -08001012 if (ring->l2_accel_priv)
1013 adapter = ring->l2_accel_priv->real_adapter;
1014 else
1015 adapter = netdev_priv(ring->netdev);
1016
1017 hw = &adapter->hw;
1018 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1019 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001020
1021 if (head != tail)
1022 return (head < tail) ?
1023 tail - head : (tail + ring->count - head);
1024
1025 return 0;
1026}
1027
1028static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1029{
1030 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1031 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1032 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001033
1034 clear_check_for_tx_hang(tx_ring);
1035
1036 /*
1037 * Check for a hung queue, but be thorough. This verifies
1038 * that a transmit has been completed since the previous
1039 * check AND there is at least one packet pending. The
1040 * ARMED bit is set to indicate a potential hang. The
1041 * bit is cleared if a pause frame is received to remove
1042 * false hang detection due to PFC or 802.3x frames. By
1043 * requiring this to fail twice we avoid races with
1044 * pfc clearing the ARMED bit and conditions where we
1045 * run the check_tx_hang logic with a transmit completion
1046 * pending but without time to complete it yet.
1047 */
Mark Rustade90dd262014-07-22 06:51:08 +00001048 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001049 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001050 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1051 &tx_ring->state);
1052 /* update completed stats and continue */
1053 tx_ring->tx_stats.tx_done_old = tx_done;
1054 /* reset the countdown */
1055 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001056
Mark Rustade90dd262014-07-22 06:51:08 +00001057 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001058}
1059
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001060/**
1061 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1062 * @adapter: driver private struct
1063 **/
1064static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1065{
1066
1067 /* Do the reset outside of interrupt context */
1068 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1069 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Jacob Keller12ff3f32012-12-01 07:57:17 +00001070 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001071 ixgbe_service_event_schedule(adapter);
1072 }
1073}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001074
Auke Kok9a799d72007-09-15 14:07:45 -07001075/**
1076 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001077 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001078 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -07001079 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001080static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001081 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07001082{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001083 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001084 struct ixgbe_tx_buffer *tx_buffer;
1085 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001086 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001087 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001088 unsigned int i = tx_ring->next_to_clean;
1089
1090 if (test_bit(__IXGBE_DOWN, &adapter->state))
1091 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001092
Alexander Duyckd3d00232011-07-15 02:31:25 +00001093 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001094 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001095 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001096
Alexander Duyck729739b2012-02-08 07:51:06 +00001097 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001098 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001099
Alexander Duyckd3d00232011-07-15 02:31:25 +00001100 /* if next_to_watch is not set then there is no work pending */
1101 if (!eop_desc)
1102 break;
1103
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001104 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001105 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001106
Alexander Duyckd3d00232011-07-15 02:31:25 +00001107 /* if DD is not set pending work has not been completed */
1108 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1109 break;
1110
Alexander Duyckd3d00232011-07-15 02:31:25 +00001111 /* clear next_to_watch to prevent false hangs */
1112 tx_buffer->next_to_watch = NULL;
1113
Alexander Duyck091a6242012-02-08 07:51:01 +00001114 /* update the statistics for this packet */
1115 total_bytes += tx_buffer->bytecount;
1116 total_packets += tx_buffer->gso_segs;
1117
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001118 /* free the skb */
Rick Jonesfe1f2a92014-09-12 17:44:06 +00001119 dev_consume_skb_any(tx_buffer->skb);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001120
Alexander Duyck729739b2012-02-08 07:51:06 +00001121 /* unmap skb header data */
1122 dma_unmap_single(tx_ring->dev,
1123 dma_unmap_addr(tx_buffer, dma),
1124 dma_unmap_len(tx_buffer, len),
1125 DMA_TO_DEVICE);
1126
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001127 /* clear tx_buffer data */
1128 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +00001129 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001130
Alexander Duyck729739b2012-02-08 07:51:06 +00001131 /* unmap remaining buffers */
1132 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001133 tx_buffer++;
1134 tx_desc++;
1135 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001136 if (unlikely(!i)) {
1137 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001138 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001139 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001140 }
1141
Alexander Duyck729739b2012-02-08 07:51:06 +00001142 /* unmap any remaining paged data */
1143 if (dma_unmap_len(tx_buffer, len)) {
1144 dma_unmap_page(tx_ring->dev,
1145 dma_unmap_addr(tx_buffer, dma),
1146 dma_unmap_len(tx_buffer, len),
1147 DMA_TO_DEVICE);
1148 dma_unmap_len_set(tx_buffer, len, 0);
1149 }
1150 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001151
Alexander Duyck729739b2012-02-08 07:51:06 +00001152 /* move us one more past the eop_desc for start of next pkt */
1153 tx_buffer++;
1154 tx_desc++;
1155 i++;
1156 if (unlikely(!i)) {
1157 i -= tx_ring->count;
1158 tx_buffer = tx_ring->tx_buffer_info;
1159 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1160 }
1161
1162 /* issue prefetch for next Tx descriptor */
1163 prefetch(tx_desc);
1164
1165 /* update budget accounting */
1166 budget--;
1167 } while (likely(budget));
1168
1169 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001170 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001171 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001172 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001173 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001174 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001175 q_vector->tx.total_bytes += total_bytes;
1176 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001177
John Fastabendc84d3242010-11-16 19:27:12 -08001178 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001179 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001180 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001181 e_err(drv, "Detected Tx Unit Hang\n"
1182 " Tx Queue <%d>\n"
1183 " TDH, TDT <%x>, <%x>\n"
1184 " next_to_use <%x>\n"
1185 " next_to_clean <%x>\n"
1186 "tx_buffer_info[next_to_clean]\n"
1187 " time_stamp <%lx>\n"
1188 " jiffies <%lx>\n",
1189 tx_ring->queue_index,
1190 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1191 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001192 tx_ring->next_to_use, i,
1193 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001194
1195 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1196
1197 e_info(probe,
1198 "tx hang %d detected on queue %d, resetting adapter\n",
1199 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1200
1201 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001202 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001203
1204 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001205 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001206 }
Auke Kok9a799d72007-09-15 14:07:45 -07001207
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001208 netdev_tx_completed_queue(txring_txq(tx_ring),
1209 total_packets, total_bytes);
1210
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001211#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001212 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001213 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001214 /* Make sure that anybody stopping the queue after this
1215 * sees the new next_to_clean.
1216 */
1217 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001218 if (__netif_subqueue_stopped(tx_ring->netdev,
1219 tx_ring->queue_index)
1220 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1221 netif_wake_subqueue(tx_ring->netdev,
1222 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001223 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001224 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001225 }
Auke Kok9a799d72007-09-15 14:07:45 -07001226
Alexander Duyck59224552011-08-31 00:01:06 +00001227 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001228}
1229
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001230#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001231static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001232 struct ixgbe_ring *tx_ring,
1233 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001234{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001235 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001236 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1237 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001238
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001239 switch (hw->mac.type) {
1240 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001241 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001242 break;
1243 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001244 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001245 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1246 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1247 break;
1248 default:
1249 /* for unknown hardware do not write register */
1250 return;
1251 }
1252
1253 /*
1254 * We can enable relaxed ordering for reads, but not writes when
1255 * DCA is enabled. This is due to a known issue in some chipsets
1256 * which will cause the DCA tag to be cleared.
1257 */
1258 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1259 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1260 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1261
1262 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1263}
1264
1265static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1266 struct ixgbe_ring *rx_ring,
1267 int cpu)
1268{
1269 struct ixgbe_hw *hw = &adapter->hw;
1270 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1271 u8 reg_idx = rx_ring->reg_idx;
1272
1273
1274 switch (hw->mac.type) {
1275 case ixgbe_mac_82599EB:
1276 case ixgbe_mac_X540:
1277 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001278 break;
1279 default:
1280 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001281 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001282
1283 /*
1284 * We can enable relaxed ordering for reads, but not writes when
1285 * DCA is enabled. This is due to a known issue in some chipsets
1286 * which will cause the DCA tag to be cleared.
1287 */
1288 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001289 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1290
1291 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001292}
1293
1294static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1295{
1296 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001297 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001298 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001299
1300 if (q_vector->cpu == cpu)
1301 goto out_no_update;
1302
Alexander Duycka5579282012-02-08 07:50:04 +00001303 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001304 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001305
Alexander Duycka5579282012-02-08 07:50:04 +00001306 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001307 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001308
1309 q_vector->cpu = cpu;
1310out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001311 put_cpu();
1312}
1313
1314static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1315{
1316 int i;
1317
1318 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1319 return;
1320
Alexander Duycke35ec122009-05-21 13:07:12 +00001321 /* always use CB2 mode, difference is masked in the CB driver */
1322 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1323
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001324 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001325 adapter->q_vector[i]->cpu = -1;
1326 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001327 }
1328}
1329
1330static int __ixgbe_notify_dca(struct device *dev, void *data)
1331{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001332 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001333 unsigned long event = *(unsigned long *)data;
1334
Don Skidmore2a72c312011-07-20 02:27:05 +00001335 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001336 return 0;
1337
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001338 switch (event) {
1339 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001340 /* if we're already enabled, don't do it again */
1341 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1342 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001343 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001344 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001345 ixgbe_setup_dca(adapter);
1346 break;
1347 }
1348 /* Fall Through since DCA is disabled. */
1349 case DCA_PROVIDER_REMOVE:
1350 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1351 dca_remove_requester(dev);
1352 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1353 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1354 }
1355 break;
1356 }
1357
Denis V. Lunev652f0932008-03-27 14:39:17 +03001358 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001359}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001360
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001361#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b82015-04-29 10:57:39 +08001362
1363#define IXGBE_RSS_L4_TYPES_MASK \
1364 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1365 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1366 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1367 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1368
Alexander Duyck8a0da212012-01-31 02:59:49 +00001369static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1370 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001371 struct sk_buff *skb)
1372{
Fan Du7edda4b82015-04-29 10:57:39 +08001373 u16 rss_type;
1374
1375 if (!(ring->netdev->features & NETIF_F_RXHASH))
1376 return;
1377
1378 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1379 IXGBE_RXDADV_RSSTYPE_MASK;
1380
1381 if (!rss_type)
1382 return;
1383
1384 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1385 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1386 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001387}
1388
Alexander Duyckf8003262012-03-03 02:35:52 +00001389#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001390/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001391 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001392 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001393 * @rx_desc: advanced rx descriptor
1394 *
1395 * Returns : true if it is FCoE pkt
1396 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001397static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001398 union ixgbe_adv_rx_desc *rx_desc)
1399{
1400 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1401
Alexander Duyck57efd442012-06-25 21:54:46 +00001402 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001403 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1404 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1405 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1406}
1407
Alexander Duyckf8003262012-03-03 02:35:52 +00001408#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001409/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001410 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001411 * @ring: structure containing ring specific data
1412 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001413 * @skb: skb currently being received and modified
1414 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001415static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001416 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001417 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001418{
Don Skidmore3f207802014-12-23 07:40:34 +00001419 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1420 __le16 hdr_info = rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
1421 bool encap_pkt = false;
1422
Alexander Duyck8a0da212012-01-31 02:59:49 +00001423 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001424
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001425 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001426 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001427 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001428
Don Skidmore3f207802014-12-23 07:40:34 +00001429 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) &&
1430 (hdr_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL >> 16))) {
1431 encap_pkt = true;
1432 skb->encapsulation = 1;
1433 skb->ip_summed = CHECKSUM_NONE;
1434 }
1435
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001436 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001437 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1438 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001439 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001440 return;
1441 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001442
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001443 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001444 return;
1445
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001446 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001447 /*
1448 * 82599 errata, UDP frames with a 0 checksum can be marked as
1449 * checksum errors.
1450 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001451 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1452 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001453 return;
1454
Alexander Duyck8a0da212012-01-31 02:59:49 +00001455 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001456 return;
1457 }
1458
Auke Kok9a799d72007-09-15 14:07:45 -07001459 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001460 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001461 if (encap_pkt) {
1462 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1463 return;
1464
1465 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
1466 ring->rx_stats.csum_err++;
1467 return;
1468 }
1469 /* If we checked the outer header let the stack know */
1470 skb->csum_level = 1;
1471 }
Auke Kok9a799d72007-09-15 14:07:45 -07001472}
1473
Alexander Duyckf990b792012-01-31 02:59:34 +00001474static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1475 struct ixgbe_rx_buffer *bi)
1476{
1477 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001478 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001479
Alexander Duyckf8003262012-03-03 02:35:52 +00001480 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001481 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001482 return true;
1483
Alexander Duyckf8003262012-03-03 02:35:52 +00001484 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001485 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1486 if (unlikely(!page)) {
1487 rx_ring->rx_stats.alloc_rx_page_failed++;
1488 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001489 }
1490
Alexander Duyckf8003262012-03-03 02:35:52 +00001491 /* map page for use */
1492 dma = dma_map_page(rx_ring->dev, page, 0,
1493 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001494
Alexander Duyckf8003262012-03-03 02:35:52 +00001495 /*
1496 * if mapping failed free memory back to system since
1497 * there isn't much point in holding memory we can't use
1498 */
1499 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001500 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001501
Alexander Duyckf990b792012-01-31 02:59:34 +00001502 rx_ring->rx_stats.alloc_rx_page_failed++;
1503 return false;
1504 }
1505
Alexander Duyckf8003262012-03-03 02:35:52 +00001506 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001507 bi->page = page;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001508 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001509
Alexander Duyckf990b792012-01-31 02:59:34 +00001510 return true;
1511}
1512
Auke Kok9a799d72007-09-15 14:07:45 -07001513/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001514 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001515 * @rx_ring: ring to place buffers on
1516 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001517 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001518void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001519{
Auke Kok9a799d72007-09-15 14:07:45 -07001520 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001521 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001522 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001523
Alexander Duyckf8003262012-03-03 02:35:52 +00001524 /* nothing to do */
1525 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001526 return;
1527
Alexander Duycke4f74022012-01-31 02:59:44 +00001528 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001529 bi = &rx_ring->rx_buffer_info[i];
1530 i -= rx_ring->count;
1531
Alexander Duyckf8003262012-03-03 02:35:52 +00001532 do {
1533 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001534 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001535
Alexander Duyckf8003262012-03-03 02:35:52 +00001536 /*
1537 * Refresh the desc even if buffer_addrs didn't change
1538 * because each write-back erases this info.
1539 */
1540 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001541
Alexander Duyckf990b792012-01-31 02:59:34 +00001542 rx_desc++;
1543 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001544 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001545 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001546 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001547 bi = rx_ring->rx_buffer_info;
1548 i -= rx_ring->count;
1549 }
1550
Alexander Duyck18cb6522014-11-14 00:56:29 +00001551 /* clear the status bits for the next_to_use descriptor */
1552 rx_desc->wb.upper.status_error = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001553
1554 cleaned_count--;
1555 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001556
Alexander Duyckf990b792012-01-31 02:59:34 +00001557 i += rx_ring->count;
1558
Alexander Duyckad435ec2014-11-14 00:56:35 +00001559 if (rx_ring->next_to_use != i) {
1560 rx_ring->next_to_use = i;
1561
1562 /* update next to alloc since we have filled the ring */
1563 rx_ring->next_to_alloc = i;
1564
1565 /* Force memory writes to complete before letting h/w
1566 * know there are new descriptors to fetch. (Only
1567 * applicable for weak-ordered memory model archs,
1568 * such as IA-64).
1569 */
1570 wmb();
1571 writel(i, rx_ring->tail);
1572 }
Auke Kok9a799d72007-09-15 14:07:45 -07001573}
1574
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001575static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1576 struct sk_buff *skb)
1577{
Alexander Duyckf8003262012-03-03 02:35:52 +00001578 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001579
1580 /* set gso_size to avoid messing up TCP MSS */
1581 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1582 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001583 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001584}
1585
1586static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1587 struct sk_buff *skb)
1588{
1589 /* if append_cnt is 0 then frame is not RSC */
1590 if (!IXGBE_CB(skb)->append_cnt)
1591 return;
1592
1593 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1594 rx_ring->rx_stats.rsc_flush++;
1595
1596 ixgbe_set_rsc_gso_size(rx_ring, skb);
1597
1598 /* gso_size is computed using append_cnt so always clear it last */
1599 IXGBE_CB(skb)->append_cnt = 0;
1600}
1601
Alexander Duyck8a0da212012-01-31 02:59:49 +00001602/**
1603 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1604 * @rx_ring: rx descriptor ring packet is being transacted on
1605 * @rx_desc: pointer to the EOP Rx descriptor
1606 * @skb: pointer to current skb being populated
1607 *
1608 * This function checks the ring, descriptor, and packet information in
1609 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1610 * other fields within the skb.
1611 **/
1612static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1613 union ixgbe_adv_rx_desc *rx_desc,
1614 struct sk_buff *skb)
1615{
John Fastabend43e95f12012-05-15 06:12:17 +00001616 struct net_device *dev = rx_ring->netdev;
1617
Alexander Duyck8a0da212012-01-31 02:59:49 +00001618 ixgbe_update_rsc_stats(rx_ring, skb);
1619
1620 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1621
1622 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1623
Jakub Kicinskieda183c2014-04-02 10:33:28 +00001624 if (unlikely(ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_TS)))
1625 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector->adapter, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001626
Patrick McHardyf6469682013-04-19 02:04:27 +00001627 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001628 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001629 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001630 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001631 }
1632
1633 skb_record_rx_queue(skb, rx_ring->queue_index);
1634
John Fastabend43e95f12012-05-15 06:12:17 +00001635 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001636}
1637
1638static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1639 struct sk_buff *skb)
1640{
Jacob Kellerb4640032013-10-01 04:33:54 -07001641 if (ixgbe_qv_busy_polling(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001642 netif_receive_skb(skb);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001643 else
Alexander Duyck856f6062015-02-25 17:45:54 +00001644 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001645}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001646
Alexander Duyckf8003262012-03-03 02:35:52 +00001647/**
1648 * ixgbe_is_non_eop - process handling of non-EOP buffers
1649 * @rx_ring: Rx ring being processed
1650 * @rx_desc: Rx descriptor for current buffer
1651 * @skb: Current socket buffer containing buffer in progress
1652 *
1653 * This function updates next to clean. If the buffer is an EOP buffer
1654 * this function exits returning false, otherwise it will place the
1655 * sk_buff in the next buffer to be chained and return true indicating
1656 * that this is in fact a non-EOP buffer.
1657 **/
1658static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1659 union ixgbe_adv_rx_desc *rx_desc,
1660 struct sk_buff *skb)
1661{
1662 u32 ntc = rx_ring->next_to_clean + 1;
1663
1664 /* fetch, update, and store next to clean */
1665 ntc = (ntc < rx_ring->count) ? ntc : 0;
1666 rx_ring->next_to_clean = ntc;
1667
1668 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1669
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001670 /* update RSC append count if present */
1671 if (ring_is_rsc_enabled(rx_ring)) {
1672 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1673 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1674
1675 if (unlikely(rsc_enabled)) {
1676 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1677
1678 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1679 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1680
1681 /* update ntc based on RSC value */
1682 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1683 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1684 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1685 }
1686 }
1687
1688 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001689 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1690 return false;
1691
Alexander Duyckf8003262012-03-03 02:35:52 +00001692 /* place skb in next buffer to be received */
1693 rx_ring->rx_buffer_info[ntc].skb = skb;
1694 rx_ring->rx_stats.non_eop_descs++;
1695
1696 return true;
1697}
1698
1699/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001700 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1701 * @rx_ring: rx descriptor ring packet is being transacted on
1702 * @skb: pointer to current skb being adjusted
1703 *
1704 * This function is an ixgbe specific version of __pskb_pull_tail. The
1705 * main difference between this version and the original function is that
1706 * this function can make several assumptions about the state of things
1707 * that allow for significant optimizations versus the standard function.
1708 * As a result we can do things like drop a frag and maintain an accurate
1709 * truesize for the skb.
1710 */
1711static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1712 struct sk_buff *skb)
1713{
1714 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1715 unsigned char *va;
1716 unsigned int pull_len;
1717
1718 /*
1719 * it is valid to use page_address instead of kmap since we are
1720 * working with pages allocated out of the lomem pool per
1721 * alloc_page(GFP_ATOMIC)
1722 */
1723 va = skb_frag_address(frag);
1724
1725 /*
1726 * we need the header to contain the greater of either ETH_HLEN or
1727 * 60 bytes if the skb->len is less than 60 for skb_pad.
1728 */
Alexander Duyck8496e3382014-09-05 19:22:18 -04001729 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001730
1731 /* align pull length to size of long to optimize memcpy performance */
1732 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1733
1734 /* update all of the pointers */
1735 skb_frag_size_sub(frag, pull_len);
1736 frag->page_offset += pull_len;
1737 skb->data_len -= pull_len;
1738 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001739}
1740
1741/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001742 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1743 * @rx_ring: rx descriptor ring packet is being transacted on
1744 * @skb: pointer to current skb being updated
1745 *
1746 * This function provides a basic DMA sync up for the first fragment of an
1747 * skb. The reason for doing this is that the first fragment cannot be
1748 * unmapped until we have reached the end of packet descriptor for a buffer
1749 * chain.
1750 */
1751static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1752 struct sk_buff *skb)
1753{
1754 /* if the page was released unmap it, else just sync our portion */
1755 if (unlikely(IXGBE_CB(skb)->page_released)) {
1756 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1757 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1758 IXGBE_CB(skb)->page_released = false;
1759 } else {
1760 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1761
1762 dma_sync_single_range_for_cpu(rx_ring->dev,
1763 IXGBE_CB(skb)->dma,
1764 frag->page_offset,
1765 ixgbe_rx_bufsz(rx_ring),
1766 DMA_FROM_DEVICE);
1767 }
1768 IXGBE_CB(skb)->dma = 0;
1769}
1770
1771/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001772 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1773 * @rx_ring: rx descriptor ring packet is being transacted on
1774 * @rx_desc: pointer to the EOP Rx descriptor
1775 * @skb: pointer to current skb being fixed
1776 *
1777 * Check for corrupted packet headers caused by senders on the local L2
1778 * embedded NIC switch not setting up their Tx Descriptors right. These
1779 * should be very rare.
1780 *
1781 * Also address the case where we are pulling data in on pages only
1782 * and as such no data is present in the skb header.
1783 *
1784 * In addition if skb is not at least 60 bytes we need to pad it so that
1785 * it is large enough to qualify as a valid Ethernet frame.
1786 *
1787 * Returns true if an error was encountered and skb was freed.
1788 **/
1789static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1790 union ixgbe_adv_rx_desc *rx_desc,
1791 struct sk_buff *skb)
1792{
Alexander Duyckf8003262012-03-03 02:35:52 +00001793 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001794
1795 /* verify that the packet does not have any known errors */
1796 if (unlikely(ixgbe_test_staterr(rx_desc,
1797 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1798 !(netdev->features & NETIF_F_RXALL))) {
1799 dev_kfree_skb_any(skb);
1800 return true;
1801 }
1802
Alexander Duyck19861ce2012-07-20 08:08:33 +00001803 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001804 if (skb_is_nonlinear(skb))
1805 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001806
Alexander Duyck57efd442012-06-25 21:54:46 +00001807#ifdef IXGBE_FCOE
1808 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1809 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1810 return false;
1811
1812#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001813 /* if eth_skb_pad returns an error the skb was freed */
1814 if (eth_skb_pad(skb))
1815 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001816
1817 return false;
1818}
1819
1820/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001821 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1822 * @rx_ring: rx descriptor ring to store buffers on
1823 * @old_buff: donor buffer to have page reused
1824 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001825 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001826 **/
1827static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1828 struct ixgbe_rx_buffer *old_buff)
1829{
1830 struct ixgbe_rx_buffer *new_buff;
1831 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001832
1833 new_buff = &rx_ring->rx_buffer_info[nta];
1834
1835 /* update, and store next to alloc */
1836 nta++;
1837 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1838
1839 /* transfer page from old buffer to new buffer */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001840 *new_buff = *old_buff;
Alexander Duyckf8003262012-03-03 02:35:52 +00001841
1842 /* sync the buffer for use by the device */
1843 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001844 new_buff->page_offset,
1845 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001846 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001847}
1848
Alexander Duyck18cb6522014-11-14 00:56:29 +00001849static inline bool ixgbe_page_is_reserved(struct page *page)
1850{
1851 return (page_to_nid(page) != numa_mem_id()) || page->pfmemalloc;
1852}
1853
Alexander Duyckf8003262012-03-03 02:35:52 +00001854/**
1855 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1856 * @rx_ring: rx descriptor ring to transact packets on
1857 * @rx_buffer: buffer containing page to add
1858 * @rx_desc: descriptor containing length of buffer written by hardware
1859 * @skb: sk_buff to place the data into
1860 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001861 * This function will add the data contained in rx_buffer->page to the skb.
1862 * This is done either through a direct copy if the data in the buffer is
1863 * less than the skb header size, otherwise it will just attach the page as
1864 * a frag to the skb.
1865 *
1866 * The function will then update the page offset if necessary and return
1867 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001868 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001869static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001870 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001871 union ixgbe_adv_rx_desc *rx_desc,
1872 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001873{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001874 struct page *page = rx_buffer->page;
1875 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001876#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001877 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001878#else
1879 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1880 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1881 ixgbe_rx_bufsz(rx_ring);
1882#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001883
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001884 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1885 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1886
1887 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1888
Alexander Duyck18cb6522014-11-14 00:56:29 +00001889 /* page is not reserved, we can reuse buffer as-is */
1890 if (likely(!ixgbe_page_is_reserved(page)))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001891 return true;
1892
1893 /* this page cannot be reused so discard it */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001894 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001895 return false;
1896 }
1897
Alexander Duyck0549ae22012-07-20 08:08:18 +00001898 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1899 rx_buffer->page_offset, size, truesize);
1900
Alexander Duyck09816fb2012-07-20 08:08:23 +00001901 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001902 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001903 return false;
1904
1905#if (PAGE_SIZE < 8192)
1906 /* if we are only owner of page we can reuse it */
1907 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001908 return false;
1909
1910 /* flip page offset to other buffer */
1911 rx_buffer->page_offset ^= truesize;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001912#else
1913 /* move offset up to the next cache line */
1914 rx_buffer->page_offset += truesize;
1915
1916 if (rx_buffer->page_offset > last_offset)
1917 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001918#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001919
Alexander Duyck18cb6522014-11-14 00:56:29 +00001920 /* Even if we own the page, we are not allowed to use atomic_set()
1921 * This would break get_page_unless_zero() users.
1922 */
1923 atomic_inc(&page->_count);
1924
Alexander Duyck0549ae22012-07-20 08:08:18 +00001925 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001926}
1927
Alexander Duyck18806c92012-07-20 08:08:44 +00001928static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1929 union ixgbe_adv_rx_desc *rx_desc)
1930{
1931 struct ixgbe_rx_buffer *rx_buffer;
1932 struct sk_buff *skb;
1933 struct page *page;
1934
1935 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1936 page = rx_buffer->page;
1937 prefetchw(page);
1938
1939 skb = rx_buffer->skb;
1940
1941 if (likely(!skb)) {
1942 void *page_addr = page_address(page) +
1943 rx_buffer->page_offset;
1944
1945 /* prefetch first cache line of first page */
1946 prefetch(page_addr);
1947#if L1_CACHE_BYTES < 128
1948 prefetch(page_addr + L1_CACHE_BYTES);
1949#endif
1950
1951 /* allocate a skb to store the frags */
Alexander Duyck67fd8932014-12-09 19:40:56 -08001952 skb = napi_alloc_skb(&rx_ring->q_vector->napi,
1953 IXGBE_RX_HDR_SIZE);
Alexander Duyck18806c92012-07-20 08:08:44 +00001954 if (unlikely(!skb)) {
1955 rx_ring->rx_stats.alloc_rx_buff_failed++;
1956 return NULL;
1957 }
1958
1959 /*
1960 * we will be copying header into skb->data in
1961 * pskb_may_pull so it is in our interest to prefetch
1962 * it now to avoid a possible cache miss
1963 */
1964 prefetchw(skb->data);
1965
1966 /*
1967 * Delay unmapping of the first packet. It carries the
1968 * header information, HW may still access the header
1969 * after the writeback. Only unmap it when EOP is
1970 * reached
1971 */
1972 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1973 goto dma_sync;
1974
1975 IXGBE_CB(skb)->dma = rx_buffer->dma;
1976 } else {
1977 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1978 ixgbe_dma_sync_frag(rx_ring, skb);
1979
1980dma_sync:
1981 /* we are reusing so sync this buffer for CPU use */
1982 dma_sync_single_range_for_cpu(rx_ring->dev,
1983 rx_buffer->dma,
1984 rx_buffer->page_offset,
1985 ixgbe_rx_bufsz(rx_ring),
1986 DMA_FROM_DEVICE);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001987
1988 rx_buffer->skb = NULL;
Alexander Duyck18806c92012-07-20 08:08:44 +00001989 }
1990
1991 /* pull page into skb */
1992 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1993 /* hand second half of page back to the ring */
1994 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1995 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1996 /* the page has been released from the ring */
1997 IXGBE_CB(skb)->page_released = true;
1998 } else {
1999 /* we are not reusing the buffer so unmap it */
2000 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
2001 ixgbe_rx_pg_size(rx_ring),
2002 DMA_FROM_DEVICE);
2003 }
2004
2005 /* clear contents of buffer_info */
Alexander Duyck18806c92012-07-20 08:08:44 +00002006 rx_buffer->page = NULL;
2007
2008 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002009}
2010
2011/**
2012 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2013 * @q_vector: structure containing interrupt and ring information
2014 * @rx_ring: rx descriptor ring to transact packets on
2015 * @budget: Total limit on number of packets to process
2016 *
2017 * This function provides a "bounce buffer" approach to Rx interrupt
2018 * processing. The advantage to this is that on systems that have
2019 * expensive overhead for IOMMU access this provides a means of avoiding
2020 * it by maintaining the mapping of the page to the syste.
2021 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002022 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002023 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002024static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002025 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002026 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002027{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002028 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00002029#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00002030 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00002031 int ddp_bytes;
2032 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002033#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002034 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002035
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002036 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002037 union ixgbe_adv_rx_desc *rx_desc;
2038 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002039
Alexander Duyckf8003262012-03-03 02:35:52 +00002040 /* return some buffers to hardware, one at a time is too slow */
2041 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2042 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2043 cleaned_count = 0;
2044 }
Auke Kok9a799d72007-09-15 14:07:45 -07002045
Alexander Duyck18806c92012-07-20 08:08:44 +00002046 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07002047
Alexander Duyck124b74c2014-12-11 15:02:28 -08002048 if (!rx_desc->wb.upper.status_error)
Alexander Duyckf8003262012-03-03 02:35:52 +00002049 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002050
Alexander Duyck124b74c2014-12-11 15:02:28 -08002051 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002052 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002053 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002054 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002055 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002056
Alexander Duyck18806c92012-07-20 08:08:44 +00002057 /* retrieve a buffer from the ring */
2058 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00002059
Alexander Duyck18806c92012-07-20 08:08:44 +00002060 /* exit if we failed to retrieve a buffer */
2061 if (!skb)
2062 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002063
Auke Kok9a799d72007-09-15 14:07:45 -07002064 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002065
Alexander Duyckf8003262012-03-03 02:35:52 +00002066 /* place incomplete frames back on ring for completion */
2067 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2068 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002069
Alexander Duyckf8003262012-03-03 02:35:52 +00002070 /* verify the packet layout is correct */
2071 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2072 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002073
2074 /* probably a little skewed due to removing CRC */
2075 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002076
Alexander Duyck8a0da212012-01-31 02:59:49 +00002077 /* populate checksum, timestamp, VLAN, and protocol */
2078 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2079
Yi Zou332d4a72009-05-13 13:11:53 +00002080#ifdef IXGBE_FCOE
2081 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002082 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002083 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002084 /* include DDPed FCoE data */
2085 if (ddp_bytes > 0) {
2086 if (!mss) {
2087 mss = rx_ring->netdev->mtu -
2088 sizeof(struct fcoe_hdr) -
2089 sizeof(struct fc_frame_header) -
2090 sizeof(struct fcoe_crc_eof);
2091 if (mss > 512)
2092 mss &= ~511;
2093 }
2094 total_rx_bytes += ddp_bytes;
2095 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2096 mss);
2097 }
David S. Miller823dcd22011-08-20 10:39:12 -07002098 if (!ddp_bytes) {
2099 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002100 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002101 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002102 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002103
Yi Zou332d4a72009-05-13 13:11:53 +00002104#endif /* IXGBE_FCOE */
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03002105 skb_mark_napi_id(skb, &q_vector->napi);
Alexander Duyck8a0da212012-01-31 02:59:49 +00002106 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002107
Alexander Duyckf8003262012-03-03 02:35:52 +00002108 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002109 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002110 }
Auke Kok9a799d72007-09-15 14:07:45 -07002111
Alexander Duyckc267fc12010-11-16 19:27:00 -08002112 u64_stats_update_begin(&rx_ring->syncp);
2113 rx_ring->stats.packets += total_rx_packets;
2114 rx_ring->stats.bytes += total_rx_bytes;
2115 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002116 q_vector->rx.total_packets += total_rx_packets;
2117 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002118
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002119 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002120}
2121
Cong Wange0d10952013-08-01 11:10:25 +08002122#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002123/* must be called with local_bh_disable()d */
2124static int ixgbe_low_latency_recv(struct napi_struct *napi)
2125{
2126 struct ixgbe_q_vector *q_vector =
2127 container_of(napi, struct ixgbe_q_vector, napi);
2128 struct ixgbe_adapter *adapter = q_vector->adapter;
2129 struct ixgbe_ring *ring;
2130 int found = 0;
2131
2132 if (test_bit(__IXGBE_DOWN, &adapter->state))
2133 return LL_FLUSH_FAILED;
2134
2135 if (!ixgbe_qv_lock_poll(q_vector))
2136 return LL_FLUSH_BUSY;
2137
2138 ixgbe_for_each_ring(ring, q_vector->rx) {
2139 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
Jacob Kellerb4640032013-10-01 04:33:54 -07002140#ifdef BP_EXTENDED_STATS
Eliezer Tamir7e15b902013-06-10 11:40:31 +03002141 if (found)
2142 ring->stats.cleaned += found;
2143 else
2144 ring->stats.misses++;
2145#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002146 if (found)
2147 break;
2148 }
2149
2150 ixgbe_qv_unlock_poll(q_vector);
2151
2152 return found;
2153}
Cong Wange0d10952013-08-01 11:10:25 +08002154#endif /* CONFIG_NET_RX_BUSY_POLL */
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002155
Auke Kok9a799d72007-09-15 14:07:45 -07002156/**
2157 * ixgbe_configure_msix - Configure MSI-X hardware
2158 * @adapter: board private structure
2159 *
2160 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2161 * interrupts.
2162 **/
2163static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2164{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002165 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002166 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002167 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002168
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002169 /* Populate MSIX to EITR Select */
2170 if (adapter->num_vfs > 32) {
2171 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2172 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2173 }
2174
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002175 /*
2176 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002177 * corresponding register.
2178 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002179 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002180 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002181 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002182
Alexander Duycka5579282012-02-08 07:50:04 +00002183 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002184 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002185
Alexander Duycka5579282012-02-08 07:50:04 +00002186 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002187 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002188
Alexander Duyckfe49f042009-06-04 16:00:09 +00002189 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002190 }
2191
Alexander Duyckbd508172010-11-16 19:27:03 -08002192 switch (adapter->hw.mac.type) {
2193 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002194 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002195 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002196 break;
2197 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002198 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002199 case ixgbe_mac_X550:
2200 case ixgbe_mac_X550EM_x:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002201 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002202 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002203 default:
2204 break;
2205 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002206 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002207
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002208 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002209 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002210 mask &= ~(IXGBE_EIMS_OTHER |
2211 IXGBE_EIMS_MAILBOX |
2212 IXGBE_EIMS_LSC);
2213
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002214 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002215}
2216
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002217enum latency_range {
2218 lowest_latency = 0,
2219 low_latency = 1,
2220 bulk_latency = 2,
2221 latency_invalid = 255
2222};
2223
2224/**
2225 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002226 * @q_vector: structure containing interrupt and ring information
2227 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002228 *
2229 * Stores a new ITR value based on packets and byte
2230 * counts during the last interrupt. The advantage of per interrupt
2231 * computation is faster updates and more accurate ITR for the current
2232 * traffic pattern. Constants in this function were computed
2233 * based on theoretical maximum wire speed and thresholds were set based
2234 * on testing data as well as attempting to minimize response time
2235 * while increasing bulk throughput.
2236 * this functionality is controlled by the InterruptThrottleRate module
2237 * parameter (see ixgbe_param.c)
2238 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002239static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2240 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002241{
Alexander Duyckbd198052011-06-11 01:45:08 +00002242 int bytes = ring_container->total_bytes;
2243 int packets = ring_container->total_packets;
2244 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002245 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002246 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002247
2248 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002249 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002250
2251 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002252 * 0-10MB/s lowest (100000 ints/s)
2253 * 10-20MB/s low (20000 ints/s)
2254 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002255 */
2256 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002257 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002258 if (timepassed_us == 0)
2259 return;
2260
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002261 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2262
2263 switch (itr_setting) {
2264 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002265 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002266 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002267 break;
2268 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002269 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002270 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002271 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002272 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002273 break;
2274 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002275 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002276 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002277 break;
2278 }
2279
Alexander Duyckbd198052011-06-11 01:45:08 +00002280 /* clear work counters since we have the values we need */
2281 ring_container->total_bytes = 0;
2282 ring_container->total_packets = 0;
2283
2284 /* write updated itr to ring container */
2285 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002286}
2287
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002288/**
2289 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002290 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002291 *
2292 * This function is made to be called by ethtool and by the driver
2293 * when it needs to update EITR registers at runtime. Hardware
2294 * specific quirks/differences are taken care of here.
2295 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002296void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002297{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002298 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002299 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002300 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002301 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002302
Alexander Duyckbd508172010-11-16 19:27:03 -08002303 switch (adapter->hw.mac.type) {
2304 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002305 /* must write high and low 16 bits to reset counter */
2306 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002307 break;
2308 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002309 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002310 case ixgbe_mac_X550:
2311 case ixgbe_mac_X550EM_x:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002312 /*
2313 * set the WDIS bit to not clear the timer bits and cause an
2314 * immediate assertion of the interrupt
2315 */
2316 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002317 break;
2318 default:
2319 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002320 }
2321 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2322}
2323
Alexander Duyckbd198052011-06-11 01:45:08 +00002324static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002325{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002326 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002327 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002328
Alexander Duyckbd198052011-06-11 01:45:08 +00002329 ixgbe_update_itr(q_vector, &q_vector->tx);
2330 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002331
Alexander Duyck08c88332011-06-11 01:45:03 +00002332 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002333
2334 switch (current_itr) {
2335 /* counts and packets in update_itr are dependent on these numbers */
2336 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002337 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002338 break;
2339 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002340 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002341 break;
2342 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002343 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002344 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002345 default:
2346 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002347 }
2348
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002349 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002350 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002351 new_itr = (10 * new_itr * q_vector->itr) /
2352 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002353
Alexander Duyckbd198052011-06-11 01:45:08 +00002354 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002355 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002356
2357 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002358 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002359}
2360
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002361/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002362 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002363 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002364 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002365static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002366{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002367 struct ixgbe_hw *hw = &adapter->hw;
2368 u32 eicr = adapter->interrupt_event;
2369
Alexander Duyckf0f97782011-04-22 04:08:09 +00002370 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002371 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002372
Alexander Duyckf0f97782011-04-22 04:08:09 +00002373 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2374 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2375 return;
2376
2377 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2378
Joe Perches7ca647b2010-09-07 21:35:40 +00002379 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002380 case IXGBE_DEV_ID_82599_T3_LOM:
2381 /*
2382 * Since the warning interrupt is for both ports
2383 * we don't have to check if:
2384 * - This interrupt wasn't for our port.
2385 * - We may have missed the interrupt so always have to
2386 * check if we got a LSC
2387 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002388 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002389 !(eicr & IXGBE_EICR_LSC))
2390 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002391
Alexander Duyckf0f97782011-04-22 04:08:09 +00002392 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002393 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002394 bool link_up = false;
2395
Josh Hay3d292262012-12-15 03:28:19 +00002396 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002397
Alexander Duyckf0f97782011-04-22 04:08:09 +00002398 if (link_up)
2399 return;
2400 }
2401
2402 /* Check if this is not due to overtemp */
2403 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2404 return;
2405
2406 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002407 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002408 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2409 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002410 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002411 return;
2412 break;
2413 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002414 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002415
2416 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002417}
2418
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002419static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2420{
2421 struct ixgbe_hw *hw = &adapter->hw;
2422
2423 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002424 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002425 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002426 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002427 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002428 }
2429}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002430
Jacob Keller4f51bf72011-08-20 04:49:45 +00002431static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2432{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002433 struct ixgbe_hw *hw = &adapter->hw;
2434
Jacob Keller4f51bf72011-08-20 04:49:45 +00002435 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2436 return;
2437
2438 switch (adapter->hw.mac.type) {
2439 case ixgbe_mac_82599EB:
2440 /*
2441 * Need to check link state so complete overtemp check
2442 * on service task
2443 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002444 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2445 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002446 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2447 adapter->interrupt_event = eicr;
2448 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2449 ixgbe_service_event_schedule(adapter);
2450 return;
2451 }
2452 return;
2453 case ixgbe_mac_X540:
2454 if (!(eicr & IXGBE_EICR_TS))
2455 return;
2456 break;
2457 default:
2458 return;
2459 }
2460
Don Skidmoref44e7512015-06-09 16:36:23 -07002461 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002462}
2463
Don Skidmore45788d22015-06-09 16:59:04 -07002464static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2465{
2466 switch (hw->mac.type) {
2467 case ixgbe_mac_82598EB:
2468 if (hw->phy.type == ixgbe_phy_nl)
2469 return true;
2470 return false;
2471 case ixgbe_mac_82599EB:
2472 case ixgbe_mac_X550EM_x:
2473 switch (hw->mac.ops.get_media_type(hw)) {
2474 case ixgbe_media_type_fiber:
2475 case ixgbe_media_type_fiber_qsfp:
2476 return true;
2477 default:
2478 return false;
2479 }
2480 default:
2481 return false;
2482 }
2483}
2484
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002485static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2486{
2487 struct ixgbe_hw *hw = &adapter->hw;
2488
Don Skidmore9a900ec2015-06-09 17:15:01 -07002489 if (eicr & IXGBE_EICR_GPI_SDP2(hw)) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002490 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002491 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002492 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2493 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2494 ixgbe_service_event_schedule(adapter);
2495 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002496 }
2497
Don Skidmore9a900ec2015-06-09 17:15:01 -07002498 if (eicr & IXGBE_EICR_GPI_SDP1(hw)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002499 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002500 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002501 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2502 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2503 ixgbe_service_event_schedule(adapter);
2504 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002505 }
2506}
2507
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002508static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2509{
2510 struct ixgbe_hw *hw = &adapter->hw;
2511
2512 adapter->lsc_int++;
2513 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2514 adapter->link_check_timeout = jiffies;
2515 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2516 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002517 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002518 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002519 }
2520}
2521
Alexander Duyckfe49f042009-06-04 16:00:09 +00002522static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2523 u64 qmask)
2524{
2525 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002526 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002527
Alexander Duyckbd508172010-11-16 19:27:03 -08002528 switch (hw->mac.type) {
2529 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002530 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002531 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2532 break;
2533 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002534 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002535 case ixgbe_mac_X550:
2536 case ixgbe_mac_X550EM_x:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002537 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002538 if (mask)
2539 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002540 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002541 if (mask)
2542 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2543 break;
2544 default:
2545 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002546 }
2547 /* skip the flush */
2548}
2549
2550static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002551 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002552{
2553 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002554 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002555
Alexander Duyckbd508172010-11-16 19:27:03 -08002556 switch (hw->mac.type) {
2557 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002558 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002559 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2560 break;
2561 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002562 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002563 case ixgbe_mac_X550:
2564 case ixgbe_mac_X550EM_x:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002565 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002566 if (mask)
2567 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002568 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002569 if (mask)
2570 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2571 break;
2572 default:
2573 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002574 }
2575 /* skip the flush */
2576}
2577
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002578/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002579 * ixgbe_irq_enable - Enable default interrupt generation settings
2580 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002581 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002582static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2583 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002584{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002585 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002586 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002587
Alexander Duyck2c4af692011-07-15 07:29:55 +00002588 /* don't reenable LSC while waiting for link */
2589 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2590 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002591
Alexander Duyck2c4af692011-07-15 07:29:55 +00002592 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002593 switch (adapter->hw.mac.type) {
2594 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002595 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002596 break;
2597 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002598 case ixgbe_mac_X550:
2599 case ixgbe_mac_X550EM_x:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002600 mask |= IXGBE_EIMS_TS;
2601 break;
2602 default:
2603 break;
2604 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002605 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002606 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002607 switch (adapter->hw.mac.type) {
2608 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002609 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2610 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002611 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00002612 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002613 case ixgbe_mac_X550:
2614 case ixgbe_mac_X550EM_x:
Don Skidmore597f22d2015-06-09 16:52:02 -07002615 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
2616 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00002617 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002618 mask |= IXGBE_EIMS_MAILBOX;
2619 break;
2620 default:
2621 break;
2622 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002623
Alexander Duyck2c4af692011-07-15 07:29:55 +00002624 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2625 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2626 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002627
Alexander Duyck2c4af692011-07-15 07:29:55 +00002628 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2629 if (queues)
2630 ixgbe_irq_enable_queues(adapter, ~0);
2631 if (flush)
2632 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002633}
2634
Alexander Duyck2c4af692011-07-15 07:29:55 +00002635static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002636{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002637 struct ixgbe_adapter *adapter = data;
2638 struct ixgbe_hw *hw = &adapter->hw;
2639 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002640
Alexander Duyck2c4af692011-07-15 07:29:55 +00002641 /*
2642 * Workaround for Silicon errata. Use clear-by-write instead
2643 * of clear-by-read. Reading with EICS will return the
2644 * interrupt causes without clearing, which later be done
2645 * with the write to EICR.
2646 */
2647 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002648
2649 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08002650 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00002651 * the bits are high when ixgbe_msix_other is called. There is a race
2652 * condition otherwise which results in possible performance loss
2653 * especially if the ixgbe_msix_other interrupt is triggering
2654 * consistently (as it would when PPS is turned on for the X540 device)
2655 */
2656 eicr &= 0xFFFF0000;
2657
Alexander Duyck2c4af692011-07-15 07:29:55 +00002658 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002659
Alexander Duyck2c4af692011-07-15 07:29:55 +00002660 if (eicr & IXGBE_EICR_LSC)
2661 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002662
Alexander Duyck2c4af692011-07-15 07:29:55 +00002663 if (eicr & IXGBE_EICR_MAILBOX)
2664 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002665
Alexander Duyck2c4af692011-07-15 07:29:55 +00002666 switch (hw->mac.type) {
2667 case ixgbe_mac_82599EB:
2668 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002669 case ixgbe_mac_X550:
2670 case ixgbe_mac_X550EM_x:
Don Skidmore597f22d2015-06-09 16:52:02 -07002671 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
2672 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
2673 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
2674 ixgbe_service_event_schedule(adapter);
2675 IXGBE_WRITE_REG(hw, IXGBE_EICR,
2676 IXGBE_EICR_GPI_SDP0_X540);
2677 }
Don Skidmored773ce22014-02-25 17:58:53 -08002678 if (eicr & IXGBE_EICR_ECC) {
2679 e_info(link, "Received ECC Err, initiating reset\n");
2680 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2681 ixgbe_service_event_schedule(adapter);
2682 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2683 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002684 /* Handle Flow Director Full threshold interrupt */
2685 if (eicr & IXGBE_EICR_FLOW_DIR) {
2686 int reinit_count = 0;
2687 int i;
2688 for (i = 0; i < adapter->num_tx_queues; i++) {
2689 struct ixgbe_ring *ring = adapter->tx_ring[i];
2690 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2691 &ring->state))
2692 reinit_count++;
2693 }
2694 if (reinit_count) {
2695 /* no more flow director interrupts until after init */
2696 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2697 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2698 ixgbe_service_event_schedule(adapter);
2699 }
2700 }
2701 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002702 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002703 break;
2704 default:
2705 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002706 }
2707
Alexander Duyck2c4af692011-07-15 07:29:55 +00002708 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002709
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002710 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2711 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002712
Alexander Duyck2c4af692011-07-15 07:29:55 +00002713 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002714 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002715 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002716
Alexander Duyck2c4af692011-07-15 07:29:55 +00002717 return IRQ_HANDLED;
2718}
2719
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002720static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002721{
2722 struct ixgbe_q_vector *q_vector = data;
2723
Auke Kok9a799d72007-09-15 14:07:45 -07002724 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002725
2726 if (q_vector->rx.ring || q_vector->tx.ring)
2727 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002728
2729 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002730}
2731
Auke Kok9a799d72007-09-15 14:07:45 -07002732/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002733 * ixgbe_poll - NAPI Rx polling callback
2734 * @napi: structure for representing this polling device
2735 * @budget: how many packets driver is allowed to clean
2736 *
2737 * This function is used for legacy and MSI, NAPI mode
2738 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002739int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002740{
2741 struct ixgbe_q_vector *q_vector =
2742 container_of(napi, struct ixgbe_q_vector, napi);
2743 struct ixgbe_adapter *adapter = q_vector->adapter;
2744 struct ixgbe_ring *ring;
2745 int per_ring_budget;
2746 bool clean_complete = true;
2747
2748#ifdef CONFIG_IXGBE_DCA
2749 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2750 ixgbe_update_dca(q_vector);
2751#endif
2752
2753 ixgbe_for_each_ring(ring, q_vector->tx)
2754 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2755
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002756 if (!ixgbe_qv_lock_napi(q_vector))
2757 return budget;
2758
Alexander Duyckeb01b972012-02-08 07:51:27 +00002759 /* attempt to distribute budget to each queue fairly, but don't allow
2760 * the budget to go below 1 because we'll exit polling */
2761 if (q_vector->rx.count > 1)
2762 per_ring_budget = max(budget/q_vector->rx.count, 1);
2763 else
2764 per_ring_budget = budget;
2765
2766 ixgbe_for_each_ring(ring, q_vector->rx)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002767 clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring,
2768 per_ring_budget) < per_ring_budget);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002769
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002770 ixgbe_qv_unlock_napi(q_vector);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002771 /* If all work not completed, return budget and keep polling */
2772 if (!clean_complete)
2773 return budget;
2774
2775 /* all work done, exit the polling mode */
2776 napi_complete(napi);
2777 if (adapter->rx_itr_setting & 1)
2778 ixgbe_set_itr(q_vector);
2779 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2780 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2781
2782 return 0;
2783}
2784
2785/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002786 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2787 * @adapter: board private structure
2788 *
2789 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2790 * interrupts from the kernel.
2791 **/
2792static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2793{
2794 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002795 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002796 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002797
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002798 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002799 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002800 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002801
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002802 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002803 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002804 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002805 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002806 } else if (q_vector->rx.ring) {
2807 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2808 "%s-%s-%d", netdev->name, "rx", ri++);
2809 } else if (q_vector->tx.ring) {
2810 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2811 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002812 } else {
2813 /* skip this unused q_vector */
2814 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002815 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002816 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2817 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002818 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002819 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002820 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002821 goto free_queue_irqs;
2822 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002823 /* If Flow Director is enabled, set interrupt affinity */
2824 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2825 /* assign the mask for this irq */
2826 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002827 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002828 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002829 }
2830
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002831 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002832 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002833 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002834 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002835 goto free_queue_irqs;
2836 }
2837
2838 return 0;
2839
2840free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002841 while (vector) {
2842 vector--;
2843 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2844 NULL);
2845 free_irq(adapter->msix_entries[vector].vector,
2846 adapter->q_vector[vector]);
2847 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002848 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2849 pci_disable_msix(adapter->pdev);
2850 kfree(adapter->msix_entries);
2851 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002852 return err;
2853}
2854
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002855/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002856 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002857 * @irq: interrupt number
2858 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002859 **/
2860static irqreturn_t ixgbe_intr(int irq, void *data)
2861{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002862 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002863 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002864 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002865 u32 eicr;
2866
Don Skidmore54037502009-02-21 15:42:56 -08002867 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002868 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002869 * before the read of EICR.
2870 */
2871 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2872
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002873 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002874 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002875 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002876 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002877 /*
2878 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002879 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002880 * have disabled interrupts due to EIAM
2881 * finish the workaround of silicon errata on 82598. Unmask
2882 * the interrupt that we masked before the EICR read.
2883 */
2884 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2885 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002886 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002887 }
Auke Kok9a799d72007-09-15 14:07:45 -07002888
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002889 if (eicr & IXGBE_EICR_LSC)
2890 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002891
Alexander Duyckbd508172010-11-16 19:27:03 -08002892 switch (hw->mac.type) {
2893 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002894 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002895 /* Fall through */
2896 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002897 case ixgbe_mac_X550:
2898 case ixgbe_mac_X550EM_x:
Don Skidmored773ce22014-02-25 17:58:53 -08002899 if (eicr & IXGBE_EICR_ECC) {
2900 e_info(link, "Received ECC Err, initiating reset\n");
2901 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2902 ixgbe_service_event_schedule(adapter);
2903 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2904 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00002905 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002906 break;
2907 default:
2908 break;
2909 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002910
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002911 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002912 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2913 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002914
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002915 /* would disable interrupts here but EIAM disabled it */
2916 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002917
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002918 /*
2919 * re-enable link(maybe) and non-queue interrupts, no flush.
2920 * ixgbe_poll will re-enable the queue interrupts
2921 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002922 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2923 ixgbe_irq_enable(adapter, false, false);
2924
Auke Kok9a799d72007-09-15 14:07:45 -07002925 return IRQ_HANDLED;
2926}
2927
2928/**
2929 * ixgbe_request_irq - initialize interrupts
2930 * @adapter: board private structure
2931 *
2932 * Attempts to configure interrupts using the best available
2933 * capabilities of the hardware and kernel.
2934 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002935static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002936{
2937 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002938 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002939
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002940 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002941 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002942 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002943 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002944 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002945 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002946 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002947 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002948
Alexander Duyckde88eee2012-02-08 07:49:59 +00002949 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002950 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002951
Auke Kok9a799d72007-09-15 14:07:45 -07002952 return err;
2953}
2954
2955static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2956{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002957 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002958
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002959 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002960 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002961 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002962 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002963
2964 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2965 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2966 struct msix_entry *entry = &adapter->msix_entries[vector];
2967
2968 /* free only the irqs that were actually requested */
2969 if (!q_vector->rx.ring && !q_vector->tx.ring)
2970 continue;
2971
2972 /* clear the affinity_mask in the IRQ descriptor */
2973 irq_set_affinity_hint(entry->vector, NULL);
2974
2975 free_irq(entry->vector, q_vector);
2976 }
2977
2978 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002979}
2980
2981/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002982 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2983 * @adapter: board private structure
2984 **/
2985static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2986{
Alexander Duyckbd508172010-11-16 19:27:03 -08002987 switch (adapter->hw.mac.type) {
2988 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002989 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002990 break;
2991 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002992 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002993 case ixgbe_mac_X550:
2994 case ixgbe_mac_X550EM_x:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002995 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2996 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002997 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002998 break;
2999 default:
3000 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003001 }
3002 IXGBE_WRITE_FLUSH(&adapter->hw);
3003 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003004 int vector;
3005
3006 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3007 synchronize_irq(adapter->msix_entries[vector].vector);
3008
3009 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003010 } else {
3011 synchronize_irq(adapter->pdev->irq);
3012 }
3013}
3014
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003015/**
Auke Kok9a799d72007-09-15 14:07:45 -07003016 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3017 *
3018 **/
3019static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3020{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003021 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003022
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003023 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003024
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003025 ixgbe_set_ivar(adapter, 0, 0, 0);
3026 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003027
Emil Tantilov396e7992010-07-01 20:05:12 +00003028 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003029}
3030
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003031/**
3032 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3033 * @adapter: board private structure
3034 * @ring: structure containing ring specific data
3035 *
3036 * Configure the Tx descriptor ring after a reset.
3037 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003038void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3039 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003040{
3041 struct ixgbe_hw *hw = &adapter->hw;
3042 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003043 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003044 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003045 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003046
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003047 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003048 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003049 IXGBE_WRITE_FLUSH(hw);
3050
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003051 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003052 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003053 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3054 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3055 ring->count * sizeof(union ixgbe_adv_tx_desc));
3056 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3057 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003058 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003059
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003060 /*
3061 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003062 * higher than 1 when:
3063 * - ITR is 0 as it could cause false TX hangs
3064 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003065 *
3066 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3067 * to or less than the number of on chip descriptors, which is
3068 * currently 40.
3069 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003070 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003071 txdctl |= (1 << 16); /* WTHRESH = 1 */
3072 else
3073 txdctl |= (8 << 16); /* WTHRESH = 8 */
3074
Alexander Duycke954b372012-02-08 07:49:38 +00003075 /*
3076 * Setting PTHRESH to 32 both improves performance
3077 * and avoids a TX hang with DFP enabled
3078 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003079 txdctl |= (1 << 8) | /* HTHRESH = 1 */
3080 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003081
3082 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003083 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003084 ring->atr_sample_rate = adapter->atr_sample_rate;
3085 ring->atr_count = 0;
3086 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3087 } else {
3088 ring->atr_sample_rate = 0;
3089 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003090
Alexander Duyckfd786b72013-01-12 06:33:31 +00003091 /* initialize XPS */
3092 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3093 struct ixgbe_q_vector *q_vector = ring->q_vector;
3094
3095 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003096 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003097 &q_vector->affinity_mask,
3098 ring->queue_index);
3099 }
3100
John Fastabendc84d3242010-11-16 19:27:12 -08003101 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3102
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003103 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003104 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3105
3106 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3107 if (hw->mac.type == ixgbe_mac_82598EB &&
3108 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3109 return;
3110
3111 /* poll to verify queue is enabled */
3112 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003113 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003114 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3115 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3116 if (!wait_loop)
3117 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003118}
3119
Alexander Duyck120ff942010-08-19 13:34:50 +00003120static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3121{
3122 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003123 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003124 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003125
3126 if (hw->mac.type == ixgbe_mac_82598EB)
3127 return;
3128
3129 /* disable the arbiter while setting MTQC */
3130 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3131 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3132 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3133
3134 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003135 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3136 mtqc = IXGBE_MTQC_VT_ENA;
3137 if (tcs > 4)
3138 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3139 else if (tcs > 1)
3140 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3141 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3142 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003143 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003144 mtqc |= IXGBE_MTQC_64VF;
3145 } else {
3146 if (tcs > 4)
3147 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3148 else if (tcs > 1)
3149 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3150 else
3151 mtqc = IXGBE_MTQC_64Q_1PB;
3152 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003153
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003154 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003155
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003156 /* Enable Security TX Buffer IFG for multiple pb */
3157 if (tcs) {
3158 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3159 sectx |= IXGBE_SECTX_DCB;
3160 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003161 }
3162
3163 /* re-enable the arbiter */
3164 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3165 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3166}
3167
Auke Kok9a799d72007-09-15 14:07:45 -07003168/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003169 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003170 * @adapter: board private structure
3171 *
3172 * Configure the Tx unit of the MAC after a reset.
3173 **/
3174static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3175{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003176 struct ixgbe_hw *hw = &adapter->hw;
3177 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003178 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003179
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003180 ixgbe_setup_mtqc(adapter);
3181
3182 if (hw->mac.type != ixgbe_mac_82598EB) {
3183 /* DMATXCTL.EN must be before Tx queues are enabled */
3184 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3185 dmatxctl |= IXGBE_DMATXCTL_TE;
3186 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3187 }
3188
Auke Kok9a799d72007-09-15 14:07:45 -07003189 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003190 for (i = 0; i < adapter->num_tx_queues; i++)
3191 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003192}
3193
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003194static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3195 struct ixgbe_ring *ring)
3196{
3197 struct ixgbe_hw *hw = &adapter->hw;
3198 u8 reg_idx = ring->reg_idx;
3199 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3200
3201 srrctl |= IXGBE_SRRCTL_DROP_EN;
3202
3203 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3204}
3205
3206static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3207 struct ixgbe_ring *ring)
3208{
3209 struct ixgbe_hw *hw = &adapter->hw;
3210 u8 reg_idx = ring->reg_idx;
3211 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3212
3213 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3214
3215 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3216}
3217
3218#ifdef CONFIG_IXGBE_DCB
3219void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3220#else
3221static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3222#endif
3223{
3224 int i;
3225 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3226
3227 if (adapter->ixgbe_ieee_pfc)
3228 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3229
3230 /*
3231 * We should set the drop enable bit if:
3232 * SR-IOV is enabled
3233 * or
3234 * Number of Rx queues > 1 and flow control is disabled
3235 *
3236 * This allows us to avoid head of line blocking for security
3237 * and performance reasons.
3238 */
3239 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3240 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3241 for (i = 0; i < adapter->num_rx_queues; i++)
3242 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3243 } else {
3244 for (i = 0; i < adapter->num_rx_queues; i++)
3245 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3246 }
3247}
3248
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003249#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003250
Yi Zoua6616b42009-08-06 13:05:23 +00003251static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003252 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003253{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003254 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003255 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003256 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003257
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003258 if (hw->mac.type == ixgbe_mac_82598EB) {
3259 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3260
3261 /*
3262 * if VMDq is not active we must program one srrctl register
3263 * per RSS queue since we have enabled RDRXCTL.MVMEN
3264 */
3265 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003266 }
3267
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003268 /* configure header buffer length, needed for RSC */
3269 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003270
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003271 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00003272 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003273
3274 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003275 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003276
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003277 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003278}
3279
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003280/**
3281 * Return a number of entries in the RSS indirection table
3282 *
3283 * @adapter: device handle
3284 *
3285 * - 82598/82599/X540: 128
3286 * - X550(non-SRIOV mode): 512
3287 * - X550(SRIOV mode): 64
3288 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003289u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003290{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003291 if (adapter->hw.mac.type < ixgbe_mac_X550)
3292 return 128;
3293 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3294 return 64;
3295 else
3296 return 512;
3297}
3298
3299/**
3300 * Write the RETA table to HW
3301 *
3302 * @adapter: device handle
3303 *
3304 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3305 */
3306static void ixgbe_store_reta(struct ixgbe_adapter *adapter)
3307{
3308 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003309 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003310 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003311 u32 indices_multi;
3312 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003313
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003314 /* Fill out the redirection table as follows:
3315 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3316 * indices.
3317 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3318 * - X550: 8 bit wide entries containing 6 bit RSS index
3319 */
3320 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3321 indices_multi = 0x11;
3322 else
3323 indices_multi = 0x1;
3324
3325 /* Write redirection table to HW */
3326 for (i = 0; i < reta_entries; i++) {
3327 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3328 if ((i & 3) == 3) {
3329 if (i < 128)
3330 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3331 else
3332 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3333 reta);
3334 reta = 0;
3335 }
3336 }
3337}
3338
3339/**
3340 * Write the RETA table to HW (for x550 devices in SRIOV mode)
3341 *
3342 * @adapter: device handle
3343 *
3344 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3345 */
3346static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3347{
3348 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3349 struct ixgbe_hw *hw = &adapter->hw;
3350 u32 vfreta = 0;
3351 unsigned int pf_pool = adapter->num_vfs;
3352
3353 /* Write redirection table to HW */
3354 for (i = 0; i < reta_entries; i++) {
3355 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3356 if ((i & 3) == 3) {
3357 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3358 vfreta);
3359 vfreta = 0;
3360 }
3361 }
3362}
3363
3364static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3365{
3366 struct ixgbe_hw *hw = &adapter->hw;
3367 u32 i, j;
3368 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3369 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3370
3371 /* Program table for at least 2 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003372 * make full use of any rings they may have. We will use the
3373 * PSRTYPE register to control how many rings we use within the PF.
3374 */
3375 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3376 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003377
Alexander Duyck05abb122010-08-19 13:35:41 +00003378 /* Fill out hash function seeds */
3379 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003380 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003381
Alexander Duyck05abb122010-08-19 13:35:41 +00003382 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003383 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3384
Don Skidmore0f9b2322014-11-18 09:35:08 +00003385 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003386 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003387 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003388
3389 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003390 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003391
3392 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003393}
3394
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003395static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003396{
3397 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003398 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3399 unsigned int pf_pool = adapter->num_vfs;
3400 int i, j;
3401
3402 /* Fill out hash function seeds */
3403 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003404 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
3405 adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003406
3407 /* Fill out the redirection table */
3408 for (i = 0, j = 0; i < 64; i++, j++) {
3409 if (j == rss_i)
3410 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003411
3412 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003413 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003414
3415 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003416}
3417
3418static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3419{
3420 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003421 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003422 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003423
3424 /* Disable indicating checksum in descriptor, enables RSS hash */
3425 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3426 rxcsum |= IXGBE_RXCSUM_PCSD;
3427 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3428
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003429 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003430 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003431 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003432 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003433 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003434
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003435 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3436 if (tcs > 4)
3437 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3438 else if (tcs > 1)
3439 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3440 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3441 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3442 else
3443 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3444 } else {
3445 if (tcs > 4)
3446 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3447 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003448 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3449 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003450 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003451 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003452 }
3453
Alexander Duyck05abb122010-08-19 13:35:41 +00003454 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003455 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3456 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3457 IXGBE_MRQC_RSS_FIELD_IPV6 |
3458 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003459
Alexander Duyckef6afc02012-02-08 07:51:53 +00003460 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003461 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003462 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003463 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003464
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003465 netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003466 if ((hw->mac.type >= ixgbe_mac_X550) &&
3467 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3468 unsigned int pf_pool = adapter->num_vfs;
3469
3470 /* Enable VF RSS mode */
3471 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3472 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3473
3474 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003475 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003476 vfmrqc = IXGBE_MRQC_RSSEN;
3477 vfmrqc |= rss_field;
3478 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3479 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003480 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003481 mrqc |= rss_field;
3482 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3483 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003484}
3485
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003486/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003487 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3488 * @adapter: address of board private structure
3489 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003490 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003491static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003492 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003493{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003494 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003495 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003496 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003497
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003498 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003499 return;
3500
Alexander Duyck73670962010-08-19 13:38:34 +00003501 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003502 rscctrl |= IXGBE_RSCCTL_RSCEN;
3503 /*
3504 * we must limit the number of descriptors so that the
3505 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003506 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003507 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003508 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003509 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003510}
3511
Alexander Duyck9e10e042010-08-19 13:40:06 +00003512#define IXGBE_MAX_RX_DESC_POLL 10
3513static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3514 struct ixgbe_ring *ring)
3515{
3516 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003517 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3518 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003519 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003520
Mark Rustadb0483c82014-01-14 18:53:17 -08003521 if (ixgbe_removed(hw->hw_addr))
3522 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003523 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3524 if (hw->mac.type == ixgbe_mac_82598EB &&
3525 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3526 return;
3527
3528 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003529 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003530 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3531 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3532
3533 if (!wait_loop) {
3534 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3535 "the polling period\n", reg_idx);
3536 }
3537}
3538
Yi Zou2d39d572011-01-06 14:29:56 +00003539void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3540 struct ixgbe_ring *ring)
3541{
3542 struct ixgbe_hw *hw = &adapter->hw;
3543 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3544 u32 rxdctl;
3545 u8 reg_idx = ring->reg_idx;
3546
Mark Rustadb0483c82014-01-14 18:53:17 -08003547 if (ixgbe_removed(hw->hw_addr))
3548 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003549 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3550 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3551
3552 /* write value back with RXDCTL.ENABLE bit cleared */
3553 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3554
3555 if (hw->mac.type == ixgbe_mac_82598EB &&
3556 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3557 return;
3558
3559 /* the hardware may take up to 100us to really disable the rx queue */
3560 do {
3561 udelay(10);
3562 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3563 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3564
3565 if (!wait_loop) {
3566 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3567 "the polling period\n", reg_idx);
3568 }
3569}
3570
Alexander Duyck84418e32010-08-19 13:40:54 +00003571void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3572 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003573{
3574 struct ixgbe_hw *hw = &adapter->hw;
3575 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003576 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003577 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003578
Alexander Duyck9e10e042010-08-19 13:40:06 +00003579 /* disable queue to avoid issues while updating state */
3580 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003581 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003582
Alexander Duyckacd37172010-08-19 13:36:05 +00003583 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3584 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3585 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3586 ring->count * sizeof(union ixgbe_adv_rx_desc));
3587 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3588 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003589 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003590
3591 ixgbe_configure_srrctl(adapter, ring);
3592 ixgbe_configure_rscctl(adapter, ring);
3593
3594 if (hw->mac.type == ixgbe_mac_82598EB) {
3595 /*
3596 * enable cache line friendly hardware writes:
3597 * PTHRESH=32 descriptors (half the internal cache),
3598 * this also removes ugly rx_no_buffer_count increment
3599 * HTHRESH=4 descriptors (to minimize latency on fetch)
3600 * WTHRESH=8 burst writeback up to two cache lines
3601 */
3602 rxdctl &= ~0x3FFFFF;
3603 rxdctl |= 0x080420;
3604 }
3605
3606 /* enable receive descriptor ring */
3607 rxdctl |= IXGBE_RXDCTL_ENABLE;
3608 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3609
3610 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003611 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003612}
3613
Alexander Duyck48654522010-08-19 13:36:27 +00003614static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3615{
3616 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003617 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003618 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003619
3620 /* PSRTYPE must be initialized in non 82598 adapters */
3621 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003622 IXGBE_PSRTYPE_UDPHDR |
3623 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003624 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003625 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003626
3627 if (hw->mac.type == ixgbe_mac_82598EB)
3628 return;
3629
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003630 if (rss_i > 3)
3631 psrtype |= 2 << 29;
3632 else if (rss_i > 1)
3633 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003634
John Fastabend2a47fa42013-11-06 09:54:52 -08003635 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3636 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003637}
3638
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003639static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3640{
3641 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003642 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003643 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003644 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003645
3646 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3647 return;
3648
3649 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003650 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3651 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003652 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003653 vmdctl |= IXGBE_VT_CTL_REPLEN;
3654 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003655
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003656 vf_shift = VMDQ_P(0) % 32;
3657 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003658
3659 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003660 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3661 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3662 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3663 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07003664 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00003665 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003666
3667 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003668 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003669
3670 /*
3671 * Set up VF register offsets for selected VT Mode,
3672 * i.e. 32 or 64 VFs for SR-IOV
3673 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003674 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3675 case IXGBE_82599_VMDQ_8Q_MASK:
3676 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3677 break;
3678 case IXGBE_82599_VMDQ_4Q_MASK:
3679 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3680 break;
3681 default:
3682 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3683 break;
3684 }
3685
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003686 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3687
Alexander Duyck435b19f2012-05-18 06:34:08 +00003688
Greg Rosea985b6c32010-11-18 03:02:52 +00003689 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003690 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003691 adapter->num_vfs);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003692
3693 /* Ensure LLDP is set for Ethertype Antispoofing if we will be
3694 * calling set_ethertype_anti_spoofing for each VF in loop below
3695 */
3696 if (hw->mac.ops.set_ethertype_anti_spoofing)
3697 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP),
3698 (IXGBE_ETQF_FILTER_EN | /* enable filter */
3699 IXGBE_ETQF_TX_ANTISPOOF | /* tx antispoof */
3700 IXGBE_ETH_P_LLDP)); /* LLDP eth type */
3701
Greg Rosede4c7f62011-09-29 05:57:33 +00003702 /* For VFs that have spoof checking turned off */
3703 for (i = 0; i < adapter->num_vfs; i++) {
3704 if (!adapter->vfinfo[i].spoofchk_enabled)
3705 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003706
3707 /* enable ethertype anti spoofing if hw supports it */
3708 if (hw->mac.ops.set_ethertype_anti_spoofing)
3709 hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03003710
3711 /* Enable/Disable RSS query feature */
3712 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
3713 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00003714 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003715}
3716
Alexander Duyck477de6e2010-08-19 13:38:11 +00003717static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003718{
Auke Kok9a799d72007-09-15 14:07:45 -07003719 struct ixgbe_hw *hw = &adapter->hw;
3720 struct net_device *netdev = adapter->netdev;
3721 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003722 struct ixgbe_ring *rx_ring;
3723 int i;
3724 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003725
Alexander Duyck477de6e2010-08-19 13:38:11 +00003726#ifdef IXGBE_FCOE
3727 /* adjust max frame to be able to do baby jumbo for FCoE */
3728 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3729 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3730 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3731
3732#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003733
3734 /* adjust max frame to be at least the size of a standard frame */
3735 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3736 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3737
Alexander Duyck477de6e2010-08-19 13:38:11 +00003738 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3739 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3740 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3741 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3742
3743 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003744 }
3745
Auke Kok9a799d72007-09-15 14:07:45 -07003746 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003747 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3748 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003749 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3750
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003751 /*
3752 * Setup the HW Rx Head and Tail Descriptor Pointers and
3753 * the Base and Length of the Rx Descriptor Ring
3754 */
Auke Kok9a799d72007-09-15 14:07:45 -07003755 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003756 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003757 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3758 set_ring_rsc_enabled(rx_ring);
3759 else
3760 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003761 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003762}
3763
Alexander Duyck73670962010-08-19 13:38:34 +00003764static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3765{
3766 struct ixgbe_hw *hw = &adapter->hw;
3767 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3768
3769 switch (hw->mac.type) {
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003770 case ixgbe_mac_X550:
3771 case ixgbe_mac_X550EM_x:
Alexander Duyck73670962010-08-19 13:38:34 +00003772 case ixgbe_mac_82598EB:
3773 /*
3774 * For VMDq support of different descriptor types or
3775 * buffer sizes through the use of multiple SRRCTL
3776 * registers, RDRXCTL.MVMEN must be set to 1
3777 *
3778 * also, the manual doesn't mention it clearly but DCA hints
3779 * will only use queue 0's tags unless this bit is set. Side
3780 * effects of setting this bit are only that SRRCTL must be
3781 * fully programmed [0..15]
3782 */
3783 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3784 break;
3785 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003786 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003787 /* Disable RSC for ACK packets */
3788 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3789 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3790 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3791 /* hardware requires some bits to be set by default */
3792 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3793 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3794 break;
3795 default:
3796 /* We should do nothing since we don't know this hardware */
3797 return;
3798 }
3799
3800 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3801}
3802
Alexander Duyck477de6e2010-08-19 13:38:11 +00003803/**
3804 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3805 * @adapter: board private structure
3806 *
3807 * Configure the Rx unit of the MAC after a reset.
3808 **/
3809static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3810{
3811 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003812 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003813 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003814
3815 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07003816 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003817
3818 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003819 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003820
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003821 /* RSC Setup */
3822 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
3823 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
3824 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
3825 rfctl |= IXGBE_RFCTL_RSC_DIS;
3826 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
3827
Alexander Duyck9e10e042010-08-19 13:40:06 +00003828 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003829 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003830
Alexander Duyck477de6e2010-08-19 13:38:11 +00003831 /* set_rx_buffer_len must be called before ring initialization */
3832 ixgbe_set_rx_buffer_len(adapter);
3833
3834 /*
3835 * Setup the HW Rx Head and Tail Descriptor Pointers and
3836 * the Base and Length of the Rx Descriptor Ring
3837 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003838 for (i = 0; i < adapter->num_rx_queues; i++)
3839 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003840
Don Skidmore1f9ac572015-03-13 13:54:30 -07003841 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003842 /* disable drop enable for 82598 parts */
3843 if (hw->mac.type == ixgbe_mac_82598EB)
3844 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3845
3846 /* enable all receives */
3847 rxctrl |= IXGBE_RXCTRL_RXEN;
3848 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003849}
3850
Patrick McHardy80d5c362013-04-19 02:04:28 +00003851static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3852 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003853{
3854 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003855 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003856
3857 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003858 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003859 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003860
3861 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003862}
3863
Patrick McHardy80d5c362013-04-19 02:04:28 +00003864static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
3865 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003866{
3867 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003868 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003869
Auke Kok9a799d72007-09-15 14:07:45 -07003870 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003871 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003872 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003873
3874 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003875}
3876
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003877/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003878 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3879 * @adapter: driver data
3880 */
3881static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3882{
3883 struct ixgbe_hw *hw = &adapter->hw;
3884 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003885 int i, j;
3886
3887 switch (hw->mac.type) {
3888 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003889 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3890 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003891 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3892 break;
3893 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003894 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003895 case ixgbe_mac_X550:
3896 case ixgbe_mac_X550EM_x:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003897 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08003898 struct ixgbe_ring *ring = adapter->rx_ring[i];
3899
3900 if (ring->l2_accel_priv)
3901 continue;
3902 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003903 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3904 vlnctrl &= ~IXGBE_RXDCTL_VME;
3905 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3906 }
3907 break;
3908 default:
3909 break;
3910 }
3911}
3912
3913/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003914 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003915 * @adapter: driver data
3916 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003917static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003918{
3919 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003920 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003921 int i, j;
3922
3923 switch (hw->mac.type) {
3924 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003925 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3926 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003927 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3928 break;
3929 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003930 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003931 case ixgbe_mac_X550:
3932 case ixgbe_mac_X550EM_x:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003933 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08003934 struct ixgbe_ring *ring = adapter->rx_ring[i];
3935
3936 if (ring->l2_accel_priv)
3937 continue;
3938 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003939 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3940 vlnctrl |= IXGBE_RXDCTL_VME;
3941 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3942 }
3943 break;
3944 default:
3945 break;
3946 }
3947}
3948
Auke Kok9a799d72007-09-15 14:07:45 -07003949static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3950{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003951 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003952
Patrick McHardy80d5c362013-04-19 02:04:28 +00003953 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003954
3955 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00003956 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003957}
3958
3959/**
Jacob Kellerb335e752014-03-25 07:45:27 +00003960 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
3961 * @netdev: network interface device structure
3962 *
3963 * Writes multicast address list to the MTA hash table.
3964 * Returns: -ENOMEM on failure
3965 * 0 on no addresses written
3966 * X on writing X addresses to MTA
3967 **/
3968static int ixgbe_write_mc_addr_list(struct net_device *netdev)
3969{
3970 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3971 struct ixgbe_hw *hw = &adapter->hw;
3972
3973 if (!netif_running(netdev))
3974 return 0;
3975
3976 if (hw->mac.ops.update_mc_addr_list)
3977 hw->mac.ops.update_mc_addr_list(hw, netdev);
3978 else
3979 return -ENOMEM;
3980
3981#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00003982 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00003983#endif
3984
3985 return netdev_mc_count(netdev);
3986}
3987
Jacob Keller5d7daa32014-03-29 06:51:25 +00003988#ifdef CONFIG_PCI_IOV
3989void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
3990{
3991 struct ixgbe_hw *hw = &adapter->hw;
3992 int i;
3993 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3994 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
3995 hw->mac.ops.set_rar(hw, i, adapter->mac_table[i].addr,
3996 adapter->mac_table[i].queue,
3997 IXGBE_RAH_AV);
3998 else
3999 hw->mac.ops.clear_rar(hw, i);
4000
4001 adapter->mac_table[i].state &= ~(IXGBE_MAC_STATE_MODIFIED);
4002 }
4003}
4004#endif
4005
4006static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4007{
4008 struct ixgbe_hw *hw = &adapter->hw;
4009 int i;
4010 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4011 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_MODIFIED) {
4012 if (adapter->mac_table[i].state &
4013 IXGBE_MAC_STATE_IN_USE)
4014 hw->mac.ops.set_rar(hw, i,
4015 adapter->mac_table[i].addr,
4016 adapter->mac_table[i].queue,
4017 IXGBE_RAH_AV);
4018 else
4019 hw->mac.ops.clear_rar(hw, i);
4020
4021 adapter->mac_table[i].state &=
4022 ~(IXGBE_MAC_STATE_MODIFIED);
4023 }
4024 }
4025}
4026
4027static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4028{
4029 int i;
4030 struct ixgbe_hw *hw = &adapter->hw;
4031
4032 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4033 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
4034 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
Joe Perchesc7bf7162015-03-02 19:54:47 -08004035 eth_zero_addr(adapter->mac_table[i].addr);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004036 adapter->mac_table[i].queue = 0;
4037 }
4038 ixgbe_sync_mac_table(adapter);
4039}
4040
4041static int ixgbe_available_rars(struct ixgbe_adapter *adapter)
4042{
4043 struct ixgbe_hw *hw = &adapter->hw;
4044 int i, count = 0;
4045
4046 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4047 if (adapter->mac_table[i].state == 0)
4048 count++;
4049 }
4050 return count;
4051}
4052
4053/* this function destroys the first RAR entry */
4054static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter,
4055 u8 *addr)
4056{
4057 struct ixgbe_hw *hw = &adapter->hw;
4058
4059 memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN);
4060 adapter->mac_table[0].queue = VMDQ_P(0);
4061 adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
4062 IXGBE_MAC_STATE_IN_USE);
4063 hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
4064 adapter->mac_table[0].queue,
4065 IXGBE_RAH_AV);
4066}
4067
4068int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
4069{
4070 struct ixgbe_hw *hw = &adapter->hw;
4071 int i;
4072
4073 if (is_zero_ether_addr(addr))
4074 return -EINVAL;
4075
4076 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4077 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
4078 continue;
4079 adapter->mac_table[i].state |= (IXGBE_MAC_STATE_MODIFIED |
4080 IXGBE_MAC_STATE_IN_USE);
4081 ether_addr_copy(adapter->mac_table[i].addr, addr);
4082 adapter->mac_table[i].queue = queue;
4083 ixgbe_sync_mac_table(adapter);
4084 return i;
4085 }
4086 return -ENOMEM;
4087}
4088
4089int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
4090{
4091 /* search table for addr, if found, set to 0 and sync */
4092 int i;
4093 struct ixgbe_hw *hw = &adapter->hw;
4094
4095 if (is_zero_ether_addr(addr))
4096 return -EINVAL;
4097
4098 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4099 if (ether_addr_equal(addr, adapter->mac_table[i].addr) &&
4100 adapter->mac_table[i].queue == queue) {
4101 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
4102 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
Joe Perchesc7bf7162015-03-02 19:54:47 -08004103 eth_zero_addr(adapter->mac_table[i].addr);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004104 adapter->mac_table[i].queue = 0;
4105 ixgbe_sync_mac_table(adapter);
4106 return 0;
4107 }
4108 }
4109 return -ENOMEM;
4110}
Jacob Kellerb335e752014-03-25 07:45:27 +00004111/**
Alexander Duyck28500622010-06-15 09:25:48 +00004112 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4113 * @netdev: network interface device structure
4114 *
4115 * Writes unicast address list to the RAR table.
4116 * Returns: -ENOMEM on failure/insufficient address space
4117 * 0 on no addresses written
4118 * X on writing X addresses to the RAR table
4119 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004120static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004121{
4122 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004123 int count = 0;
4124
4125 /* return ENOMEM indicating insufficient memory for addresses */
Jacob Keller5d7daa32014-03-29 06:51:25 +00004126 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter))
Alexander Duyck28500622010-06-15 09:25:48 +00004127 return -ENOMEM;
4128
John Fastabend95447462012-05-31 12:42:26 +00004129 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004130 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004131 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004132 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4133 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004134 count++;
4135 }
4136 }
Alexander Duyck28500622010-06-15 09:25:48 +00004137 return count;
4138}
4139
4140/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004141 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004142 * @netdev: network interface device structure
4143 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004144 * The set_rx_method entry point is called whenever the unicast/multicast
4145 * address list or the network interface flags are updated. This routine is
4146 * responsible for configuring the hardware for proper unicast, multicast and
4147 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004148 **/
Greg Rose7f870472010-01-09 02:25:29 +00004149void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004150{
4151 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4152 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004153 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Jacob Kellera9b89432014-03-25 07:45:26 +00004154 u32 vlnctrl;
Alexander Duyck28500622010-06-15 09:25:48 +00004155 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004156
4157 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004158 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Jacob Kellera9b89432014-03-25 07:45:26 +00004159 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07004160
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004161 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004162 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004163 fctrl |= IXGBE_FCTRL_BAM;
4164 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4165 fctrl |= IXGBE_FCTRL_PMCF;
4166
Alexander Duyck28500622010-06-15 09:25:48 +00004167 /* clear the bits we are changing the status of */
4168 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellera9b89432014-03-25 07:45:26 +00004169 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004170 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004171 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004172 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004173 vmolr |= IXGBE_VMOLR_MPE;
Greg Rose670224f2013-02-22 02:14:39 +00004174 /* Only disable hardware filter vlans in promiscuous mode
4175 * if SR-IOV and VMDQ are disabled - otherwise ensure
4176 * that hardware VLAN filters remain enabled.
4177 */
Vlad Yasevich4556dc52014-11-21 23:52:52 -08004178 if (adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED |
4179 IXGBE_FLAG_SRIOV_ENABLED))
Jacob Kellera9b89432014-03-25 07:45:26 +00004180 vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004181 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004182 if (netdev->flags & IFF_ALLMULTI) {
4183 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004184 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004185 }
Jacob Kellera9b89432014-03-25 07:45:26 +00004186 vlnctrl |= IXGBE_VLNCTRL_VFE;
Emil Tantilove433ea12010-05-13 17:33:00 +00004187 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004188 }
4189
4190 /*
4191 * Write addresses to available RAR registers, if there is not
4192 * sufficient space to store all the addresses then enable
4193 * unicast promiscuous mode
4194 */
Jacob Keller5d7daa32014-03-29 06:51:25 +00004195 count = ixgbe_write_uc_addr_list(netdev, VMDQ_P(0));
John Fastabend9dcb3732012-04-15 06:44:25 +00004196 if (count < 0) {
4197 fctrl |= IXGBE_FCTRL_UPE;
4198 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004199 }
4200
Emil Tantilovcf789592013-10-26 08:13:20 +00004201 /* Write addresses to the MTA, if the attempt fails
4202 * then we should just turn on promiscuous mode so
4203 * that we can at least receive multicast traffic
4204 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004205 count = ixgbe_write_mc_addr_list(netdev);
4206 if (count < 0) {
4207 fctrl |= IXGBE_FCTRL_MPE;
4208 vmolr |= IXGBE_VMOLR_MPE;
4209 } else if (count) {
4210 vmolr |= IXGBE_VMOLR_ROMPE;
4211 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004212
4213 if (hw->mac.type != ixgbe_mac_82598EB) {
4214 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004215 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4216 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004217 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004218 }
4219
Ben Greear3f2d1c02012-03-08 08:28:41 +00004220 /* This is useful for sniffing bad packets. */
4221 if (adapter->netdev->features & NETIF_F_RXALL) {
4222 /* UPE and MPE will be handled by normal PROMISC logic
4223 * in e1000e_set_rx_mode */
4224 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4225 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4226 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4227
4228 fctrl &= ~(IXGBE_FCTRL_DPF);
4229 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4230 }
4231
Jacob Kellera9b89432014-03-25 07:45:26 +00004232 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004233 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004234
Patrick McHardyf6469682013-04-19 02:04:27 +00004235 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004236 ixgbe_vlan_strip_enable(adapter);
4237 else
4238 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004239}
4240
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004241static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4242{
4243 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004244
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004245 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
4246 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004247 napi_enable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004248 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004249}
4250
4251static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4252{
4253 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004254
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004255 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004256 napi_disable(&adapter->q_vector[q_idx]->napi);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004257 while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) {
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004258 pr_info("QV %d locked\n", q_idx);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004259 usleep_range(1000, 20000);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004260 }
4261 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004262}
4263
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004264#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004265/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004266 * ixgbe_configure_dcb - Configure DCB hardware
4267 * @adapter: ixgbe adapter struct
4268 *
4269 * This is called by the driver on open to configure the DCB hardware.
4270 * This is also called by the gennetlink interface when reconfiguring
4271 * the DCB state.
4272 */
4273static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4274{
4275 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00004276 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004277
Alexander Duyck67ebd792010-08-19 13:34:04 +00004278 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4279 if (hw->mac.type == ixgbe_mac_82598EB)
4280 netif_set_gso_max_size(adapter->netdev, 65536);
4281 return;
4282 }
4283
4284 if (hw->mac.type == ixgbe_mac_82598EB)
4285 netif_set_gso_max_size(adapter->netdev, 32768);
4286
John Fastabendb1208182011-10-15 05:00:10 +00004287#ifdef IXGBE_FCOE
4288 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4289 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4290#endif
4291
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004292 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004293 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004294 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4295 DCB_TX_CONFIG);
4296 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4297 DCB_RX_CONFIG);
4298 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004299 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4300 ixgbe_dcb_hw_ets(&adapter->hw,
4301 adapter->ixgbe_ieee_ets,
4302 max_frame);
4303 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4304 adapter->ixgbe_ieee_pfc->pfc_en,
4305 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004306 }
John Fastabend8187cd42011-02-23 05:58:08 +00004307
4308 /* Enable RSS Hash per TC */
4309 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004310 u32 msb = 0;
4311 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004312
Alexander Duyckd411a932012-06-30 00:14:01 +00004313 while (rss_i) {
4314 msb++;
4315 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004316 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004317
Alexander Duyck4ae63732012-06-22 06:46:33 +00004318 /* write msb to all 8 TCs in one write */
4319 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004320 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004321}
John Fastabend9da712d2011-08-23 03:14:22 +00004322#endif
4323
4324/* Additional bittime to account for IXGBE framing */
4325#define IXGBE_ETH_FRAMING 20
4326
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004327/**
John Fastabend9da712d2011-08-23 03:14:22 +00004328 * ixgbe_hpbthresh - calculate high water mark for flow control
4329 *
4330 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004331 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004332 */
4333static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4334{
4335 struct ixgbe_hw *hw = &adapter->hw;
4336 struct net_device *dev = adapter->netdev;
4337 int link, tc, kb, marker;
4338 u32 dv_id, rx_pba;
4339
4340 /* Calculate max LAN frame size */
4341 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4342
4343#ifdef IXGBE_FCOE
4344 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004345 if ((dev->features & NETIF_F_FCOE_MTU) &&
4346 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4347 (pb == ixgbe_fcoe_get_tc(adapter)))
4348 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004349#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004350
John Fastabend9da712d2011-08-23 03:14:22 +00004351 /* Calculate delay value for device */
4352 switch (hw->mac.type) {
4353 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004354 case ixgbe_mac_X550:
4355 case ixgbe_mac_X550EM_x:
John Fastabend9da712d2011-08-23 03:14:22 +00004356 dv_id = IXGBE_DV_X540(link, tc);
4357 break;
4358 default:
4359 dv_id = IXGBE_DV(link, tc);
4360 break;
4361 }
4362
4363 /* Loopback switch introduces additional latency */
4364 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4365 dv_id += IXGBE_B2BT(tc);
4366
4367 /* Delay value is calculated in bit times convert to KB */
4368 kb = IXGBE_BT2KB(dv_id);
4369 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4370
4371 marker = rx_pba - kb;
4372
4373 /* It is possible that the packet buffer is not large enough
4374 * to provide required headroom. In this case throw an error
4375 * to user and a do the best we can.
4376 */
4377 if (marker < 0) {
4378 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4379 "headroom to support flow control."
4380 "Decrease MTU or number of traffic classes\n", pb);
4381 marker = tc + 1;
4382 }
4383
4384 return marker;
4385}
4386
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004387/**
John Fastabend9da712d2011-08-23 03:14:22 +00004388 * ixgbe_lpbthresh - calculate low water mark for for flow control
4389 *
4390 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004391 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004392 */
Jacob Kellere5776622014-04-05 02:35:52 +00004393static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00004394{
4395 struct ixgbe_hw *hw = &adapter->hw;
4396 struct net_device *dev = adapter->netdev;
4397 int tc;
4398 u32 dv_id;
4399
4400 /* Calculate max LAN frame size */
4401 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4402
Jacob Kellere5776622014-04-05 02:35:52 +00004403#ifdef IXGBE_FCOE
4404 /* FCoE traffic class uses FCOE jumbo frames */
4405 if ((dev->features & NETIF_F_FCOE_MTU) &&
4406 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4407 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4408 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4409#endif
4410
John Fastabend9da712d2011-08-23 03:14:22 +00004411 /* Calculate delay value for device */
4412 switch (hw->mac.type) {
4413 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004414 case ixgbe_mac_X550:
4415 case ixgbe_mac_X550EM_x:
John Fastabend9da712d2011-08-23 03:14:22 +00004416 dv_id = IXGBE_LOW_DV_X540(tc);
4417 break;
4418 default:
4419 dv_id = IXGBE_LOW_DV(tc);
4420 break;
4421 }
4422
4423 /* Delay value is calculated in bit times convert to KB */
4424 return IXGBE_BT2KB(dv_id);
4425}
4426
4427/*
4428 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4429 */
4430static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4431{
4432 struct ixgbe_hw *hw = &adapter->hw;
4433 int num_tc = netdev_get_num_tc(adapter->netdev);
4434 int i;
4435
4436 if (!num_tc)
4437 num_tc = 1;
4438
John Fastabend9da712d2011-08-23 03:14:22 +00004439 for (i = 0; i < num_tc; i++) {
4440 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00004441 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00004442
4443 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00004444 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4445 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004446 }
Jacob Kellere5776622014-04-05 02:35:52 +00004447
4448 for (; i < MAX_TRAFFIC_CLASS; i++)
4449 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004450}
John Fastabend80605c652011-05-02 12:34:10 +00004451
4452static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4453{
John Fastabend80605c652011-05-02 12:34:10 +00004454 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004455 int hdrm;
4456 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004457
4458 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4459 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004460 hdrm = 32 << adapter->fdir_pballoc;
4461 else
4462 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004463
Alexander Duyckf7e10272011-07-21 00:40:35 +00004464 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004465 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004466}
4467
Alexander Duycke4911d52011-05-11 07:18:52 +00004468static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4469{
4470 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004471 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004472 struct ixgbe_fdir_filter *filter;
4473
4474 spin_lock(&adapter->fdir_perfect_lock);
4475
4476 if (!hlist_empty(&adapter->fdir_filter_list))
4477 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4478
Sasha Levinb67bfe02013-02-27 17:06:00 -08004479 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004480 &adapter->fdir_filter_list, fdir_node) {
4481 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004482 &filter->filter,
4483 filter->sw_idx,
4484 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4485 IXGBE_FDIR_DROP_QUEUE :
4486 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004487 }
4488
4489 spin_unlock(&adapter->fdir_perfect_lock);
4490}
4491
John Fastabend2a47fa42013-11-06 09:54:52 -08004492static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4493 struct ixgbe_adapter *adapter)
4494{
4495 struct ixgbe_hw *hw = &adapter->hw;
4496 u32 vmolr;
4497
4498 /* No unicast promiscuous support for VMDQ devices. */
4499 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4500 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4501
4502 /* clear the affected bit */
4503 vmolr &= ~IXGBE_VMOLR_MPE;
4504
4505 if (dev->flags & IFF_ALLMULTI) {
4506 vmolr |= IXGBE_VMOLR_MPE;
4507 } else {
4508 vmolr |= IXGBE_VMOLR_ROMPE;
4509 hw->mac.ops.update_mc_addr_list(hw, dev);
4510 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00004511 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08004512 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4513}
4514
John Fastabend2a47fa42013-11-06 09:54:52 -08004515static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4516{
4517 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004518 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004519 struct ixgbe_hw *hw = &adapter->hw;
4520 u16 pool = vadapter->pool;
4521 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4522 IXGBE_PSRTYPE_UDPHDR |
4523 IXGBE_PSRTYPE_IPV4HDR |
4524 IXGBE_PSRTYPE_L2HDR |
4525 IXGBE_PSRTYPE_IPV6HDR;
4526
4527 if (hw->mac.type == ixgbe_mac_82598EB)
4528 return;
4529
4530 if (rss_i > 3)
4531 psrtype |= 2 << 29;
4532 else if (rss_i > 1)
4533 psrtype |= 1 << 29;
4534
4535 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4536}
4537
4538/**
4539 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4540 * @rx_ring: ring to free buffers from
4541 **/
4542static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4543{
4544 struct device *dev = rx_ring->dev;
4545 unsigned long size;
4546 u16 i;
4547
4548 /* ring already cleared, nothing to do */
4549 if (!rx_ring->rx_buffer_info)
4550 return;
4551
4552 /* Free all the Rx ring sk_buffs */
4553 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyck18cb6522014-11-14 00:56:29 +00004554 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08004555
John Fastabend2a47fa42013-11-06 09:54:52 -08004556 if (rx_buffer->skb) {
4557 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00004558 if (IXGBE_CB(skb)->page_released)
John Fastabend2a47fa42013-11-06 09:54:52 -08004559 dma_unmap_page(dev,
4560 IXGBE_CB(skb)->dma,
4561 ixgbe_rx_bufsz(rx_ring),
4562 DMA_FROM_DEVICE);
John Fastabend2a47fa42013-11-06 09:54:52 -08004563 dev_kfree_skb(skb);
Junwei Zhang4d2fcfb2014-10-22 15:29:03 +00004564 rx_buffer->skb = NULL;
John Fastabend2a47fa42013-11-06 09:54:52 -08004565 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00004566
4567 if (!rx_buffer->page)
4568 continue;
4569
4570 dma_unmap_page(dev, rx_buffer->dma,
4571 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
4572 __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring));
4573
John Fastabend2a47fa42013-11-06 09:54:52 -08004574 rx_buffer->page = NULL;
4575 }
4576
4577 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4578 memset(rx_ring->rx_buffer_info, 0, size);
4579
4580 /* Zero out the descriptor ring */
4581 memset(rx_ring->desc, 0, rx_ring->size);
4582
4583 rx_ring->next_to_alloc = 0;
4584 rx_ring->next_to_clean = 0;
4585 rx_ring->next_to_use = 0;
4586}
4587
4588static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
4589 struct ixgbe_ring *rx_ring)
4590{
4591 struct ixgbe_adapter *adapter = vadapter->real_adapter;
4592 int index = rx_ring->queue_index + vadapter->rx_base_queue;
4593
4594 /* shutdown specific queue receive and wait for dma to settle */
4595 ixgbe_disable_rx_queue(adapter, rx_ring);
4596 usleep_range(10000, 20000);
4597 ixgbe_irq_disable_queues(adapter, ((u64)1 << index));
4598 ixgbe_clean_rx_ring(rx_ring);
4599 rx_ring->l2_accel_priv = NULL;
4600}
4601
John Fastabendae72c8d2013-11-09 07:11:26 +00004602static int ixgbe_fwd_ring_down(struct net_device *vdev,
4603 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08004604{
4605 struct ixgbe_adapter *adapter = accel->real_adapter;
4606 unsigned int rxbase = accel->rx_base_queue;
4607 unsigned int txbase = accel->tx_base_queue;
4608 int i;
4609
4610 netif_tx_stop_all_queues(vdev);
4611
4612 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4613 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4614 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
4615 }
4616
4617 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4618 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
4619 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
4620 }
4621
4622
4623 return 0;
4624}
4625
4626static int ixgbe_fwd_ring_up(struct net_device *vdev,
4627 struct ixgbe_fwd_adapter *accel)
4628{
4629 struct ixgbe_adapter *adapter = accel->real_adapter;
4630 unsigned int rxbase, txbase, queues;
4631 int i, baseq, err = 0;
4632
4633 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
4634 return 0;
4635
4636 baseq = accel->pool * adapter->num_rx_queues_per_pool;
4637 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4638 accel->pool, adapter->num_rx_pools,
4639 baseq, baseq + adapter->num_rx_queues_per_pool,
4640 adapter->fwd_bitmask);
4641
4642 accel->netdev = vdev;
4643 accel->rx_base_queue = rxbase = baseq;
4644 accel->tx_base_queue = txbase = baseq;
4645
4646 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
4647 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4648
4649 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4650 adapter->rx_ring[rxbase + i]->netdev = vdev;
4651 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
4652 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
4653 }
4654
4655 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4656 adapter->tx_ring[txbase + i]->netdev = vdev;
4657 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
4658 }
4659
4660 queues = min_t(unsigned int,
4661 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
4662 err = netif_set_real_num_tx_queues(vdev, queues);
4663 if (err)
4664 goto fwd_queue_err;
4665
John Fastabend2a47fa42013-11-06 09:54:52 -08004666 err = netif_set_real_num_rx_queues(vdev, queues);
4667 if (err)
4668 goto fwd_queue_err;
4669
4670 if (is_valid_ether_addr(vdev->dev_addr))
4671 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
4672
4673 ixgbe_fwd_psrtype(accel);
4674 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
4675 return err;
4676fwd_queue_err:
4677 ixgbe_fwd_ring_down(vdev, accel);
4678 return err;
4679}
4680
4681static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
4682{
4683 struct net_device *upper;
4684 struct list_head *iter;
4685 int err;
4686
4687 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
4688 if (netif_is_macvlan(upper)) {
4689 struct macvlan_dev *dfwd = netdev_priv(upper);
4690 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
4691
4692 if (dfwd->fwd_priv) {
4693 err = ixgbe_fwd_ring_up(upper, vadapter);
4694 if (err)
4695 continue;
4696 }
4697 }
4698 }
4699}
4700
Auke Kok9a799d72007-09-15 14:07:45 -07004701static void ixgbe_configure(struct ixgbe_adapter *adapter)
4702{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004703 struct ixgbe_hw *hw = &adapter->hw;
4704
John Fastabend80605c652011-05-02 12:34:10 +00004705 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004706#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00004707 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004708#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00004709 /*
4710 * We must restore virtualization before VLANs or else
4711 * the VLVF registers will not be populated
4712 */
4713 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004714
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004715 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004716 ixgbe_restore_vlan(adapter);
4717
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004718 switch (hw->mac.type) {
4719 case ixgbe_mac_82599EB:
4720 case ixgbe_mac_X540:
4721 hw->mac.ops.disable_rx_buff(hw);
4722 break;
4723 default:
4724 break;
4725 }
4726
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004727 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004728 ixgbe_init_fdir_signature_82599(&adapter->hw,
4729 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00004730 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
4731 ixgbe_init_fdir_perfect_82599(&adapter->hw,
4732 adapter->fdir_pballoc);
4733 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004734 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004735
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004736 switch (hw->mac.type) {
4737 case ixgbe_mac_82599EB:
4738 case ixgbe_mac_X540:
4739 hw->mac.ops.enable_rx_buff(hw);
4740 break;
4741 default:
4742 break;
4743 }
4744
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004745#ifdef IXGBE_FCOE
4746 /* configure FCoE L2 filters, redirection table, and Rx control */
4747 ixgbe_configure_fcoe(adapter);
4748
4749#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07004750 ixgbe_configure_tx(adapter);
4751 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08004752 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004753}
4754
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004755/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004756 * ixgbe_sfp_link_config - set up SFP+ link
4757 * @adapter: pointer to private adapter struct
4758 **/
4759static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
4760{
Alexander Duyck70864002011-04-27 09:13:56 +00004761 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004762 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00004763 * is that an SFP was inserted/removed after the reset
4764 * but before SFP detection was enabled. As such the best
4765 * solution is to just start searching as soon as we start
4766 */
4767 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
4768 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004769
Alexander Duyck70864002011-04-27 09:13:56 +00004770 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004771}
4772
4773/**
4774 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004775 * @hw: pointer to private hardware struct
4776 *
4777 * Returns 0 on success, negative on failure
4778 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004779static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004780{
Josh Hay3d292262012-12-15 03:28:19 +00004781 u32 speed;
4782 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07004783 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004784
4785 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00004786 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004787
4788 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00004789 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004790
Josh Hay3d292262012-12-15 03:28:19 +00004791 speed = hw->phy.autoneg_advertised;
4792 if ((!speed) && (hw->mac.ops.get_link_capabilities))
4793 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
4794 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004795 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00004796 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004797
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004798 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00004799 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00004800
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004801 return ret;
4802}
4803
Alexander Duycka34bcff2010-08-19 13:39:20 +00004804static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004805{
Auke Kok9a799d72007-09-15 14:07:45 -07004806 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004807 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004808
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004809 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004810 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4811 IXGBE_GPIE_OCD;
4812 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004813 /*
4814 * use EIAM to auto-mask when MSI-X interrupt is asserted
4815 * this saves a register write for every interrupt
4816 */
4817 switch (hw->mac.type) {
4818 case ixgbe_mac_82598EB:
4819 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4820 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004821 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004822 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004823 case ixgbe_mac_X550:
4824 case ixgbe_mac_X550EM_x:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004825 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004826 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4827 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4828 break;
4829 }
4830 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004831 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4832 * specifically only auto mask tx and rx interrupts */
4833 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004834 }
4835
Alexander Duycka34bcff2010-08-19 13:39:20 +00004836 /* XXX: to interrupt immediately for EICS writes, enable this */
4837 /* gpie |= IXGBE_GPIE_EIMEN; */
4838
4839 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4840 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004841
4842 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4843 case IXGBE_82599_VMDQ_8Q_MASK:
4844 gpie |= IXGBE_GPIE_VTMODE_16;
4845 break;
4846 case IXGBE_82599_VMDQ_4Q_MASK:
4847 gpie |= IXGBE_GPIE_VTMODE_32;
4848 break;
4849 default:
4850 gpie |= IXGBE_GPIE_VTMODE_64;
4851 break;
4852 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004853 }
4854
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004855 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004856 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4857 switch (adapter->hw.mac.type) {
4858 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07004859 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00004860 break;
4861 case ixgbe_mac_X540:
4862 gpie |= IXGBE_EIMS_TS;
4863 break;
4864 default:
4865 break;
4866 }
4867 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004868
Alexander Duycka34bcff2010-08-19 13:39:20 +00004869 /* Enable fan failure interrupt */
4870 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07004871 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004872
Don Skidmore2698b202011-04-13 07:01:52 +00004873 if (hw->mac.type == ixgbe_mac_82599EB) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07004874 gpie |= IXGBE_SDP1_GPIEN_8259X;
4875 gpie |= IXGBE_SDP2_GPIEN_8259X;
Don Skidmore2698b202011-04-13 07:01:52 +00004876 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004877
4878 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4879}
4880
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004881static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004882{
4883 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004884 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004885 u32 ctrl_ext;
4886
4887 ixgbe_get_hw_control(adapter);
4888 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004889
Auke Kok9a799d72007-09-15 14:07:45 -07004890 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4891 ixgbe_configure_msix(adapter);
4892 else
4893 ixgbe_configure_msi_and_legacy(adapter);
4894
Emil Tantilovec74a472012-09-20 03:33:56 +00004895 /* enable the optics for 82599 SFP+ fiber */
4896 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004897 hw->mac.ops.enable_tx_laser(hw);
4898
Don Skidmore961fac82015-06-09 16:09:47 -07004899 if (hw->phy.ops.set_phy_power)
4900 hw->phy.ops.set_phy_power(hw, true);
4901
Peter Zijlstra4e857c52014-03-17 18:06:10 +01004902 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07004903 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004904 ixgbe_napi_enable_all(adapter);
4905
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004906 if (ixgbe_is_sfp(hw)) {
4907 ixgbe_sfp_link_config(adapter);
4908 } else {
4909 err = ixgbe_non_sfp_link_config(hw);
4910 if (err)
4911 e_err(probe, "link_config FAILED %d\n", err);
4912 }
4913
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004914 /* clear any pending interrupts, may auto mask */
4915 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004916 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004917
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004918 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004919 * If this adapter has a fan, check to see if we had a failure
4920 * before we enabled the interrupt.
4921 */
4922 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4923 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4924 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004925 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004926 }
4927
Auke Kok9a799d72007-09-15 14:07:45 -07004928 /* bring the link up in the watchdog, this could race with our first
4929 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004930 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4931 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004932 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004933
4934 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4935 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4936 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4937 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004938}
4939
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004940void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4941{
4942 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004943 /* put off any impending NetWatchDogTimeout */
4944 adapter->netdev->trans_start = jiffies;
4945
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004946 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004947 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004948 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004949 /*
4950 * If SR-IOV enabled then wait a bit before bringing the adapter
4951 * back up to give the VFs time to respond to the reset. The
4952 * two second wait is based upon the watchdog timer cycle in
4953 * the VF driver.
4954 */
4955 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4956 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004957 ixgbe_up(adapter);
4958 clear_bit(__IXGBE_RESETTING, &adapter->state);
4959}
4960
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004961void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004962{
4963 /* hardware has been reset, we need to reload some things */
4964 ixgbe_configure(adapter);
4965
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004966 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004967}
4968
4969void ixgbe_reset(struct ixgbe_adapter *adapter)
4970{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004971 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004972 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004973 int err;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004974 u8 old_addr[ETH_ALEN];
Don Skidmore8ca783a2009-05-26 20:40:47 -07004975
Mark Rustadb0483c82014-01-14 18:53:17 -08004976 if (ixgbe_removed(hw->hw_addr))
4977 return;
Alexander Duyck70864002011-04-27 09:13:56 +00004978 /* lock SFP init bit to prevent race conditions with the watchdog */
4979 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4980 usleep_range(1000, 2000);
4981
4982 /* clear all SFP and link config related flags while holding SFP_INIT */
4983 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4984 IXGBE_FLAG2_SFP_NEEDS_RESET);
4985 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4986
Don Skidmore8ca783a2009-05-26 20:40:47 -07004987 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004988 switch (err) {
4989 case 0:
4990 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004991 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004992 break;
4993 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004994 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004995 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004996 case IXGBE_ERR_EEPROM_VERSION:
4997 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004998 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004999 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005000 "your hardware. If you are experiencing problems "
5001 "please contact your Intel or hardware "
5002 "representative who provided you with this "
5003 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005004 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005005 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005006 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005007 }
Auke Kok9a799d72007-09-15 14:07:45 -07005008
Alexander Duyck70864002011-04-27 09:13:56 +00005009 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Jacob Keller5d7daa32014-03-29 06:51:25 +00005010 /* do not flush user set addresses */
5011 memcpy(old_addr, &adapter->mac_table[0].addr, netdev->addr_len);
5012 ixgbe_flush_sw_mac_table(adapter);
5013 ixgbe_mac_set_default_filter(adapter, old_addr);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005014
5015 /* update SAN MAC vmdq pool selection */
5016 if (hw->mac.san_mac_rar_index)
5017 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005018
Jacob Keller8fecf672013-06-21 08:14:32 +00005019 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005020 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005021
5022 if (hw->phy.ops.set_phy_power) {
5023 if (!netif_running(adapter->netdev) && !adapter->wol)
5024 hw->phy.ops.set_phy_power(hw, false);
5025 else
5026 hw->phy.ops.set_phy_power(hw, true);
5027 }
Auke Kok9a799d72007-09-15 14:07:45 -07005028}
5029
Auke Kok9a799d72007-09-15 14:07:45 -07005030/**
Auke Kok9a799d72007-09-15 14:07:45 -07005031 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005032 * @tx_ring: ring to be cleaned
5033 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005034static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005035{
5036 struct ixgbe_tx_buffer *tx_buffer_info;
5037 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005038 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07005039
Alexander Duyck84418e32010-08-19 13:40:54 +00005040 /* ring already cleared, nothing to do */
5041 if (!tx_ring->tx_buffer_info)
5042 return;
Auke Kok9a799d72007-09-15 14:07:45 -07005043
Alexander Duyck84418e32010-08-19 13:40:54 +00005044 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07005045 for (i = 0; i < tx_ring->count; i++) {
5046 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005047 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07005048 }
5049
John Fastabenddad8a3b2012-04-23 12:22:39 +00005050 netdev_tx_reset_queue(txring_txq(tx_ring));
5051
Auke Kok9a799d72007-09-15 14:07:45 -07005052 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5053 memset(tx_ring->tx_buffer_info, 0, size);
5054
5055 /* Zero out the descriptor ring */
5056 memset(tx_ring->desc, 0, tx_ring->size);
5057
5058 tx_ring->next_to_use = 0;
5059 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005060}
5061
5062/**
Auke Kok9a799d72007-09-15 14:07:45 -07005063 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5064 * @adapter: board private structure
5065 **/
5066static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5067{
5068 int i;
5069
5070 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005071 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005072}
5073
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005074/**
5075 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5076 * @adapter: board private structure
5077 **/
5078static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5079{
5080 int i;
5081
5082 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005083 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005084}
5085
Alexander Duycke4911d52011-05-11 07:18:52 +00005086static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5087{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005088 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005089 struct ixgbe_fdir_filter *filter;
5090
5091 spin_lock(&adapter->fdir_perfect_lock);
5092
Sasha Levinb67bfe02013-02-27 17:06:00 -08005093 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005094 &adapter->fdir_filter_list, fdir_node) {
5095 hlist_del(&filter->fdir_node);
5096 kfree(filter);
5097 }
5098 adapter->fdir_filter_count = 0;
5099
5100 spin_unlock(&adapter->fdir_perfect_lock);
5101}
5102
Auke Kok9a799d72007-09-15 14:07:45 -07005103void ixgbe_down(struct ixgbe_adapter *adapter)
5104{
5105 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005106 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08005107 struct net_device *upper;
5108 struct list_head *iter;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005109 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005110
5111 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005112 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5113 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005114
5115 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005116 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005117
Yi Zou2d39d572011-01-06 14:29:56 +00005118 /* disable all enabled rx queues */
5119 for (i = 0; i < adapter->num_rx_queues; i++)
5120 /* this call also flushes the previous write */
5121 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5122
Don Skidmore032b4322011-03-18 09:32:53 +00005123 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005124
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005125 netif_tx_stop_all_queues(netdev);
5126
Alexander Duyck70864002011-04-27 09:13:56 +00005127 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005128 netif_carrier_off(netdev);
5129 netif_tx_disable(netdev);
5130
John Fastabend2a47fa42013-11-06 09:54:52 -08005131 /* disable any upper devices */
5132 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
5133 if (netif_is_macvlan(upper)) {
5134 struct macvlan_dev *vlan = netdev_priv(upper);
5135
5136 if (vlan->fwd_priv) {
5137 netif_tx_stop_all_queues(upper);
5138 netif_carrier_off(upper);
5139 netif_tx_disable(upper);
5140 }
5141 }
5142 }
5143
John Fastabendc0dfb902010-04-27 02:13:39 +00005144 ixgbe_irq_disable(adapter);
5145
5146 ixgbe_napi_disable_all(adapter);
5147
Alexander Duyckd034acf2011-04-27 09:25:34 +00005148 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
5149 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00005150 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5151
5152 del_timer_sync(&adapter->service_timer);
5153
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005154 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005155 /* Clear EITR Select mapping */
5156 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5157
5158 /* Mark all the VFs as inactive */
5159 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005160 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005161
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005162 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005163 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005164
Auke Kok9a799d72007-09-15 14:07:45 -07005165 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005166 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005167 }
5168
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005169 /* disable transmits in the hardware now that interrupts are off */
5170 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005171 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005172 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005173 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005174
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005175 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005176 switch (hw->mac.type) {
5177 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005178 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005179 case ixgbe_mac_X550:
5180 case ixgbe_mac_X550EM_x:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005181 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005182 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5183 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005184 break;
5185 default:
5186 break;
5187 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005188
Paul Larson6f4a0e42008-06-24 17:00:56 -07005189 if (!pci_channel_offline(adapter->pdev))
5190 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005191
Emil Tantilovec74a472012-09-20 03:33:56 +00005192 /* power down the optics for 82599 SFP+ fiber */
5193 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005194 hw->mac.ops.disable_tx_laser(hw);
5195
Auke Kok9a799d72007-09-15 14:07:45 -07005196 ixgbe_clean_all_tx_rings(adapter);
5197 ixgbe_clean_all_rx_rings(adapter);
5198
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005199#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07005200 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00005201 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07005202#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005203}
5204
Auke Kok9a799d72007-09-15 14:07:45 -07005205/**
Auke Kok9a799d72007-09-15 14:07:45 -07005206 * ixgbe_tx_timeout - Respond to a Tx Hang
5207 * @netdev: network interface device structure
5208 **/
5209static void ixgbe_tx_timeout(struct net_device *netdev)
5210{
5211 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5212
5213 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005214 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005215}
5216
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005217/**
Auke Kok9a799d72007-09-15 14:07:45 -07005218 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5219 * @adapter: board private structure to initialize
5220 *
5221 * ixgbe_sw_init initializes the Adapter private data structure.
5222 * Fields are initialized based on PCI device information and
5223 * OS network device settings (MTU size).
5224 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05005225static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005226{
5227 struct ixgbe_hw *hw = &adapter->hw;
5228 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005229 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005230 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005231#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005232 int j;
5233 struct tc_configuration *tc;
5234#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005235
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005236 /* PCI config space info */
5237
5238 hw->vendor_id = pdev->vendor;
5239 hw->device_id = pdev->device;
5240 hw->revision_id = pdev->revision;
5241 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5242 hw->subsystem_device_id = pdev->subsystem_device;
5243
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005244 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00005245 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005246 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005247 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5248 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005249 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5250 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005251 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5252 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005253 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5254#ifdef CONFIG_IXGBE_DCA
5255 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5256#endif
5257#ifdef IXGBE_FCOE
5258 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5259 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5260#ifdef CONFIG_IXGBE_DCB
5261 /* Default traffic class to use for FCoE */
5262 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5263#endif /* CONFIG_IXGBE_DCB */
5264#endif /* IXGBE_FCOE */
5265
Jacob Keller5d7daa32014-03-29 06:51:25 +00005266 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5267 hw->mac.num_rar_entries,
5268 GFP_ATOMIC);
5269
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005270 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005271 switch (hw->mac.type) {
5272 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005273 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
5274 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
5275
Don Skidmorebf069c92009-05-07 10:39:54 +00005276 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5277 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005278
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005279 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005280 adapter->ring_feature[RING_F_FDIR].limit = 0;
5281 adapter->atr_sample_rate = 0;
5282 adapter->fdir_pballoc = 0;
5283#ifdef IXGBE_FCOE
5284 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5285 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5286#ifdef CONFIG_IXGBE_DCB
5287 adapter->fcoe.up = 0;
5288#endif /* IXGBE_DCB */
5289#endif /* IXGBE_FCOE */
5290 break;
5291 case ixgbe_mac_82599EB:
5292 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5293 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005294 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005295 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005296 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005297 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5298 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005299 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005300 case ixgbe_mac_X550EM_x:
5301 case ixgbe_mac_X550:
5302#ifdef CONFIG_IXGBE_DCA
5303 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
5304#endif
5305 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08005306 default:
5307 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005308 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005309
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005310#ifdef IXGBE_FCOE
5311 /* FCoE support exists, always init the FCoE lock */
5312 spin_lock_init(&adapter->fcoe.lock);
5313
5314#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005315 /* n-tuple support exists, always init our spinlock */
5316 spin_lock_init(&adapter->fdir_perfect_lock);
5317
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005318#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005319 switch (hw->mac.type) {
5320 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005321 case ixgbe_mac_X550:
5322 case ixgbe_mac_X550EM_x:
John Fastabend4de2a022011-09-27 03:52:01 +00005323 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5324 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5325 break;
5326 default:
5327 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5328 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5329 break;
5330 }
5331
Alexander Duyck2f90b862008-11-20 20:52:10 -08005332 /* Configure DCB traffic classes */
5333 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5334 tc = &adapter->dcb_cfg.tc_config[j];
5335 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5336 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5337 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5338 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5339 tc->dcb_pfc = pfc_disabled;
5340 }
John Fastabend4de2a022011-09-27 03:52:01 +00005341
5342 /* Initialize default user to priority mapping, UPx->TC0 */
5343 tc = &adapter->dcb_cfg.tc_config[0];
5344 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5345 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5346
Alexander Duyck2f90b862008-11-20 20:52:10 -08005347 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5348 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005349 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005350 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005351 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00005352 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5353 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08005354
5355#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005356
5357 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005358 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005359 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005360 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005361 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5362 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005363 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005364
Alexander Duyck99d74482012-05-09 08:09:25 +00005365#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005366 if (max_vfs > 0)
5367 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 +00005368
Jacob Keller170e8542013-11-09 04:52:32 -08005369 /* assign number of SR-IOV VFs */
5370 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005371 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Jacob Keller170e8542013-11-09 04:52:32 -08005372 adapter->num_vfs = 0;
5373 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5374 } else {
5375 adapter->num_vfs = max_vfs;
5376 }
5377 }
5378#endif /* CONFIG_PCI_IOV */
5379
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005380 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005381 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005382 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005383
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005384 /* set default ring sizes */
5385 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5386 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5387
Alexander Duyckbd198052011-06-11 01:45:08 +00005388 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005389 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005390
Auke Kok9a799d72007-09-15 14:07:45 -07005391 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005392 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005393 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005394 return -EIO;
5395 }
5396
John Fastabend2a47fa42013-11-06 09:54:52 -08005397 /* PF holds first pool slot */
5398 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005399 set_bit(__IXGBE_DOWN, &adapter->state);
5400
5401 return 0;
5402}
5403
5404/**
5405 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005406 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005407 *
5408 * Return 0 on success, negative on failure
5409 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005410int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005411{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005412 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005413 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005414 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005415 int size;
5416
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005417 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005418
5419 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005420 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005421
Mark Rustadca8dfe22014-07-24 06:19:24 +00005422 tx_ring->tx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005423 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005424 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005425 if (!tx_ring->tx_buffer_info)
5426 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005427
John Stultz827da442013-10-07 15:51:58 -07005428 u64_stats_init(&tx_ring->syncp);
5429
Auke Kok9a799d72007-09-15 14:07:45 -07005430 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005431 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005432 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005433
Mark Rustadca8dfe22014-07-24 06:19:24 +00005434 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005435 tx_ring->desc = dma_alloc_coherent(dev,
5436 tx_ring->size,
5437 &tx_ring->dma,
5438 GFP_KERNEL);
5439 set_dev_node(dev, orig_node);
5440 if (!tx_ring->desc)
5441 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5442 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005443 if (!tx_ring->desc)
5444 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005445
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005446 tx_ring->next_to_use = 0;
5447 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005448 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005449
5450err:
5451 vfree(tx_ring->tx_buffer_info);
5452 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005453 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005454 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005455}
5456
5457/**
Alexander Duyck69888672008-09-11 20:05:39 -07005458 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5459 * @adapter: board private structure
5460 *
5461 * If this function returns with an error, then it's possible one or
5462 * more of the rings is populated (while the rest are not). It is the
5463 * callers duty to clean those orphaned rings.
5464 *
5465 * Return 0 on success, negative on failure
5466 **/
5467static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5468{
5469 int i, err = 0;
5470
5471 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005472 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005473 if (!err)
5474 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005475
Emil Tantilov396e7992010-07-01 20:05:12 +00005476 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005477 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07005478 }
5479
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005480 return 0;
5481err_setup_tx:
5482 /* rewind the index freeing the rings as we go */
5483 while (i--)
5484 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005485 return err;
5486}
5487
5488/**
Auke Kok9a799d72007-09-15 14:07:45 -07005489 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005490 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005491 *
5492 * Returns 0 on success, negative on failure
5493 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005494int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005495{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005496 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005497 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005498 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005499 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005500
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005501 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005502
5503 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005504 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005505
Mark Rustadca8dfe22014-07-24 06:19:24 +00005506 rx_ring->rx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005507 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005508 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005509 if (!rx_ring->rx_buffer_info)
5510 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005511
John Stultz827da442013-10-07 15:51:58 -07005512 u64_stats_init(&rx_ring->syncp);
5513
Auke Kok9a799d72007-09-15 14:07:45 -07005514 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005515 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5516 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005517
Mark Rustadca8dfe22014-07-24 06:19:24 +00005518 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005519 rx_ring->desc = dma_alloc_coherent(dev,
5520 rx_ring->size,
5521 &rx_ring->dma,
5522 GFP_KERNEL);
5523 set_dev_node(dev, orig_node);
5524 if (!rx_ring->desc)
5525 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5526 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005527 if (!rx_ring->desc)
5528 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005529
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005530 rx_ring->next_to_clean = 0;
5531 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005532
5533 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005534err:
5535 vfree(rx_ring->rx_buffer_info);
5536 rx_ring->rx_buffer_info = NULL;
5537 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005538 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005539}
5540
5541/**
Alexander Duyck69888672008-09-11 20:05:39 -07005542 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5543 * @adapter: board private structure
5544 *
5545 * If this function returns with an error, then it's possible one or
5546 * more of the rings is populated (while the rest are not). It is the
5547 * callers duty to clean those orphaned rings.
5548 *
5549 * Return 0 on success, negative on failure
5550 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005551static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5552{
5553 int i, err = 0;
5554
5555 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005556 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005557 if (!err)
5558 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005559
Emil Tantilov396e7992010-07-01 20:05:12 +00005560 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005561 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07005562 }
5563
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005564#ifdef IXGBE_FCOE
5565 err = ixgbe_setup_fcoe_ddp_resources(adapter);
5566 if (!err)
5567#endif
5568 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005569err_setup_rx:
5570 /* rewind the index freeing the rings as we go */
5571 while (i--)
5572 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005573 return err;
5574}
5575
5576/**
Auke Kok9a799d72007-09-15 14:07:45 -07005577 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005578 * @tx_ring: Tx descriptor ring for a specific queue
5579 *
5580 * Free all transmit software resources
5581 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005582void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005583{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005584 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005585
5586 vfree(tx_ring->tx_buffer_info);
5587 tx_ring->tx_buffer_info = NULL;
5588
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005589 /* if not set, then don't free */
5590 if (!tx_ring->desc)
5591 return;
5592
5593 dma_free_coherent(tx_ring->dev, tx_ring->size,
5594 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005595
5596 tx_ring->desc = NULL;
5597}
5598
5599/**
5600 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5601 * @adapter: board private structure
5602 *
5603 * Free all transmit software resources
5604 **/
5605static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5606{
5607 int i;
5608
5609 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005610 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005611 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005612}
5613
5614/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005615 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005616 * @rx_ring: ring to clean the resources from
5617 *
5618 * Free all receive software resources
5619 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005620void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005621{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005622 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005623
5624 vfree(rx_ring->rx_buffer_info);
5625 rx_ring->rx_buffer_info = NULL;
5626
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005627 /* if not set, then don't free */
5628 if (!rx_ring->desc)
5629 return;
5630
5631 dma_free_coherent(rx_ring->dev, rx_ring->size,
5632 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005633
5634 rx_ring->desc = NULL;
5635}
5636
5637/**
5638 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5639 * @adapter: board private structure
5640 *
5641 * Free all receive software resources
5642 **/
5643static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5644{
5645 int i;
5646
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005647#ifdef IXGBE_FCOE
5648 ixgbe_free_fcoe_ddp_resources(adapter);
5649
5650#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005651 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005652 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005653 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005654}
5655
5656/**
Auke Kok9a799d72007-09-15 14:07:45 -07005657 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5658 * @netdev: network interface device structure
5659 * @new_mtu: new value for maximum frame size
5660 *
5661 * Returns 0 on success, negative on failure
5662 **/
5663static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5664{
5665 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5666 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5667
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005668 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005669 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5670 return -EINVAL;
5671
5672 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00005673 * For 82599EB we cannot allow legacy VFs to enable their receive
5674 * paths when MTU greater than 1500 is configured. So display a
5675 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00005676 */
5677 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5678 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Alexander Duyckc5604512013-01-09 08:50:42 +00005679 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck872844d2012-08-15 02:10:43 +00005680 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005681
Emil Tantilov396e7992010-07-01 20:05:12 +00005682 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005683
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005684 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005685 netdev->mtu = new_mtu;
5686
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005687 if (netif_running(netdev))
5688 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005689
5690 return 0;
5691}
5692
5693/**
5694 * ixgbe_open - Called when a network interface is made active
5695 * @netdev: network interface device structure
5696 *
5697 * Returns 0 on success, negative value on failure
5698 *
5699 * The open entry point is called when a network interface is made
5700 * active by the system (IFF_UP). At this point all resources needed
5701 * for transmit and receive operations are allocated, the interrupt
5702 * handler is registered with the OS, the watchdog timer is started,
5703 * and the stack is notified that the interface is ready.
5704 **/
5705static int ixgbe_open(struct net_device *netdev)
5706{
5707 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07005708 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08005709 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07005710
Auke Kok4bebfaa2008-02-11 09:26:01 -08005711 /* disallow open during test */
5712 if (test_bit(__IXGBE_TESTING, &adapter->state))
5713 return -EBUSY;
5714
Jesse Brandeburg54386462009-04-17 20:44:27 +00005715 netif_carrier_off(netdev);
5716
Auke Kok9a799d72007-09-15 14:07:45 -07005717 /* allocate transmit descriptors */
5718 err = ixgbe_setup_all_tx_resources(adapter);
5719 if (err)
5720 goto err_setup_tx;
5721
Auke Kok9a799d72007-09-15 14:07:45 -07005722 /* allocate receive descriptors */
5723 err = ixgbe_setup_all_rx_resources(adapter);
5724 if (err)
5725 goto err_setup_rx;
5726
5727 ixgbe_configure(adapter);
5728
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005729 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005730 if (err)
5731 goto err_req_irq;
5732
Alexander Duyckac802f52012-07-12 05:52:53 +00005733 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08005734 if (adapter->num_rx_pools > 1)
5735 queues = adapter->num_rx_queues_per_pool;
5736 else
5737 queues = adapter->num_tx_queues;
5738
5739 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00005740 if (err)
5741 goto err_set_queues;
5742
John Fastabend2a47fa42013-11-06 09:54:52 -08005743 if (adapter->num_rx_pools > 1 &&
5744 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
5745 queues = IXGBE_MAX_L2A_QUEUES;
5746 else
5747 queues = adapter->num_rx_queues;
5748 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00005749 if (err)
5750 goto err_set_queues;
5751
Jacob Keller1a71ab22012-08-25 03:54:19 +00005752 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005753
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005754 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005755
Don Skidmore3f207802014-12-23 07:40:34 +00005756#if IS_ENABLED(CONFIG_IXGBE_VXLAN)
5757 vxlan_get_rx_port(netdev);
5758
5759#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005760 return 0;
5761
Alexander Duyckac802f52012-07-12 05:52:53 +00005762err_set_queues:
5763 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005764err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005765 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005766 if (hw->phy.ops.set_phy_power && !adapter->wol)
5767 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005768err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005769 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005770err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07005771 ixgbe_reset(adapter);
5772
5773 return err;
5774}
5775
Jacob Kellera0cccce2014-05-16 05:12:29 +00005776static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
5777{
5778 ixgbe_ptp_suspend(adapter);
5779
5780 ixgbe_down(adapter);
5781 ixgbe_free_irq(adapter);
5782
5783 ixgbe_free_all_tx_resources(adapter);
5784 ixgbe_free_all_rx_resources(adapter);
5785}
5786
Auke Kok9a799d72007-09-15 14:07:45 -07005787/**
5788 * ixgbe_close - Disables a network interface
5789 * @netdev: network interface device structure
5790 *
5791 * Returns 0, this is not allowed to fail
5792 *
5793 * The close entry point is called when an interface is de-activated
5794 * by the OS. The hardware is still under the drivers control, but
5795 * needs to be disabled. A global MAC reset is issued to stop the
5796 * hardware, and all transmit and receive resources are freed.
5797 **/
5798static int ixgbe_close(struct net_device *netdev)
5799{
5800 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005801
Jacob Keller1a71ab22012-08-25 03:54:19 +00005802 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005803
Jacob Kellera0cccce2014-05-16 05:12:29 +00005804 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005805
Alexander Duycke4911d52011-05-11 07:18:52 +00005806 ixgbe_fdir_filter_exit(adapter);
5807
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005808 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005809
5810 return 0;
5811}
5812
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005813#ifdef CONFIG_PM
5814static int ixgbe_resume(struct pci_dev *pdev)
5815{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005816 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5817 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005818 u32 err;
5819
Mark Rustad0391bbe2014-02-28 15:48:55 -08005820 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005821 pci_set_power_state(pdev, PCI_D0);
5822 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005823 /*
5824 * pci_restore_state clears dev->state_saved so call
5825 * pci_save_state to restore it.
5826 */
5827 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005828
5829 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005830 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005831 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005832 return err;
5833 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005834 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00005835 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005836 pci_set_master(pdev);
5837
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005838 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005839
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005840 ixgbe_reset(adapter);
5841
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005842 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5843
Alexander Duyckac802f52012-07-12 05:52:53 +00005844 rtnl_lock();
5845 err = ixgbe_init_interrupt_scheme(adapter);
5846 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005847 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005848
5849 rtnl_unlock();
5850
5851 if (err)
5852 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005853
5854 netif_device_attach(netdev);
5855
5856 return 0;
5857}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005858#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005859
5860static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005861{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005862 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5863 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005864 struct ixgbe_hw *hw = &adapter->hw;
5865 u32 ctrl, fctrl;
5866 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005867#ifdef CONFIG_PM
5868 int retval = 0;
5869#endif
5870
5871 netif_device_detach(netdev);
5872
akepner499ab5c2013-03-13 14:54:58 +00005873 rtnl_lock();
Jacob Kellera0cccce2014-05-16 05:12:29 +00005874 if (netif_running(netdev))
5875 ixgbe_close_suspend(adapter);
akepner499ab5c2013-03-13 14:54:58 +00005876 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005877
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005878 ixgbe_clear_interrupt_scheme(adapter);
5879
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005880#ifdef CONFIG_PM
5881 retval = pci_save_state(pdev);
5882 if (retval)
5883 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005884
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005885#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00005886 if (hw->mac.ops.stop_link_on_d3)
5887 hw->mac.ops.stop_link_on_d3(hw);
5888
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005889 if (wufc) {
5890 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005891
Emil Tantilovec74a472012-09-20 03:33:56 +00005892 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5893 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005894 hw->mac.ops.enable_tx_laser(hw);
5895
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005896 /* turn on all-multi mode if wake on multicast is enabled */
5897 if (wufc & IXGBE_WUFC_MC) {
5898 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5899 fctrl |= IXGBE_FCTRL_MPE;
5900 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5901 }
5902
5903 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5904 ctrl |= IXGBE_CTRL_GIO_DIS;
5905 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5906
5907 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5908 } else {
5909 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5910 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5911 }
5912
Alexander Duyckbd508172010-11-16 19:27:03 -08005913 switch (hw->mac.type) {
5914 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005915 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005916 break;
5917 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005918 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005919 case ixgbe_mac_X550:
5920 case ixgbe_mac_X550EM_x:
Alexander Duyckbd508172010-11-16 19:27:03 -08005921 pci_wake_from_d3(pdev, !!wufc);
5922 break;
5923 default:
5924 break;
5925 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005926
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005927 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07005928 if (hw->phy.ops.set_phy_power && !*enable_wake)
5929 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005930
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005931 ixgbe_release_hw_control(adapter);
5932
Mark Rustad41c62842014-03-12 00:38:35 +00005933 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
5934 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005935
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005936 return 0;
5937}
5938
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005939#ifdef CONFIG_PM
5940static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5941{
5942 int retval;
5943 bool wake;
5944
5945 retval = __ixgbe_shutdown(pdev, &wake);
5946 if (retval)
5947 return retval;
5948
5949 if (wake) {
5950 pci_prepare_to_sleep(pdev);
5951 } else {
5952 pci_wake_from_d3(pdev, false);
5953 pci_set_power_state(pdev, PCI_D3hot);
5954 }
5955
5956 return 0;
5957}
5958#endif /* CONFIG_PM */
5959
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005960static void ixgbe_shutdown(struct pci_dev *pdev)
5961{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005962 bool wake;
5963
5964 __ixgbe_shutdown(pdev, &wake);
5965
5966 if (system_state == SYSTEM_POWER_OFF) {
5967 pci_wake_from_d3(pdev, wake);
5968 pci_set_power_state(pdev, PCI_D3hot);
5969 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005970}
5971
5972/**
Auke Kok9a799d72007-09-15 14:07:45 -07005973 * ixgbe_update_stats - Update the board statistics counters.
5974 * @adapter: board private structure
5975 **/
5976void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5977{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005978 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005979 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005980 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005981 u64 total_mpc = 0;
5982 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005983 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5984 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005985 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005986
Don Skidmored08935c2010-06-11 13:20:29 +00005987 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5988 test_bit(__IXGBE_RESETTING, &adapter->state))
5989 return;
5990
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005991 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005992 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005993 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005994 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005995 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5996 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005997 }
5998 adapter->rsc_total_count = rsc_count;
5999 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006000 }
6001
Alexander Duyck5b7da512010-11-16 19:26:50 -08006002 for (i = 0; i < adapter->num_rx_queues; i++) {
6003 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6004 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
6005 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6006 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006007 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006008 bytes += rx_ring->stats.bytes;
6009 packets += rx_ring->stats.packets;
6010 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006011 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006012 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6013 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006014 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006015 netdev->stats.rx_bytes = bytes;
6016 netdev->stats.rx_packets = packets;
6017
6018 bytes = 0;
6019 packets = 0;
6020 /* gather some stats to the adapter struct that are per queue */
6021 for (i = 0; i < adapter->num_tx_queues; i++) {
6022 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6023 restart_queue += tx_ring->tx_stats.restart_queue;
6024 tx_busy += tx_ring->tx_stats.tx_busy;
6025 bytes += tx_ring->stats.bytes;
6026 packets += tx_ring->stats.packets;
6027 }
6028 adapter->restart_queue = restart_queue;
6029 adapter->tx_busy = tx_busy;
6030 netdev->stats.tx_bytes = bytes;
6031 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006032
Joe Perches7ca647b2010-09-07 21:35:40 +00006033 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006034
6035 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006036 for (i = 0; i < 8; i++) {
6037 /* for packet buffers not used, the register should read 0 */
6038 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6039 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006040 hwstats->mpc[i] += mpc;
6041 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006042 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6043 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006044 switch (hw->mac.type) {
6045 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006046 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6047 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6048 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006049 hwstats->pxonrxc[i] +=
6050 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006051 break;
6052 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006053 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006054 case ixgbe_mac_X550:
6055 case ixgbe_mac_X550EM_x:
Alexander Duyckbd508172010-11-16 19:27:03 -08006056 hwstats->pxonrxc[i] +=
6057 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006058 break;
6059 default:
6060 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006061 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006062 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006063
6064 /*16 register reads */
6065 for (i = 0; i < 16; i++) {
6066 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6067 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6068 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006069 (hw->mac.type == ixgbe_mac_X540) ||
6070 (hw->mac.type == ixgbe_mac_X550) ||
6071 (hw->mac.type == ixgbe_mac_X550EM_x)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006072 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6073 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6074 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6075 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6076 }
6077 }
6078
Joe Perches7ca647b2010-09-07 21:35:40 +00006079 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006080 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006081 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006082
John Fastabendc84d3242010-11-16 19:27:12 -08006083 ixgbe_update_xoff_received(adapter);
6084
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006085 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006086 switch (hw->mac.type) {
6087 case ixgbe_mac_82598EB:
6088 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006089 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6090 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6091 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6092 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006093 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006094 case ixgbe_mac_X550:
6095 case ixgbe_mac_X550EM_x:
6096 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006097 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6098 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6099 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6100 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6101 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006102 for (i = 0; i < 16; i++)
6103 adapter->hw_rx_no_dma_resources +=
6104 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006105 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006106 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006107 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006108 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006109 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006110 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006111 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006112 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6113 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006114#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006115 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6116 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6117 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6118 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6119 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6120 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006121 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006122 if (adapter->fcoe.ddp_pool) {
6123 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6124 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6125 unsigned int cpu;
6126 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006127 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006128 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6129 noddp += ddp_pool->noddp;
6130 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006131 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006132 hwstats->fcoe_noddp = noddp;
6133 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006134 }
Yi Zou6d455222009-05-13 13:12:16 +00006135#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006136 break;
6137 default:
6138 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006139 }
Auke Kok9a799d72007-09-15 14:07:45 -07006140 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006141 hwstats->bprc += bprc;
6142 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006143 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006144 hwstats->mprc -= bprc;
6145 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6146 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6147 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6148 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6149 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6150 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6151 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6152 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006153 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006154 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006155 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006156 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006157 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6158 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006159 /*
6160 * 82598 errata - tx of flow control packets is included in tx counters
6161 */
6162 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006163 hwstats->gptc -= xon_off_tot;
6164 hwstats->mptc -= xon_off_tot;
6165 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6166 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6167 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6168 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6169 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6170 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6171 hwstats->ptc64 -= xon_off_tot;
6172 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6173 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6174 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6175 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6176 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6177 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006178
6179 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006180 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006181
6182 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006183 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006184 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006185 netdev->stats.rx_length_errors = hwstats->rlec;
6186 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006187 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006188}
6189
6190/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006191 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006192 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006193 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006194static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006195{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006196 struct ixgbe_hw *hw = &adapter->hw;
6197 int i;
6198
Alexander Duyckd034acf2011-04-27 09:25:34 +00006199 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6200 return;
6201
6202 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6203
6204 /* if interface is down do nothing */
6205 if (test_bit(__IXGBE_DOWN, &adapter->state))
6206 return;
6207
6208 /* do nothing if we are not using signature filters */
6209 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6210 return;
6211
6212 adapter->fdir_overflow++;
6213
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006214 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6215 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006216 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00006217 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006218 /* re-enable flow director interrupts */
6219 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006220 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006221 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006222 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006223 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006224}
6225
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006226/**
6227 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006228 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006229 *
6230 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006231 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006232 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006233 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006234 */
6235static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6236{
Auke Kok9a799d72007-09-15 14:07:45 -07006237 struct ixgbe_hw *hw = &adapter->hw;
6238 u64 eics = 0;
6239 int i;
6240
Mark Rustad09f40ae2014-01-14 18:53:11 -08006241 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006242 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006243 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006244 test_bit(__IXGBE_RESETTING, &adapter->state))
6245 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006246
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006247 /* Force detection of hung controller */
6248 if (netif_carrier_ok(adapter->netdev)) {
6249 for (i = 0; i < adapter->num_tx_queues; i++)
6250 set_check_for_tx_hang(adapter->tx_ring[i]);
6251 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006252
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006253 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006254 /*
6255 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006256 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006257 * would set *both* EIMS and EICS for any bit in EIAM
6258 */
6259 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6260 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006261 } else {
6262 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006263 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006264 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006265 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006266 eics |= ((u64)1 << i);
6267 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006268 }
6269
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006270 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006271 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00006272}
6273
6274/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006275 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006276 * @adapter: pointer to the device adapter structure
6277 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006278 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006279static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006280{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006281 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006282 u32 link_speed = adapter->link_speed;
6283 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006284 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006285
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006286 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6287 return;
6288
6289 if (hw->mac.ops.check_link) {
6290 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006291 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006292 /* always assume link is up, if no check link function */
6293 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6294 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006295 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006296
6297 if (adapter->ixgbe_ieee_pfc)
6298 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6299
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006300 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006301 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006302 ixgbe_set_rx_drop_en(adapter);
6303 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006304
6305 if (link_up ||
6306 time_after(jiffies, (adapter->link_check_timeout +
6307 IXGBE_TRY_LINK_TIMEOUT))) {
6308 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6309 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6310 IXGBE_WRITE_FLUSH(hw);
6311 }
6312
6313 adapter->link_up = link_up;
6314 adapter->link_speed = link_speed;
6315}
6316
Alexander Duyck107d3012012-10-02 00:17:03 +00006317static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6318{
6319#ifdef CONFIG_IXGBE_DCB
6320 struct net_device *netdev = adapter->netdev;
6321 struct dcb_app app = {
6322 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6323 .protocol = 0,
6324 };
6325 u8 up = 0;
6326
6327 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6328 up = dcb_ieee_getapp_mask(netdev, &app);
6329
6330 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6331#endif
6332}
6333
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006334/**
6335 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6336 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006337 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006338 **/
6339static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6340{
6341 struct net_device *netdev = adapter->netdev;
6342 struct ixgbe_hw *hw = &adapter->hw;
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006343 struct net_device *upper;
6344 struct list_head *iter;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006345 u32 link_speed = adapter->link_speed;
6346 bool flow_rx, flow_tx;
6347
6348 /* only continue if link was previously down */
6349 if (netif_carrier_ok(netdev))
6350 return;
6351
6352 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6353
6354 switch (hw->mac.type) {
6355 case ixgbe_mac_82598EB: {
6356 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6357 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6358 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6359 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6360 }
6361 break;
6362 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006363 case ixgbe_mac_X550:
6364 case ixgbe_mac_X550EM_x:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006365 case ixgbe_mac_82599EB: {
6366 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6367 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6368 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6369 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6370 }
6371 break;
6372 default:
6373 flow_tx = false;
6374 flow_rx = false;
6375 break;
6376 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006377
Jacob Keller6cb562d2012-12-05 07:24:41 +00006378 adapter->last_rx_ptp_check = jiffies;
6379
Jacob Keller8fecf672013-06-21 08:14:32 +00006380 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006381 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006382
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006383 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6384 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6385 "10 Gbps" :
6386 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6387 "1 Gbps" :
6388 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6389 "100 Mbps" :
6390 "unknown speed"))),
6391 ((flow_rx && flow_tx) ? "RX/TX" :
6392 (flow_rx ? "RX" :
6393 (flow_tx ? "TX" : "None"))));
6394
6395 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006396 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006397
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006398 /* enable transmits */
6399 netif_tx_wake_all_queues(adapter->netdev);
6400
6401 /* enable any upper devices */
6402 rtnl_lock();
6403 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
6404 if (netif_is_macvlan(upper)) {
6405 struct macvlan_dev *vlan = netdev_priv(upper);
6406
6407 if (vlan->fwd_priv)
6408 netif_tx_wake_all_queues(upper);
6409 }
6410 }
6411 rtnl_unlock();
6412
Alexander Duyck107d3012012-10-02 00:17:03 +00006413 /* update the default user priority for VFs */
6414 ixgbe_update_default_up(adapter);
6415
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006416 /* ping all the active vfs to let them know link has changed */
6417 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006418}
6419
6420/**
6421 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6422 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006423 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006424 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00006425static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006426{
6427 struct net_device *netdev = adapter->netdev;
6428 struct ixgbe_hw *hw = &adapter->hw;
6429
6430 adapter->link_up = false;
6431 adapter->link_speed = 0;
6432
6433 /* only continue if link was up previously */
6434 if (!netif_carrier_ok(netdev))
6435 return;
6436
6437 /* poll for SFP+ cable when link is down */
6438 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6439 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6440
Jacob Keller8fecf672013-06-21 08:14:32 +00006441 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006442 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006443
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006444 e_info(drv, "NIC Link is Down\n");
6445 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006446
6447 /* ping all the active vfs to let them know link has changed */
6448 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006449}
6450
Emil Tantilov07923c12014-08-12 07:12:08 +00006451static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
6452{
6453 int i;
6454
6455 for (i = 0; i < adapter->num_tx_queues; i++) {
6456 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6457
6458 if (tx_ring->next_to_use != tx_ring->next_to_clean)
6459 return true;
6460 }
6461
6462 return false;
6463}
6464
6465static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
6466{
6467 struct ixgbe_hw *hw = &adapter->hw;
6468 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
6469 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
6470
6471 int i, j;
6472
6473 if (!adapter->num_vfs)
6474 return false;
6475
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006476 /* resetting the PF is only needed for MAC before X550 */
6477 if (hw->mac.type >= ixgbe_mac_X550)
6478 return false;
6479
Emil Tantilov07923c12014-08-12 07:12:08 +00006480 for (i = 0; i < adapter->num_vfs; i++) {
6481 for (j = 0; j < q_per_pool; j++) {
6482 u32 h, t;
6483
6484 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
6485 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
6486
6487 if (h != t)
6488 return true;
6489 }
6490 }
6491
6492 return false;
6493}
6494
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006495/**
6496 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006497 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006498 **/
6499static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6500{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006501 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00006502 if (ixgbe_ring_tx_pending(adapter) ||
6503 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006504 /* We've lost link, so the controller stops DMA,
6505 * but we've got queued Tx work that's never going
6506 * to get done, so reset controller to flush Tx.
6507 * (Do the reset outside of interrupt context).
6508 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00006509 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006510 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006511 }
6512 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006513}
6514
Emil Tantilov9079e412014-11-19 03:18:19 +00006515#ifdef CONFIG_PCI_IOV
6516static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
6517 struct pci_dev *vfdev)
6518{
6519 if (!pci_wait_for_pending_transaction(vfdev))
6520 e_dev_warn("Issuing VFLR with pending transactions\n");
6521
6522 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
6523 pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
6524
6525 msleep(100);
6526}
6527
6528static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6529{
6530 struct ixgbe_hw *hw = &adapter->hw;
6531 struct pci_dev *pdev = adapter->pdev;
6532 struct pci_dev *vfdev;
6533 u32 gpc;
6534 int pos;
6535 unsigned short vf_id;
6536
6537 if (!(netif_carrier_ok(adapter->netdev)))
6538 return;
6539
6540 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6541 if (gpc) /* If incrementing then no need for the check below */
6542 return;
6543 /* Check to see if a bad DMA write target from an errant or
6544 * malicious VF has caused a PCIe error. If so then we can
6545 * issue a VFLR to the offending VF(s) and then resume without
6546 * requesting a full slot reset.
6547 */
6548
6549 if (!pdev)
6550 return;
6551
6552 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
6553 if (!pos)
6554 return;
6555
6556 /* get the device ID for the VF */
6557 pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID, &vf_id);
6558
6559 /* check status reg for all VFs owned by this PF */
6560 vfdev = pci_get_device(pdev->vendor, vf_id, NULL);
6561 while (vfdev) {
6562 if (vfdev->is_virtfn && (vfdev->physfn == pdev)) {
6563 u16 status_reg;
6564
6565 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
6566 if (status_reg & PCI_STATUS_REC_MASTER_ABORT)
6567 /* issue VFLR */
6568 ixgbe_issue_vf_flr(adapter, vfdev);
6569 }
6570
6571 vfdev = pci_get_device(pdev->vendor, vf_id, vfdev);
6572 }
6573}
6574
Greg Rosea985b6c32010-11-18 03:02:52 +00006575static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6576{
6577 u32 ssvpc;
6578
Greg Rose0584d992012-08-08 00:00:58 +00006579 /* Do not perform spoof check for 82598 or if not in IOV mode */
6580 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
6581 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00006582 return;
6583
6584 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6585
6586 /*
6587 * ssvpc register is cleared on read, if zero then no
6588 * spoofed packets in the last interval.
6589 */
6590 if (!ssvpc)
6591 return;
6592
Emil Tantilovd6ea0752012-08-08 06:28:37 +00006593 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00006594}
Emil Tantilov9079e412014-11-19 03:18:19 +00006595#else
6596static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
6597{
6598}
6599
6600static void
6601ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
6602{
6603}
6604#endif /* CONFIG_PCI_IOV */
6605
Greg Rosea985b6c32010-11-18 03:02:52 +00006606
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006607/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006608 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006609 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006610 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006611static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006612{
Mark Rustad09f40ae2014-01-14 18:53:11 -08006613 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006614 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006615 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00006616 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006617 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006618
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006619 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006620
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006621 if (adapter->link_up)
6622 ixgbe_watchdog_link_is_up(adapter);
6623 else
6624 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006625
Emil Tantilov9079e412014-11-19 03:18:19 +00006626 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00006627 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006628 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006629
6630 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006631}
6632
Alexander Duyck70864002011-04-27 09:13:56 +00006633/**
6634 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006635 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00006636 **/
6637static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6638{
6639 struct ixgbe_hw *hw = &adapter->hw;
6640 s32 err;
6641
6642 /* not searching for SFP so there is nothing to do here */
6643 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6644 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6645 return;
6646
6647 /* someone else is in init, wait until next service event */
6648 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6649 return;
6650
6651 err = hw->phy.ops.identify_sfp(hw);
6652 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6653 goto sfp_out;
6654
6655 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6656 /* If no cable is present, then we need to reset
6657 * the next time we find a good cable. */
6658 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6659 }
6660
6661 /* exit on error */
6662 if (err)
6663 goto sfp_out;
6664
6665 /* exit if reset not needed */
6666 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6667 goto sfp_out;
6668
6669 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6670
6671 /*
6672 * A module may be identified correctly, but the EEPROM may not have
6673 * support for that module. setup_sfp() will fail in that case, so
6674 * we should not allow that module to load.
6675 */
6676 if (hw->mac.type == ixgbe_mac_82598EB)
6677 err = hw->phy.ops.reset(hw);
6678 else
6679 err = hw->mac.ops.setup_sfp(hw);
6680
6681 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6682 goto sfp_out;
6683
6684 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6685 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6686
6687sfp_out:
6688 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6689
6690 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6691 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6692 e_dev_err("failed to initialize because an unsupported "
6693 "SFP+ module type was detected.\n");
6694 e_dev_err("Reload the driver after installing a "
6695 "supported module.\n");
6696 unregister_netdev(adapter->netdev);
6697 }
6698}
6699
6700/**
6701 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006702 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00006703 **/
6704static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6705{
6706 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00006707 u32 speed;
6708 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00006709
6710 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6711 return;
6712
6713 /* someone else is in init, wait until next service event */
6714 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6715 return;
6716
6717 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6718
Josh Hay3d292262012-12-15 03:28:19 +00006719 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00006720 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00006721 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00006722
6723 /* setup the highest link when no autoneg */
6724 if (!autoneg) {
6725 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
6726 speed = IXGBE_LINK_SPEED_10GB_FULL;
6727 }
6728 }
6729
Alexander Duyck70864002011-04-27 09:13:56 +00006730 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00006731 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00006732
6733 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6734 adapter->link_check_timeout = jiffies;
6735 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6736}
6737
6738/**
6739 * ixgbe_service_timer - Timer Call-back
6740 * @data: pointer to adapter cast into an unsigned long
6741 **/
6742static void ixgbe_service_timer(unsigned long data)
6743{
6744 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6745 unsigned long next_event_offset;
6746
6747 /* poll faster when waiting for link */
6748 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6749 next_event_offset = HZ / 10;
6750 else
6751 next_event_offset = HZ * 2;
6752
6753 /* Reset the timer */
6754 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6755
Emil Tantilov9079e412014-11-19 03:18:19 +00006756 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006757}
6758
Don Skidmore597f22d2015-06-09 16:52:02 -07006759static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
6760{
6761 struct ixgbe_hw *hw = &adapter->hw;
6762 u32 status;
6763
6764 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
6765 return;
6766
6767 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
6768
6769 if (!hw->phy.ops.handle_lasi)
6770 return;
6771
6772 status = hw->phy.ops.handle_lasi(&adapter->hw);
6773 if (status != IXGBE_ERR_OVERTEMP)
6774 return;
6775
6776 e_crit(drv, "%s\n", ixgbe_overheat_msg);
6777}
6778
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006779static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6780{
6781 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6782 return;
6783
6784 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6785
Mark Rustad09f40ae2014-01-14 18:53:11 -08006786 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006787 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006788 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006789 test_bit(__IXGBE_RESETTING, &adapter->state))
6790 return;
6791
6792 ixgbe_dump(adapter);
6793 netdev_err(adapter->netdev, "Reset adapter\n");
6794 adapter->tx_timeout_count++;
6795
John Fastabend8f4c5c92014-01-16 02:30:05 -08006796 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006797 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08006798 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006799}
6800
Alexander Duyck70864002011-04-27 09:13:56 +00006801/**
6802 * ixgbe_service_task - manages and runs subtasks
6803 * @work: pointer to work_struct containing our data
6804 **/
6805static void ixgbe_service_task(struct work_struct *work)
6806{
6807 struct ixgbe_adapter *adapter = container_of(work,
6808 struct ixgbe_adapter,
6809 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08006810 if (ixgbe_removed(adapter->hw.hw_addr)) {
6811 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
6812 rtnl_lock();
6813 ixgbe_down(adapter);
6814 rtnl_unlock();
6815 }
6816 ixgbe_service_event_complete(adapter);
6817 return;
6818 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006819 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07006820 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006821 ixgbe_sfp_detection_subtask(adapter);
6822 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006823 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006824 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006825 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006826 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00006827
Jacob Keller8fecf672013-06-21 08:14:32 +00006828 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00006829 ixgbe_ptp_overflow_check(adapter);
6830 ixgbe_ptp_rx_hang(adapter);
6831 }
Alexander Duyck70864002011-04-27 09:13:56 +00006832
6833 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006834}
6835
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006836static int ixgbe_tso(struct ixgbe_ring *tx_ring,
6837 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006838 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00006839{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006840 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006841 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006842 u32 mss_l4len_idx, l4len;
Francois Romieu2049e1f2014-03-30 03:14:27 +00006843 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07006844
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00006845 if (skb->ip_summed != CHECKSUM_PARTIAL)
6846 return 0;
6847
Alexander Duyck897ab152011-05-27 05:31:47 +00006848 if (!skb_is_gso(skb))
6849 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006850
Francois Romieu2049e1f2014-03-30 03:14:27 +00006851 err = skb_cow_head(skb, 0);
6852 if (err < 0)
6853 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006854
Alexander Duyck897ab152011-05-27 05:31:47 +00006855 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6856 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6857
Joe Perchesa1108ff2014-03-13 05:19:25 +00006858 if (first->protocol == htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006859 struct iphdr *iph = ip_hdr(skb);
6860 iph->tot_len = 0;
6861 iph->check = 0;
6862 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6863 iph->daddr, 0,
6864 IPPROTO_TCP,
6865 0);
6866 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006867 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6868 IXGBE_TX_FLAGS_CSUM |
6869 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006870 } else if (skb_is_gso_v6(skb)) {
6871 ipv6_hdr(skb)->payload_len = 0;
6872 tcp_hdr(skb)->check =
6873 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6874 &ipv6_hdr(skb)->daddr,
6875 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00006876 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6877 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00006878 }
6879
Alexander Duyck091a6242012-02-08 07:51:01 +00006880 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00006881 l4len = tcp_hdrlen(skb);
6882 *hdr_len = skb_transport_offset(skb) + l4len;
6883
Alexander Duyck091a6242012-02-08 07:51:01 +00006884 /* update gso size and bytecount with header size */
6885 first->gso_segs = skb_shinfo(skb)->gso_segs;
6886 first->bytecount += (first->gso_segs - 1) * *hdr_len;
6887
Alexander Duyckc44f5f52012-10-30 06:01:45 +00006888 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00006889 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6890 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00006891
6892 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6893 vlan_macip_lens = skb_network_header_len(skb);
6894 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006895 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006896
6897 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006898 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00006899
6900 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006901}
6902
Alexander Duyck244e27a2012-02-08 07:51:11 +00006903static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6904 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07006905{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006906 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006907 u32 vlan_macip_lens = 0;
6908 u32 mss_l4len_idx = 0;
6909 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006910
Alexander Duyck897ab152011-05-27 05:31:47 +00006911 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck472148c2012-11-07 02:34:28 +00006912 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6913 !(first->tx_flags & IXGBE_TX_FLAGS_CC))
6914 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00006915 } else {
6916 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006917 switch (first->protocol) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00006918 case htons(ETH_P_IP):
Alexander Duyck897ab152011-05-27 05:31:47 +00006919 vlan_macip_lens |= skb_network_header_len(skb);
6920 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6921 l4_hdr = ip_hdr(skb)->protocol;
6922 break;
Joe Perchesa1108ff2014-03-13 05:19:25 +00006923 case htons(ETH_P_IPV6):
Alexander Duyck897ab152011-05-27 05:31:47 +00006924 vlan_macip_lens |= skb_network_header_len(skb);
6925 l4_hdr = ipv6_hdr(skb)->nexthdr;
6926 break;
6927 default:
6928 if (unlikely(net_ratelimit())) {
6929 dev_warn(tx_ring->dev,
6930 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006931 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00006932 }
6933 break;
6934 }
Auke Kok9a799d72007-09-15 14:07:45 -07006935
Alexander Duyck897ab152011-05-27 05:31:47 +00006936 switch (l4_hdr) {
6937 case IPPROTO_TCP:
6938 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6939 mss_l4len_idx = tcp_hdrlen(skb) <<
6940 IXGBE_ADVTXD_L4LEN_SHIFT;
6941 break;
6942 case IPPROTO_SCTP:
6943 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6944 mss_l4len_idx = sizeof(struct sctphdr) <<
6945 IXGBE_ADVTXD_L4LEN_SHIFT;
6946 break;
6947 case IPPROTO_UDP:
6948 mss_l4len_idx = sizeof(struct udphdr) <<
6949 IXGBE_ADVTXD_L4LEN_SHIFT;
6950 break;
6951 default:
6952 if (unlikely(net_ratelimit())) {
6953 dev_warn(tx_ring->dev,
6954 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006955 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006956 }
6957 break;
6958 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006959
6960 /* update TX checksum flag */
6961 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006962 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006963
Alexander Duyck244e27a2012-02-08 07:51:11 +00006964 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006965 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006966 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006967
6968 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6969 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006970}
6971
Alexander Duyck472148c2012-11-07 02:34:28 +00006972#define IXGBE_SET_FLAG(_input, _flag, _result) \
6973 ((_flag <= _result) ? \
6974 ((u32)(_input & _flag) * (_result / _flag)) : \
6975 ((u32)(_input & _flag) / (_flag / _result)))
6976
6977static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006978{
6979 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00006980 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
6981 IXGBE_ADVTXD_DCMD_DEXT |
6982 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006983
6984 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00006985 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
6986 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006987
Alexander Duyckd3d00232011-07-15 02:31:25 +00006988 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006989 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
6990 IXGBE_ADVTXD_DCMD_TSE);
6991
6992 /* set timestamp bit if present */
6993 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
6994 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006995
Alexander Duyck62748b72012-07-20 08:09:01 +00006996 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00006997 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00006998
Alexander Duyckd3d00232011-07-15 02:31:25 +00006999 return cmd_type;
7000}
7001
Alexander Duyck729739b2012-02-08 07:51:06 +00007002static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7003 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007004{
Alexander Duyck472148c2012-11-07 02:34:28 +00007005 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007006
7007 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007008 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7009 IXGBE_TX_FLAGS_CSUM,
7010 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007011
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007012 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007013 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7014 IXGBE_TX_FLAGS_IPV4,
7015 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007016
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007017 /*
7018 * Check Context must be set if Tx switch is enabled, which it
7019 * always is for case where virtual functions are running
7020 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007021 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7022 IXGBE_TX_FLAGS_CC,
7023 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007024
Alexander Duyck472148c2012-11-07 02:34:28 +00007025 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007026}
7027
Daniel Borkmann2367a172014-08-26 19:34:18 +02007028static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7029{
7030 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7031
7032 /* Herbert's original patch had:
7033 * smp_mb__after_netif_stop_queue();
7034 * but since that doesn't exist yet, just open code it.
7035 */
7036 smp_mb();
7037
7038 /* We need to check again in a case another CPU has just
7039 * made room available.
7040 */
7041 if (likely(ixgbe_desc_unused(tx_ring) < size))
7042 return -EBUSY;
7043
7044 /* A reprieve! - use start_queue because it doesn't call schedule */
7045 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7046 ++tx_ring->tx_stats.restart_queue;
7047 return 0;
7048}
7049
7050static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7051{
7052 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7053 return 0;
7054
7055 return __ixgbe_maybe_stop_tx(tx_ring, size);
7056}
7057
Alexander Duyckd3d00232011-07-15 02:31:25 +00007058#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7059 IXGBE_TXD_CMD_RS)
7060
7061static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007062 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007063 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007064{
Alexander Duyck729739b2012-02-08 07:51:06 +00007065 struct sk_buff *skb = first->skb;
7066 struct ixgbe_tx_buffer *tx_buffer;
7067 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007068 struct skb_frag_struct *frag;
7069 dma_addr_t dma;
7070 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007071 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007072 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007073 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007074
Alexander Duyck729739b2012-02-08 07:51:06 +00007075 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7076
Alexander Duyckec718252012-10-30 06:01:55 +00007077 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7078
7079 size = skb_headlen(skb);
7080 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007081
Alexander Duyckd3d00232011-07-15 02:31:25 +00007082#ifdef IXGBE_FCOE
7083 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007084 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007085 size -= sizeof(struct fcoe_crc_eof) - data_len;
7086 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007087 } else {
7088 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007089 }
Auke Kok9a799d72007-09-15 14:07:45 -07007090 }
7091
Alexander Duyckd3d00232011-07-15 02:31:25 +00007092#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007093 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007094
Alexander Duyckec718252012-10-30 06:01:55 +00007095 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007096
Alexander Duyckec718252012-10-30 06:01:55 +00007097 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7098 if (dma_mapping_error(tx_ring->dev, dma))
7099 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007100
Alexander Duyckec718252012-10-30 06:01:55 +00007101 /* record length, and DMA address */
7102 dma_unmap_len_set(tx_buffer, len, size);
7103 dma_unmap_addr_set(tx_buffer, dma, dma);
7104
7105 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7106
Alexander Duyck729739b2012-02-08 07:51:06 +00007107 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007108 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007109 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007110
Alexander Duyckd3d00232011-07-15 02:31:25 +00007111 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007112 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007113 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007114 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007115 i = 0;
7116 }
Alexander Duyckec718252012-10-30 06:01:55 +00007117 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007118
7119 dma += IXGBE_MAX_DATA_PER_TXD;
7120 size -= IXGBE_MAX_DATA_PER_TXD;
7121
7122 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007123 }
7124
Alexander Duyck729739b2012-02-08 07:51:06 +00007125 if (likely(!data_len))
7126 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007127
Alexander Duyck472148c2012-11-07 02:34:28 +00007128 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007129
Alexander Duyck729739b2012-02-08 07:51:06 +00007130 i++;
7131 tx_desc++;
7132 if (i == tx_ring->count) {
7133 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7134 i = 0;
7135 }
Alexander Duyckec718252012-10-30 06:01:55 +00007136 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007137
Alexander Duyckd3d00232011-07-15 02:31:25 +00007138#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007139 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007140#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007141 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007142#endif
7143 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007144
Alexander Duyck729739b2012-02-08 07:51:06 +00007145 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7146 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007147
Alexander Duyck729739b2012-02-08 07:51:06 +00007148 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007149 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007150
Alexander Duyck729739b2012-02-08 07:51:06 +00007151 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007152 cmd_type |= size | IXGBE_TXD_CMD;
7153 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007154
Alexander Duyck091a6242012-02-08 07:51:01 +00007155 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007156
Alexander Duyckd3d00232011-07-15 02:31:25 +00007157 /* set the timestamp */
7158 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007159
7160 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007161 * Force memory writes to complete before letting h/w know there
7162 * are new descriptors to fetch. (Only applicable for weak-ordered
7163 * memory model archs, such as IA-64).
7164 *
7165 * We also need this memory barrier to make certain all of the
7166 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007167 */
7168 wmb();
7169
Alexander Duyckd3d00232011-07-15 02:31:25 +00007170 /* set next_to_watch value indicating a packet is present */
7171 first->next_to_watch = tx_desc;
7172
Alexander Duyck729739b2012-02-08 07:51:06 +00007173 i++;
7174 if (i == tx_ring->count)
7175 i = 0;
7176
7177 tx_ring->next_to_use = i;
7178
Daniel Borkmann2367a172014-08-26 19:34:18 +02007179 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7180
7181 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00007182 writel(i, tx_ring->tail);
7183
7184 /* we need this if more than one processor can write to our tail
7185 * at a time, it synchronizes IO on IA64/Altix systems
7186 */
7187 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02007188 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02007189
Alexander Duyckd3d00232011-07-15 02:31:25 +00007190 return;
7191dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00007192 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00007193
7194 /* clear dma mappings for failed tx_buffer_info map */
7195 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007196 tx_buffer = &tx_ring->tx_buffer_info[i];
7197 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
7198 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007199 break;
7200 if (i == 0)
7201 i = tx_ring->count;
7202 i--;
7203 }
7204
Alexander Duyckd3d00232011-07-15 02:31:25 +00007205 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07007206}
7207
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007208static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007209 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007210{
Alexander Duyck69830522011-01-06 14:29:58 +00007211 struct ixgbe_q_vector *q_vector = ring->q_vector;
7212 union ixgbe_atr_hash_dword input = { .dword = 0 };
7213 union ixgbe_atr_hash_dword common = { .dword = 0 };
7214 union {
7215 unsigned char *network;
7216 struct iphdr *ipv4;
7217 struct ipv6hdr *ipv6;
7218 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007219 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00007220 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007221
Alexander Duyck69830522011-01-06 14:29:58 +00007222 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7223 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00007224 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007225
Alexander Duyck69830522011-01-06 14:29:58 +00007226 /* do nothing if sampling is disabled */
7227 if (!ring->atr_sample_rate)
7228 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007229
Alexander Duyck69830522011-01-06 14:29:58 +00007230 ring->atr_count++;
7231
7232 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007233 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00007234
7235 /* Currently only IPv4/IPv6 with TCP is supported */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007236 if ((first->protocol != htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00007237 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Joe Perchesa1108ff2014-03-13 05:19:25 +00007238 (first->protocol != htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00007239 hdr.ipv4->protocol != IPPROTO_TCP))
7240 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007241
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007242 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007243
Alexander Duyck66f32a82011-06-29 05:43:22 +00007244 /* skip this packet since it is invalid or the socket is closing */
7245 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00007246 return;
7247
7248 /* sample on all syn packets or once every atr sample count */
7249 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
7250 return;
7251
7252 /* reset sample count */
7253 ring->atr_count = 0;
7254
Alexander Duyck244e27a2012-02-08 07:51:11 +00007255 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00007256
7257 /*
7258 * src and dst are inverted, think how the receiver sees them
7259 *
7260 * The input is broken into two sections, a non-compressed section
7261 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7262 * is XORed together and stored in the compressed dword.
7263 */
7264 input.formatted.vlan_id = vlan_id;
7265
7266 /*
7267 * since src port and flex bytes occupy the same word XOR them together
7268 * and write the value to source port portion of compressed dword
7269 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007270 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00007271 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00007272 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00007273 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00007274 common.port.dst ^= th->source;
7275
Joe Perchesa1108ff2014-03-13 05:19:25 +00007276 if (first->protocol == htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00007277 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7278 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
7279 } else {
7280 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7281 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7282 hdr.ipv6->saddr.s6_addr32[1] ^
7283 hdr.ipv6->saddr.s6_addr32[2] ^
7284 hdr.ipv6->saddr.s6_addr32[3] ^
7285 hdr.ipv6->daddr.s6_addr32[0] ^
7286 hdr.ipv6->daddr.s6_addr32[1] ^
7287 hdr.ipv6->daddr.s6_addr32[2] ^
7288 hdr.ipv6->daddr.s6_addr32[3];
7289 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007290
7291 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007292 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7293 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007294}
7295
Jason Wangf663dd92014-01-10 16:18:26 +08007296static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01007297 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007298{
Jason Wangf663dd92014-01-10 16:18:26 +08007299 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7300#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00007301 struct ixgbe_adapter *adapter;
7302 struct ixgbe_ring_feature *f;
7303 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08007304#endif
7305
7306 if (fwd_adapter)
7307 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7308
7309#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00007310
Alexander Duyck97488bd2013-01-12 06:33:37 +00007311 /*
7312 * only execute the code below if protocol is FCoE
7313 * or FIP and we have FCoE enabled on the adapter
7314 */
7315 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00007316 case htons(ETH_P_FCOE):
7317 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00007318 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00007319
Alexander Duyck97488bd2013-01-12 06:33:37 +00007320 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7321 break;
7322 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01007323 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007324 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007325
Alexander Duyck97488bd2013-01-12 06:33:37 +00007326 f = &adapter->ring_feature[RING_F_FCOE];
7327
7328 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7329 smp_processor_id();
7330
7331 while (txq >= f->indices)
7332 txq -= f->indices;
7333
7334 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08007335#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01007336 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08007337#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007338}
7339
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007340netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007341 struct ixgbe_adapter *adapter,
7342 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007343{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007344 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007345 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007346 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007347 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00007348 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007349 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007350 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007351
Alexander Duycka535c302011-05-27 05:31:52 +00007352 /*
7353 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007354 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007355 * + 2 desc gap to keep tail from touching head,
7356 * + 1 desc for context descriptor,
7357 * otherwise try next time
7358 */
Alexander Duycka535c302011-05-27 05:31:52 +00007359 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7360 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00007361
Alexander Duycka535c302011-05-27 05:31:52 +00007362 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7363 tx_ring->tx_stats.tx_busy++;
7364 return NETDEV_TX_BUSY;
7365 }
7366
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007367 /* record the location of the first descriptor for this packet */
7368 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7369 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00007370 first->bytecount = skb->len;
7371 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007372
Alexander Duyck66f32a82011-06-29 05:43:22 +00007373 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01007374 if (skb_vlan_tag_present(skb)) {
7375 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007376 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7377 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007378 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007379 struct vlan_hdr *vhdr, _vhdr;
7380 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7381 if (!vhdr)
7382 goto out_drop;
7383
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007384 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7385 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007386 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007387 }
Toshiaki Makita02136682015-01-29 20:37:09 +09007388 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00007389
Mark Rustadd5234932014-08-09 07:02:09 +00007390 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
7391 adapter->ptp_clock &&
7392 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
7393 &adapter->state)) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007394 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
7395 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00007396
7397 /* schedule check for Tx timestamp */
7398 adapter->ptp_tx_skb = skb_get(skb);
7399 adapter->ptp_tx_start = jiffies;
7400 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007401 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007402
Jakub Kicinskiff29a862014-03-15 14:55:16 +00007403 skb_tx_timestamp(skb);
7404
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007405#ifdef CONFIG_PCI_IOV
7406 /*
7407 * Use the l2switch_enable flag - would be false if the DMA
7408 * Tx switch had been disabled.
7409 */
7410 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00007411 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007412
7413#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007414 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007415 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007416 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7417 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007418 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007419 tx_flags |= (skb->priority & 0x7) <<
7420 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007421 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7422 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007423
7424 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00007425 goto out_drop;
7426 vhdr = (struct vlan_ethhdr *)skb->data;
7427 vhdr->h_vlan_TCI = htons(tx_flags >>
7428 IXGBE_TX_FLAGS_VLAN_SHIFT);
7429 } else {
7430 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7431 }
7432 }
Alexander Duycka535c302011-05-27 05:31:52 +00007433
Alexander Duyck244e27a2012-02-08 07:51:11 +00007434 /* record initial flags and protocol */
7435 first->tx_flags = tx_flags;
7436 first->protocol = protocol;
7437
Yi Zoueacd73f2009-05-13 13:11:06 +00007438#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007439 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007440 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00007441 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00007442 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00007443 if (tso < 0)
7444 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07007445
Alexander Duyck66f32a82011-06-29 05:43:22 +00007446 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007447 }
Auke Kok9a799d72007-09-15 14:07:45 -07007448
Auke Kok9a799d72007-09-15 14:07:45 -07007449#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007450 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007451 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007452 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007453 else if (!tso)
7454 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007455
7456 /* add the ATR filter if ATR is on */
7457 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00007458 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007459
7460#ifdef IXGBE_FCOE
7461xmit_fcoe:
7462#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007463 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007464
Auke Kok9a799d72007-09-15 14:07:45 -07007465 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007466
7467out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007468 dev_kfree_skb_any(first->skb);
7469 first->skb = NULL;
7470
Alexander Duyck897ab152011-05-27 05:31:47 +00007471 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007472}
7473
John Fastabend2a47fa42013-11-06 09:54:52 -08007474static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
7475 struct net_device *netdev,
7476 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007477{
7478 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007479 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07007480
Alexander Duycka50c29d2012-02-08 07:50:40 +00007481 /*
7482 * The minimum packet size for olinfo paylen is 17 so pad the skb
7483 * in order to meet this minimum size requirement.
7484 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08007485 if (skb_put_padto(skb, 17))
7486 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00007487
John Fastabend2a47fa42013-11-06 09:54:52 -08007488 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
7489
Auke Kok9a799d72007-09-15 14:07:45 -07007490 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7491}
7492
John Fastabend2a47fa42013-11-06 09:54:52 -08007493static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7494 struct net_device *netdev)
7495{
7496 return __ixgbe_xmit_frame(skb, netdev, NULL);
7497}
7498
Auke Kok9a799d72007-09-15 14:07:45 -07007499/**
7500 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7501 * @netdev: network interface device structure
7502 * @p: pointer to an address structure
7503 *
7504 * Returns 0 on success, negative on failure
7505 **/
7506static int ixgbe_set_mac(struct net_device *netdev, void *p)
7507{
7508 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7509 struct ixgbe_hw *hw = &adapter->hw;
7510 struct sockaddr *addr = p;
Jacob Keller5d7daa32014-03-29 06:51:25 +00007511 int ret;
Auke Kok9a799d72007-09-15 14:07:45 -07007512
7513 if (!is_valid_ether_addr(addr->sa_data))
7514 return -EADDRNOTAVAIL;
7515
Jacob Keller5d7daa32014-03-29 06:51:25 +00007516 ixgbe_del_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
Auke Kok9a799d72007-09-15 14:07:45 -07007517 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007518 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007519
Jacob Keller5d7daa32014-03-29 06:51:25 +00007520 ret = ixgbe_add_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
7521 return ret > 0 ? 0 : ret;
Auke Kok9a799d72007-09-15 14:07:45 -07007522}
7523
Ben Hutchings6b73e102009-04-29 08:08:58 +00007524static int
7525ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7526{
7527 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7528 struct ixgbe_hw *hw = &adapter->hw;
7529 u16 value;
7530 int rc;
7531
7532 if (prtad != hw->phy.mdio.prtad)
7533 return -EINVAL;
7534 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7535 if (!rc)
7536 rc = value;
7537 return rc;
7538}
7539
7540static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7541 u16 addr, u16 value)
7542{
7543 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7544 struct ixgbe_hw *hw = &adapter->hw;
7545
7546 if (prtad != hw->phy.mdio.prtad)
7547 return -EINVAL;
7548 return hw->phy.ops.write_reg(hw, addr, devad, value);
7549}
7550
7551static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7552{
7553 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7554
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007555 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007556 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08007557 return ixgbe_ptp_set_ts_config(adapter, req);
7558 case SIOCGHWTSTAMP:
7559 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007560 default:
7561 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7562 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00007563}
7564
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007565/**
7566 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007567 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007568 * @netdev: network interface device structure
7569 *
7570 * Returns non-zero on failure
7571 **/
7572static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7573{
7574 int err = 0;
7575 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007576 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007577
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007578 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007579 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007580 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007581 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007582
7583 /* update SAN MAC vmdq pool selection */
7584 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007585 }
7586 return err;
7587}
7588
7589/**
7590 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007591 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007592 * @netdev: network interface device structure
7593 *
7594 * Returns non-zero on failure
7595 **/
7596static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7597{
7598 int err = 0;
7599 struct ixgbe_adapter *adapter = netdev_priv(dev);
7600 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7601
7602 if (is_valid_ether_addr(mac->san_addr)) {
7603 rtnl_lock();
7604 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7605 rtnl_unlock();
7606 }
7607 return err;
7608}
7609
Auke Kok9a799d72007-09-15 14:07:45 -07007610#ifdef CONFIG_NET_POLL_CONTROLLER
7611/*
7612 * Polling 'interrupt' - used by things like netconsole to send skbs
7613 * without having to re-enable interrupts. It's not called while
7614 * the interrupt routine is executing.
7615 */
7616static void ixgbe_netpoll(struct net_device *netdev)
7617{
7618 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007619 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007620
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007621 /* if interface is down do nothing */
7622 if (test_bit(__IXGBE_DOWN, &adapter->state))
7623 return;
7624
Alexander Duyck856f6062015-02-25 17:45:54 +00007625 /* loop through and schedule all active queues */
7626 for (i = 0; i < adapter->num_q_vectors; i++)
7627 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07007628}
Auke Kok9a799d72007-09-15 14:07:45 -07007629
Alexander Duyck581330b2012-02-08 07:51:47 +00007630#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00007631static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7632 struct rtnl_link_stats64 *stats)
7633{
7634 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7635 int i;
7636
Eric Dumazet1a515022010-11-16 19:26:42 -08007637 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007638 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007639 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007640 u64 bytes, packets;
7641 unsigned int start;
7642
Eric Dumazet1a515022010-11-16 19:26:42 -08007643 if (ring) {
7644 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07007645 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08007646 packets = ring->stats.packets;
7647 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07007648 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08007649 stats->rx_packets += packets;
7650 stats->rx_bytes += bytes;
7651 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007652 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007653
7654 for (i = 0; i < adapter->num_tx_queues; i++) {
7655 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7656 u64 bytes, packets;
7657 unsigned int start;
7658
7659 if (ring) {
7660 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07007661 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007662 packets = ring->stats.packets;
7663 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07007664 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007665 stats->tx_packets += packets;
7666 stats->tx_bytes += bytes;
7667 }
7668 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007669 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007670 /* following stats updated by ixgbe_watchdog_task() */
7671 stats->multicast = netdev->stats.multicast;
7672 stats->rx_errors = netdev->stats.rx_errors;
7673 stats->rx_length_errors = netdev->stats.rx_length_errors;
7674 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7675 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7676 return stats;
7677}
7678
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007679#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007680/**
7681 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7682 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00007683 * @tc: number of traffic classes currently enabled
7684 *
7685 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7686 * 802.1Q priority maps to a packet buffer that exists.
7687 */
7688static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7689{
7690 struct ixgbe_hw *hw = &adapter->hw;
7691 u32 reg, rsave;
7692 int i;
7693
7694 /* 82598 have a static priority to TC mapping that can not
7695 * be changed so no validation is needed.
7696 */
7697 if (hw->mac.type == ixgbe_mac_82598EB)
7698 return;
7699
7700 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7701 rsave = reg;
7702
7703 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7704 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7705
7706 /* If up2tc is out of bounds default to zero */
7707 if (up2tc > tc)
7708 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7709 }
7710
7711 if (reg != rsave)
7712 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7713
7714 return;
7715}
7716
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007717/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00007718 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
7719 * @adapter: Pointer to adapter struct
7720 *
7721 * Populate the netdev user priority to tc map
7722 */
7723static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
7724{
7725 struct net_device *dev = adapter->netdev;
7726 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
7727 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
7728 u8 prio;
7729
7730 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
7731 u8 tc = 0;
7732
7733 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
7734 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
7735 else if (ets)
7736 tc = ets->prio_tc[prio];
7737
7738 netdev_set_prio_tc_map(dev, prio, tc);
7739 }
7740}
7741
Alexander Duyckcca73c52013-01-12 06:33:44 +00007742#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00007743/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007744 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00007745 *
7746 * @netdev: net device to configure
7747 * @tc: number of traffic classes to enable
7748 */
7749int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7750{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007751 struct ixgbe_adapter *adapter = netdev_priv(dev);
7752 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08007753 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007754
John Fastabend8b1c0b22011-05-03 02:26:48 +00007755 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007756 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00007757 (hw->mac.type == ixgbe_mac_82598EB &&
7758 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00007759 return -EINVAL;
7760
John Fastabend2a47fa42013-11-06 09:54:52 -08007761 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
7762 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
7763 return -EBUSY;
7764
John Fastabend8b1c0b22011-05-03 02:26:48 +00007765 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007766 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007767 * hardware is not flexible enough to do this dynamically.
7768 */
7769 if (netif_running(dev))
7770 ixgbe_close(dev);
7771 ixgbe_clear_interrupt_scheme(adapter);
7772
Alexander Duyckcca73c52013-01-12 06:33:44 +00007773#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00007774 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007775 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007776 ixgbe_set_prio_tc_map(adapter);
7777
John Fastabende7589ea2011-07-18 22:38:36 +00007778 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007779
Alexander Duyck943561d2012-05-09 22:14:44 -07007780 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
7781 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007782 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07007783 }
John Fastabende7589ea2011-07-18 22:38:36 +00007784 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007785 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007786
Alexander Duyck943561d2012-05-09 22:14:44 -07007787 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7788 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007789
7790 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007791
7792 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7793 adapter->dcb_cfg.pfc_mode_enable = false;
7794 }
7795
John Fastabend8b1c0b22011-05-03 02:26:48 +00007796 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00007797
7798#endif /* CONFIG_IXGBE_DCB */
7799 ixgbe_init_interrupt_scheme(adapter);
7800
John Fastabend8b1c0b22011-05-03 02:26:48 +00007801 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00007802 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00007803
7804 return 0;
7805}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007806
Greg Roseda36b642012-12-11 08:26:43 +00007807#ifdef CONFIG_PCI_IOV
7808void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
7809{
7810 struct net_device *netdev = adapter->netdev;
7811
7812 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00007813 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00007814 rtnl_unlock();
7815}
7816
7817#endif
Don Skidmore082757a2011-07-21 05:55:00 +00007818void ixgbe_do_reset(struct net_device *netdev)
7819{
7820 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7821
7822 if (netif_running(netdev))
7823 ixgbe_reinit_locked(adapter);
7824 else
7825 ixgbe_reset(adapter);
7826}
7827
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007828static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007829 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007830{
7831 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7832
Don Skidmore082757a2011-07-21 05:55:00 +00007833 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007834 if (!(features & NETIF_F_RXCSUM))
7835 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00007836
Alexander Duyck567d2de2012-02-11 07:18:57 +00007837 /* Turn off LRO if not RSC capable */
7838 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
7839 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007840
Alexander Duyck567d2de2012-02-11 07:18:57 +00007841 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00007842}
7843
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007844static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007845 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007846{
7847 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00007848 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00007849 bool need_reset = false;
7850
Don Skidmore082757a2011-07-21 05:55:00 +00007851 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007852 if (!(features & NETIF_F_LRO)) {
7853 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00007854 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00007855 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
7856 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
7857 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7858 if (adapter->rx_itr_setting == 1 ||
7859 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
7860 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
7861 need_reset = true;
7862 } else if ((changed ^ features) & NETIF_F_LRO) {
7863 e_info(probe, "rx-usecs set too low, "
7864 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00007865 }
7866 }
7867
7868 /*
7869 * Check if Flow Director n-tuple support was enabled or disabled. If
7870 * the state changed, we need to reset.
7871 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007872 switch (features & NETIF_F_NTUPLE) {
7873 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00007874 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007875 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
7876 need_reset = true;
7877
Alexander Duyck567d2de2012-02-11 07:18:57 +00007878 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7879 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00007880 break;
7881 default:
7882 /* turn off perfect filters, enable ATR and reset */
7883 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7884 need_reset = true;
7885
7886 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7887
7888 /* We cannot enable ATR if SR-IOV is enabled */
7889 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7890 break;
7891
7892 /* We cannot enable ATR if we have 2 or more traffic classes */
7893 if (netdev_get_num_tc(netdev) > 1)
7894 break;
7895
7896 /* We cannot enable ATR if RSS is disabled */
7897 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
7898 break;
7899
7900 /* A sample rate of 0 indicates ATR disabled */
7901 if (!adapter->atr_sample_rate)
7902 break;
7903
7904 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7905 break;
Don Skidmore082757a2011-07-21 05:55:00 +00007906 }
7907
Patrick McHardyf6469682013-04-19 02:04:27 +00007908 if (features & NETIF_F_HW_VLAN_CTAG_RX)
John Fastabend146d4cc2012-05-15 05:59:26 +00007909 ixgbe_vlan_strip_enable(adapter);
7910 else
7911 ixgbe_vlan_strip_disable(adapter);
7912
Ben Greear3f2d1c02012-03-08 08:28:41 +00007913 if (changed & NETIF_F_RXALL)
7914 need_reset = true;
7915
Alexander Duyck567d2de2012-02-11 07:18:57 +00007916 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00007917 if (need_reset)
7918 ixgbe_do_reset(netdev);
7919
7920 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00007921}
7922
Don Skidmore3f207802014-12-23 07:40:34 +00007923/**
7924 * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up
7925 * @dev: The port's netdev
7926 * @sa_family: Socket Family that VXLAN is notifiying us about
7927 * @port: New UDP port number that VXLAN started listening to
7928 **/
7929static void ixgbe_add_vxlan_port(struct net_device *dev, sa_family_t sa_family,
7930 __be16 port)
7931{
7932 struct ixgbe_adapter *adapter = netdev_priv(dev);
7933 struct ixgbe_hw *hw = &adapter->hw;
7934 u16 new_port = ntohs(port);
7935
7936 if (sa_family == AF_INET6)
7937 return;
7938
7939 if (adapter->vxlan_port == new_port) {
7940 netdev_info(dev, "Port %d already offloaded\n", new_port);
7941 return;
7942 }
7943
7944 if (adapter->vxlan_port) {
7945 netdev_info(dev,
7946 "Hit Max num of UDP ports, not adding port %d\n",
7947 new_port);
7948 return;
7949 }
7950
7951 adapter->vxlan_port = new_port;
7952 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, new_port);
7953}
7954
7955/**
7956 * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away
7957 * @dev: The port's netdev
7958 * @sa_family: Socket Family that VXLAN is notifying us about
7959 * @port: UDP port number that VXLAN stopped listening to
7960 **/
7961static void ixgbe_del_vxlan_port(struct net_device *dev, sa_family_t sa_family,
7962 __be16 port)
7963{
7964 struct ixgbe_adapter *adapter = netdev_priv(dev);
7965 struct ixgbe_hw *hw = &adapter->hw;
7966 u16 new_port = ntohs(port);
7967
7968 if (sa_family == AF_INET6)
7969 return;
7970
7971 if (adapter->vxlan_port != new_port) {
7972 netdev_info(dev, "Port %d was not found, not deleting\n",
7973 new_port);
7974 return;
7975 }
7976
7977 adapter->vxlan_port = 0;
7978 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, 0);
7979}
7980
stephen hemmingeredc7d572012-10-01 12:32:33 +00007981static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007982 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01007983 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007984 u16 flags)
7985{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00007986 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00007987 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyckbcfd3432014-07-17 02:11:22 +00007988 if (IXGBE_MAX_PF_MACVLANS <= netdev_uc_count(dev))
7989 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007990 }
7991
Jiri Pirkof6f64242014-11-28 14:34:15 +01007992 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007993}
7994
Don Skidmore219efe92015-04-09 22:03:22 -07007995/**
7996 * ixgbe_configure_bridge_mode - set various bridge modes
7997 * @adapter - the private structure
7998 * @mode - requested bridge mode
7999 *
8000 * Configure some settings require for various bridge modes.
8001 **/
8002static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
8003 __u16 mode)
8004{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008005 struct ixgbe_hw *hw = &adapter->hw;
8006 unsigned int p, num_pools;
8007 u32 vmdctl;
8008
Don Skidmore219efe92015-04-09 22:03:22 -07008009 switch (mode) {
8010 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008011 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07008012 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008013
8014 /* must enable Rx switching replication to allow multicast
8015 * packet reception on all VFs, and to enable source address
8016 * pruning.
8017 */
8018 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
8019 vmdctl |= IXGBE_VT_CTL_REPLEN;
8020 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
8021
8022 /* enable Rx source address pruning. Note, this requires
8023 * replication to be enabled or else it does nothing.
8024 */
8025 num_pools = adapter->num_vfs + adapter->num_rx_pools;
8026 for (p = 0; p < num_pools; p++) {
8027 if (hw->mac.ops.set_source_address_pruning)
8028 hw->mac.ops.set_source_address_pruning(hw,
8029 true,
8030 p);
8031 }
Don Skidmore219efe92015-04-09 22:03:22 -07008032 break;
8033 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008034 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07008035 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
8036 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07008037
8038 /* disable Rx switching replication unless we have SR-IOV
8039 * virtual functions
8040 */
8041 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
8042 if (!adapter->num_vfs)
8043 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
8044 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
8045
8046 /* disable Rx source address pruning, since we don't expect to
8047 * be receiving external loopback of our transmitted frames.
8048 */
8049 num_pools = adapter->num_vfs + adapter->num_rx_pools;
8050 for (p = 0; p < num_pools; p++) {
8051 if (hw->mac.ops.set_source_address_pruning)
8052 hw->mac.ops.set_source_address_pruning(hw,
8053 false,
8054 p);
8055 }
Don Skidmore219efe92015-04-09 22:03:22 -07008056 break;
8057 default:
8058 return -EINVAL;
8059 }
8060
8061 adapter->bridge_mode = mode;
8062
8063 e_info(drv, "enabling bridge mode: %s\n",
8064 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
8065
8066 return 0;
8067}
8068
John Fastabend815cccb2012-10-24 08:13:09 +00008069static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08008070 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00008071{
8072 struct ixgbe_adapter *adapter = netdev_priv(dev);
8073 struct nlattr *attr, *br_spec;
8074 int rem;
8075
8076 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8077 return -EOPNOTSUPP;
8078
8079 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01008080 if (!br_spec)
8081 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00008082
8083 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07008084 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00008085 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00008086
8087 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8088 continue;
8089
Thomas Grafb7c1a312014-11-26 13:42:17 +01008090 if (nla_len(attr) < sizeof(mode))
8091 return -EINVAL;
8092
John Fastabend815cccb2012-10-24 08:13:09 +00008093 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07008094 status = ixgbe_configure_bridge_mode(adapter, mode);
8095 if (status)
8096 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07008097
8098 break;
John Fastabend815cccb2012-10-24 08:13:09 +00008099 }
8100
8101 return 0;
8102}
8103
8104static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00008105 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02008106 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00008107{
8108 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00008109
8110 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8111 return 0;
8112
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07008113 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07008114 adapter->bridge_mode, 0, 0, nlflags,
8115 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00008116}
8117
John Fastabend2a47fa42013-11-06 09:54:52 -08008118static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
8119{
8120 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
8121 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00008122 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08008123 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08008124 int pool, err;
8125
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00008126 /* Hardware has a limited number of available pools. Each VF, and the
8127 * PF require a pool. Check to ensure we don't attempt to use more
8128 * then the available number of pools.
8129 */
8130 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
8131 return ERR_PTR(-EINVAL);
8132
John Fastabend219354d2013-11-08 00:50:32 -08008133#ifdef CONFIG_RPS
8134 if (vdev->num_rx_queues != vdev->num_tx_queues) {
8135 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
8136 vdev->name);
8137 return ERR_PTR(-EINVAL);
8138 }
8139#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08008140 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08008141 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08008142 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
8143 netdev_info(pdev,
8144 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
8145 pdev->name);
8146 return ERR_PTR(-EINVAL);
8147 }
8148
8149 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
8150 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
8151 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
8152 return ERR_PTR(-EBUSY);
8153
8154 fwd_adapter = kcalloc(1, sizeof(struct ixgbe_fwd_adapter), GFP_KERNEL);
8155 if (!fwd_adapter)
8156 return ERR_PTR(-ENOMEM);
8157
8158 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
8159 adapter->num_rx_pools++;
8160 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08008161 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08008162
8163 /* Enable VMDq flag so device will be set in VM mode */
8164 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08008165 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08008166 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08008167
8168 /* Force reinit of ring allocation with VMDQ enabled */
8169 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8170 if (err)
8171 goto fwd_add_err;
8172 fwd_adapter->pool = pool;
8173 fwd_adapter->real_adapter = adapter;
8174 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
8175 if (err)
8176 goto fwd_add_err;
8177 netif_tx_start_all_queues(vdev);
8178 return fwd_adapter;
8179fwd_add_err:
8180 /* unwind counter and free adapter struct */
8181 netdev_info(pdev,
8182 "%s: dfwd hardware acceleration failed\n", vdev->name);
8183 clear_bit(pool, &adapter->fwd_bitmask);
8184 adapter->num_rx_pools--;
8185 kfree(fwd_adapter);
8186 return ERR_PTR(err);
8187}
8188
8189static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
8190{
8191 struct ixgbe_fwd_adapter *fwd_adapter = priv;
8192 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08008193 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08008194
8195 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
8196 adapter->num_rx_pools--;
8197
John Fastabend51f37732013-11-08 00:51:10 -08008198 limit = find_last_bit(&adapter->fwd_bitmask, 32);
8199 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08008200 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
8201 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8202 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
8203 fwd_adapter->pool, adapter->num_rx_pools,
8204 fwd_adapter->rx_base_queue,
8205 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
8206 adapter->fwd_bitmask);
8207 kfree(fwd_adapter);
8208}
8209
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008210static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00008211 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008212 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08008213 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008214 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00008215 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008216 .ndo_validate_addr = eth_validate_addr,
8217 .ndo_set_mac_address = ixgbe_set_mac,
8218 .ndo_change_mtu = ixgbe_change_mtu,
8219 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008220 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
8221 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00008222 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00008223 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
8224 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04008225 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00008226 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03008227 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Greg Rose7f016482010-05-04 22:12:06 +00008228 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00008229 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008230#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00008231 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008232#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008233#ifdef CONFIG_NET_POLL_CONTROLLER
8234 .ndo_poll_controller = ixgbe_netpoll,
8235#endif
Cong Wange0d10952013-08-01 11:10:25 +08008236#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03008237 .ndo_busy_poll = ixgbe_low_latency_recv,
Eliezer Tamir5a85e732013-06-10 11:40:20 +03008238#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008239#ifdef IXGBE_FCOE
8240 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00008241 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00008242 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00008243 .ndo_fcoe_enable = ixgbe_fcoe_enable,
8244 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00008245 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00008246 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00008247#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00008248 .ndo_set_features = ixgbe_set_features,
8249 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008250 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00008251 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
8252 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08008253 .ndo_dfwd_add_station = ixgbe_fwd_add,
8254 .ndo_dfwd_del_station = ixgbe_fwd_del,
Don Skidmore3f207802014-12-23 07:40:34 +00008255 .ndo_add_vxlan_port = ixgbe_add_vxlan_port,
8256 .ndo_del_vxlan_port = ixgbe_del_vxlan_port,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008257};
8258
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008259/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00008260 * ixgbe_enumerate_functions - Get the number of ports this device has
8261 * @adapter: adapter structure
8262 *
8263 * This function enumerates the phsyical functions co-located on a single slot,
8264 * in order to determine how many ports a device has. This is most useful in
8265 * determining the required GT/s of PCIe bandwidth necessary for optimal
8266 * performance.
8267 **/
8268static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
8269{
Jacob Kellercaafb952014-07-19 07:17:17 +00008270 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00008271 int physfns = 0;
8272
Jacob Kellerf1f96572013-08-31 02:45:38 +00008273 /* Some cards can not use the generic count PCIe functions method,
8274 * because they are behind a parent switch, so we hardcode these with
8275 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00008276 */
Jacob Keller88189702014-07-19 07:17:16 +00008277 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00008278 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00008279
8280 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
8281 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00008282 if (entry->is_virtfn)
8283 continue;
8284
8285 /* When the devices on the bus don't all match our device ID,
8286 * we can't reliably determine the correct number of
8287 * functions. This can occur if a function has been direct
8288 * attached to a virtual machine using VT-d, for example. In
8289 * this case, simply return -1 to indicate this.
8290 */
8291 if ((entry->vendor != pdev->vendor) ||
8292 (entry->device != pdev->device))
8293 return -1;
8294
8295 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00008296 }
8297
8298 return physfns;
8299}
8300
8301/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00008302 * ixgbe_wol_supported - Check whether device supports WoL
8303 * @hw: hw specific details
8304 * @device_id: the device ID
8305 * @subdev_id: the subsystem device ID
8306 *
8307 * This function is used by probe and ethtool to determine
8308 * which devices have WoL support
8309 *
8310 **/
8311int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
8312 u16 subdevice_id)
8313{
8314 struct ixgbe_hw *hw = &adapter->hw;
8315 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
8316 int is_wol_supported = 0;
8317
8318 switch (device_id) {
8319 case IXGBE_DEV_ID_82599_SFP:
8320 /* Only these subdevices could supports WOL */
8321 switch (subdevice_id) {
Mark Rustad87557442014-02-25 17:58:55 -08008322 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008323 case IXGBE_SUBDEV_ID_82599_560FLR:
8324 /* only support first port */
8325 if (hw->bus.func != 0)
8326 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00008327 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008328 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00008329 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00008330 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller979fe5f2013-04-03 04:41:37 +00008331 case IXGBE_SUBDEV_ID_82599_LOM_SFP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008332 is_wol_supported = 1;
8333 break;
8334 }
8335 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00008336 case IXGBE_DEV_ID_82599EN_SFP:
8337 /* Only this subdevice supports WOL */
8338 switch (subdevice_id) {
8339 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
8340 is_wol_supported = 1;
8341 break;
8342 }
8343 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008344 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
8345 /* All except this subdevice support WOL */
8346 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
8347 is_wol_supported = 1;
8348 break;
8349 case IXGBE_DEV_ID_82599_KX4:
8350 is_wol_supported = 1;
8351 break;
8352 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00008353 case IXGBE_DEV_ID_X540T1:
Don Skidmoredf8c26f2015-06-09 16:00:17 -07008354 case IXGBE_DEV_ID_X550T:
8355 case IXGBE_DEV_ID_X550EM_X_KX4:
8356 case IXGBE_DEV_ID_X550EM_X_KR:
8357 case IXGBE_DEV_ID_X550EM_X_10G_T:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008358 /* check eeprom to see if enabled wol */
8359 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
8360 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
8361 (hw->bus.func == 0))) {
8362 is_wol_supported = 1;
8363 }
8364 break;
8365 }
8366
8367 return is_wol_supported;
8368}
8369
8370/**
Martin K Petersenc762dff2014-11-15 14:24:51 +00008371 * ixgbe_get_platform_mac_addr - Look up MAC address in Open Firmware / IDPROM
8372 * @adapter: Pointer to adapter struct
8373 */
8374static void ixgbe_get_platform_mac_addr(struct ixgbe_adapter *adapter)
8375{
8376#ifdef CONFIG_OF
8377 struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
8378 struct ixgbe_hw *hw = &adapter->hw;
8379 const unsigned char *addr;
8380
8381 addr = of_get_mac_address(dp);
8382 if (addr) {
8383 ether_addr_copy(hw->mac.perm_addr, addr);
8384 return;
8385 }
8386#endif /* CONFIG_OF */
8387
8388#ifdef CONFIG_SPARC
8389 ether_addr_copy(hw->mac.perm_addr, idprom->id_ethaddr);
8390#endif /* CONFIG_SPARC */
8391}
8392
8393/**
Auke Kok9a799d72007-09-15 14:07:45 -07008394 * ixgbe_probe - Device Initialization Routine
8395 * @pdev: PCI device information struct
8396 * @ent: entry in ixgbe_pci_tbl
8397 *
8398 * Returns 0 on success, negative on failure
8399 *
8400 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
8401 * The OS initialization, configuring of the adapter private structure,
8402 * and a hardware reset occur.
8403 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00008404static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07008405{
8406 struct net_device *netdev;
8407 struct ixgbe_adapter *adapter = NULL;
8408 struct ixgbe_hw *hw;
8409 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +00008410 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008411 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00008412 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008413 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +00008414#ifdef IXGBE_FCOE
8415 u16 device_caps;
8416#endif
Don Skidmore289700db2010-12-03 03:32:58 +00008417 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07008418
Andy Gospodarekbded64a2010-07-21 06:40:31 +00008419 /* Catch broken hardware that put the wrong VF device ID in
8420 * the PCIe SR-IOV capability.
8421 */
8422 if (pdev->is_virtfn) {
8423 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
8424 pci_name(pdev), pdev->vendor, pdev->device);
8425 return -EINVAL;
8426 }
8427
gouji-new9ce77662009-05-06 10:44:45 +00008428 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008429 if (err)
8430 return err;
8431
Russell Kingf5f2eda2013-06-10 12:47:42 +01008432 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07008433 pci_using_dac = 1;
8434 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01008435 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07008436 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01008437 dev_err(&pdev->dev,
8438 "No usable DMA configuration, aborting\n");
8439 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07008440 }
8441 pci_using_dac = 0;
8442 }
8443
gouji-new9ce77662009-05-06 10:44:45 +00008444 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008445 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07008446 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00008447 dev_err(&pdev->dev,
8448 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07008449 goto err_pci_reg;
8450 }
8451
Frans Pop19d5afd2009-10-02 10:04:12 -07008452 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008453
Auke Kok9a799d72007-09-15 14:07:45 -07008454 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07008455 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008456
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008457 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00008458#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008459 /* 8 TC w/ 4 queues per TC */
8460 indices = 4 * MAX_TRAFFIC_CLASS;
8461#else
8462 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00008463#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008464 }
John Fastabende901acd2011-04-26 07:26:08 +00008465
John Fastabendc85a2612010-02-25 23:15:21 +00008466 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07008467 if (!netdev) {
8468 err = -ENOMEM;
8469 goto err_alloc_etherdev;
8470 }
8471
Auke Kok9a799d72007-09-15 14:07:45 -07008472 SET_NETDEV_DEV(netdev, &pdev->dev);
8473
Auke Kok9a799d72007-09-15 14:07:45 -07008474 adapter = netdev_priv(netdev);
8475
8476 adapter->netdev = netdev;
8477 adapter->pdev = pdev;
8478 hw = &adapter->hw;
8479 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00008480 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07008481
Jeff Kirsher05857982008-09-11 19:57:00 -07008482 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00008483 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08008484 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07008485 if (!hw->hw_addr) {
8486 err = -EIO;
8487 goto err_ioremap;
8488 }
8489
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008490 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07008491 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008492 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +00008493 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -07008494
Auke Kok9a799d72007-09-15 14:07:45 -07008495 /* Setup hw api */
8496 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008497 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -07008498 hw->mvals = ii->mvals;
Auke Kok9a799d72007-09-15 14:07:45 -07008499
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008500 /* EEPROM */
8501 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
Don Skidmore9a900ec2015-06-09 17:15:01 -07008502 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +00008503 if (ixgbe_removed(hw->hw_addr)) {
8504 err = -EIO;
8505 goto err_ioremap;
8506 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008507 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
8508 if (!(eec & (1 << 8)))
8509 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
8510
8511 /* PHY */
8512 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08008513 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00008514 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
8515 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
8516 hw->phy.mdio.mmds = 0;
8517 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
8518 hw->phy.mdio.dev = netdev;
8519 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
8520 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08008521
Don Skidmore8ca783a2009-05-26 20:40:47 -07008522 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07008523
8524 /* setup the private structure */
8525 err = ixgbe_sw_init(adapter);
8526 if (err)
8527 goto err_sw_init;
8528
Don Skidmoree86bff02010-02-11 04:14:08 +00008529 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08008530 switch (adapter->hw.mac.type) {
8531 case ixgbe_mac_82599EB:
8532 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00008533 case ixgbe_mac_X550:
8534 case ixgbe_mac_X550EM_x:
Don Skidmoree86bff02010-02-11 04:14:08 +00008535 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08008536 break;
8537 default:
8538 break;
8539 }
Don Skidmoree86bff02010-02-11 04:14:08 +00008540
Don Skidmorebf069c92009-05-07 10:39:54 +00008541 /*
8542 * If there is a fan on this device and it has failed log the
8543 * failure.
8544 */
8545 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
8546 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
8547 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00008548 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00008549 }
8550
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00008551 if (allow_unsupported_sfp)
8552 hw->allow_unsupported_sfp = allow_unsupported_sfp;
8553
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008554 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07008555 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008556 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07008557 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07008558 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
8559 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07008560 err = 0;
8561 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00008562 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
8563 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008564 goto err_sw_init;
8565 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008566 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008567 goto err_sw_init;
8568 }
8569
Alexander Duyck99d74482012-05-09 08:09:25 +00008570#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00008571 /* SR-IOV not supported on the 82598 */
8572 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8573 goto skip_sriov;
8574 /* Mailbox */
8575 ixgbe_init_mbx_params_pf(hw);
8576 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
ethan.zhaodcc23e32014-01-16 19:41:04 -08008577 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ethan.zhao31ac9102014-01-16 19:41:05 -08008578 ixgbe_enable_sriov(adapter);
Greg Rose60a1a682012-12-11 08:26:33 +00008579skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008580
Alexander Duyck99d74482012-05-09 08:09:25 +00008581#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00008582 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00008583 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00008584 NETIF_F_IPV6_CSUM |
Patrick McHardyf6469682013-04-19 02:04:27 +00008585 NETIF_F_HW_VLAN_CTAG_TX |
8586 NETIF_F_HW_VLAN_CTAG_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00008587 NETIF_F_TSO |
8588 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00008589 NETIF_F_RXHASH |
John Fastabend8bf12642013-11-12 12:13:29 +00008590 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07008591
John Fastabend8bf12642013-11-12 12:13:29 +00008592 netdev->hw_features = netdev->features | NETIF_F_HW_L2FW_DOFFLOAD;
Jeff Kirsherad31c402008-06-05 04:05:30 -07008593
Don Skidmore58be7662011-04-12 09:42:11 +00008594 switch (adapter->hw.mac.type) {
8595 case ixgbe_mac_82599EB:
8596 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00008597 case ixgbe_mac_X550:
8598 case ixgbe_mac_X550EM_x:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00008599 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00008600 netdev->hw_features |= NETIF_F_SCTP_CSUM |
8601 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00008602 break;
8603 default:
8604 break;
8605 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00008606
Ben Greear3f2d1c02012-03-08 08:28:41 +00008607 netdev->hw_features |= NETIF_F_RXALL;
Alexander Duyck87031c02015-04-09 22:03:24 -07008608 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Ben Greear3f2d1c02012-03-08 08:28:41 +00008609
Jeff Kirsherad31c402008-06-05 04:05:30 -07008610 netdev->vlan_features |= NETIF_F_TSO;
8611 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07008612 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00008613 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07008614 netdev->vlan_features |= NETIF_F_SG;
8615
Jiri Pirko01789342011-08-16 06:29:00 +00008616 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00008617 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00008618
Don Skidmore3f207802014-12-23 07:40:34 +00008619 switch (adapter->hw.mac.type) {
8620 case ixgbe_mac_X550:
8621 case ixgbe_mac_X550EM_x:
8622 netdev->hw_enc_features |= NETIF_F_RXCSUM;
8623 break;
8624 default:
8625 break;
8626 }
8627
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08008628#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08008629 netdev->dcbnl_ops = &dcbnl_ops;
8630#endif
8631
Yi Zoueacd73f2009-05-13 13:11:06 +00008632#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00008633 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008634 unsigned int fcoe_l;
8635
Yi Zoueacd73f2009-05-13 13:11:06 +00008636 if (hw->mac.ops.get_device_caps) {
8637 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00008638 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
8639 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00008640 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008641
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008642
8643 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
8644 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008645
Alexander Duycka58915c2012-05-25 06:38:18 +00008646 netdev->features |= NETIF_F_FSO |
8647 NETIF_F_FCOE_CRC;
8648
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008649 netdev->vlan_features |= NETIF_F_FSO |
8650 NETIF_F_FCOE_CRC |
8651 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00008652 }
Yi Zoueacd73f2009-05-13 13:11:06 +00008653#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00008654 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07008655 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00008656 netdev->vlan_features |= NETIF_F_HIGHDMA;
8657 }
Auke Kok9a799d72007-09-15 14:07:45 -07008658
Don Skidmore082757a2011-07-21 05:55:00 +00008659 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
8660 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00008661 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00008662 netdev->features |= NETIF_F_LRO;
8663
Auke Kok9a799d72007-09-15 14:07:45 -07008664 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008665 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008666 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07008667 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00008668 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008669 }
8670
Martin K Petersenc762dff2014-11-15 14:24:51 +00008671 ixgbe_get_platform_mac_addr(adapter);
8672
Auke Kok9a799d72007-09-15 14:07:45 -07008673 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008674
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00008675 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008676 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07008677 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00008678 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008679 }
8680
Jacob Keller5d7daa32014-03-29 06:51:25 +00008681 ixgbe_mac_set_default_filter(adapter, hw->mac.perm_addr);
8682
Alexander Duyck70864002011-04-27 09:13:56 +00008683 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00008684 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008685
Mark Rustad58cf6632014-03-12 00:38:40 +00008686 if (ixgbe_removed(hw->hw_addr)) {
8687 err = -EIO;
8688 goto err_sw_init;
8689 }
Alexander Duyck70864002011-04-27 09:13:56 +00008690 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +00008691 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008692 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07008693
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008694 err = ixgbe_init_interrupt_scheme(adapter);
8695 if (err)
8696 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008697
Jacob Keller8e2813f2012-04-21 06:05:40 +00008698 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00008699 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008700 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00008701 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00008702 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00008703 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00008704 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00008705
PJ Waskiewicze8e26352009-02-27 15:45:05 +00008706 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
8707
Emil Tantilov15e52092011-09-29 05:01:29 +00008708 /* save off EEPROM version number */
8709 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
8710 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
8711
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008712 /* pick up the PCI bus settings for reporting later */
8713 hw->mac.ops.get_bus_info(hw);
Jacob Kellere027d1a2013-07-31 06:53:31 +00008714 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00008715 ixgbe_get_parent_bus_info(adapter);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008716
Jacob Kellere027d1a2013-07-31 06:53:31 +00008717 /* calculate the expected PCIe bandwidth required for optimal
8718 * performance. Note that some older parts will never have enough
8719 * bandwidth due to being older generation PCIe parts. We clamp these
8720 * parts to ensure no warning is displayed if it can't be fixed.
8721 */
8722 switch (hw->mac.type) {
8723 case ixgbe_mac_82598EB:
8724 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
8725 break;
8726 default:
8727 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
8728 break;
Auke Kok0c254d82008-02-11 09:25:56 -08008729 }
Jacob Kellercaafb952014-07-19 07:17:17 +00008730
8731 /* don't check link if we failed to enumerate functions */
8732 if (expected_gts > 0)
8733 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08008734
Mark Rustad339de302014-06-06 01:57:06 +00008735 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00008736 if (err)
Mark Rustad339de302014-06-06 01:57:06 +00008737 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00008738 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
8739 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
8740 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +00008741 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +00008742 else
8743 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
8744 hw->mac.type, hw->phy.type, part_str);
8745
8746 e_dev_info("%pM\n", netdev->dev_addr);
8747
Auke Kok9a799d72007-09-15 14:07:45 -07008748 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008749 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008750 if (err == IXGBE_ERR_EEPROM_VERSION) {
8751 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00008752 e_dev_warn("This device is a pre-production adapter/LOM. "
8753 "Please be aware there may be issues associated "
8754 "with your hardware. If you are experiencing "
8755 "problems please contact your Intel or hardware "
8756 "representative who provided you with this "
8757 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008758 }
Auke Kok9a799d72007-09-15 14:07:45 -07008759 strcpy(netdev->name, "eth%d");
8760 err = register_netdev(netdev);
8761 if (err)
8762 goto err_register;
8763
Emil Tantilov0fb6a552014-12-04 03:03:38 +00008764 pci_set_drvdata(pdev, adapter);
8765
Emil Tantilovec74a472012-09-20 03:33:56 +00008766 /* power down the optics for 82599 SFP+ fiber */
8767 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00008768 hw->mac.ops.disable_tx_laser(hw);
8769
Jesse Brandeburg54386462009-04-17 20:44:27 +00008770 /* carrier off reporting is important to ethtool even BEFORE open */
8771 netif_carrier_off(netdev);
8772
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008773#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03008774 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008775 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008776 ixgbe_setup_dca(adapter);
8777 }
8778#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008779 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008780 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008781 for (i = 0; i < adapter->num_vfs; i++)
8782 ixgbe_vf_configuration(pdev, (i | 0x10000000));
8783 }
8784
Jacob Keller2466dd92011-09-08 03:50:54 +00008785 /* firmware requires driver version to be 0xFFFFFFFF
8786 * since os does not support feature
8787 */
Emil Tantilov9612de92011-05-07 07:40:20 +00008788 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00008789 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
8790 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00008791
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008792 /* add san mac addr to netdev */
8793 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008794
Neerav Parikhea818752012-01-04 20:23:40 +00008795 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008796
Don Skidmore12109822012-05-04 06:07:08 +00008797#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008798 if (ixgbe_sysfs_init(adapter))
8799 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00008800#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008801
Catherine Sullivan00949162012-08-10 01:59:10 +00008802 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00008803
Emil Tantilovd1a35ee2014-05-13 08:24:00 +00008804 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
8805 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +00008806 hw->mac.ops.setup_link(hw,
8807 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
8808 true);
8809
Auke Kok9a799d72007-09-15 14:07:45 -07008810 return 0;
8811
8812err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008813 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00008814 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008815err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00008816 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00008817 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -08008818 iounmap(adapter->io_addr);
Jacob Keller5d7daa32014-03-29 06:51:25 +00008819 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -07008820err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008821 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07008822 free_netdev(netdev);
8823err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00008824 pci_release_selected_regions(pdev,
8825 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008826err_pci_reg:
8827err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008828 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00008829 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008830 return err;
8831}
8832
8833/**
8834 * ixgbe_remove - Device Removal Routine
8835 * @pdev: PCI device information struct
8836 *
8837 * ixgbe_remove is called by the PCI subsystem to alert the driver
8838 * that it should release a PCI device. The could be caused by a
8839 * Hot-Plug event, or because the driver is going to be removed from
8840 * memory.
8841 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05008842static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07008843{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008844 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +00008845 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008846 bool disable_dev;
Auke Kok9a799d72007-09-15 14:07:45 -07008847
Emil Tantilov0fb6a552014-12-04 03:03:38 +00008848 /* if !adapter then we already cleaned up in probe */
8849 if (!adapter)
8850 return;
8851
8852 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +00008853 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00008854
Mark Rustad09f40ae2014-01-14 18:53:11 -08008855 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008856 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008857
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008858
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008859#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008860 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8861 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8862 dca_remove_requester(&pdev->dev);
8863 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8864 }
8865
8866#endif
Don Skidmore12109822012-05-04 06:07:08 +00008867#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008868 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00008869#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008870
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008871 /* remove the added san mac */
8872 ixgbe_del_sanmac_netdev(netdev);
8873
Donald Skidmorec4900be2008-11-20 21:11:42 -08008874 if (netdev->reg_state == NETREG_REGISTERED)
8875 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008876
Greg Roseda36b642012-12-11 08:26:43 +00008877#ifdef CONFIG_PCI_IOV
8878 /*
8879 * Only disable SR-IOV on unload if the user specified the now
8880 * deprecated max_vfs module parameter.
8881 */
8882 if (max_vfs)
8883 ixgbe_disable_sriov(adapter);
8884#endif
Alexander Duyck7a921c92009-05-06 10:43:28 +00008885 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008886
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008887 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008888
Alexander Duyck2b1588c2012-03-17 02:39:16 +00008889#ifdef CONFIG_DCB
8890 kfree(adapter->ixgbe_ieee_pfc);
8891 kfree(adapter->ixgbe_ieee_ets);
8892
8893#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -08008894 iounmap(adapter->io_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008895 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008896 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008897
Emil Tantilov849c4542010-06-03 16:53:41 +00008898 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008899
Jacob Keller5d7daa32014-03-29 06:51:25 +00008900 kfree(adapter->mac_table);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008901 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07008902 free_netdev(netdev);
8903
Frans Pop19d5afd2009-10-02 10:04:12 -07008904 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008905
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008906 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00008907 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008908}
8909
8910/**
8911 * ixgbe_io_error_detected - called when PCI error is detected
8912 * @pdev: Pointer to PCI device
8913 * @state: The current pci connection state
8914 *
8915 * This function is called after a PCI bus error affecting
8916 * this device has been detected.
8917 */
8918static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008919 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008920{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008921 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8922 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008923
Greg Rose83c61fa2011-09-07 05:59:35 +00008924#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -08008925 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +00008926 struct pci_dev *bdev, *vfdev;
8927 u32 dw0, dw1, dw2, dw3;
8928 int vf, pos;
8929 u16 req_id, pf_func;
8930
8931 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8932 adapter->num_vfs == 0)
8933 goto skip_bad_vf_detection;
8934
8935 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08008936 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00008937 bdev = bdev->bus->self;
8938
8939 if (!bdev)
8940 goto skip_bad_vf_detection;
8941
8942 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8943 if (!pos)
8944 goto skip_bad_vf_detection;
8945
Mark Rustad14438462014-02-28 15:48:57 -08008946 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
8947 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
8948 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
8949 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
8950 if (ixgbe_removed(hw->hw_addr))
8951 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +00008952
8953 req_id = dw1 >> 16;
8954 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8955 if (!(req_id & 0x0080))
8956 goto skip_bad_vf_detection;
8957
8958 pf_func = req_id & 0x01;
8959 if ((pf_func & 1) == (pdev->devfn & 1)) {
8960 unsigned int device_id;
8961
8962 vf = (req_id & 0x7F) >> 1;
8963 e_dev_err("VF %d has caused a PCIe error\n", vf);
8964 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8965 "%8.8x\tdw3: %8.8x\n",
8966 dw0, dw1, dw2, dw3);
8967 switch (adapter->hw.mac.type) {
8968 case ixgbe_mac_82599EB:
8969 device_id = IXGBE_82599_VF_DEVICE_ID;
8970 break;
8971 case ixgbe_mac_X540:
8972 device_id = IXGBE_X540_VF_DEVICE_ID;
8973 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00008974 case ixgbe_mac_X550:
8975 device_id = IXGBE_DEV_ID_X550_VF;
8976 break;
8977 case ixgbe_mac_X550EM_x:
8978 device_id = IXGBE_DEV_ID_X550EM_X_VF;
8979 break;
Greg Rose83c61fa2011-09-07 05:59:35 +00008980 default:
8981 device_id = 0;
8982 break;
8983 }
8984
8985 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00008986 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00008987 while (vfdev) {
8988 if (vfdev->devfn == (req_id & 0xFF))
8989 break;
Jon Mason36e90312012-07-19 21:02:09 +00008990 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00008991 device_id, vfdev);
8992 }
8993 /*
8994 * There's a slim chance the VF could have been hot plugged,
8995 * so if it is no longer present we don't need to issue the
8996 * VFLR. Just clean up the AER in that case.
8997 */
8998 if (vfdev) {
Emil Tantilov9079e412014-11-19 03:18:19 +00008999 ixgbe_issue_vf_flr(adapter, vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +00009000 /* Free device reference count */
9001 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +00009002 }
9003
9004 pci_cleanup_aer_uncorrect_error_status(pdev);
9005 }
9006
9007 /*
9008 * Even though the error may have occurred on the other port
9009 * we still need to increment the vf error reference count for
9010 * both ports because the I/O resume function will be called
9011 * for both of them.
9012 */
9013 adapter->vferr_refcount++;
9014
9015 return PCI_ERS_RESULT_RECOVERED;
9016
9017skip_bad_vf_detection:
9018#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +00009019 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
9020 return PCI_ERS_RESULT_DISCONNECT;
9021
Mark Rustad41c62842014-03-12 00:38:35 +00009022 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07009023 netif_device_detach(netdev);
9024
Mark Rustad41c62842014-03-12 00:38:35 +00009025 if (state == pci_channel_io_perm_failure) {
9026 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +00009027 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +00009028 }
Breno Leitao3044b8d2009-05-06 10:44:26 +00009029
Auke Kok9a799d72007-09-15 14:07:45 -07009030 if (netif_running(netdev))
9031 ixgbe_down(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +00009032
9033 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
9034 pci_disable_device(pdev);
9035 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -07009036
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07009037 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07009038 return PCI_ERS_RESULT_NEED_RESET;
9039}
9040
9041/**
9042 * ixgbe_io_slot_reset - called after the pci bus has been reset.
9043 * @pdev: Pointer to PCI device
9044 *
9045 * Restart the card from scratch, as if from a cold-boot.
9046 */
9047static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
9048{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009049 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009050 pci_ers_result_t result;
9051 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07009052
gouji-new9ce77662009-05-06 10:44:45 +00009053 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00009054 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009055 result = PCI_ERS_RESULT_DISCONNECT;
9056 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +01009057 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00009058 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -08009059 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009060 pci_set_master(pdev);
9061 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00009062 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009063
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07009064 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009065
9066 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00009067 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009068 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07009069 }
Auke Kok9a799d72007-09-15 14:07:45 -07009070
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009071 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9072 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009073 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
9074 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009075 /* non-fatal, continue */
9076 }
Auke Kok9a799d72007-09-15 14:07:45 -07009077
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009078 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07009079}
9080
9081/**
9082 * ixgbe_io_resume - called when traffic can start flowing again.
9083 * @pdev: Pointer to PCI device
9084 *
9085 * This callback is called when the error recovery driver tells us that
9086 * its OK to resume normal operation.
9087 */
9088static void ixgbe_io_resume(struct pci_dev *pdev)
9089{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009090 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
9091 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07009092
Greg Rose83c61fa2011-09-07 05:59:35 +00009093#ifdef CONFIG_PCI_IOV
9094 if (adapter->vferr_refcount) {
9095 e_info(drv, "Resuming after VF err\n");
9096 adapter->vferr_refcount--;
9097 return;
9098 }
9099
9100#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00009101 if (netif_running(netdev))
9102 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009103
9104 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009105}
9106
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07009107static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07009108 .error_detected = ixgbe_io_error_detected,
9109 .slot_reset = ixgbe_io_slot_reset,
9110 .resume = ixgbe_io_resume,
9111};
9112
9113static struct pci_driver ixgbe_driver = {
9114 .name = ixgbe_driver_name,
9115 .id_table = ixgbe_pci_tbl,
9116 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05009117 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07009118#ifdef CONFIG_PM
9119 .suspend = ixgbe_suspend,
9120 .resume = ixgbe_resume,
9121#endif
9122 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +00009123 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -07009124 .err_handler = &ixgbe_err_handler
9125};
9126
9127/**
9128 * ixgbe_init_module - Driver Registration Routine
9129 *
9130 * ixgbe_init_module is the first routine called when the driver is
9131 * loaded. All it does is register with the PCI subsystem.
9132 **/
9133static int __init ixgbe_init_module(void)
9134{
9135 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00009136 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00009137 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07009138
Catherine Sullivan00949162012-08-10 01:59:10 +00009139 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +00009140
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009141 ret = pci_register_driver(&ixgbe_driver);
9142 if (ret) {
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009143 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009144 return ret;
9145 }
9146
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009147#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009148 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009149#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009150
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009151 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07009152}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07009153
Auke Kok9a799d72007-09-15 14:07:45 -07009154module_init(ixgbe_init_module);
9155
9156/**
9157 * ixgbe_exit_module - Driver Exit Cleanup Routine
9158 *
9159 * ixgbe_exit_module is called just before the driver is removed
9160 * from memory.
9161 **/
9162static void __exit ixgbe_exit_module(void)
9163{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009164#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009165 dca_unregister_notify(&dca_notifier);
9166#endif
Auke Kok9a799d72007-09-15 14:07:45 -07009167 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00009168
Catherine Sullivan00949162012-08-10 01:59:10 +00009169 ixgbe_dbg_exit();
Auke Kok9a799d72007-09-15 14:07:45 -07009170}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009171
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009172#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009173static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00009174 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009175{
9176 int ret_val;
9177
9178 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00009179 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009180
9181 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
9182}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009183
Alexander Duyckb4533682009-03-31 21:32:42 +00009184#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00009185
Auke Kok9a799d72007-09-15 14:07:45 -07009186module_exit(ixgbe_exit_module);
9187
9188/* ixgbe_main.c */