blob: 851c41377b47d7abea11624ea53d97617808965e [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>
45#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000046#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070047#include <linux/if_vlan.h>
John Fastabend2a47fa42013-11-06 09:54:52 -080048#include <linux/if_macvlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000049#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040050#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000051#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070052
53#include "ixgbe.h"
54#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000055#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000056#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070057
58char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070059static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000060 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000061#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000062char ixgbe_default_device_descr[] =
63 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000064#else
65static char ixgbe_default_device_descr[] =
66 "Intel(R) 10 Gigabit Network Connection";
67#endif
Don Skidmoref341c4e2014-01-17 01:21:37 -080068#define DRV_VERSION "3.19.1-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070069const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000070static const char ixgbe_copyright[] =
Mark Rustad0391bbe2014-02-28 15:48:55 -080071 "Copyright (c) 1999-2014 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070072
73static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070074 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000075 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080076 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070077};
78
79/* ixgbe_pci_tbl - PCI Device ID Table
80 *
81 * Wildcard entries (PCI_ANY_ID) should come last
82 * Last entry must be all 0s
83 *
84 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
85 * Class, Class Mask, private data (not used) }
86 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000087static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000088 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Don Skidmore8f583322013-07-27 06:25:38 +0000114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Auke Kok9a799d72007-09-15 14:07:45 -0700118 /* required last entry */
119 {0, }
120};
121MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
122
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400123#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800124static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000125 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800126static struct notifier_block dca_notifier = {
127 .notifier_call = ixgbe_notify_dca,
128 .next = NULL,
129 .priority = 0
130};
131#endif
132
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000133#ifdef CONFIG_PCI_IOV
134static unsigned int max_vfs;
135module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000136MODULE_PARM_DESC(max_vfs,
Jacob Keller170e8542013-11-09 04:52:32 -0800137 "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 +0000138#endif /* CONFIG_PCI_IOV */
139
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000140static unsigned int allow_unsupported_sfp;
141module_param(allow_unsupported_sfp, uint, 0);
142MODULE_PARM_DESC(allow_unsupported_sfp,
143 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
144
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000145#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
146static int debug = -1;
147module_param(debug, int, 0);
148MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
149
Auke Kok9a799d72007-09-15 14:07:45 -0700150MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
151MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
152MODULE_LICENSE("GPL");
153MODULE_VERSION(DRV_VERSION);
154
Mark Rustad14438462014-02-28 15:48:57 -0800155static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
156
Jacob Kellerb8e82002013-04-09 07:20:09 +0000157static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
158 u32 reg, u16 *value)
159{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000160 struct pci_dev *parent_dev;
161 struct pci_bus *parent_bus;
162
163 parent_bus = adapter->pdev->bus->parent;
164 if (!parent_bus)
165 return -1;
166
167 parent_dev = parent_bus->self;
168 if (!parent_dev)
169 return -1;
170
Yijing Wangc0798ed2013-09-04 17:30:08 +0000171 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000172 return -1;
173
Yijing Wangc0798ed2013-09-04 17:30:08 +0000174 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800175 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
176 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
177 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000178 return 0;
179}
180
181static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
182{
183 struct ixgbe_hw *hw = &adapter->hw;
184 u16 link_status = 0;
185 int err;
186
187 hw->bus.type = ixgbe_bus_type_pci_express;
188
189 /* Get the negotiated link width and speed from PCI config space of the
190 * parent, as this device is behind a switch
191 */
192 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
193
194 /* assume caller will handle error case */
195 if (err)
196 return err;
197
198 hw->bus.width = ixgbe_convert_bus_width(link_status);
199 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
200
201 return 0;
202}
203
Jacob Kellere027d1a2013-07-31 06:53:31 +0000204/**
205 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
206 * @hw: hw specific details
207 *
208 * This function is used by probe to determine whether a device's PCI-Express
209 * bandwidth details should be gathered from the parent bus instead of from the
210 * device. Used to ensure that various locations all have the correct device ID
211 * checks.
212 */
213static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
214{
215 switch (hw->device_id) {
216 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000217 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000218 return true;
219 default:
220 return false;
221 }
222}
223
224static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
225 int expected_gts)
226{
227 int max_gts = 0;
228 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
229 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
230 struct pci_dev *pdev;
231
232 /* determine whether to use the the parent device
233 */
234 if (ixgbe_pcie_from_parent(&adapter->hw))
235 pdev = adapter->pdev->bus->parent->self;
236 else
237 pdev = adapter->pdev;
238
239 if (pcie_get_minimum_link(pdev, &speed, &width) ||
240 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
241 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
242 return;
243 }
244
245 switch (speed) {
246 case PCIE_SPEED_2_5GT:
247 /* 8b/10b encoding reduces max throughput by 20% */
248 max_gts = 2 * width;
249 break;
250 case PCIE_SPEED_5_0GT:
251 /* 8b/10b encoding reduces max throughput by 20% */
252 max_gts = 4 * width;
253 break;
254 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000255 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000256 max_gts = 8 * width;
257 break;
258 default:
259 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
260 return;
261 }
262
263 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
264 max_gts);
265 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
266 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
267 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
268 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
269 "Unknown"),
270 width,
271 (speed == PCIE_SPEED_2_5GT ? "20%" :
272 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000273 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000274 "Unknown"));
275
276 if (max_gts < expected_gts) {
277 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
278 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
279 expected_gts);
280 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
281 }
282}
283
Alexander Duyck70864002011-04-27 09:13:56 +0000284static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
285{
286 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800287 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000288 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
289 schedule_work(&adapter->service_task);
290}
291
Mark Rustad2a1a0912014-01-14 18:53:15 -0800292static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
293{
294 struct ixgbe_adapter *adapter = hw->back;
295
296 if (!hw->hw_addr)
297 return;
298 hw->hw_addr = NULL;
299 e_dev_err("Adapter removed\n");
Mark Rustadb0483c82014-01-14 18:53:17 -0800300 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800301}
302
303void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
304{
305 u32 value;
306
307 /* The following check not only optimizes a bit by not
308 * performing a read on the status register when the
309 * register just read was a status register read that
310 * returned IXGBE_FAILED_READ_REG. It also blocks any
311 * potential recursion.
312 */
313 if (reg == IXGBE_STATUS) {
314 ixgbe_remove_adapter(hw);
315 return;
316 }
317 value = ixgbe_read_reg(hw, IXGBE_STATUS);
318 if (value == IXGBE_FAILED_READ_REG)
319 ixgbe_remove_adapter(hw);
320}
321
Mark Rustad14438462014-02-28 15:48:57 -0800322static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
323{
324 u16 value;
325
326 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
327 if (value == IXGBE_FAILED_READ_CFG_WORD) {
328 ixgbe_remove_adapter(hw);
329 return true;
330 }
331 return false;
332}
333
334u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
335{
336 struct ixgbe_adapter *adapter = hw->back;
337 u16 value;
338
339 if (ixgbe_removed(hw->hw_addr))
340 return IXGBE_FAILED_READ_CFG_WORD;
341 pci_read_config_word(adapter->pdev, reg, &value);
342 if (value == IXGBE_FAILED_READ_CFG_WORD &&
343 ixgbe_check_cfg_remove(hw, adapter->pdev))
344 return IXGBE_FAILED_READ_CFG_WORD;
345 return value;
346}
347
348#ifdef CONFIG_PCI_IOV
349static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
350{
351 struct ixgbe_adapter *adapter = hw->back;
352 u32 value;
353
354 if (ixgbe_removed(hw->hw_addr))
355 return IXGBE_FAILED_READ_CFG_DWORD;
356 pci_read_config_dword(adapter->pdev, reg, &value);
357 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
358 ixgbe_check_cfg_remove(hw, adapter->pdev))
359 return IXGBE_FAILED_READ_CFG_DWORD;
360 return value;
361}
362#endif /* CONFIG_PCI_IOV */
363
Alexander Duyck70864002011-04-27 09:13:56 +0000364static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
365{
366 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
367
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000368 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000369 smp_mb__before_clear_bit();
370 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
371}
372
Taku Izumidcd79ae2010-04-27 14:39:53 +0000373struct ixgbe_reg_info {
374 u32 ofs;
375 char *name;
376};
377
378static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
379
380 /* General Registers */
381 {IXGBE_CTRL, "CTRL"},
382 {IXGBE_STATUS, "STATUS"},
383 {IXGBE_CTRL_EXT, "CTRL_EXT"},
384
385 /* Interrupt Registers */
386 {IXGBE_EICR, "EICR"},
387
388 /* RX Registers */
389 {IXGBE_SRRCTL(0), "SRRCTL"},
390 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
391 {IXGBE_RDLEN(0), "RDLEN"},
392 {IXGBE_RDH(0), "RDH"},
393 {IXGBE_RDT(0), "RDT"},
394 {IXGBE_RXDCTL(0), "RXDCTL"},
395 {IXGBE_RDBAL(0), "RDBAL"},
396 {IXGBE_RDBAH(0), "RDBAH"},
397
398 /* TX Registers */
399 {IXGBE_TDBAL(0), "TDBAL"},
400 {IXGBE_TDBAH(0), "TDBAH"},
401 {IXGBE_TDLEN(0), "TDLEN"},
402 {IXGBE_TDH(0), "TDH"},
403 {IXGBE_TDT(0), "TDT"},
404 {IXGBE_TXDCTL(0), "TXDCTL"},
405
406 /* List Terminator */
407 {}
408};
409
410
411/*
412 * ixgbe_regdump - register printout routine
413 */
414static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
415{
416 int i = 0, j = 0;
417 char rname[16];
418 u32 regs[64];
419
420 switch (reginfo->ofs) {
421 case IXGBE_SRRCTL(0):
422 for (i = 0; i < 64; i++)
423 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
424 break;
425 case IXGBE_DCA_RXCTRL(0):
426 for (i = 0; i < 64; i++)
427 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
428 break;
429 case IXGBE_RDLEN(0):
430 for (i = 0; i < 64; i++)
431 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
432 break;
433 case IXGBE_RDH(0):
434 for (i = 0; i < 64; i++)
435 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
436 break;
437 case IXGBE_RDT(0):
438 for (i = 0; i < 64; i++)
439 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
440 break;
441 case IXGBE_RXDCTL(0):
442 for (i = 0; i < 64; i++)
443 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
444 break;
445 case IXGBE_RDBAL(0):
446 for (i = 0; i < 64; i++)
447 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
448 break;
449 case IXGBE_RDBAH(0):
450 for (i = 0; i < 64; i++)
451 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
452 break;
453 case IXGBE_TDBAL(0):
454 for (i = 0; i < 64; i++)
455 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
456 break;
457 case IXGBE_TDBAH(0):
458 for (i = 0; i < 64; i++)
459 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
460 break;
461 case IXGBE_TDLEN(0):
462 for (i = 0; i < 64; i++)
463 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
464 break;
465 case IXGBE_TDH(0):
466 for (i = 0; i < 64; i++)
467 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
468 break;
469 case IXGBE_TDT(0):
470 for (i = 0; i < 64; i++)
471 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
472 break;
473 case IXGBE_TXDCTL(0):
474 for (i = 0; i < 64; i++)
475 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
476 break;
477 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000478 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000479 IXGBE_READ_REG(hw, reginfo->ofs));
480 return;
481 }
482
483 for (i = 0; i < 8; i++) {
484 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000485 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000486 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000487 pr_cont(" %08x", regs[i*8+j]);
488 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000489 }
490
491}
492
493/*
494 * ixgbe_dump - Print registers, tx-rings and rx-rings
495 */
496static void ixgbe_dump(struct ixgbe_adapter *adapter)
497{
498 struct net_device *netdev = adapter->netdev;
499 struct ixgbe_hw *hw = &adapter->hw;
500 struct ixgbe_reg_info *reginfo;
501 int n = 0;
502 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000503 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000504 union ixgbe_adv_tx_desc *tx_desc;
505 struct my_u0 { u64 a; u64 b; } *u0;
506 struct ixgbe_ring *rx_ring;
507 union ixgbe_adv_rx_desc *rx_desc;
508 struct ixgbe_rx_buffer *rx_buffer_info;
509 u32 staterr;
510 int i = 0;
511
512 if (!netif_msg_hw(adapter))
513 return;
514
515 /* Print netdevice Info */
516 if (netdev) {
517 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000518 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000519 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000520 pr_info("%-15s %016lX %016lX %016lX\n",
521 netdev->name,
522 netdev->state,
523 netdev->trans_start,
524 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000525 }
526
527 /* Print Registers */
528 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000529 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000530 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
531 reginfo->name; reginfo++) {
532 ixgbe_regdump(hw, reginfo);
533 }
534
535 /* Print TX Ring Summary */
536 if (!netdev || !netif_running(netdev))
537 goto exit;
538
539 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000540 pr_info(" %s %s %s %s\n",
541 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
542 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000543 for (n = 0; n < adapter->num_tx_queues; n++) {
544 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000545 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000546 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000547 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000548 (u64)dma_unmap_addr(tx_buffer, dma),
549 dma_unmap_len(tx_buffer, len),
550 tx_buffer->next_to_watch,
551 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000552 }
553
554 /* Print TX Rings */
555 if (!netif_msg_tx_done(adapter))
556 goto rx_ring_summary;
557
558 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
559
560 /* Transmit Descriptor Formats
561 *
Josh Hay39ac8682012-09-26 05:59:36 +0000562 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000563 * +--------------------------------------------------------------+
564 * 0 | Buffer Address [63:0] |
565 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000566 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000567 * +--------------------------------------------------------------+
568 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000569 *
570 * 82598 Advanced Transmit Descriptor (Write-Back Format)
571 * +--------------------------------------------------------------+
572 * 0 | RSV [63:0] |
573 * +--------------------------------------------------------------+
574 * 8 | RSV | STA | NXTSEQ |
575 * +--------------------------------------------------------------+
576 * 63 36 35 32 31 0
577 *
578 * 82599+ Advanced Transmit Descriptor
579 * +--------------------------------------------------------------+
580 * 0 | Buffer Address [63:0] |
581 * +--------------------------------------------------------------+
582 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
583 * +--------------------------------------------------------------+
584 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
585 *
586 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
587 * +--------------------------------------------------------------+
588 * 0 | RSV [63:0] |
589 * +--------------------------------------------------------------+
590 * 8 | RSV | STA | RSV |
591 * +--------------------------------------------------------------+
592 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000593 */
594
595 for (n = 0; n < adapter->num_tx_queues; n++) {
596 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000597 pr_info("------------------------------------\n");
598 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
599 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000600 pr_info("%s%s %s %s %s %s\n",
601 "T [desc] [address 63:0 ] ",
602 "[PlPOIdStDDt Ln] [bi->dma ] ",
603 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000604
605 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000606 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000607 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000608 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000609 if (dma_unmap_len(tx_buffer, len) > 0) {
610 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
611 i,
612 le64_to_cpu(u0->a),
613 le64_to_cpu(u0->b),
614 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000615 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000616 tx_buffer->next_to_watch,
617 (u64)tx_buffer->time_stamp,
618 tx_buffer->skb);
619 if (i == tx_ring->next_to_use &&
620 i == tx_ring->next_to_clean)
621 pr_cont(" NTC/U\n");
622 else if (i == tx_ring->next_to_use)
623 pr_cont(" NTU\n");
624 else if (i == tx_ring->next_to_clean)
625 pr_cont(" NTC\n");
626 else
627 pr_cont("\n");
628
629 if (netif_msg_pktdata(adapter) &&
630 tx_buffer->skb)
631 print_hex_dump(KERN_INFO, "",
632 DUMP_PREFIX_ADDRESS, 16, 1,
633 tx_buffer->skb->data,
634 dma_unmap_len(tx_buffer, len),
635 true);
636 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000637 }
638 }
639
640 /* Print RX Rings Summary */
641rx_ring_summary:
642 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000643 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000644 for (n = 0; n < adapter->num_rx_queues; n++) {
645 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000646 pr_info("%5d %5X %5X\n",
647 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000648 }
649
650 /* Print RX Rings */
651 if (!netif_msg_rx_status(adapter))
652 goto exit;
653
654 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
655
Josh Hay39ac8682012-09-26 05:59:36 +0000656 /* Receive Descriptor Formats
657 *
658 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000659 * 63 1 0
660 * +-----------------------------------------------------+
661 * 0 | Packet Buffer Address [63:1] |A0/NSE|
662 * +----------------------------------------------+------+
663 * 8 | Header Buffer Address [63:1] | DD |
664 * +-----------------------------------------------------+
665 *
666 *
Josh Hay39ac8682012-09-26 05:59:36 +0000667 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000668 *
669 * 63 48 47 32 31 30 21 20 16 15 4 3 0
670 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000671 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
672 * | Packet | IP | | | | Type | Type |
673 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000674 * +------------------------------------------------------+
675 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
676 * +------------------------------------------------------+
677 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000678 *
679 * 82599+ Advanced Receive Descriptor (Read) Format
680 * 63 1 0
681 * +-----------------------------------------------------+
682 * 0 | Packet Buffer Address [63:1] |A0/NSE|
683 * +----------------------------------------------+------+
684 * 8 | Header Buffer Address [63:1] | DD |
685 * +-----------------------------------------------------+
686 *
687 *
688 * 82599+ Advanced Receive Descriptor (Write-Back) Format
689 *
690 * 63 48 47 32 31 30 21 20 17 16 4 3 0
691 * +------------------------------------------------------+
692 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
693 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
694 * |/ Flow Dir Flt ID | | | | | |
695 * +------------------------------------------------------+
696 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
697 * +------------------------------------------------------+
698 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000699 */
Josh Hay39ac8682012-09-26 05:59:36 +0000700
Taku Izumidcd79ae2010-04-27 14:39:53 +0000701 for (n = 0; n < adapter->num_rx_queues; n++) {
702 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000703 pr_info("------------------------------------\n");
704 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
705 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000706 pr_info("%s%s%s",
707 "R [desc] [ PktBuf A0] ",
708 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000709 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000710 pr_info("%s%s%s",
711 "RWB[desc] [PcsmIpSHl PtRs] ",
712 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000713 "<-- Adv Rx Write-Back format\n");
714
715 for (i = 0; i < rx_ring->count; i++) {
716 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000717 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000718 u0 = (struct my_u0 *)rx_desc;
719 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
720 if (staterr & IXGBE_RXD_STAT_DD) {
721 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000722 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000723 "%016llX ---------------- %p", i,
724 le64_to_cpu(u0->a),
725 le64_to_cpu(u0->b),
726 rx_buffer_info->skb);
727 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000728 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000729 "%016llX %016llX %p", i,
730 le64_to_cpu(u0->a),
731 le64_to_cpu(u0->b),
732 (u64)rx_buffer_info->dma,
733 rx_buffer_info->skb);
734
Emil Tantilov9c50c032012-07-26 01:21:24 +0000735 if (netif_msg_pktdata(adapter) &&
736 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000737 print_hex_dump(KERN_INFO, "",
738 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000739 page_address(rx_buffer_info->page) +
740 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000741 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000742 }
743 }
744
745 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000746 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000747 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000748 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000749 else
Joe Perchesc7689572010-09-07 21:35:17 +0000750 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000751
752 }
753 }
754
755exit:
756 return;
757}
758
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800759static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
760{
761 u32 ctrl_ext;
762
763 /* Let firmware take over control of h/w */
764 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
765 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000766 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800767}
768
769static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
770{
771 u32 ctrl_ext;
772
773 /* Let firmware know the driver has taken over */
774 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
775 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000776 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800777}
Auke Kok9a799d72007-09-15 14:07:45 -0700778
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000779/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000780 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
781 * @adapter: pointer to adapter struct
782 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
783 * @queue: queue to map the corresponding interrupt to
784 * @msix_vector: the vector to map to the corresponding queue
785 *
786 */
787static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000788 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700789{
790 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000791 struct ixgbe_hw *hw = &adapter->hw;
792 switch (hw->mac.type) {
793 case ixgbe_mac_82598EB:
794 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
795 if (direction == -1)
796 direction = 0;
797 index = (((direction * 64) + queue) >> 2) & 0x1F;
798 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
799 ivar &= ~(0xFF << (8 * (queue & 0x3)));
800 ivar |= (msix_vector << (8 * (queue & 0x3)));
801 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
802 break;
803 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800804 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000805 if (direction == -1) {
806 /* other causes */
807 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
808 index = ((queue & 1) * 8);
809 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
810 ivar &= ~(0xFF << index);
811 ivar |= (msix_vector << index);
812 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
813 break;
814 } else {
815 /* tx or rx causes */
816 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
817 index = ((16 * (queue & 1)) + (8 * direction));
818 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
819 ivar &= ~(0xFF << index);
820 ivar |= (msix_vector << index);
821 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
822 break;
823 }
824 default:
825 break;
826 }
Auke Kok9a799d72007-09-15 14:07:45 -0700827}
828
Alexander Duyckfe49f042009-06-04 16:00:09 +0000829static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000830 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000831{
832 u32 mask;
833
Alexander Duyckbd508172010-11-16 19:27:03 -0800834 switch (adapter->hw.mac.type) {
835 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000836 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
837 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800838 break;
839 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800840 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000841 mask = (qmask & 0xFFFFFFFF);
842 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
843 mask = (qmask >> 32);
844 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800845 break;
846 default:
847 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000848 }
849}
850
Alexander Duyck729739b2012-02-08 07:51:06 +0000851void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
852 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000853{
Alexander Duyck729739b2012-02-08 07:51:06 +0000854 if (tx_buffer->skb) {
855 dev_kfree_skb_any(tx_buffer->skb);
856 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000857 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000858 dma_unmap_addr(tx_buffer, dma),
859 dma_unmap_len(tx_buffer, len),
860 DMA_TO_DEVICE);
861 } else if (dma_unmap_len(tx_buffer, len)) {
862 dma_unmap_page(ring->dev,
863 dma_unmap_addr(tx_buffer, dma),
864 dma_unmap_len(tx_buffer, len),
865 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000866 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000867 tx_buffer->next_to_watch = NULL;
868 tx_buffer->skb = NULL;
869 dma_unmap_len_set(tx_buffer, len, 0);
870 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700871}
872
Alexander Duyck943561d2012-05-09 22:14:44 -0700873static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
874{
875 struct ixgbe_hw *hw = &adapter->hw;
876 struct ixgbe_hw_stats *hwstats = &adapter->stats;
877 int i;
878 u32 data;
879
880 if ((hw->fc.current_mode != ixgbe_fc_full) &&
881 (hw->fc.current_mode != ixgbe_fc_rx_pause))
882 return;
883
884 switch (hw->mac.type) {
885 case ixgbe_mac_82598EB:
886 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
887 break;
888 default:
889 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
890 }
891 hwstats->lxoffrxc += data;
892
893 /* refill credits (no tx hang) if we received xoff */
894 if (!data)
895 return;
896
897 for (i = 0; i < adapter->num_tx_queues; i++)
898 clear_bit(__IXGBE_HANG_CHECK_ARMED,
899 &adapter->tx_ring[i]->state);
900}
901
John Fastabendc84d3242010-11-16 19:27:12 -0800902static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700903{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700904 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800905 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800906 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000907 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800908 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700909 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700910
Alexander Duyck943561d2012-05-09 22:14:44 -0700911 if (adapter->ixgbe_ieee_pfc)
912 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800913
Alexander Duyck943561d2012-05-09 22:14:44 -0700914 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
915 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800916 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700917 }
John Fastabendc84d3242010-11-16 19:27:12 -0800918
919 /* update stats for each tc, only valid with PFC enabled */
920 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000921 u32 pxoffrxc;
922
John Fastabendc84d3242010-11-16 19:27:12 -0800923 switch (hw->mac.type) {
924 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000925 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800926 break;
927 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000928 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800929 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000930 hwstats->pxoffrxc[i] += pxoffrxc;
931 /* Get the TC for given UP */
932 tc = netdev_get_prio_tc_map(adapter->netdev, i);
933 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -0700934 }
935
John Fastabendc84d3242010-11-16 19:27:12 -0800936 /* disarm tx queues that have received xoff frames */
937 for (i = 0; i < adapter->num_tx_queues; i++) {
938 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -0800939
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000940 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800941 if (xoff[tc])
942 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
943 }
944}
945
946static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
947{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000948 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800949}
950
951static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
952{
John Fastabend2a47fa42013-11-06 09:54:52 -0800953 struct ixgbe_adapter *adapter;
954 struct ixgbe_hw *hw;
955 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -0800956
John Fastabend2a47fa42013-11-06 09:54:52 -0800957 if (ring->l2_accel_priv)
958 adapter = ring->l2_accel_priv->real_adapter;
959 else
960 adapter = netdev_priv(ring->netdev);
961
962 hw = &adapter->hw;
963 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
964 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -0800965
966 if (head != tail)
967 return (head < tail) ?
968 tail - head : (tail + ring->count - head);
969
970 return 0;
971}
972
973static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
974{
975 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
976 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
977 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
978 bool ret = false;
979
980 clear_check_for_tx_hang(tx_ring);
981
982 /*
983 * Check for a hung queue, but be thorough. This verifies
984 * that a transmit has been completed since the previous
985 * check AND there is at least one packet pending. The
986 * ARMED bit is set to indicate a potential hang. The
987 * bit is cleared if a pause frame is received to remove
988 * false hang detection due to PFC or 802.3x frames. By
989 * requiring this to fail twice we avoid races with
990 * pfc clearing the ARMED bit and conditions where we
991 * run the check_tx_hang logic with a transmit completion
992 * pending but without time to complete it yet.
993 */
994 if ((tx_done_old == tx_done) && tx_pending) {
995 /* make sure it is true for two checks in a row */
996 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
997 &tx_ring->state);
998 } else {
999 /* update completed stats and continue */
1000 tx_ring->tx_stats.tx_done_old = tx_done;
1001 /* reset the countdown */
1002 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1003 }
1004
1005 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -07001006}
1007
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001008/**
1009 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1010 * @adapter: driver private struct
1011 **/
1012static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1013{
1014
1015 /* Do the reset outside of interrupt context */
1016 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1017 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Jacob Keller12ff3f32012-12-01 07:57:17 +00001018 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001019 ixgbe_service_event_schedule(adapter);
1020 }
1021}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001022
Auke Kok9a799d72007-09-15 14:07:45 -07001023/**
1024 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001025 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001026 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -07001027 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001028static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001029 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07001030{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001031 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001032 struct ixgbe_tx_buffer *tx_buffer;
1033 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001034 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001035 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001036 unsigned int i = tx_ring->next_to_clean;
1037
1038 if (test_bit(__IXGBE_DOWN, &adapter->state))
1039 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001040
Alexander Duyckd3d00232011-07-15 02:31:25 +00001041 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001042 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001043 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001044
Alexander Duyck729739b2012-02-08 07:51:06 +00001045 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001046 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001047
Alexander Duyckd3d00232011-07-15 02:31:25 +00001048 /* if next_to_watch is not set then there is no work pending */
1049 if (!eop_desc)
1050 break;
1051
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001052 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001053 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001054
Alexander Duyckd3d00232011-07-15 02:31:25 +00001055 /* if DD is not set pending work has not been completed */
1056 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1057 break;
1058
Alexander Duyckd3d00232011-07-15 02:31:25 +00001059 /* clear next_to_watch to prevent false hangs */
1060 tx_buffer->next_to_watch = NULL;
1061
Alexander Duyck091a6242012-02-08 07:51:01 +00001062 /* update the statistics for this packet */
1063 total_bytes += tx_buffer->bytecount;
1064 total_packets += tx_buffer->gso_segs;
1065
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001066 /* free the skb */
1067 dev_kfree_skb_any(tx_buffer->skb);
1068
Alexander Duyck729739b2012-02-08 07:51:06 +00001069 /* unmap skb header data */
1070 dma_unmap_single(tx_ring->dev,
1071 dma_unmap_addr(tx_buffer, dma),
1072 dma_unmap_len(tx_buffer, len),
1073 DMA_TO_DEVICE);
1074
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001075 /* clear tx_buffer data */
1076 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +00001077 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001078
Alexander Duyck729739b2012-02-08 07:51:06 +00001079 /* unmap remaining buffers */
1080 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001081 tx_buffer++;
1082 tx_desc++;
1083 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001084 if (unlikely(!i)) {
1085 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001086 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001087 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001088 }
1089
Alexander Duyck729739b2012-02-08 07:51:06 +00001090 /* unmap any remaining paged data */
1091 if (dma_unmap_len(tx_buffer, len)) {
1092 dma_unmap_page(tx_ring->dev,
1093 dma_unmap_addr(tx_buffer, dma),
1094 dma_unmap_len(tx_buffer, len),
1095 DMA_TO_DEVICE);
1096 dma_unmap_len_set(tx_buffer, len, 0);
1097 }
1098 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001099
Alexander Duyck729739b2012-02-08 07:51:06 +00001100 /* move us one more past the eop_desc for start of next pkt */
1101 tx_buffer++;
1102 tx_desc++;
1103 i++;
1104 if (unlikely(!i)) {
1105 i -= tx_ring->count;
1106 tx_buffer = tx_ring->tx_buffer_info;
1107 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1108 }
1109
1110 /* issue prefetch for next Tx descriptor */
1111 prefetch(tx_desc);
1112
1113 /* update budget accounting */
1114 budget--;
1115 } while (likely(budget));
1116
1117 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001118 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001119 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001120 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001121 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001122 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001123 q_vector->tx.total_bytes += total_bytes;
1124 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001125
John Fastabendc84d3242010-11-16 19:27:12 -08001126 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001127 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001128 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001129 e_err(drv, "Detected Tx Unit Hang\n"
1130 " Tx Queue <%d>\n"
1131 " TDH, TDT <%x>, <%x>\n"
1132 " next_to_use <%x>\n"
1133 " next_to_clean <%x>\n"
1134 "tx_buffer_info[next_to_clean]\n"
1135 " time_stamp <%lx>\n"
1136 " jiffies <%lx>\n",
1137 tx_ring->queue_index,
1138 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1139 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001140 tx_ring->next_to_use, i,
1141 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001142
1143 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1144
1145 e_info(probe,
1146 "tx hang %d detected on queue %d, resetting adapter\n",
1147 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1148
1149 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001150 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001151
1152 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001153 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001154 }
Auke Kok9a799d72007-09-15 14:07:45 -07001155
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001156 netdev_tx_completed_queue(txring_txq(tx_ring),
1157 total_packets, total_bytes);
1158
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001159#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001160 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001161 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001162 /* Make sure that anybody stopping the queue after this
1163 * sees the new next_to_clean.
1164 */
1165 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001166 if (__netif_subqueue_stopped(tx_ring->netdev,
1167 tx_ring->queue_index)
1168 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1169 netif_wake_subqueue(tx_ring->netdev,
1170 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001171 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001172 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001173 }
Auke Kok9a799d72007-09-15 14:07:45 -07001174
Alexander Duyck59224552011-08-31 00:01:06 +00001175 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001176}
1177
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001178#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001179static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001180 struct ixgbe_ring *tx_ring,
1181 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001182{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001183 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001184 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1185 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001186
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001187 switch (hw->mac.type) {
1188 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001189 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001190 break;
1191 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001192 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001193 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1194 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1195 break;
1196 default:
1197 /* for unknown hardware do not write register */
1198 return;
1199 }
1200
1201 /*
1202 * We can enable relaxed ordering for reads, but not writes when
1203 * DCA is enabled. This is due to a known issue in some chipsets
1204 * which will cause the DCA tag to be cleared.
1205 */
1206 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1207 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1208 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1209
1210 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1211}
1212
1213static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1214 struct ixgbe_ring *rx_ring,
1215 int cpu)
1216{
1217 struct ixgbe_hw *hw = &adapter->hw;
1218 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1219 u8 reg_idx = rx_ring->reg_idx;
1220
1221
1222 switch (hw->mac.type) {
1223 case ixgbe_mac_82599EB:
1224 case ixgbe_mac_X540:
1225 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001226 break;
1227 default:
1228 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001229 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001230
1231 /*
1232 * We can enable relaxed ordering for reads, but not writes when
1233 * DCA is enabled. This is due to a known issue in some chipsets
1234 * which will cause the DCA tag to be cleared.
1235 */
1236 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001237 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1238
1239 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001240}
1241
1242static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1243{
1244 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001245 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001246 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001247
1248 if (q_vector->cpu == cpu)
1249 goto out_no_update;
1250
Alexander Duycka5579282012-02-08 07:50:04 +00001251 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001252 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001253
Alexander Duycka5579282012-02-08 07:50:04 +00001254 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001255 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001256
1257 q_vector->cpu = cpu;
1258out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001259 put_cpu();
1260}
1261
1262static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1263{
1264 int i;
1265
1266 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1267 return;
1268
Alexander Duycke35ec122009-05-21 13:07:12 +00001269 /* always use CB2 mode, difference is masked in the CB driver */
1270 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1271
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001272 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001273 adapter->q_vector[i]->cpu = -1;
1274 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001275 }
1276}
1277
1278static int __ixgbe_notify_dca(struct device *dev, void *data)
1279{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001280 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001281 unsigned long event = *(unsigned long *)data;
1282
Don Skidmore2a72c312011-07-20 02:27:05 +00001283 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001284 return 0;
1285
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001286 switch (event) {
1287 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001288 /* if we're already enabled, don't do it again */
1289 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1290 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001291 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001292 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001293 ixgbe_setup_dca(adapter);
1294 break;
1295 }
1296 /* Fall Through since DCA is disabled. */
1297 case DCA_PROVIDER_REMOVE:
1298 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1299 dca_remove_requester(dev);
1300 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1301 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1302 }
1303 break;
1304 }
1305
Denis V. Lunev652f0932008-03-27 14:39:17 +03001306 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001307}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001308
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001309#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001310static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1311 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001312 struct sk_buff *skb)
1313{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001314 if (ring->netdev->features & NETIF_F_RXHASH)
Tom Herbert38da9852013-12-18 16:47:04 +00001315 skb_set_hash(skb,
1316 le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1317 PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001318}
1319
Alexander Duyckf8003262012-03-03 02:35:52 +00001320#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001321/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001322 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001323 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001324 * @rx_desc: advanced rx descriptor
1325 *
1326 * Returns : true if it is FCoE pkt
1327 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001328static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001329 union ixgbe_adv_rx_desc *rx_desc)
1330{
1331 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1332
Alexander Duyck57efd442012-06-25 21:54:46 +00001333 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001334 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1335 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1336 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1337}
1338
Alexander Duyckf8003262012-03-03 02:35:52 +00001339#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001340/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001341 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001342 * @ring: structure containing ring specific data
1343 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001344 * @skb: skb currently being received and modified
1345 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001346static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001347 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001348 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001349{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001350 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001351
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001352 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001353 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001354 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001355
1356 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001357 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1358 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001359 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001360 return;
1361 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001362
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001363 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001364 return;
1365
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001366 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001367 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001368
1369 /*
1370 * 82599 errata, UDP frames with a 0 checksum can be marked as
1371 * checksum errors.
1372 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001373 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1374 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001375 return;
1376
Alexander Duyck8a0da212012-01-31 02:59:49 +00001377 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001378 return;
1379 }
1380
Auke Kok9a799d72007-09-15 14:07:45 -07001381 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001382 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001383}
1384
Alexander Duyck84ea2592010-11-16 19:26:49 -08001385static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001386{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001387 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001388
1389 /* update next to alloc since we have filled the ring */
1390 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001391 /*
1392 * Force memory writes to complete before letting h/w
1393 * know there are new descriptors to fetch. (Only
1394 * applicable for weak-ordered memory model archs,
1395 * such as IA-64).
1396 */
1397 wmb();
Mark Rustad84227bc2014-01-14 18:53:13 -08001398 ixgbe_write_tail(rx_ring, val);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001399}
1400
Alexander Duyckf990b792012-01-31 02:59:34 +00001401static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1402 struct ixgbe_rx_buffer *bi)
1403{
1404 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001405 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001406
Alexander Duyckf8003262012-03-03 02:35:52 +00001407 /* since we are recycling buffers we should seldom need to alloc */
1408 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001409 return true;
1410
Alexander Duyckf8003262012-03-03 02:35:52 +00001411 /* alloc new page for storage */
1412 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001413 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1414 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001415 if (unlikely(!page)) {
1416 rx_ring->rx_stats.alloc_rx_page_failed++;
1417 return false;
1418 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001419 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001420 }
1421
Alexander Duyckf8003262012-03-03 02:35:52 +00001422 /* map page for use */
1423 dma = dma_map_page(rx_ring->dev, page, 0,
1424 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001425
Alexander Duyckf8003262012-03-03 02:35:52 +00001426 /*
1427 * if mapping failed free memory back to system since
1428 * there isn't much point in holding memory we can't use
1429 */
1430 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001431 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001432 bi->page = NULL;
1433
Alexander Duyckf990b792012-01-31 02:59:34 +00001434 rx_ring->rx_stats.alloc_rx_page_failed++;
1435 return false;
1436 }
1437
Alexander Duyckf8003262012-03-03 02:35:52 +00001438 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001439 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001440
Alexander Duyckf990b792012-01-31 02:59:34 +00001441 return true;
1442}
1443
Auke Kok9a799d72007-09-15 14:07:45 -07001444/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001445 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001446 * @rx_ring: ring to place buffers on
1447 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001448 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001449void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001450{
Auke Kok9a799d72007-09-15 14:07:45 -07001451 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001452 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001453 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001454
Alexander Duyckf8003262012-03-03 02:35:52 +00001455 /* nothing to do */
1456 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001457 return;
1458
Alexander Duycke4f74022012-01-31 02:59:44 +00001459 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001460 bi = &rx_ring->rx_buffer_info[i];
1461 i -= rx_ring->count;
1462
Alexander Duyckf8003262012-03-03 02:35:52 +00001463 do {
1464 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001465 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001466
Alexander Duyckf8003262012-03-03 02:35:52 +00001467 /*
1468 * Refresh the desc even if buffer_addrs didn't change
1469 * because each write-back erases this info.
1470 */
1471 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001472
Alexander Duyckf990b792012-01-31 02:59:34 +00001473 rx_desc++;
1474 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001475 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001476 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001477 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001478 bi = rx_ring->rx_buffer_info;
1479 i -= rx_ring->count;
1480 }
1481
1482 /* clear the hdr_addr for the next_to_use descriptor */
1483 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001484
1485 cleaned_count--;
1486 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001487
Alexander Duyckf990b792012-01-31 02:59:34 +00001488 i += rx_ring->count;
1489
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001490 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001491 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001492}
1493
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001494/**
1495 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1496 * @data: pointer to the start of the headers
1497 * @max_len: total length of section to find headers in
1498 *
1499 * This function is meant to determine the length of headers that will
1500 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1501 * motivation of doing this is to only perform one pull for IPv4 TCP
1502 * packets so that we can do basic things like calculating the gso_size
1503 * based on the average data per packet.
1504 **/
1505static unsigned int ixgbe_get_headlen(unsigned char *data,
1506 unsigned int max_len)
1507{
1508 union {
1509 unsigned char *network;
1510 /* l2 headers */
1511 struct ethhdr *eth;
1512 struct vlan_hdr *vlan;
1513 /* l3 headers */
1514 struct iphdr *ipv4;
Alexander Duycka048b402012-05-24 08:26:29 +00001515 struct ipv6hdr *ipv6;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001516 } hdr;
1517 __be16 protocol;
1518 u8 nexthdr = 0; /* default to not TCP */
1519 u8 hlen;
1520
1521 /* this should never happen, but better safe than sorry */
1522 if (max_len < ETH_HLEN)
1523 return max_len;
1524
1525 /* initialize network frame pointer */
1526 hdr.network = data;
1527
1528 /* set first protocol and move network header forward */
1529 protocol = hdr.eth->h_proto;
1530 hdr.network += ETH_HLEN;
1531
1532 /* handle any vlan tag if present */
1533 if (protocol == __constant_htons(ETH_P_8021Q)) {
1534 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1535 return max_len;
1536
1537 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1538 hdr.network += VLAN_HLEN;
1539 }
1540
1541 /* handle L3 protocols */
1542 if (protocol == __constant_htons(ETH_P_IP)) {
1543 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1544 return max_len;
1545
1546 /* access ihl as a u8 to avoid unaligned access on ia64 */
1547 hlen = (hdr.network[0] & 0x0F) << 2;
1548
1549 /* verify hlen meets minimum size requirements */
1550 if (hlen < sizeof(struct iphdr))
1551 return hdr.network - data;
1552
Alexander Duycked83da12012-11-13 01:13:33 +00001553 /* record next protocol if header is present */
Alexander Duyck20967f42013-02-01 08:56:41 +00001554 if (!(hdr.ipv4->frag_off & htons(IP_OFFSET)))
Alexander Duycked83da12012-11-13 01:13:33 +00001555 nexthdr = hdr.ipv4->protocol;
Alexander Duycka048b402012-05-24 08:26:29 +00001556 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1557 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1558 return max_len;
1559
1560 /* record next protocol */
1561 nexthdr = hdr.ipv6->nexthdr;
Alexander Duycked83da12012-11-13 01:13:33 +00001562 hlen = sizeof(struct ipv6hdr);
Alexander Duyckf8003262012-03-03 02:35:52 +00001563#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001564 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1565 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1566 return max_len;
Alexander Duycked83da12012-11-13 01:13:33 +00001567 hlen = FCOE_HEADER_LEN;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001568#endif
1569 } else {
1570 return hdr.network - data;
1571 }
1572
Alexander Duycked83da12012-11-13 01:13:33 +00001573 /* relocate pointer to start of L4 header */
1574 hdr.network += hlen;
1575
Alexander Duycka048b402012-05-24 08:26:29 +00001576 /* finally sort out TCP/UDP */
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001577 if (nexthdr == IPPROTO_TCP) {
1578 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1579 return max_len;
1580
1581 /* access doff as a u8 to avoid unaligned access on ia64 */
1582 hlen = (hdr.network[12] & 0xF0) >> 2;
1583
1584 /* verify hlen meets minimum size requirements */
1585 if (hlen < sizeof(struct tcphdr))
1586 return hdr.network - data;
1587
1588 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001589 } else if (nexthdr == IPPROTO_UDP) {
1590 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1591 return max_len;
1592
1593 hdr.network += sizeof(struct udphdr);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001594 }
1595
1596 /*
1597 * If everything has gone correctly hdr.network should be the
1598 * data section of the packet and will be the end of the header.
1599 * If not then it probably represents the end of the last recognized
1600 * header.
1601 */
1602 if ((hdr.network - data) < max_len)
1603 return hdr.network - data;
1604 else
1605 return max_len;
1606}
1607
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001608static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1609 struct sk_buff *skb)
1610{
Alexander Duyckf8003262012-03-03 02:35:52 +00001611 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001612
1613 /* set gso_size to avoid messing up TCP MSS */
1614 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1615 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001616 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001617}
1618
1619static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1620 struct sk_buff *skb)
1621{
1622 /* if append_cnt is 0 then frame is not RSC */
1623 if (!IXGBE_CB(skb)->append_cnt)
1624 return;
1625
1626 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1627 rx_ring->rx_stats.rsc_flush++;
1628
1629 ixgbe_set_rsc_gso_size(rx_ring, skb);
1630
1631 /* gso_size is computed using append_cnt so always clear it last */
1632 IXGBE_CB(skb)->append_cnt = 0;
1633}
1634
Alexander Duyck8a0da212012-01-31 02:59:49 +00001635/**
1636 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1637 * @rx_ring: rx descriptor ring packet is being transacted on
1638 * @rx_desc: pointer to the EOP Rx descriptor
1639 * @skb: pointer to current skb being populated
1640 *
1641 * This function checks the ring, descriptor, and packet information in
1642 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1643 * other fields within the skb.
1644 **/
1645static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1646 union ixgbe_adv_rx_desc *rx_desc,
1647 struct sk_buff *skb)
1648{
John Fastabend43e95f12012-05-15 06:12:17 +00001649 struct net_device *dev = rx_ring->netdev;
1650
Alexander Duyck8a0da212012-01-31 02:59:49 +00001651 ixgbe_update_rsc_stats(rx_ring, skb);
1652
1653 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1654
1655 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1656
Jacob Keller6cb562d2012-12-05 07:24:41 +00001657 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001658
Patrick McHardyf6469682013-04-19 02:04:27 +00001659 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001660 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001661 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001662 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001663 }
1664
1665 skb_record_rx_queue(skb, rx_ring->queue_index);
1666
John Fastabend43e95f12012-05-15 06:12:17 +00001667 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001668}
1669
1670static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1671 struct sk_buff *skb)
1672{
1673 struct ixgbe_adapter *adapter = q_vector->adapter;
1674
Jacob Kellerb4640032013-10-01 04:33:54 -07001675 if (ixgbe_qv_busy_polling(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001676 netif_receive_skb(skb);
1677 else if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
Alexander Duyck8a0da212012-01-31 02:59:49 +00001678 napi_gro_receive(&q_vector->napi, skb);
1679 else
1680 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001681}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001682
Alexander Duyckf8003262012-03-03 02:35:52 +00001683/**
1684 * ixgbe_is_non_eop - process handling of non-EOP buffers
1685 * @rx_ring: Rx ring being processed
1686 * @rx_desc: Rx descriptor for current buffer
1687 * @skb: Current socket buffer containing buffer in progress
1688 *
1689 * This function updates next to clean. If the buffer is an EOP buffer
1690 * this function exits returning false, otherwise it will place the
1691 * sk_buff in the next buffer to be chained and return true indicating
1692 * that this is in fact a non-EOP buffer.
1693 **/
1694static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1695 union ixgbe_adv_rx_desc *rx_desc,
1696 struct sk_buff *skb)
1697{
1698 u32 ntc = rx_ring->next_to_clean + 1;
1699
1700 /* fetch, update, and store next to clean */
1701 ntc = (ntc < rx_ring->count) ? ntc : 0;
1702 rx_ring->next_to_clean = ntc;
1703
1704 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1705
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001706 /* update RSC append count if present */
1707 if (ring_is_rsc_enabled(rx_ring)) {
1708 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1709 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1710
1711 if (unlikely(rsc_enabled)) {
1712 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1713
1714 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1715 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1716
1717 /* update ntc based on RSC value */
1718 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1719 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1720 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1721 }
1722 }
1723
1724 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001725 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1726 return false;
1727
Alexander Duyckf8003262012-03-03 02:35:52 +00001728 /* place skb in next buffer to be received */
1729 rx_ring->rx_buffer_info[ntc].skb = skb;
1730 rx_ring->rx_stats.non_eop_descs++;
1731
1732 return true;
1733}
1734
1735/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001736 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1737 * @rx_ring: rx descriptor ring packet is being transacted on
1738 * @skb: pointer to current skb being adjusted
1739 *
1740 * This function is an ixgbe specific version of __pskb_pull_tail. The
1741 * main difference between this version and the original function is that
1742 * this function can make several assumptions about the state of things
1743 * that allow for significant optimizations versus the standard function.
1744 * As a result we can do things like drop a frag and maintain an accurate
1745 * truesize for the skb.
1746 */
1747static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1748 struct sk_buff *skb)
1749{
1750 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1751 unsigned char *va;
1752 unsigned int pull_len;
1753
1754 /*
1755 * it is valid to use page_address instead of kmap since we are
1756 * working with pages allocated out of the lomem pool per
1757 * alloc_page(GFP_ATOMIC)
1758 */
1759 va = skb_frag_address(frag);
1760
1761 /*
1762 * we need the header to contain the greater of either ETH_HLEN or
1763 * 60 bytes if the skb->len is less than 60 for skb_pad.
1764 */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001765 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001766
1767 /* align pull length to size of long to optimize memcpy performance */
1768 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1769
1770 /* update all of the pointers */
1771 skb_frag_size_sub(frag, pull_len);
1772 frag->page_offset += pull_len;
1773 skb->data_len -= pull_len;
1774 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001775}
1776
1777/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001778 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1779 * @rx_ring: rx descriptor ring packet is being transacted on
1780 * @skb: pointer to current skb being updated
1781 *
1782 * This function provides a basic DMA sync up for the first fragment of an
1783 * skb. The reason for doing this is that the first fragment cannot be
1784 * unmapped until we have reached the end of packet descriptor for a buffer
1785 * chain.
1786 */
1787static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1788 struct sk_buff *skb)
1789{
1790 /* if the page was released unmap it, else just sync our portion */
1791 if (unlikely(IXGBE_CB(skb)->page_released)) {
1792 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1793 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1794 IXGBE_CB(skb)->page_released = false;
1795 } else {
1796 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1797
1798 dma_sync_single_range_for_cpu(rx_ring->dev,
1799 IXGBE_CB(skb)->dma,
1800 frag->page_offset,
1801 ixgbe_rx_bufsz(rx_ring),
1802 DMA_FROM_DEVICE);
1803 }
1804 IXGBE_CB(skb)->dma = 0;
1805}
1806
1807/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001808 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1809 * @rx_ring: rx descriptor ring packet is being transacted on
1810 * @rx_desc: pointer to the EOP Rx descriptor
1811 * @skb: pointer to current skb being fixed
1812 *
1813 * Check for corrupted packet headers caused by senders on the local L2
1814 * embedded NIC switch not setting up their Tx Descriptors right. These
1815 * should be very rare.
1816 *
1817 * Also address the case where we are pulling data in on pages only
1818 * and as such no data is present in the skb header.
1819 *
1820 * In addition if skb is not at least 60 bytes we need to pad it so that
1821 * it is large enough to qualify as a valid Ethernet frame.
1822 *
1823 * Returns true if an error was encountered and skb was freed.
1824 **/
1825static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1826 union ixgbe_adv_rx_desc *rx_desc,
1827 struct sk_buff *skb)
1828{
Alexander Duyckf8003262012-03-03 02:35:52 +00001829 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001830
1831 /* verify that the packet does not have any known errors */
1832 if (unlikely(ixgbe_test_staterr(rx_desc,
1833 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1834 !(netdev->features & NETIF_F_RXALL))) {
1835 dev_kfree_skb_any(skb);
1836 return true;
1837 }
1838
Alexander Duyck19861ce2012-07-20 08:08:33 +00001839 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001840 if (skb_is_nonlinear(skb))
1841 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001842
Alexander Duyck57efd442012-06-25 21:54:46 +00001843#ifdef IXGBE_FCOE
1844 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1845 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1846 return false;
1847
1848#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001849 /* if skb_pad returns an error the skb was freed */
1850 if (unlikely(skb->len < 60)) {
1851 int pad_len = 60 - skb->len;
1852
1853 if (skb_pad(skb, pad_len))
1854 return true;
1855 __skb_put(skb, pad_len);
1856 }
1857
1858 return false;
1859}
1860
1861/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001862 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1863 * @rx_ring: rx descriptor ring to store buffers on
1864 * @old_buff: donor buffer to have page reused
1865 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001866 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001867 **/
1868static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1869 struct ixgbe_rx_buffer *old_buff)
1870{
1871 struct ixgbe_rx_buffer *new_buff;
1872 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001873
1874 new_buff = &rx_ring->rx_buffer_info[nta];
1875
1876 /* update, and store next to alloc */
1877 nta++;
1878 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1879
1880 /* transfer page from old buffer to new buffer */
1881 new_buff->page = old_buff->page;
1882 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001883 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001884
1885 /* sync the buffer for use by the device */
1886 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001887 new_buff->page_offset,
1888 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001889 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001890}
1891
1892/**
1893 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1894 * @rx_ring: rx descriptor ring to transact packets on
1895 * @rx_buffer: buffer containing page to add
1896 * @rx_desc: descriptor containing length of buffer written by hardware
1897 * @skb: sk_buff to place the data into
1898 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001899 * This function will add the data contained in rx_buffer->page to the skb.
1900 * This is done either through a direct copy if the data in the buffer is
1901 * less than the skb header size, otherwise it will just attach the page as
1902 * a frag to the skb.
1903 *
1904 * The function will then update the page offset if necessary and return
1905 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001906 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001907static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001908 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001909 union ixgbe_adv_rx_desc *rx_desc,
1910 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001911{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001912 struct page *page = rx_buffer->page;
1913 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001914#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001915 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001916#else
1917 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1918 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1919 ixgbe_rx_bufsz(rx_ring);
1920#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001921
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001922 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1923 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1924
1925 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1926
1927 /* we can reuse buffer as-is, just make sure it is local */
1928 if (likely(page_to_nid(page) == numa_node_id()))
1929 return true;
1930
1931 /* this page cannot be reused so discard it */
1932 put_page(page);
1933 return false;
1934 }
1935
Alexander Duyck0549ae22012-07-20 08:08:18 +00001936 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1937 rx_buffer->page_offset, size, truesize);
1938
Alexander Duyck09816fb2012-07-20 08:08:23 +00001939 /* avoid re-using remote pages */
1940 if (unlikely(page_to_nid(page) != numa_node_id()))
1941 return false;
1942
1943#if (PAGE_SIZE < 8192)
1944 /* if we are only owner of page we can reuse it */
1945 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001946 return false;
1947
1948 /* flip page offset to other buffer */
1949 rx_buffer->page_offset ^= truesize;
1950
Alexander Duyck09816fb2012-07-20 08:08:23 +00001951 /*
1952 * since we are the only owner of the page and we need to
1953 * increment it, just set the value to 2 in order to avoid
1954 * an unecessary locked operation
1955 */
1956 atomic_set(&page->_count, 2);
1957#else
1958 /* move offset up to the next cache line */
1959 rx_buffer->page_offset += truesize;
1960
1961 if (rx_buffer->page_offset > last_offset)
1962 return false;
1963
Alexander Duyck0549ae22012-07-20 08:08:18 +00001964 /* bump ref count on page before it is given to the stack */
1965 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001966#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001967
1968 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001969}
1970
Alexander Duyck18806c92012-07-20 08:08:44 +00001971static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1972 union ixgbe_adv_rx_desc *rx_desc)
1973{
1974 struct ixgbe_rx_buffer *rx_buffer;
1975 struct sk_buff *skb;
1976 struct page *page;
1977
1978 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1979 page = rx_buffer->page;
1980 prefetchw(page);
1981
1982 skb = rx_buffer->skb;
1983
1984 if (likely(!skb)) {
1985 void *page_addr = page_address(page) +
1986 rx_buffer->page_offset;
1987
1988 /* prefetch first cache line of first page */
1989 prefetch(page_addr);
1990#if L1_CACHE_BYTES < 128
1991 prefetch(page_addr + L1_CACHE_BYTES);
1992#endif
1993
1994 /* allocate a skb to store the frags */
1995 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1996 IXGBE_RX_HDR_SIZE);
1997 if (unlikely(!skb)) {
1998 rx_ring->rx_stats.alloc_rx_buff_failed++;
1999 return NULL;
2000 }
2001
2002 /*
2003 * we will be copying header into skb->data in
2004 * pskb_may_pull so it is in our interest to prefetch
2005 * it now to avoid a possible cache miss
2006 */
2007 prefetchw(skb->data);
2008
2009 /*
2010 * Delay unmapping of the first packet. It carries the
2011 * header information, HW may still access the header
2012 * after the writeback. Only unmap it when EOP is
2013 * reached
2014 */
2015 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
2016 goto dma_sync;
2017
2018 IXGBE_CB(skb)->dma = rx_buffer->dma;
2019 } else {
2020 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2021 ixgbe_dma_sync_frag(rx_ring, skb);
2022
2023dma_sync:
2024 /* we are reusing so sync this buffer for CPU use */
2025 dma_sync_single_range_for_cpu(rx_ring->dev,
2026 rx_buffer->dma,
2027 rx_buffer->page_offset,
2028 ixgbe_rx_bufsz(rx_ring),
2029 DMA_FROM_DEVICE);
2030 }
2031
2032 /* pull page into skb */
2033 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
2034 /* hand second half of page back to the ring */
2035 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
2036 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
2037 /* the page has been released from the ring */
2038 IXGBE_CB(skb)->page_released = true;
2039 } else {
2040 /* we are not reusing the buffer so unmap it */
2041 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
2042 ixgbe_rx_pg_size(rx_ring),
2043 DMA_FROM_DEVICE);
2044 }
2045
2046 /* clear contents of buffer_info */
2047 rx_buffer->skb = NULL;
2048 rx_buffer->dma = 0;
2049 rx_buffer->page = NULL;
2050
2051 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002052}
2053
2054/**
2055 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2056 * @q_vector: structure containing interrupt and ring information
2057 * @rx_ring: rx descriptor ring to transact packets on
2058 * @budget: Total limit on number of packets to process
2059 *
2060 * This function provides a "bounce buffer" approach to Rx interrupt
2061 * processing. The advantage to this is that on systems that have
2062 * expensive overhead for IOMMU access this provides a means of avoiding
2063 * it by maintaining the mapping of the page to the syste.
2064 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002065 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002066 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002067static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002068 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002069 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002070{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002071 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00002072#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00002073 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00002074 int ddp_bytes;
2075 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002076#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002077 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002078
Alexander Duyckf8003262012-03-03 02:35:52 +00002079 do {
Alexander Duyckf8003262012-03-03 02:35:52 +00002080 union ixgbe_adv_rx_desc *rx_desc;
2081 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002082
Alexander Duyckf8003262012-03-03 02:35:52 +00002083 /* return some buffers to hardware, one at a time is too slow */
2084 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2085 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2086 cleaned_count = 0;
2087 }
Auke Kok9a799d72007-09-15 14:07:45 -07002088
Alexander Duyck18806c92012-07-20 08:08:44 +00002089 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07002090
Alexander Duyckf8003262012-03-03 02:35:52 +00002091 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
2092 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002093
Alexander Duyckf8003262012-03-03 02:35:52 +00002094 /*
2095 * This memory barrier is needed to keep us from reading
2096 * any other fields out of the rx_desc until we know the
2097 * RXD_STAT_DD bit is set
2098 */
2099 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002100
Alexander Duyck18806c92012-07-20 08:08:44 +00002101 /* retrieve a buffer from the ring */
2102 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00002103
Alexander Duyck18806c92012-07-20 08:08:44 +00002104 /* exit if we failed to retrieve a buffer */
2105 if (!skb)
2106 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002107
Auke Kok9a799d72007-09-15 14:07:45 -07002108 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002109
Alexander Duyckf8003262012-03-03 02:35:52 +00002110 /* place incomplete frames back on ring for completion */
2111 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2112 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002113
Alexander Duyckf8003262012-03-03 02:35:52 +00002114 /* verify the packet layout is correct */
2115 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2116 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002117
2118 /* probably a little skewed due to removing CRC */
2119 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002120
Alexander Duyck8a0da212012-01-31 02:59:49 +00002121 /* populate checksum, timestamp, VLAN, and protocol */
2122 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2123
Yi Zou332d4a72009-05-13 13:11:53 +00002124#ifdef IXGBE_FCOE
2125 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002126 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002127 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002128 /* include DDPed FCoE data */
2129 if (ddp_bytes > 0) {
2130 if (!mss) {
2131 mss = rx_ring->netdev->mtu -
2132 sizeof(struct fcoe_hdr) -
2133 sizeof(struct fc_frame_header) -
2134 sizeof(struct fcoe_crc_eof);
2135 if (mss > 512)
2136 mss &= ~511;
2137 }
2138 total_rx_bytes += ddp_bytes;
2139 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2140 mss);
2141 }
David S. Miller823dcd22011-08-20 10:39:12 -07002142 if (!ddp_bytes) {
2143 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002144 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002145 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002146 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002147
Yi Zou332d4a72009-05-13 13:11:53 +00002148#endif /* IXGBE_FCOE */
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03002149 skb_mark_napi_id(skb, &q_vector->napi);
Alexander Duyck8a0da212012-01-31 02:59:49 +00002150 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002151
Alexander Duyckf8003262012-03-03 02:35:52 +00002152 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002153 total_rx_packets++;
2154 } while (likely(total_rx_packets < budget));
Auke Kok9a799d72007-09-15 14:07:45 -07002155
Alexander Duyckc267fc12010-11-16 19:27:00 -08002156 u64_stats_update_begin(&rx_ring->syncp);
2157 rx_ring->stats.packets += total_rx_packets;
2158 rx_ring->stats.bytes += total_rx_bytes;
2159 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002160 q_vector->rx.total_packets += total_rx_packets;
2161 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002162
Alexander Duyckf8003262012-03-03 02:35:52 +00002163 if (cleaned_count)
2164 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2165
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002166 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002167}
2168
Cong Wange0d10952013-08-01 11:10:25 +08002169#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002170/* must be called with local_bh_disable()d */
2171static int ixgbe_low_latency_recv(struct napi_struct *napi)
2172{
2173 struct ixgbe_q_vector *q_vector =
2174 container_of(napi, struct ixgbe_q_vector, napi);
2175 struct ixgbe_adapter *adapter = q_vector->adapter;
2176 struct ixgbe_ring *ring;
2177 int found = 0;
2178
2179 if (test_bit(__IXGBE_DOWN, &adapter->state))
2180 return LL_FLUSH_FAILED;
2181
2182 if (!ixgbe_qv_lock_poll(q_vector))
2183 return LL_FLUSH_BUSY;
2184
2185 ixgbe_for_each_ring(ring, q_vector->rx) {
2186 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
Jacob Kellerb4640032013-10-01 04:33:54 -07002187#ifdef BP_EXTENDED_STATS
Eliezer Tamir7e15b902013-06-10 11:40:31 +03002188 if (found)
2189 ring->stats.cleaned += found;
2190 else
2191 ring->stats.misses++;
2192#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002193 if (found)
2194 break;
2195 }
2196
2197 ixgbe_qv_unlock_poll(q_vector);
2198
2199 return found;
2200}
Cong Wange0d10952013-08-01 11:10:25 +08002201#endif /* CONFIG_NET_RX_BUSY_POLL */
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002202
Auke Kok9a799d72007-09-15 14:07:45 -07002203/**
2204 * ixgbe_configure_msix - Configure MSI-X hardware
2205 * @adapter: board private structure
2206 *
2207 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2208 * interrupts.
2209 **/
2210static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2211{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002212 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002213 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002214 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002215
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002216 /* Populate MSIX to EITR Select */
2217 if (adapter->num_vfs > 32) {
2218 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2219 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2220 }
2221
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002222 /*
2223 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002224 * corresponding register.
2225 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002226 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002227 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002228 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002229
Alexander Duycka5579282012-02-08 07:50:04 +00002230 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002231 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002232
Alexander Duycka5579282012-02-08 07:50:04 +00002233 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002234 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002235
Alexander Duyckfe49f042009-06-04 16:00:09 +00002236 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002237 }
2238
Alexander Duyckbd508172010-11-16 19:27:03 -08002239 switch (adapter->hw.mac.type) {
2240 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002241 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002242 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002243 break;
2244 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002245 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002246 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002247 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002248 default:
2249 break;
2250 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002251 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002252
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002253 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002254 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002255 mask &= ~(IXGBE_EIMS_OTHER |
2256 IXGBE_EIMS_MAILBOX |
2257 IXGBE_EIMS_LSC);
2258
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002259 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002260}
2261
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002262enum latency_range {
2263 lowest_latency = 0,
2264 low_latency = 1,
2265 bulk_latency = 2,
2266 latency_invalid = 255
2267};
2268
2269/**
2270 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002271 * @q_vector: structure containing interrupt and ring information
2272 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002273 *
2274 * Stores a new ITR value based on packets and byte
2275 * counts during the last interrupt. The advantage of per interrupt
2276 * computation is faster updates and more accurate ITR for the current
2277 * traffic pattern. Constants in this function were computed
2278 * based on theoretical maximum wire speed and thresholds were set based
2279 * on testing data as well as attempting to minimize response time
2280 * while increasing bulk throughput.
2281 * this functionality is controlled by the InterruptThrottleRate module
2282 * parameter (see ixgbe_param.c)
2283 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002284static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2285 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002286{
Alexander Duyckbd198052011-06-11 01:45:08 +00002287 int bytes = ring_container->total_bytes;
2288 int packets = ring_container->total_packets;
2289 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002290 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002291 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002292
2293 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002294 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002295
2296 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002297 * 0-10MB/s lowest (100000 ints/s)
2298 * 10-20MB/s low (20000 ints/s)
2299 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002300 */
2301 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002302 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002303 if (timepassed_us == 0)
2304 return;
2305
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002306 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2307
2308 switch (itr_setting) {
2309 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002310 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002311 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002312 break;
2313 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002314 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002315 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002316 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002317 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002318 break;
2319 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002320 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002321 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002322 break;
2323 }
2324
Alexander Duyckbd198052011-06-11 01:45:08 +00002325 /* clear work counters since we have the values we need */
2326 ring_container->total_bytes = 0;
2327 ring_container->total_packets = 0;
2328
2329 /* write updated itr to ring container */
2330 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002331}
2332
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002333/**
2334 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002335 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002336 *
2337 * This function is made to be called by ethtool and by the driver
2338 * when it needs to update EITR registers at runtime. Hardware
2339 * specific quirks/differences are taken care of here.
2340 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002341void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002342{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002343 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002344 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002345 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002346 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002347
Alexander Duyckbd508172010-11-16 19:27:03 -08002348 switch (adapter->hw.mac.type) {
2349 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002350 /* must write high and low 16 bits to reset counter */
2351 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002352 break;
2353 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002354 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002355 /*
2356 * set the WDIS bit to not clear the timer bits and cause an
2357 * immediate assertion of the interrupt
2358 */
2359 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002360 break;
2361 default:
2362 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002363 }
2364 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2365}
2366
Alexander Duyckbd198052011-06-11 01:45:08 +00002367static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002368{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002369 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002370 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002371
Alexander Duyckbd198052011-06-11 01:45:08 +00002372 ixgbe_update_itr(q_vector, &q_vector->tx);
2373 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002374
Alexander Duyck08c88332011-06-11 01:45:03 +00002375 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002376
2377 switch (current_itr) {
2378 /* counts and packets in update_itr are dependent on these numbers */
2379 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002380 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002381 break;
2382 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002383 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002384 break;
2385 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002386 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002387 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002388 default:
2389 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002390 }
2391
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002392 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002393 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002394 new_itr = (10 * new_itr * q_vector->itr) /
2395 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002396
Alexander Duyckbd198052011-06-11 01:45:08 +00002397 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002398 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002399
2400 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002401 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002402}
2403
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002404/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002405 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002406 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002407 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002408static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002409{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002410 struct ixgbe_hw *hw = &adapter->hw;
2411 u32 eicr = adapter->interrupt_event;
2412
Alexander Duyckf0f97782011-04-22 04:08:09 +00002413 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002414 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002415
Alexander Duyckf0f97782011-04-22 04:08:09 +00002416 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2417 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2418 return;
2419
2420 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2421
Joe Perches7ca647b2010-09-07 21:35:40 +00002422 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002423 case IXGBE_DEV_ID_82599_T3_LOM:
2424 /*
2425 * Since the warning interrupt is for both ports
2426 * we don't have to check if:
2427 * - This interrupt wasn't for our port.
2428 * - We may have missed the interrupt so always have to
2429 * check if we got a LSC
2430 */
2431 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2432 !(eicr & IXGBE_EICR_LSC))
2433 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002434
Alexander Duyckf0f97782011-04-22 04:08:09 +00002435 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002436 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002437 bool link_up = false;
2438
Josh Hay3d292262012-12-15 03:28:19 +00002439 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002440
Alexander Duyckf0f97782011-04-22 04:08:09 +00002441 if (link_up)
2442 return;
2443 }
2444
2445 /* Check if this is not due to overtemp */
2446 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2447 return;
2448
2449 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002450 default:
2451 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2452 return;
2453 break;
2454 }
2455 e_crit(drv,
2456 "Network adapter has been stopped because it has over heated. "
2457 "Restart the computer. If the problem persists, "
2458 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002459
2460 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002461}
2462
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002463static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2464{
2465 struct ixgbe_hw *hw = &adapter->hw;
2466
2467 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2468 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002469 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002470 /* write to clear the interrupt */
2471 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2472 }
2473}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002474
Jacob Keller4f51bf72011-08-20 04:49:45 +00002475static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2476{
2477 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2478 return;
2479
2480 switch (adapter->hw.mac.type) {
2481 case ixgbe_mac_82599EB:
2482 /*
2483 * Need to check link state so complete overtemp check
2484 * on service task
2485 */
2486 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2487 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2488 adapter->interrupt_event = eicr;
2489 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2490 ixgbe_service_event_schedule(adapter);
2491 return;
2492 }
2493 return;
2494 case ixgbe_mac_X540:
2495 if (!(eicr & IXGBE_EICR_TS))
2496 return;
2497 break;
2498 default:
2499 return;
2500 }
2501
2502 e_crit(drv,
2503 "Network adapter has been stopped because it has over heated. "
2504 "Restart the computer. If the problem persists, "
2505 "power off the system and replace the adapter\n");
2506}
2507
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002508static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2509{
2510 struct ixgbe_hw *hw = &adapter->hw;
2511
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002512 if (eicr & IXGBE_EICR_GPI_SDP2) {
2513 /* Clear the interrupt */
2514 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002515 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2516 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2517 ixgbe_service_event_schedule(adapter);
2518 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002519 }
2520
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002521 if (eicr & IXGBE_EICR_GPI_SDP1) {
2522 /* Clear the interrupt */
2523 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002524 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2525 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2526 ixgbe_service_event_schedule(adapter);
2527 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002528 }
2529}
2530
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002531static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2532{
2533 struct ixgbe_hw *hw = &adapter->hw;
2534
2535 adapter->lsc_int++;
2536 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2537 adapter->link_check_timeout = jiffies;
2538 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2539 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002540 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002541 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002542 }
2543}
2544
Alexander Duyckfe49f042009-06-04 16:00:09 +00002545static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2546 u64 qmask)
2547{
2548 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002549 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002550
Alexander Duyckbd508172010-11-16 19:27:03 -08002551 switch (hw->mac.type) {
2552 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002553 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002554 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2555 break;
2556 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002557 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002558 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002559 if (mask)
2560 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002561 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002562 if (mask)
2563 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2564 break;
2565 default:
2566 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002567 }
2568 /* skip the flush */
2569}
2570
2571static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002572 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002573{
2574 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002575 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002576
Alexander Duyckbd508172010-11-16 19:27:03 -08002577 switch (hw->mac.type) {
2578 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002579 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002580 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2581 break;
2582 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002583 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002584 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002585 if (mask)
2586 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002587 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002588 if (mask)
2589 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2590 break;
2591 default:
2592 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002593 }
2594 /* skip the flush */
2595}
2596
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002597/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002598 * ixgbe_irq_enable - Enable default interrupt generation settings
2599 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002600 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002601static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2602 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002603{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002604 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002605
Alexander Duyck2c4af692011-07-15 07:29:55 +00002606 /* don't reenable LSC while waiting for link */
2607 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2608 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002609
Alexander Duyck2c4af692011-07-15 07:29:55 +00002610 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002611 switch (adapter->hw.mac.type) {
2612 case ixgbe_mac_82599EB:
2613 mask |= IXGBE_EIMS_GPI_SDP0;
2614 break;
2615 case ixgbe_mac_X540:
2616 mask |= IXGBE_EIMS_TS;
2617 break;
2618 default:
2619 break;
2620 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002621 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2622 mask |= IXGBE_EIMS_GPI_SDP1;
2623 switch (adapter->hw.mac.type) {
2624 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002625 mask |= IXGBE_EIMS_GPI_SDP1;
2626 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002627 case ixgbe_mac_X540:
2628 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002629 mask |= IXGBE_EIMS_MAILBOX;
2630 break;
2631 default:
2632 break;
2633 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002634
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002635 if (adapter->hw.mac.type == ixgbe_mac_X540)
2636 mask |= IXGBE_EIMS_TIMESYNC;
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002637
Alexander Duyck2c4af692011-07-15 07:29:55 +00002638 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2639 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2640 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002641
Alexander Duyck2c4af692011-07-15 07:29:55 +00002642 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2643 if (queues)
2644 ixgbe_irq_enable_queues(adapter, ~0);
2645 if (flush)
2646 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002647}
2648
Alexander Duyck2c4af692011-07-15 07:29:55 +00002649static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002650{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002651 struct ixgbe_adapter *adapter = data;
2652 struct ixgbe_hw *hw = &adapter->hw;
2653 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002654
Alexander Duyck2c4af692011-07-15 07:29:55 +00002655 /*
2656 * Workaround for Silicon errata. Use clear-by-write instead
2657 * of clear-by-read. Reading with EICS will return the
2658 * interrupt causes without clearing, which later be done
2659 * with the write to EICR.
2660 */
2661 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002662
2663 /* The lower 16bits of the EICR register are for the queue interrupts
2664 * which should be masked here in order to not accidently clear them if
2665 * the bits are high when ixgbe_msix_other is called. There is a race
2666 * condition otherwise which results in possible performance loss
2667 * especially if the ixgbe_msix_other interrupt is triggering
2668 * consistently (as it would when PPS is turned on for the X540 device)
2669 */
2670 eicr &= 0xFFFF0000;
2671
Alexander Duyck2c4af692011-07-15 07:29:55 +00002672 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002673
Alexander Duyck2c4af692011-07-15 07:29:55 +00002674 if (eicr & IXGBE_EICR_LSC)
2675 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002676
Alexander Duyck2c4af692011-07-15 07:29:55 +00002677 if (eicr & IXGBE_EICR_MAILBOX)
2678 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002679
Alexander Duyck2c4af692011-07-15 07:29:55 +00002680 switch (hw->mac.type) {
2681 case ixgbe_mac_82599EB:
2682 case ixgbe_mac_X540:
Don Skidmored773ce22014-02-25 17:58:53 -08002683 if (eicr & IXGBE_EICR_ECC) {
2684 e_info(link, "Received ECC Err, initiating reset\n");
2685 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2686 ixgbe_service_event_schedule(adapter);
2687 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2688 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002689 /* Handle Flow Director Full threshold interrupt */
2690 if (eicr & IXGBE_EICR_FLOW_DIR) {
2691 int reinit_count = 0;
2692 int i;
2693 for (i = 0; i < adapter->num_tx_queues; i++) {
2694 struct ixgbe_ring *ring = adapter->tx_ring[i];
2695 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2696 &ring->state))
2697 reinit_count++;
2698 }
2699 if (reinit_count) {
2700 /* no more flow director interrupts until after init */
2701 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2702 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2703 ixgbe_service_event_schedule(adapter);
2704 }
2705 }
2706 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002707 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002708 break;
2709 default:
2710 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002711 }
2712
Alexander Duyck2c4af692011-07-15 07:29:55 +00002713 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002714
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002715 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2716 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002717
Alexander Duyck2c4af692011-07-15 07:29:55 +00002718 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002719 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002720 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002721
Alexander Duyck2c4af692011-07-15 07:29:55 +00002722 return IRQ_HANDLED;
2723}
2724
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002725static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002726{
2727 struct ixgbe_q_vector *q_vector = data;
2728
Auke Kok9a799d72007-09-15 14:07:45 -07002729 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002730
2731 if (q_vector->rx.ring || q_vector->tx.ring)
2732 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002733
2734 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002735}
2736
Auke Kok9a799d72007-09-15 14:07:45 -07002737/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002738 * ixgbe_poll - NAPI Rx polling callback
2739 * @napi: structure for representing this polling device
2740 * @budget: how many packets driver is allowed to clean
2741 *
2742 * This function is used for legacy and MSI, NAPI mode
2743 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002744int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002745{
2746 struct ixgbe_q_vector *q_vector =
2747 container_of(napi, struct ixgbe_q_vector, napi);
2748 struct ixgbe_adapter *adapter = q_vector->adapter;
2749 struct ixgbe_ring *ring;
2750 int per_ring_budget;
2751 bool clean_complete = true;
2752
2753#ifdef CONFIG_IXGBE_DCA
2754 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2755 ixgbe_update_dca(q_vector);
2756#endif
2757
2758 ixgbe_for_each_ring(ring, q_vector->tx)
2759 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2760
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002761 if (!ixgbe_qv_lock_napi(q_vector))
2762 return budget;
2763
Alexander Duyckeb01b972012-02-08 07:51:27 +00002764 /* attempt to distribute budget to each queue fairly, but don't allow
2765 * the budget to go below 1 because we'll exit polling */
2766 if (q_vector->rx.count > 1)
2767 per_ring_budget = max(budget/q_vector->rx.count, 1);
2768 else
2769 per_ring_budget = budget;
2770
2771 ixgbe_for_each_ring(ring, q_vector->rx)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002772 clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring,
2773 per_ring_budget) < per_ring_budget);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002774
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002775 ixgbe_qv_unlock_napi(q_vector);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002776 /* If all work not completed, return budget and keep polling */
2777 if (!clean_complete)
2778 return budget;
2779
2780 /* all work done, exit the polling mode */
2781 napi_complete(napi);
2782 if (adapter->rx_itr_setting & 1)
2783 ixgbe_set_itr(q_vector);
2784 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2785 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2786
2787 return 0;
2788}
2789
2790/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002791 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2792 * @adapter: board private structure
2793 *
2794 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2795 * interrupts from the kernel.
2796 **/
2797static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2798{
2799 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002800 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002801 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002802
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002803 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002804 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002805 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002806
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002807 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002808 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002809 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002810 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002811 } else if (q_vector->rx.ring) {
2812 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2813 "%s-%s-%d", netdev->name, "rx", ri++);
2814 } else if (q_vector->tx.ring) {
2815 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2816 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002817 } else {
2818 /* skip this unused q_vector */
2819 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002820 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002821 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2822 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002823 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002824 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002825 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002826 goto free_queue_irqs;
2827 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002828 /* If Flow Director is enabled, set interrupt affinity */
2829 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2830 /* assign the mask for this irq */
2831 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002832 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002833 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002834 }
2835
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002836 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002837 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002838 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002839 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002840 goto free_queue_irqs;
2841 }
2842
2843 return 0;
2844
2845free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002846 while (vector) {
2847 vector--;
2848 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2849 NULL);
2850 free_irq(adapter->msix_entries[vector].vector,
2851 adapter->q_vector[vector]);
2852 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002853 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2854 pci_disable_msix(adapter->pdev);
2855 kfree(adapter->msix_entries);
2856 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002857 return err;
2858}
2859
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002860/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002861 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002862 * @irq: interrupt number
2863 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002864 **/
2865static irqreturn_t ixgbe_intr(int irq, void *data)
2866{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002867 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002868 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002869 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002870 u32 eicr;
2871
Don Skidmore54037502009-02-21 15:42:56 -08002872 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002873 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002874 * before the read of EICR.
2875 */
2876 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2877
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002878 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002879 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002880 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002881 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002882 /*
2883 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002884 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002885 * have disabled interrupts due to EIAM
2886 * finish the workaround of silicon errata on 82598. Unmask
2887 * the interrupt that we masked before the EICR read.
2888 */
2889 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2890 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002891 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002892 }
Auke Kok9a799d72007-09-15 14:07:45 -07002893
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002894 if (eicr & IXGBE_EICR_LSC)
2895 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002896
Alexander Duyckbd508172010-11-16 19:27:03 -08002897 switch (hw->mac.type) {
2898 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002899 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002900 /* Fall through */
2901 case ixgbe_mac_X540:
Don Skidmored773ce22014-02-25 17:58:53 -08002902 if (eicr & IXGBE_EICR_ECC) {
2903 e_info(link, "Received ECC Err, initiating reset\n");
2904 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2905 ixgbe_service_event_schedule(adapter);
2906 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2907 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00002908 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002909 break;
2910 default:
2911 break;
2912 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002913
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002914 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002915 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2916 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002917
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002918 /* would disable interrupts here but EIAM disabled it */
2919 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002920
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002921 /*
2922 * re-enable link(maybe) and non-queue interrupts, no flush.
2923 * ixgbe_poll will re-enable the queue interrupts
2924 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002925 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2926 ixgbe_irq_enable(adapter, false, false);
2927
Auke Kok9a799d72007-09-15 14:07:45 -07002928 return IRQ_HANDLED;
2929}
2930
2931/**
2932 * ixgbe_request_irq - initialize interrupts
2933 * @adapter: board private structure
2934 *
2935 * Attempts to configure interrupts using the best available
2936 * capabilities of the hardware and kernel.
2937 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002938static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002939{
2940 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002941 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002942
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002943 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002944 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002945 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002946 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002947 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002948 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002949 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002950 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002951
Alexander Duyckde88eee2012-02-08 07:49:59 +00002952 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002953 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002954
Auke Kok9a799d72007-09-15 14:07:45 -07002955 return err;
2956}
2957
2958static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2959{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002960 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002961
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002962 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002963 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002964 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002965 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002966
2967 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2968 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2969 struct msix_entry *entry = &adapter->msix_entries[vector];
2970
2971 /* free only the irqs that were actually requested */
2972 if (!q_vector->rx.ring && !q_vector->tx.ring)
2973 continue;
2974
2975 /* clear the affinity_mask in the IRQ descriptor */
2976 irq_set_affinity_hint(entry->vector, NULL);
2977
2978 free_irq(entry->vector, q_vector);
2979 }
2980
2981 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002982}
2983
2984/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002985 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2986 * @adapter: board private structure
2987 **/
2988static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2989{
Alexander Duyckbd508172010-11-16 19:27:03 -08002990 switch (adapter->hw.mac.type) {
2991 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002992 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002993 break;
2994 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002995 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002996 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2997 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002998 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002999 break;
3000 default:
3001 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003002 }
3003 IXGBE_WRITE_FLUSH(&adapter->hw);
3004 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003005 int vector;
3006
3007 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3008 synchronize_irq(adapter->msix_entries[vector].vector);
3009
3010 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003011 } else {
3012 synchronize_irq(adapter->pdev->irq);
3013 }
3014}
3015
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003016/**
Auke Kok9a799d72007-09-15 14:07:45 -07003017 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3018 *
3019 **/
3020static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3021{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003022 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003023
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003024 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003025
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003026 ixgbe_set_ivar(adapter, 0, 0, 0);
3027 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003028
Emil Tantilov396e7992010-07-01 20:05:12 +00003029 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003030}
3031
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003032/**
3033 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3034 * @adapter: board private structure
3035 * @ring: structure containing ring specific data
3036 *
3037 * Configure the Tx descriptor ring after a reset.
3038 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003039void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3040 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003041{
3042 struct ixgbe_hw *hw = &adapter->hw;
3043 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003044 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003045 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003046 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003047
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003048 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003049 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003050 IXGBE_WRITE_FLUSH(hw);
3051
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003052 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003053 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003054 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3055 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3056 ring->count * sizeof(union ixgbe_adv_tx_desc));
3057 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3058 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003059 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003060
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003061 /*
3062 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003063 * higher than 1 when:
3064 * - ITR is 0 as it could cause false TX hangs
3065 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003066 *
3067 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3068 * to or less than the number of on chip descriptors, which is
3069 * currently 40.
3070 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003071#if IS_ENABLED(CONFIG_BQL)
3072 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
3073#else
Alexander Duycke954b372012-02-08 07:49:38 +00003074 if (!ring->q_vector || (ring->q_vector->itr < 8))
Emil Tantilov67da0972013-01-25 06:19:20 +00003075#endif
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003076 txdctl |= (1 << 16); /* WTHRESH = 1 */
3077 else
3078 txdctl |= (8 << 16); /* WTHRESH = 8 */
3079
Alexander Duycke954b372012-02-08 07:49:38 +00003080 /*
3081 * Setting PTHRESH to 32 both improves performance
3082 * and avoids a TX hang with DFP enabled
3083 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003084 txdctl |= (1 << 8) | /* HTHRESH = 1 */
3085 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003086
3087 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003088 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003089 ring->atr_sample_rate = adapter->atr_sample_rate;
3090 ring->atr_count = 0;
3091 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3092 } else {
3093 ring->atr_sample_rate = 0;
3094 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003095
Alexander Duyckfd786b72013-01-12 06:33:31 +00003096 /* initialize XPS */
3097 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3098 struct ixgbe_q_vector *q_vector = ring->q_vector;
3099
3100 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003101 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003102 &q_vector->affinity_mask,
3103 ring->queue_index);
3104 }
3105
John Fastabendc84d3242010-11-16 19:27:12 -08003106 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3107
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003108 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003109 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3110
3111 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3112 if (hw->mac.type == ixgbe_mac_82598EB &&
3113 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3114 return;
3115
3116 /* poll to verify queue is enabled */
3117 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003118 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003119 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3120 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3121 if (!wait_loop)
3122 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003123}
3124
Alexander Duyck120ff942010-08-19 13:34:50 +00003125static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3126{
3127 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003128 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003129 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003130
3131 if (hw->mac.type == ixgbe_mac_82598EB)
3132 return;
3133
3134 /* disable the arbiter while setting MTQC */
3135 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3136 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3137 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3138
3139 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003140 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3141 mtqc = IXGBE_MTQC_VT_ENA;
3142 if (tcs > 4)
3143 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3144 else if (tcs > 1)
3145 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3146 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3147 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003148 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003149 mtqc |= IXGBE_MTQC_64VF;
3150 } else {
3151 if (tcs > 4)
3152 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3153 else if (tcs > 1)
3154 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3155 else
3156 mtqc = IXGBE_MTQC_64Q_1PB;
3157 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003158
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003159 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003160
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003161 /* Enable Security TX Buffer IFG for multiple pb */
3162 if (tcs) {
3163 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3164 sectx |= IXGBE_SECTX_DCB;
3165 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003166 }
3167
3168 /* re-enable the arbiter */
3169 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3170 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3171}
3172
Auke Kok9a799d72007-09-15 14:07:45 -07003173/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003174 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003175 * @adapter: board private structure
3176 *
3177 * Configure the Tx unit of the MAC after a reset.
3178 **/
3179static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3180{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003181 struct ixgbe_hw *hw = &adapter->hw;
3182 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003183 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003184
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003185 ixgbe_setup_mtqc(adapter);
3186
3187 if (hw->mac.type != ixgbe_mac_82598EB) {
3188 /* DMATXCTL.EN must be before Tx queues are enabled */
3189 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3190 dmatxctl |= IXGBE_DMATXCTL_TE;
3191 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3192 }
3193
Auke Kok9a799d72007-09-15 14:07:45 -07003194 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003195 for (i = 0; i < adapter->num_tx_queues; i++)
3196 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003197}
3198
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003199static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3200 struct ixgbe_ring *ring)
3201{
3202 struct ixgbe_hw *hw = &adapter->hw;
3203 u8 reg_idx = ring->reg_idx;
3204 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3205
3206 srrctl |= IXGBE_SRRCTL_DROP_EN;
3207
3208 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3209}
3210
3211static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3212 struct ixgbe_ring *ring)
3213{
3214 struct ixgbe_hw *hw = &adapter->hw;
3215 u8 reg_idx = ring->reg_idx;
3216 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3217
3218 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3219
3220 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3221}
3222
3223#ifdef CONFIG_IXGBE_DCB
3224void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3225#else
3226static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3227#endif
3228{
3229 int i;
3230 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3231
3232 if (adapter->ixgbe_ieee_pfc)
3233 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3234
3235 /*
3236 * We should set the drop enable bit if:
3237 * SR-IOV is enabled
3238 * or
3239 * Number of Rx queues > 1 and flow control is disabled
3240 *
3241 * This allows us to avoid head of line blocking for security
3242 * and performance reasons.
3243 */
3244 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3245 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3246 for (i = 0; i < adapter->num_rx_queues; i++)
3247 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3248 } else {
3249 for (i = 0; i < adapter->num_rx_queues; i++)
3250 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3251 }
3252}
3253
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003254#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003255
Yi Zoua6616b42009-08-06 13:05:23 +00003256static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003257 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003258{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003259 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003260 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003261 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003262
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003263 if (hw->mac.type == ixgbe_mac_82598EB) {
3264 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3265
3266 /*
3267 * if VMDq is not active we must program one srrctl register
3268 * per RSS queue since we have enabled RDRXCTL.MVMEN
3269 */
3270 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003271 }
3272
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003273 /* configure header buffer length, needed for RSC */
3274 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003275
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003276 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00003277 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003278
3279 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003280 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003281
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003282 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003283}
3284
Alexander Duyck05abb122010-08-19 13:35:41 +00003285static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003286{
Alexander Duyck05abb122010-08-19 13:35:41 +00003287 struct ixgbe_hw *hw = &adapter->hw;
3288 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00003289 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
3290 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00003291 u32 mrqc = 0, reta = 0;
3292 u32 rxcsum;
3293 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003294 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00003295
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003296 /*
3297 * Program table for at least 2 queues w/ SR-IOV so that VFs can
3298 * make full use of any rings they may have. We will use the
3299 * PSRTYPE register to control how many rings we use within the PF.
3300 */
3301 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3302 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003303
Alexander Duyck05abb122010-08-19 13:35:41 +00003304 /* Fill out hash function seeds */
3305 for (i = 0; i < 10; i++)
3306 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003307
Alexander Duyck05abb122010-08-19 13:35:41 +00003308 /* Fill out redirection table */
3309 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003310 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003311 j = 0;
3312 /* reta = 4-byte sliding window of
3313 * 0x00..(indices-1)(indices-1)00..etc. */
3314 reta = (reta << 8) | (j * 0x11);
3315 if ((i & 3) == 3)
3316 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3317 }
3318
3319 /* Disable indicating checksum in descriptor, enables RSS hash */
3320 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3321 rxcsum |= IXGBE_RXCSUM_PCSD;
3322 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3323
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003324 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003325 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003326 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003327 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003328 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003329
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003330 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3331 if (tcs > 4)
3332 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3333 else if (tcs > 1)
3334 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3335 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3336 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3337 else
3338 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3339 } else {
3340 if (tcs > 4)
3341 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3342 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003343 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3344 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003345 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003346 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003347 }
3348
Alexander Duyck05abb122010-08-19 13:35:41 +00003349 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003350 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3351 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3352 IXGBE_MRQC_RSS_FIELD_IPV6 |
3353 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003354
Alexander Duyckef6afc02012-02-08 07:51:53 +00003355 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3356 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3357 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3358 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3359
Alexander Duyck05abb122010-08-19 13:35:41 +00003360 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003361}
3362
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003363/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003364 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3365 * @adapter: address of board private structure
3366 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003367 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003368static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003369 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003370{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003371 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003372 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003373 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003374
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003375 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003376 return;
3377
Alexander Duyck73670962010-08-19 13:38:34 +00003378 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003379 rscctrl |= IXGBE_RSCCTL_RSCEN;
3380 /*
3381 * we must limit the number of descriptors so that the
3382 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003383 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003384 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003385 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003386 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003387}
3388
Alexander Duyck9e10e042010-08-19 13:40:06 +00003389#define IXGBE_MAX_RX_DESC_POLL 10
3390static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3391 struct ixgbe_ring *ring)
3392{
3393 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003394 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3395 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003396 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003397
Mark Rustadb0483c82014-01-14 18:53:17 -08003398 if (ixgbe_removed(hw->hw_addr))
3399 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003400 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3401 if (hw->mac.type == ixgbe_mac_82598EB &&
3402 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3403 return;
3404
3405 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003406 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003407 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3408 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3409
3410 if (!wait_loop) {
3411 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3412 "the polling period\n", reg_idx);
3413 }
3414}
3415
Yi Zou2d39d572011-01-06 14:29:56 +00003416void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3417 struct ixgbe_ring *ring)
3418{
3419 struct ixgbe_hw *hw = &adapter->hw;
3420 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3421 u32 rxdctl;
3422 u8 reg_idx = ring->reg_idx;
3423
Mark Rustadb0483c82014-01-14 18:53:17 -08003424 if (ixgbe_removed(hw->hw_addr))
3425 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003426 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3427 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3428
3429 /* write value back with RXDCTL.ENABLE bit cleared */
3430 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3431
3432 if (hw->mac.type == ixgbe_mac_82598EB &&
3433 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3434 return;
3435
3436 /* the hardware may take up to 100us to really disable the rx queue */
3437 do {
3438 udelay(10);
3439 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3440 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3441
3442 if (!wait_loop) {
3443 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3444 "the polling period\n", reg_idx);
3445 }
3446}
3447
Alexander Duyck84418e32010-08-19 13:40:54 +00003448void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3449 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003450{
3451 struct ixgbe_hw *hw = &adapter->hw;
3452 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003453 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003454 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003455
Alexander Duyck9e10e042010-08-19 13:40:06 +00003456 /* disable queue to avoid issues while updating state */
3457 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003458 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003459
Alexander Duyckacd37172010-08-19 13:36:05 +00003460 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3461 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3462 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3463 ring->count * sizeof(union ixgbe_adv_rx_desc));
3464 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3465 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003466 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003467
3468 ixgbe_configure_srrctl(adapter, ring);
3469 ixgbe_configure_rscctl(adapter, ring);
3470
3471 if (hw->mac.type == ixgbe_mac_82598EB) {
3472 /*
3473 * enable cache line friendly hardware writes:
3474 * PTHRESH=32 descriptors (half the internal cache),
3475 * this also removes ugly rx_no_buffer_count increment
3476 * HTHRESH=4 descriptors (to minimize latency on fetch)
3477 * WTHRESH=8 burst writeback up to two cache lines
3478 */
3479 rxdctl &= ~0x3FFFFF;
3480 rxdctl |= 0x080420;
3481 }
3482
3483 /* enable receive descriptor ring */
3484 rxdctl |= IXGBE_RXDCTL_ENABLE;
3485 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3486
3487 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003488 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003489}
3490
Alexander Duyck48654522010-08-19 13:36:27 +00003491static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3492{
3493 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003494 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003495 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003496
3497 /* PSRTYPE must be initialized in non 82598 adapters */
3498 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003499 IXGBE_PSRTYPE_UDPHDR |
3500 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003501 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003502 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003503
3504 if (hw->mac.type == ixgbe_mac_82598EB)
3505 return;
3506
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003507 if (rss_i > 3)
3508 psrtype |= 2 << 29;
3509 else if (rss_i > 1)
3510 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003511
John Fastabend2a47fa42013-11-06 09:54:52 -08003512 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3513 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003514}
3515
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003516static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3517{
3518 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003519 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003520 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003521 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003522
3523 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3524 return;
3525
3526 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003527 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3528 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003529 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003530 vmdctl |= IXGBE_VT_CTL_REPLEN;
3531 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003532
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003533 vf_shift = VMDQ_P(0) % 32;
3534 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003535
3536 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003537 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3538 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3539 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3540 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Greg Rose9b735982012-11-08 02:41:35 +00003541 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
3542 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003543
3544 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003545 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003546
3547 /*
3548 * Set up VF register offsets for selected VT Mode,
3549 * i.e. 32 or 64 VFs for SR-IOV
3550 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003551 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3552 case IXGBE_82599_VMDQ_8Q_MASK:
3553 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3554 break;
3555 case IXGBE_82599_VMDQ_4Q_MASK:
3556 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3557 break;
3558 default:
3559 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3560 break;
3561 }
3562
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003563 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3564
Alexander Duyck435b19f2012-05-18 06:34:08 +00003565
Greg Rosea985b6c32010-11-18 03:02:52 +00003566 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003567 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003568 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003569 /* For VFs that have spoof checking turned off */
3570 for (i = 0; i < adapter->num_vfs; i++) {
3571 if (!adapter->vfinfo[i].spoofchk_enabled)
3572 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3573 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003574}
3575
Alexander Duyck477de6e2010-08-19 13:38:11 +00003576static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003577{
Auke Kok9a799d72007-09-15 14:07:45 -07003578 struct ixgbe_hw *hw = &adapter->hw;
3579 struct net_device *netdev = adapter->netdev;
3580 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003581 struct ixgbe_ring *rx_ring;
3582 int i;
3583 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003584
Alexander Duyck477de6e2010-08-19 13:38:11 +00003585#ifdef IXGBE_FCOE
3586 /* adjust max frame to be able to do baby jumbo for FCoE */
3587 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3588 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3589 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3590
3591#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003592
3593 /* adjust max frame to be at least the size of a standard frame */
3594 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3595 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3596
Alexander Duyck477de6e2010-08-19 13:38:11 +00003597 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3598 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3599 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3600 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3601
3602 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003603 }
3604
Auke Kok9a799d72007-09-15 14:07:45 -07003605 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003606 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3607 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003608 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3609
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003610 /*
3611 * Setup the HW Rx Head and Tail Descriptor Pointers and
3612 * the Base and Length of the Rx Descriptor Ring
3613 */
Auke Kok9a799d72007-09-15 14:07:45 -07003614 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003615 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003616 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3617 set_ring_rsc_enabled(rx_ring);
3618 else
3619 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003620 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003621}
3622
Alexander Duyck73670962010-08-19 13:38:34 +00003623static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3624{
3625 struct ixgbe_hw *hw = &adapter->hw;
3626 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3627
3628 switch (hw->mac.type) {
3629 case ixgbe_mac_82598EB:
3630 /*
3631 * For VMDq support of different descriptor types or
3632 * buffer sizes through the use of multiple SRRCTL
3633 * registers, RDRXCTL.MVMEN must be set to 1
3634 *
3635 * also, the manual doesn't mention it clearly but DCA hints
3636 * will only use queue 0's tags unless this bit is set. Side
3637 * effects of setting this bit are only that SRRCTL must be
3638 * fully programmed [0..15]
3639 */
3640 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3641 break;
3642 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003643 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003644 /* Disable RSC for ACK packets */
3645 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3646 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3647 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3648 /* hardware requires some bits to be set by default */
3649 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3650 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3651 break;
3652 default:
3653 /* We should do nothing since we don't know this hardware */
3654 return;
3655 }
3656
3657 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3658}
3659
Alexander Duyck477de6e2010-08-19 13:38:11 +00003660/**
3661 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3662 * @adapter: board private structure
3663 *
3664 * Configure the Rx unit of the MAC after a reset.
3665 **/
3666static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3667{
3668 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003669 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003670 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003671
3672 /* disable receives while setting up the descriptors */
3673 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3674 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3675
3676 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003677 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003678
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003679 /* RSC Setup */
3680 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
3681 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
3682 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
3683 rfctl |= IXGBE_RFCTL_RSC_DIS;
3684 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
3685
Alexander Duyck9e10e042010-08-19 13:40:06 +00003686 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003687 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003688
Alexander Duyck477de6e2010-08-19 13:38:11 +00003689 /* set_rx_buffer_len must be called before ring initialization */
3690 ixgbe_set_rx_buffer_len(adapter);
3691
3692 /*
3693 * Setup the HW Rx Head and Tail Descriptor Pointers and
3694 * the Base and Length of the Rx Descriptor Ring
3695 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003696 for (i = 0; i < adapter->num_rx_queues; i++)
3697 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003698
Alexander Duyck9e10e042010-08-19 13:40:06 +00003699 /* disable drop enable for 82598 parts */
3700 if (hw->mac.type == ixgbe_mac_82598EB)
3701 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3702
3703 /* enable all receives */
3704 rxctrl |= IXGBE_RXCTRL_RXEN;
3705 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003706}
3707
Patrick McHardy80d5c362013-04-19 02:04:28 +00003708static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3709 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003710{
3711 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003712 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003713
3714 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003715 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003716 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003717
3718 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003719}
3720
Patrick McHardy80d5c362013-04-19 02:04:28 +00003721static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
3722 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003723{
3724 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003725 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003726
Auke Kok9a799d72007-09-15 14:07:45 -07003727 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003728 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003729 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003730
3731 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003732}
3733
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003734/**
3735 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3736 * @adapter: driver data
3737 */
3738static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3739{
3740 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003741 u32 vlnctrl;
3742
3743 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3744 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3745 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3746}
3747
3748/**
3749 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3750 * @adapter: driver data
3751 */
3752static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3753{
3754 struct ixgbe_hw *hw = &adapter->hw;
3755 u32 vlnctrl;
3756
3757 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3758 vlnctrl |= IXGBE_VLNCTRL_VFE;
3759 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3760 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3761}
3762
3763/**
3764 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3765 * @adapter: driver data
3766 */
3767static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3768{
3769 struct ixgbe_hw *hw = &adapter->hw;
3770 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003771 int i, j;
3772
3773 switch (hw->mac.type) {
3774 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003775 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3776 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003777 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3778 break;
3779 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003780 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003781 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08003782 struct ixgbe_ring *ring = adapter->rx_ring[i];
3783
3784 if (ring->l2_accel_priv)
3785 continue;
3786 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003787 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3788 vlnctrl &= ~IXGBE_RXDCTL_VME;
3789 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3790 }
3791 break;
3792 default:
3793 break;
3794 }
3795}
3796
3797/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003798 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003799 * @adapter: driver data
3800 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003801static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003802{
3803 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003804 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003805 int i, j;
3806
3807 switch (hw->mac.type) {
3808 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003809 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3810 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003811 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3812 break;
3813 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003814 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003815 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08003816 struct ixgbe_ring *ring = adapter->rx_ring[i];
3817
3818 if (ring->l2_accel_priv)
3819 continue;
3820 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003821 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3822 vlnctrl |= IXGBE_RXDCTL_VME;
3823 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3824 }
3825 break;
3826 default:
3827 break;
3828 }
3829}
3830
Auke Kok9a799d72007-09-15 14:07:45 -07003831static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3832{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003833 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003834
Patrick McHardy80d5c362013-04-19 02:04:28 +00003835 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003836
3837 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00003838 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003839}
3840
3841/**
Alexander Duyck28500622010-06-15 09:25:48 +00003842 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3843 * @netdev: network interface device structure
3844 *
3845 * Writes unicast address list to the RAR table.
3846 * Returns: -ENOMEM on failure/insufficient address space
3847 * 0 on no addresses written
3848 * X on writing X addresses to the RAR table
3849 **/
3850static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3851{
3852 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3853 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend95447462012-05-31 12:42:26 +00003854 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
Alexander Duyck28500622010-06-15 09:25:48 +00003855 int count = 0;
3856
John Fastabend2a47fa42013-11-06 09:54:52 -08003857 /* In SR-IOV/VMDQ modes significantly less RAR entries are available */
John Fastabend95447462012-05-31 12:42:26 +00003858 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3859 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3860
Alexander Duyck28500622010-06-15 09:25:48 +00003861 /* return ENOMEM indicating insufficient memory for addresses */
3862 if (netdev_uc_count(netdev) > rar_entries)
3863 return -ENOMEM;
3864
John Fastabend95447462012-05-31 12:42:26 +00003865 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003866 struct netdev_hw_addr *ha;
3867 /* return error if we do not support writing to RAR table */
3868 if (!hw->mac.ops.set_rar)
3869 return -ENOMEM;
3870
3871 netdev_for_each_uc_addr(ha, netdev) {
3872 if (!rar_entries)
3873 break;
3874 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003875 VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck28500622010-06-15 09:25:48 +00003876 count++;
3877 }
3878 }
3879 /* write the addresses in reverse order to avoid write combining */
3880 for (; rar_entries > 0 ; rar_entries--)
3881 hw->mac.ops.clear_rar(hw, rar_entries);
3882
3883 return count;
3884}
3885
3886/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003887 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003888 * @netdev: network interface device structure
3889 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003890 * The set_rx_method entry point is called whenever the unicast/multicast
3891 * address list or the network interface flags are updated. This routine is
3892 * responsible for configuring the hardware for proper unicast, multicast and
3893 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003894 **/
Greg Rose7f870472010-01-09 02:25:29 +00003895void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003896{
3897 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3898 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003899 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3900 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003901
3902 /* Check for Promiscuous and All Multicast modes */
3903
3904 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3905
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003906 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003907 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003908 fctrl |= IXGBE_FCTRL_BAM;
3909 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3910 fctrl |= IXGBE_FCTRL_PMCF;
3911
Alexander Duyck28500622010-06-15 09:25:48 +00003912 /* clear the bits we are changing the status of */
3913 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3914
Auke Kok9a799d72007-09-15 14:07:45 -07003915 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003916 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003917 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003918 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Greg Rose670224f2013-02-22 02:14:39 +00003919 /* Only disable hardware filter vlans in promiscuous mode
3920 * if SR-IOV and VMDQ are disabled - otherwise ensure
3921 * that hardware VLAN filters remain enabled.
3922 */
3923 if (!(adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED |
3924 IXGBE_FLAG_SRIOV_ENABLED)))
3925 ixgbe_vlan_filter_disable(adapter);
3926 else
3927 ixgbe_vlan_filter_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003928 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003929 if (netdev->flags & IFF_ALLMULTI) {
3930 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003931 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003932 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003933 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003934 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003935 }
3936
3937 /*
3938 * Write addresses to available RAR registers, if there is not
3939 * sufficient space to store all the addresses then enable
3940 * unicast promiscuous mode
3941 */
3942 count = ixgbe_write_uc_addr_list(netdev);
3943 if (count < 0) {
3944 fctrl |= IXGBE_FCTRL_UPE;
3945 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003946 }
3947
Emil Tantilovcf789592013-10-26 08:13:20 +00003948 /* Write addresses to the MTA, if the attempt fails
3949 * then we should just turn on promiscuous mode so
3950 * that we can at least receive multicast traffic
3951 */
3952 hw->mac.ops.update_mc_addr_list(hw, netdev);
3953 vmolr |= IXGBE_VMOLR_ROMPE;
3954
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003955 if (adapter->num_vfs)
Alexander Duyck28500622010-06-15 09:25:48 +00003956 ixgbe_restore_vf_multicasts(adapter);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003957
3958 if (hw->mac.type != ixgbe_mac_82598EB) {
3959 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003960 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3961 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003962 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003963 }
3964
Ben Greear3f2d1c02012-03-08 08:28:41 +00003965 /* This is useful for sniffing bad packets. */
3966 if (adapter->netdev->features & NETIF_F_RXALL) {
3967 /* UPE and MPE will be handled by normal PROMISC logic
3968 * in e1000e_set_rx_mode */
3969 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3970 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3971 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3972
3973 fctrl &= ~(IXGBE_FCTRL_DPF);
3974 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3975 }
3976
Auke Kok9a799d72007-09-15 14:07:45 -07003977 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003978
Patrick McHardyf6469682013-04-19 02:04:27 +00003979 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00003980 ixgbe_vlan_strip_enable(adapter);
3981 else
3982 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003983}
3984
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003985static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3986{
3987 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003988
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003989 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
3990 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003991 napi_enable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003992 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003993}
3994
3995static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3996{
3997 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003998
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003999 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004000 napi_disable(&adapter->q_vector[q_idx]->napi);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004001 while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) {
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004002 pr_info("QV %d locked\n", q_idx);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004003 usleep_range(1000, 20000);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004004 }
4005 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004006}
4007
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004008#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004009/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004010 * ixgbe_configure_dcb - Configure DCB hardware
4011 * @adapter: ixgbe adapter struct
4012 *
4013 * This is called by the driver on open to configure the DCB hardware.
4014 * This is also called by the gennetlink interface when reconfiguring
4015 * the DCB state.
4016 */
4017static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4018{
4019 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00004020 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004021
Alexander Duyck67ebd792010-08-19 13:34:04 +00004022 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4023 if (hw->mac.type == ixgbe_mac_82598EB)
4024 netif_set_gso_max_size(adapter->netdev, 65536);
4025 return;
4026 }
4027
4028 if (hw->mac.type == ixgbe_mac_82598EB)
4029 netif_set_gso_max_size(adapter->netdev, 32768);
4030
John Fastabendb1208182011-10-15 05:00:10 +00004031#ifdef IXGBE_FCOE
4032 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4033 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4034#endif
4035
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004036 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004037 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004038 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4039 DCB_TX_CONFIG);
4040 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4041 DCB_RX_CONFIG);
4042 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004043 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4044 ixgbe_dcb_hw_ets(&adapter->hw,
4045 adapter->ixgbe_ieee_ets,
4046 max_frame);
4047 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4048 adapter->ixgbe_ieee_pfc->pfc_en,
4049 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004050 }
John Fastabend8187cd42011-02-23 05:58:08 +00004051
4052 /* Enable RSS Hash per TC */
4053 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004054 u32 msb = 0;
4055 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004056
Alexander Duyckd411a932012-06-30 00:14:01 +00004057 while (rss_i) {
4058 msb++;
4059 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004060 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004061
Alexander Duyck4ae63732012-06-22 06:46:33 +00004062 /* write msb to all 8 TCs in one write */
4063 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004064 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004065}
John Fastabend9da712d2011-08-23 03:14:22 +00004066#endif
4067
4068/* Additional bittime to account for IXGBE framing */
4069#define IXGBE_ETH_FRAMING 20
4070
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004071/**
John Fastabend9da712d2011-08-23 03:14:22 +00004072 * ixgbe_hpbthresh - calculate high water mark for flow control
4073 *
4074 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004075 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004076 */
4077static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4078{
4079 struct ixgbe_hw *hw = &adapter->hw;
4080 struct net_device *dev = adapter->netdev;
4081 int link, tc, kb, marker;
4082 u32 dv_id, rx_pba;
4083
4084 /* Calculate max LAN frame size */
4085 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4086
4087#ifdef IXGBE_FCOE
4088 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004089 if ((dev->features & NETIF_F_FCOE_MTU) &&
4090 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4091 (pb == ixgbe_fcoe_get_tc(adapter)))
4092 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004093
4094#endif
John Fastabend9da712d2011-08-23 03:14:22 +00004095 /* Calculate delay value for device */
4096 switch (hw->mac.type) {
4097 case ixgbe_mac_X540:
4098 dv_id = IXGBE_DV_X540(link, tc);
4099 break;
4100 default:
4101 dv_id = IXGBE_DV(link, tc);
4102 break;
4103 }
4104
4105 /* Loopback switch introduces additional latency */
4106 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4107 dv_id += IXGBE_B2BT(tc);
4108
4109 /* Delay value is calculated in bit times convert to KB */
4110 kb = IXGBE_BT2KB(dv_id);
4111 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4112
4113 marker = rx_pba - kb;
4114
4115 /* It is possible that the packet buffer is not large enough
4116 * to provide required headroom. In this case throw an error
4117 * to user and a do the best we can.
4118 */
4119 if (marker < 0) {
4120 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4121 "headroom to support flow control."
4122 "Decrease MTU or number of traffic classes\n", pb);
4123 marker = tc + 1;
4124 }
4125
4126 return marker;
4127}
4128
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004129/**
John Fastabend9da712d2011-08-23 03:14:22 +00004130 * ixgbe_lpbthresh - calculate low water mark for for flow control
4131 *
4132 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004133 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004134 */
4135static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
4136{
4137 struct ixgbe_hw *hw = &adapter->hw;
4138 struct net_device *dev = adapter->netdev;
4139 int tc;
4140 u32 dv_id;
4141
4142 /* Calculate max LAN frame size */
4143 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4144
4145 /* Calculate delay value for device */
4146 switch (hw->mac.type) {
4147 case ixgbe_mac_X540:
4148 dv_id = IXGBE_LOW_DV_X540(tc);
4149 break;
4150 default:
4151 dv_id = IXGBE_LOW_DV(tc);
4152 break;
4153 }
4154
4155 /* Delay value is calculated in bit times convert to KB */
4156 return IXGBE_BT2KB(dv_id);
4157}
4158
4159/*
4160 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4161 */
4162static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4163{
4164 struct ixgbe_hw *hw = &adapter->hw;
4165 int num_tc = netdev_get_num_tc(adapter->netdev);
4166 int i;
4167
4168 if (!num_tc)
4169 num_tc = 1;
4170
4171 hw->fc.low_water = ixgbe_lpbthresh(adapter);
4172
4173 for (i = 0; i < num_tc; i++) {
4174 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
4175
4176 /* Low water marks must not be larger than high water marks */
4177 if (hw->fc.low_water > hw->fc.high_water[i])
4178 hw->fc.low_water = 0;
4179 }
4180}
John Fastabend80605c652011-05-02 12:34:10 +00004181
4182static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4183{
John Fastabend80605c652011-05-02 12:34:10 +00004184 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004185 int hdrm;
4186 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004187
4188 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4189 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004190 hdrm = 32 << adapter->fdir_pballoc;
4191 else
4192 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004193
Alexander Duyckf7e10272011-07-21 00:40:35 +00004194 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004195 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004196}
4197
Alexander Duycke4911d52011-05-11 07:18:52 +00004198static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4199{
4200 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004201 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004202 struct ixgbe_fdir_filter *filter;
4203
4204 spin_lock(&adapter->fdir_perfect_lock);
4205
4206 if (!hlist_empty(&adapter->fdir_filter_list))
4207 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4208
Sasha Levinb67bfe02013-02-27 17:06:00 -08004209 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004210 &adapter->fdir_filter_list, fdir_node) {
4211 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004212 &filter->filter,
4213 filter->sw_idx,
4214 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4215 IXGBE_FDIR_DROP_QUEUE :
4216 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004217 }
4218
4219 spin_unlock(&adapter->fdir_perfect_lock);
4220}
4221
John Fastabend2a47fa42013-11-06 09:54:52 -08004222static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4223 struct ixgbe_adapter *adapter)
4224{
4225 struct ixgbe_hw *hw = &adapter->hw;
4226 u32 vmolr;
4227
4228 /* No unicast promiscuous support for VMDQ devices. */
4229 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4230 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4231
4232 /* clear the affected bit */
4233 vmolr &= ~IXGBE_VMOLR_MPE;
4234
4235 if (dev->flags & IFF_ALLMULTI) {
4236 vmolr |= IXGBE_VMOLR_MPE;
4237 } else {
4238 vmolr |= IXGBE_VMOLR_ROMPE;
4239 hw->mac.ops.update_mc_addr_list(hw, dev);
4240 }
4241 ixgbe_write_uc_addr_list(adapter->netdev);
4242 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4243}
4244
4245static void ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4246 u8 *addr, u16 pool)
4247{
4248 struct ixgbe_hw *hw = &adapter->hw;
4249 unsigned int entry;
4250
4251 entry = hw->mac.num_rar_entries - pool;
4252 hw->mac.ops.set_rar(hw, entry, addr, VMDQ_P(pool), IXGBE_RAH_AV);
4253}
4254
4255static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4256{
4257 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004258 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004259 struct ixgbe_hw *hw = &adapter->hw;
4260 u16 pool = vadapter->pool;
4261 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4262 IXGBE_PSRTYPE_UDPHDR |
4263 IXGBE_PSRTYPE_IPV4HDR |
4264 IXGBE_PSRTYPE_L2HDR |
4265 IXGBE_PSRTYPE_IPV6HDR;
4266
4267 if (hw->mac.type == ixgbe_mac_82598EB)
4268 return;
4269
4270 if (rss_i > 3)
4271 psrtype |= 2 << 29;
4272 else if (rss_i > 1)
4273 psrtype |= 1 << 29;
4274
4275 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4276}
4277
4278/**
4279 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4280 * @rx_ring: ring to free buffers from
4281 **/
4282static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4283{
4284 struct device *dev = rx_ring->dev;
4285 unsigned long size;
4286 u16 i;
4287
4288 /* ring already cleared, nothing to do */
4289 if (!rx_ring->rx_buffer_info)
4290 return;
4291
4292 /* Free all the Rx ring sk_buffs */
4293 for (i = 0; i < rx_ring->count; i++) {
4294 struct ixgbe_rx_buffer *rx_buffer;
4295
4296 rx_buffer = &rx_ring->rx_buffer_info[i];
4297 if (rx_buffer->skb) {
4298 struct sk_buff *skb = rx_buffer->skb;
4299 if (IXGBE_CB(skb)->page_released) {
4300 dma_unmap_page(dev,
4301 IXGBE_CB(skb)->dma,
4302 ixgbe_rx_bufsz(rx_ring),
4303 DMA_FROM_DEVICE);
4304 IXGBE_CB(skb)->page_released = false;
4305 }
4306 dev_kfree_skb(skb);
4307 }
4308 rx_buffer->skb = NULL;
4309 if (rx_buffer->dma)
4310 dma_unmap_page(dev, rx_buffer->dma,
4311 ixgbe_rx_pg_size(rx_ring),
4312 DMA_FROM_DEVICE);
4313 rx_buffer->dma = 0;
4314 if (rx_buffer->page)
4315 __free_pages(rx_buffer->page,
4316 ixgbe_rx_pg_order(rx_ring));
4317 rx_buffer->page = NULL;
4318 }
4319
4320 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4321 memset(rx_ring->rx_buffer_info, 0, size);
4322
4323 /* Zero out the descriptor ring */
4324 memset(rx_ring->desc, 0, rx_ring->size);
4325
4326 rx_ring->next_to_alloc = 0;
4327 rx_ring->next_to_clean = 0;
4328 rx_ring->next_to_use = 0;
4329}
4330
4331static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
4332 struct ixgbe_ring *rx_ring)
4333{
4334 struct ixgbe_adapter *adapter = vadapter->real_adapter;
4335 int index = rx_ring->queue_index + vadapter->rx_base_queue;
4336
4337 /* shutdown specific queue receive and wait for dma to settle */
4338 ixgbe_disable_rx_queue(adapter, rx_ring);
4339 usleep_range(10000, 20000);
4340 ixgbe_irq_disable_queues(adapter, ((u64)1 << index));
4341 ixgbe_clean_rx_ring(rx_ring);
4342 rx_ring->l2_accel_priv = NULL;
4343}
4344
John Fastabendae72c8d2013-11-09 07:11:26 +00004345static int ixgbe_fwd_ring_down(struct net_device *vdev,
4346 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08004347{
4348 struct ixgbe_adapter *adapter = accel->real_adapter;
4349 unsigned int rxbase = accel->rx_base_queue;
4350 unsigned int txbase = accel->tx_base_queue;
4351 int i;
4352
4353 netif_tx_stop_all_queues(vdev);
4354
4355 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4356 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4357 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
4358 }
4359
4360 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4361 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
4362 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
4363 }
4364
4365
4366 return 0;
4367}
4368
4369static int ixgbe_fwd_ring_up(struct net_device *vdev,
4370 struct ixgbe_fwd_adapter *accel)
4371{
4372 struct ixgbe_adapter *adapter = accel->real_adapter;
4373 unsigned int rxbase, txbase, queues;
4374 int i, baseq, err = 0;
4375
4376 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
4377 return 0;
4378
4379 baseq = accel->pool * adapter->num_rx_queues_per_pool;
4380 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4381 accel->pool, adapter->num_rx_pools,
4382 baseq, baseq + adapter->num_rx_queues_per_pool,
4383 adapter->fwd_bitmask);
4384
4385 accel->netdev = vdev;
4386 accel->rx_base_queue = rxbase = baseq;
4387 accel->tx_base_queue = txbase = baseq;
4388
4389 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
4390 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4391
4392 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4393 adapter->rx_ring[rxbase + i]->netdev = vdev;
4394 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
4395 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
4396 }
4397
4398 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4399 adapter->tx_ring[txbase + i]->netdev = vdev;
4400 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
4401 }
4402
4403 queues = min_t(unsigned int,
4404 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
4405 err = netif_set_real_num_tx_queues(vdev, queues);
4406 if (err)
4407 goto fwd_queue_err;
4408
John Fastabend2a47fa42013-11-06 09:54:52 -08004409 err = netif_set_real_num_rx_queues(vdev, queues);
4410 if (err)
4411 goto fwd_queue_err;
4412
4413 if (is_valid_ether_addr(vdev->dev_addr))
4414 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
4415
4416 ixgbe_fwd_psrtype(accel);
4417 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
4418 return err;
4419fwd_queue_err:
4420 ixgbe_fwd_ring_down(vdev, accel);
4421 return err;
4422}
4423
4424static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
4425{
4426 struct net_device *upper;
4427 struct list_head *iter;
4428 int err;
4429
4430 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
4431 if (netif_is_macvlan(upper)) {
4432 struct macvlan_dev *dfwd = netdev_priv(upper);
4433 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
4434
4435 if (dfwd->fwd_priv) {
4436 err = ixgbe_fwd_ring_up(upper, vadapter);
4437 if (err)
4438 continue;
4439 }
4440 }
4441 }
4442}
4443
Auke Kok9a799d72007-09-15 14:07:45 -07004444static void ixgbe_configure(struct ixgbe_adapter *adapter)
4445{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004446 struct ixgbe_hw *hw = &adapter->hw;
4447
John Fastabend80605c652011-05-02 12:34:10 +00004448 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004449#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00004450 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004451#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00004452 /*
4453 * We must restore virtualization before VLANs or else
4454 * the VLVF registers will not be populated
4455 */
4456 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004457
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004458 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004459 ixgbe_restore_vlan(adapter);
4460
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004461 switch (hw->mac.type) {
4462 case ixgbe_mac_82599EB:
4463 case ixgbe_mac_X540:
4464 hw->mac.ops.disable_rx_buff(hw);
4465 break;
4466 default:
4467 break;
4468 }
4469
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004470 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004471 ixgbe_init_fdir_signature_82599(&adapter->hw,
4472 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00004473 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
4474 ixgbe_init_fdir_perfect_82599(&adapter->hw,
4475 adapter->fdir_pballoc);
4476 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004477 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004478
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004479 switch (hw->mac.type) {
4480 case ixgbe_mac_82599EB:
4481 case ixgbe_mac_X540:
4482 hw->mac.ops.enable_rx_buff(hw);
4483 break;
4484 default:
4485 break;
4486 }
4487
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004488#ifdef IXGBE_FCOE
4489 /* configure FCoE L2 filters, redirection table, and Rx control */
4490 ixgbe_configure_fcoe(adapter);
4491
4492#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07004493 ixgbe_configure_tx(adapter);
4494 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08004495 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004496}
4497
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004498static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
4499{
4500 switch (hw->phy.type) {
4501 case ixgbe_phy_sfp_avago:
4502 case ixgbe_phy_sfp_ftl:
4503 case ixgbe_phy_sfp_intel:
4504 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00004505 case ixgbe_phy_sfp_passive_tyco:
4506 case ixgbe_phy_sfp_passive_unknown:
4507 case ixgbe_phy_sfp_active_unknown:
4508 case ixgbe_phy_sfp_ftl_active:
Emil Tantilov987e1d52013-08-14 07:12:27 +00004509 case ixgbe_phy_qsfp_passive_unknown:
4510 case ixgbe_phy_qsfp_active_unknown:
4511 case ixgbe_phy_qsfp_intel:
4512 case ixgbe_phy_qsfp_unknown:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004513 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00004514 case ixgbe_phy_nl:
4515 if (hw->mac.type == ixgbe_mac_82598EB)
4516 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004517 default:
4518 return false;
4519 }
4520}
4521
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004522/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004523 * ixgbe_sfp_link_config - set up SFP+ link
4524 * @adapter: pointer to private adapter struct
4525 **/
4526static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
4527{
Alexander Duyck70864002011-04-27 09:13:56 +00004528 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004529 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00004530 * is that an SFP was inserted/removed after the reset
4531 * but before SFP detection was enabled. As such the best
4532 * solution is to just start searching as soon as we start
4533 */
4534 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
4535 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004536
Alexander Duyck70864002011-04-27 09:13:56 +00004537 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004538}
4539
4540/**
4541 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004542 * @hw: pointer to private hardware struct
4543 *
4544 * Returns 0 on success, negative on failure
4545 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004546static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004547{
Josh Hay3d292262012-12-15 03:28:19 +00004548 u32 speed;
4549 bool autoneg, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004550 u32 ret = IXGBE_ERR_LINK_SETUP;
4551
4552 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00004553 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004554
4555 if (ret)
4556 goto link_cfg_out;
4557
Josh Hay3d292262012-12-15 03:28:19 +00004558 speed = hw->phy.autoneg_advertised;
4559 if ((!speed) && (hw->mac.ops.get_link_capabilities))
4560 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
4561 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004562 if (ret)
4563 goto link_cfg_out;
4564
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004565 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00004566 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004567link_cfg_out:
4568 return ret;
4569}
4570
Alexander Duycka34bcff2010-08-19 13:39:20 +00004571static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004572{
Auke Kok9a799d72007-09-15 14:07:45 -07004573 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004574 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004575
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004576 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004577 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4578 IXGBE_GPIE_OCD;
4579 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004580 /*
4581 * use EIAM to auto-mask when MSI-X interrupt is asserted
4582 * this saves a register write for every interrupt
4583 */
4584 switch (hw->mac.type) {
4585 case ixgbe_mac_82598EB:
4586 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4587 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004588 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004589 case ixgbe_mac_X540:
4590 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004591 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4592 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4593 break;
4594 }
4595 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004596 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4597 * specifically only auto mask tx and rx interrupts */
4598 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004599 }
4600
Alexander Duycka34bcff2010-08-19 13:39:20 +00004601 /* XXX: to interrupt immediately for EICS writes, enable this */
4602 /* gpie |= IXGBE_GPIE_EIMEN; */
4603
4604 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4605 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004606
4607 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4608 case IXGBE_82599_VMDQ_8Q_MASK:
4609 gpie |= IXGBE_GPIE_VTMODE_16;
4610 break;
4611 case IXGBE_82599_VMDQ_4Q_MASK:
4612 gpie |= IXGBE_GPIE_VTMODE_32;
4613 break;
4614 default:
4615 gpie |= IXGBE_GPIE_VTMODE_64;
4616 break;
4617 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004618 }
4619
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004620 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004621 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4622 switch (adapter->hw.mac.type) {
4623 case ixgbe_mac_82599EB:
4624 gpie |= IXGBE_SDP0_GPIEN;
4625 break;
4626 case ixgbe_mac_X540:
4627 gpie |= IXGBE_EIMS_TS;
4628 break;
4629 default:
4630 break;
4631 }
4632 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004633
Alexander Duycka34bcff2010-08-19 13:39:20 +00004634 /* Enable fan failure interrupt */
4635 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004636 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004637
Don Skidmore2698b202011-04-13 07:01:52 +00004638 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004639 gpie |= IXGBE_SDP1_GPIEN;
4640 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004641 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004642
4643 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4644}
4645
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004646static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004647{
4648 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08004649 struct net_device *upper;
4650 struct list_head *iter;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004651 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004652 u32 ctrl_ext;
4653
4654 ixgbe_get_hw_control(adapter);
4655 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004656
Auke Kok9a799d72007-09-15 14:07:45 -07004657 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4658 ixgbe_configure_msix(adapter);
4659 else
4660 ixgbe_configure_msi_and_legacy(adapter);
4661
Emil Tantilovec74a472012-09-20 03:33:56 +00004662 /* enable the optics for 82599 SFP+ fiber */
4663 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004664 hw->mac.ops.enable_tx_laser(hw);
4665
Mark Rustadc3049c82014-01-14 18:53:12 -08004666 smp_mb__before_clear_bit();
Auke Kok9a799d72007-09-15 14:07:45 -07004667 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004668 ixgbe_napi_enable_all(adapter);
4669
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004670 if (ixgbe_is_sfp(hw)) {
4671 ixgbe_sfp_link_config(adapter);
4672 } else {
4673 err = ixgbe_non_sfp_link_config(hw);
4674 if (err)
4675 e_err(probe, "link_config FAILED %d\n", err);
4676 }
4677
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004678 /* clear any pending interrupts, may auto mask */
4679 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004680 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004681
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004682 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004683 * If this adapter has a fan, check to see if we had a failure
4684 * before we enabled the interrupt.
4685 */
4686 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4687 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4688 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004689 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004690 }
4691
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004692 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004693 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004694
John Fastabend2a47fa42013-11-06 09:54:52 -08004695 /* enable any upper devices */
4696 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
4697 if (netif_is_macvlan(upper)) {
4698 struct macvlan_dev *vlan = netdev_priv(upper);
4699
4700 if (vlan->fwd_priv)
4701 netif_tx_start_all_queues(upper);
4702 }
4703 }
4704
Auke Kok9a799d72007-09-15 14:07:45 -07004705 /* bring the link up in the watchdog, this could race with our first
4706 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004707 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4708 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004709 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004710
4711 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4712 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4713 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4714 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004715}
4716
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004717void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4718{
4719 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004720 /* put off any impending NetWatchDogTimeout */
4721 adapter->netdev->trans_start = jiffies;
4722
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004723 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004724 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004725 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004726 /*
4727 * If SR-IOV enabled then wait a bit before bringing the adapter
4728 * back up to give the VFs time to respond to the reset. The
4729 * two second wait is based upon the watchdog timer cycle in
4730 * the VF driver.
4731 */
4732 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4733 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004734 ixgbe_up(adapter);
4735 clear_bit(__IXGBE_RESETTING, &adapter->state);
4736}
4737
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004738void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004739{
4740 /* hardware has been reset, we need to reload some things */
4741 ixgbe_configure(adapter);
4742
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004743 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004744}
4745
4746void ixgbe_reset(struct ixgbe_adapter *adapter)
4747{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004748 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004749 int err;
4750
Mark Rustadb0483c82014-01-14 18:53:17 -08004751 if (ixgbe_removed(hw->hw_addr))
4752 return;
Alexander Duyck70864002011-04-27 09:13:56 +00004753 /* lock SFP init bit to prevent race conditions with the watchdog */
4754 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4755 usleep_range(1000, 2000);
4756
4757 /* clear all SFP and link config related flags while holding SFP_INIT */
4758 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4759 IXGBE_FLAG2_SFP_NEEDS_RESET);
4760 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4761
Don Skidmore8ca783a2009-05-26 20:40:47 -07004762 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004763 switch (err) {
4764 case 0:
4765 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004766 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004767 break;
4768 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004769 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004770 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004771 case IXGBE_ERR_EEPROM_VERSION:
4772 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004773 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004774 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004775 "your hardware. If you are experiencing problems "
4776 "please contact your Intel or hardware "
4777 "representative who provided you with this "
4778 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004779 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004780 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004781 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004782 }
Auke Kok9a799d72007-09-15 14:07:45 -07004783
Alexander Duyck70864002011-04-27 09:13:56 +00004784 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4785
Auke Kok9a799d72007-09-15 14:07:45 -07004786 /* reprogram the RAR[0] in case user changed it. */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004787 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004788
4789 /* update SAN MAC vmdq pool selection */
4790 if (hw->mac.san_mac_rar_index)
4791 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004792
Jacob Keller8fecf672013-06-21 08:14:32 +00004793 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00004794 ixgbe_ptp_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004795}
4796
Auke Kok9a799d72007-09-15 14:07:45 -07004797/**
Auke Kok9a799d72007-09-15 14:07:45 -07004798 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004799 * @tx_ring: ring to be cleaned
4800 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004801static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004802{
4803 struct ixgbe_tx_buffer *tx_buffer_info;
4804 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004805 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004806
Alexander Duyck84418e32010-08-19 13:40:54 +00004807 /* ring already cleared, nothing to do */
4808 if (!tx_ring->tx_buffer_info)
4809 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004810
Alexander Duyck84418e32010-08-19 13:40:54 +00004811 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004812 for (i = 0; i < tx_ring->count; i++) {
4813 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004814 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004815 }
4816
John Fastabenddad8a3b2012-04-23 12:22:39 +00004817 netdev_tx_reset_queue(txring_txq(tx_ring));
4818
Auke Kok9a799d72007-09-15 14:07:45 -07004819 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4820 memset(tx_ring->tx_buffer_info, 0, size);
4821
4822 /* Zero out the descriptor ring */
4823 memset(tx_ring->desc, 0, tx_ring->size);
4824
4825 tx_ring->next_to_use = 0;
4826 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004827}
4828
4829/**
Auke Kok9a799d72007-09-15 14:07:45 -07004830 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4831 * @adapter: board private structure
4832 **/
4833static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4834{
4835 int i;
4836
4837 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004838 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004839}
4840
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004841/**
4842 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4843 * @adapter: board private structure
4844 **/
4845static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4846{
4847 int i;
4848
4849 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004850 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004851}
4852
Alexander Duycke4911d52011-05-11 07:18:52 +00004853static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4854{
Sasha Levinb67bfe02013-02-27 17:06:00 -08004855 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004856 struct ixgbe_fdir_filter *filter;
4857
4858 spin_lock(&adapter->fdir_perfect_lock);
4859
Sasha Levinb67bfe02013-02-27 17:06:00 -08004860 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004861 &adapter->fdir_filter_list, fdir_node) {
4862 hlist_del(&filter->fdir_node);
4863 kfree(filter);
4864 }
4865 adapter->fdir_filter_count = 0;
4866
4867 spin_unlock(&adapter->fdir_perfect_lock);
4868}
4869
Auke Kok9a799d72007-09-15 14:07:45 -07004870void ixgbe_down(struct ixgbe_adapter *adapter)
4871{
4872 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004873 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08004874 struct net_device *upper;
4875 struct list_head *iter;
Auke Kok9a799d72007-09-15 14:07:45 -07004876 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004877 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004878
4879 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08004880 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
4881 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07004882
4883 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004884 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4885 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004886
Yi Zou2d39d572011-01-06 14:29:56 +00004887 /* disable all enabled rx queues */
4888 for (i = 0; i < adapter->num_rx_queues; i++)
4889 /* this call also flushes the previous write */
4890 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4891
Don Skidmore032b4322011-03-18 09:32:53 +00004892 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004893
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004894 netif_tx_stop_all_queues(netdev);
4895
Alexander Duyck70864002011-04-27 09:13:56 +00004896 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004897 netif_carrier_off(netdev);
4898 netif_tx_disable(netdev);
4899
John Fastabend2a47fa42013-11-06 09:54:52 -08004900 /* disable any upper devices */
4901 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
4902 if (netif_is_macvlan(upper)) {
4903 struct macvlan_dev *vlan = netdev_priv(upper);
4904
4905 if (vlan->fwd_priv) {
4906 netif_tx_stop_all_queues(upper);
4907 netif_carrier_off(upper);
4908 netif_tx_disable(upper);
4909 }
4910 }
4911 }
4912
John Fastabendc0dfb902010-04-27 02:13:39 +00004913 ixgbe_irq_disable(adapter);
4914
4915 ixgbe_napi_disable_all(adapter);
4916
Alexander Duyckd034acf2011-04-27 09:25:34 +00004917 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4918 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004919 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4920
4921 del_timer_sync(&adapter->service_timer);
4922
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004923 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004924 /* Clear EITR Select mapping */
4925 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4926
4927 /* Mark all the VFs as inactive */
4928 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004929 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004930
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004931 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004932 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004933
Auke Kok9a799d72007-09-15 14:07:45 -07004934 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004935 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004936 }
4937
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004938 /* disable transmits in the hardware now that interrupts are off */
4939 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004940 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004941 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004942 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004943
4944 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004945 switch (hw->mac.type) {
4946 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004947 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004948 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004949 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4950 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004951 break;
4952 default:
4953 break;
4954 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004955
Paul Larson6f4a0e42008-06-24 17:00:56 -07004956 if (!pci_channel_offline(adapter->pdev))
4957 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004958
Emil Tantilovec74a472012-09-20 03:33:56 +00004959 /* power down the optics for 82599 SFP+ fiber */
4960 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00004961 hw->mac.ops.disable_tx_laser(hw);
4962
Auke Kok9a799d72007-09-15 14:07:45 -07004963 ixgbe_clean_all_tx_rings(adapter);
4964 ixgbe_clean_all_rx_rings(adapter);
4965
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004966#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004967 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004968 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004969#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004970}
4971
Auke Kok9a799d72007-09-15 14:07:45 -07004972/**
Auke Kok9a799d72007-09-15 14:07:45 -07004973 * ixgbe_tx_timeout - Respond to a Tx Hang
4974 * @netdev: network interface device structure
4975 **/
4976static void ixgbe_tx_timeout(struct net_device *netdev)
4977{
4978 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4979
4980 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004981 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004982}
4983
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004984/**
Auke Kok9a799d72007-09-15 14:07:45 -07004985 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4986 * @adapter: board private structure to initialize
4987 *
4988 * ixgbe_sw_init initializes the Adapter private data structure.
4989 * Fields are initialized based on PCI device information and
4990 * OS network device settings (MTU size).
4991 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004992static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004993{
4994 struct ixgbe_hw *hw = &adapter->hw;
4995 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00004996 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004997 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004998#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004999 int j;
5000 struct tc_configuration *tc;
5001#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005002
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005003 /* PCI config space info */
5004
5005 hw->vendor_id = pdev->vendor;
5006 hw->device_id = pdev->device;
5007 hw->revision_id = pdev->revision;
5008 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5009 hw->subsystem_device_id = pdev->subsystem_device;
5010
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005011 /* Set common capability flags and settings */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00005012 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005013 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005014 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5015 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005016 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5017 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005018 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5019 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005020 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5021#ifdef CONFIG_IXGBE_DCA
5022 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5023#endif
5024#ifdef IXGBE_FCOE
5025 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5026 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5027#ifdef CONFIG_IXGBE_DCB
5028 /* Default traffic class to use for FCoE */
5029 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5030#endif /* CONFIG_IXGBE_DCB */
5031#endif /* IXGBE_FCOE */
5032
5033 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005034 switch (hw->mac.type) {
5035 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005036 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
5037 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
5038
Don Skidmorebf069c92009-05-07 10:39:54 +00005039 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5040 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005041
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005042 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005043 adapter->ring_feature[RING_F_FDIR].limit = 0;
5044 adapter->atr_sample_rate = 0;
5045 adapter->fdir_pballoc = 0;
5046#ifdef IXGBE_FCOE
5047 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5048 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5049#ifdef CONFIG_IXGBE_DCB
5050 adapter->fcoe.up = 0;
5051#endif /* IXGBE_DCB */
5052#endif /* IXGBE_FCOE */
5053 break;
5054 case ixgbe_mac_82599EB:
5055 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5056 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005057 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005058 case ixgbe_mac_X540:
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005059 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
5060 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5061 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005062 break;
5063 default:
5064 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005065 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005066
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005067#ifdef IXGBE_FCOE
5068 /* FCoE support exists, always init the FCoE lock */
5069 spin_lock_init(&adapter->fcoe.lock);
5070
5071#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005072 /* n-tuple support exists, always init our spinlock */
5073 spin_lock_init(&adapter->fdir_perfect_lock);
5074
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005075#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005076 switch (hw->mac.type) {
5077 case ixgbe_mac_X540:
5078 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5079 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5080 break;
5081 default:
5082 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5083 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5084 break;
5085 }
5086
Alexander Duyck2f90b862008-11-20 20:52:10 -08005087 /* Configure DCB traffic classes */
5088 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5089 tc = &adapter->dcb_cfg.tc_config[j];
5090 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5091 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5092 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5093 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5094 tc->dcb_pfc = pfc_disabled;
5095 }
John Fastabend4de2a022011-09-27 03:52:01 +00005096
5097 /* Initialize default user to priority mapping, UPx->TC0 */
5098 tc = &adapter->dcb_cfg.tc_config[0];
5099 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5100 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5101
Alexander Duyck2f90b862008-11-20 20:52:10 -08005102 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5103 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005104 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005105 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005106 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00005107 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5108 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08005109
5110#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005111
5112 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005113 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005114 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005115 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005116 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5117 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005118 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005119
Alexander Duyck99d74482012-05-09 08:09:25 +00005120#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005121 if (max_vfs > 0)
5122 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 +00005123
Jacob Keller170e8542013-11-09 04:52:32 -08005124 /* assign number of SR-IOV VFs */
5125 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005126 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Jacob Keller170e8542013-11-09 04:52:32 -08005127 adapter->num_vfs = 0;
5128 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5129 } else {
5130 adapter->num_vfs = max_vfs;
5131 }
5132 }
5133#endif /* CONFIG_PCI_IOV */
5134
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005135 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005136 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005137 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005138
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005139 /* set default ring sizes */
5140 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5141 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5142
Alexander Duyckbd198052011-06-11 01:45:08 +00005143 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005144 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005145
Auke Kok9a799d72007-09-15 14:07:45 -07005146 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005147 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005148 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005149 return -EIO;
5150 }
5151
John Fastabend2a47fa42013-11-06 09:54:52 -08005152 /* PF holds first pool slot */
5153 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005154 set_bit(__IXGBE_DOWN, &adapter->state);
5155
5156 return 0;
5157}
5158
5159/**
5160 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005161 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005162 *
5163 * Return 0 on success, negative on failure
5164 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005165int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005166{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005167 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005168 int orig_node = dev_to_node(dev);
5169 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005170 int size;
5171
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005172 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005173
5174 if (tx_ring->q_vector)
5175 numa_node = tx_ring->q_vector->numa_node;
5176
5177 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005178 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005179 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005180 if (!tx_ring->tx_buffer_info)
5181 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005182
John Stultz827da442013-10-07 15:51:58 -07005183 u64_stats_init(&tx_ring->syncp);
5184
Auke Kok9a799d72007-09-15 14:07:45 -07005185 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005186 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005187 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005188
Alexander Duyckde88eee2012-02-08 07:49:59 +00005189 set_dev_node(dev, numa_node);
5190 tx_ring->desc = dma_alloc_coherent(dev,
5191 tx_ring->size,
5192 &tx_ring->dma,
5193 GFP_KERNEL);
5194 set_dev_node(dev, orig_node);
5195 if (!tx_ring->desc)
5196 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5197 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005198 if (!tx_ring->desc)
5199 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005200
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005201 tx_ring->next_to_use = 0;
5202 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005203 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005204
5205err:
5206 vfree(tx_ring->tx_buffer_info);
5207 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005208 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005209 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005210}
5211
5212/**
Alexander Duyck69888672008-09-11 20:05:39 -07005213 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5214 * @adapter: board private structure
5215 *
5216 * If this function returns with an error, then it's possible one or
5217 * more of the rings is populated (while the rest are not). It is the
5218 * callers duty to clean those orphaned rings.
5219 *
5220 * Return 0 on success, negative on failure
5221 **/
5222static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5223{
5224 int i, err = 0;
5225
5226 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005227 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005228 if (!err)
5229 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005230
Emil Tantilov396e7992010-07-01 20:05:12 +00005231 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005232 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07005233 }
5234
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005235 return 0;
5236err_setup_tx:
5237 /* rewind the index freeing the rings as we go */
5238 while (i--)
5239 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005240 return err;
5241}
5242
5243/**
Auke Kok9a799d72007-09-15 14:07:45 -07005244 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005245 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005246 *
5247 * Returns 0 on success, negative on failure
5248 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005249int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005250{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005251 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005252 int orig_node = dev_to_node(dev);
5253 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005254 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005255
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005256 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005257
5258 if (rx_ring->q_vector)
5259 numa_node = rx_ring->q_vector->numa_node;
5260
5261 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005262 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005263 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005264 if (!rx_ring->rx_buffer_info)
5265 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005266
John Stultz827da442013-10-07 15:51:58 -07005267 u64_stats_init(&rx_ring->syncp);
5268
Auke Kok9a799d72007-09-15 14:07:45 -07005269 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005270 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5271 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005272
Alexander Duyckde88eee2012-02-08 07:49:59 +00005273 set_dev_node(dev, numa_node);
5274 rx_ring->desc = dma_alloc_coherent(dev,
5275 rx_ring->size,
5276 &rx_ring->dma,
5277 GFP_KERNEL);
5278 set_dev_node(dev, orig_node);
5279 if (!rx_ring->desc)
5280 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5281 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005282 if (!rx_ring->desc)
5283 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005284
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005285 rx_ring->next_to_clean = 0;
5286 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005287
5288 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005289err:
5290 vfree(rx_ring->rx_buffer_info);
5291 rx_ring->rx_buffer_info = NULL;
5292 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005293 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005294}
5295
5296/**
Alexander Duyck69888672008-09-11 20:05:39 -07005297 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5298 * @adapter: board private structure
5299 *
5300 * If this function returns with an error, then it's possible one or
5301 * more of the rings is populated (while the rest are not). It is the
5302 * callers duty to clean those orphaned rings.
5303 *
5304 * Return 0 on success, negative on failure
5305 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005306static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5307{
5308 int i, err = 0;
5309
5310 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005311 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005312 if (!err)
5313 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005314
Emil Tantilov396e7992010-07-01 20:05:12 +00005315 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005316 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07005317 }
5318
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005319#ifdef IXGBE_FCOE
5320 err = ixgbe_setup_fcoe_ddp_resources(adapter);
5321 if (!err)
5322#endif
5323 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005324err_setup_rx:
5325 /* rewind the index freeing the rings as we go */
5326 while (i--)
5327 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005328 return err;
5329}
5330
5331/**
Auke Kok9a799d72007-09-15 14:07:45 -07005332 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005333 * @tx_ring: Tx descriptor ring for a specific queue
5334 *
5335 * Free all transmit software resources
5336 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005337void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005338{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005339 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005340
5341 vfree(tx_ring->tx_buffer_info);
5342 tx_ring->tx_buffer_info = NULL;
5343
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005344 /* if not set, then don't free */
5345 if (!tx_ring->desc)
5346 return;
5347
5348 dma_free_coherent(tx_ring->dev, tx_ring->size,
5349 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005350
5351 tx_ring->desc = NULL;
5352}
5353
5354/**
5355 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5356 * @adapter: board private structure
5357 *
5358 * Free all transmit software resources
5359 **/
5360static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5361{
5362 int i;
5363
5364 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005365 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005366 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005367}
5368
5369/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005370 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005371 * @rx_ring: ring to clean the resources from
5372 *
5373 * Free all receive software resources
5374 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005375void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005376{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005377 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005378
5379 vfree(rx_ring->rx_buffer_info);
5380 rx_ring->rx_buffer_info = NULL;
5381
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005382 /* if not set, then don't free */
5383 if (!rx_ring->desc)
5384 return;
5385
5386 dma_free_coherent(rx_ring->dev, rx_ring->size,
5387 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005388
5389 rx_ring->desc = NULL;
5390}
5391
5392/**
5393 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5394 * @adapter: board private structure
5395 *
5396 * Free all receive software resources
5397 **/
5398static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5399{
5400 int i;
5401
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005402#ifdef IXGBE_FCOE
5403 ixgbe_free_fcoe_ddp_resources(adapter);
5404
5405#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005406 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005407 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005408 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005409}
5410
5411/**
Auke Kok9a799d72007-09-15 14:07:45 -07005412 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5413 * @netdev: network interface device structure
5414 * @new_mtu: new value for maximum frame size
5415 *
5416 * Returns 0 on success, negative on failure
5417 **/
5418static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5419{
5420 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5421 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5422
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005423 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005424 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5425 return -EINVAL;
5426
5427 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00005428 * For 82599EB we cannot allow legacy VFs to enable their receive
5429 * paths when MTU greater than 1500 is configured. So display a
5430 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00005431 */
5432 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5433 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Alexander Duyckc5604512013-01-09 08:50:42 +00005434 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck872844d2012-08-15 02:10:43 +00005435 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005436
Emil Tantilov396e7992010-07-01 20:05:12 +00005437 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005438
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005439 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005440 netdev->mtu = new_mtu;
5441
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005442 if (netif_running(netdev))
5443 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005444
5445 return 0;
5446}
5447
5448/**
5449 * ixgbe_open - Called when a network interface is made active
5450 * @netdev: network interface device structure
5451 *
5452 * Returns 0 on success, negative value on failure
5453 *
5454 * The open entry point is called when a network interface is made
5455 * active by the system (IFF_UP). At this point all resources needed
5456 * for transmit and receive operations are allocated, the interrupt
5457 * handler is registered with the OS, the watchdog timer is started,
5458 * and the stack is notified that the interface is ready.
5459 **/
5460static int ixgbe_open(struct net_device *netdev)
5461{
5462 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend2a47fa42013-11-06 09:54:52 -08005463 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07005464
Auke Kok4bebfaa2008-02-11 09:26:01 -08005465 /* disallow open during test */
5466 if (test_bit(__IXGBE_TESTING, &adapter->state))
5467 return -EBUSY;
5468
Jesse Brandeburg54386462009-04-17 20:44:27 +00005469 netif_carrier_off(netdev);
5470
Auke Kok9a799d72007-09-15 14:07:45 -07005471 /* allocate transmit descriptors */
5472 err = ixgbe_setup_all_tx_resources(adapter);
5473 if (err)
5474 goto err_setup_tx;
5475
Auke Kok9a799d72007-09-15 14:07:45 -07005476 /* allocate receive descriptors */
5477 err = ixgbe_setup_all_rx_resources(adapter);
5478 if (err)
5479 goto err_setup_rx;
5480
5481 ixgbe_configure(adapter);
5482
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005483 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005484 if (err)
5485 goto err_req_irq;
5486
Alexander Duyckac802f52012-07-12 05:52:53 +00005487 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08005488 if (adapter->num_rx_pools > 1)
5489 queues = adapter->num_rx_queues_per_pool;
5490 else
5491 queues = adapter->num_tx_queues;
5492
5493 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00005494 if (err)
5495 goto err_set_queues;
5496
John Fastabend2a47fa42013-11-06 09:54:52 -08005497 if (adapter->num_rx_pools > 1 &&
5498 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
5499 queues = IXGBE_MAX_L2A_QUEUES;
5500 else
5501 queues = adapter->num_rx_queues;
5502 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00005503 if (err)
5504 goto err_set_queues;
5505
Jacob Keller1a71ab22012-08-25 03:54:19 +00005506 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005507
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005508 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005509
5510 return 0;
5511
Alexander Duyckac802f52012-07-12 05:52:53 +00005512err_set_queues:
5513 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005514err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005515 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005516err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005517 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005518err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07005519 ixgbe_reset(adapter);
5520
5521 return err;
5522}
5523
5524/**
5525 * ixgbe_close - Disables a network interface
5526 * @netdev: network interface device structure
5527 *
5528 * Returns 0, this is not allowed to fail
5529 *
5530 * The close entry point is called when an interface is de-activated
5531 * by the OS. The hardware is still under the drivers control, but
5532 * needs to be disabled. A global MAC reset is issued to stop the
5533 * hardware, and all transmit and receive resources are freed.
5534 **/
5535static int ixgbe_close(struct net_device *netdev)
5536{
5537 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005538
Jacob Keller1a71ab22012-08-25 03:54:19 +00005539 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005540
Auke Kok9a799d72007-09-15 14:07:45 -07005541 ixgbe_down(adapter);
5542 ixgbe_free_irq(adapter);
5543
Alexander Duycke4911d52011-05-11 07:18:52 +00005544 ixgbe_fdir_filter_exit(adapter);
5545
Auke Kok9a799d72007-09-15 14:07:45 -07005546 ixgbe_free_all_tx_resources(adapter);
5547 ixgbe_free_all_rx_resources(adapter);
5548
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005549 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005550
5551 return 0;
5552}
5553
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005554#ifdef CONFIG_PM
5555static int ixgbe_resume(struct pci_dev *pdev)
5556{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005557 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5558 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005559 u32 err;
5560
Mark Rustad0391bbe2014-02-28 15:48:55 -08005561 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005562 pci_set_power_state(pdev, PCI_D0);
5563 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005564 /*
5565 * pci_restore_state clears dev->state_saved so call
5566 * pci_save_state to restore it.
5567 */
5568 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005569
5570 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005571 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005572 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005573 return err;
5574 }
5575 pci_set_master(pdev);
5576
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005577 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005578
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005579 ixgbe_reset(adapter);
5580
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005581 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5582
Alexander Duyckac802f52012-07-12 05:52:53 +00005583 rtnl_lock();
5584 err = ixgbe_init_interrupt_scheme(adapter);
5585 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005586 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005587
5588 rtnl_unlock();
5589
5590 if (err)
5591 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005592
5593 netif_device_attach(netdev);
5594
5595 return 0;
5596}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005597#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005598
5599static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005600{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005601 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5602 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005603 struct ixgbe_hw *hw = &adapter->hw;
5604 u32 ctrl, fctrl;
5605 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005606#ifdef CONFIG_PM
5607 int retval = 0;
5608#endif
5609
5610 netif_device_detach(netdev);
5611
akepner499ab5c2013-03-13 14:54:58 +00005612 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005613 if (netif_running(netdev)) {
5614 ixgbe_down(adapter);
5615 ixgbe_free_irq(adapter);
5616 ixgbe_free_all_tx_resources(adapter);
5617 ixgbe_free_all_rx_resources(adapter);
5618 }
akepner499ab5c2013-03-13 14:54:58 +00005619 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005620
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005621 ixgbe_clear_interrupt_scheme(adapter);
5622
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005623#ifdef CONFIG_PM
5624 retval = pci_save_state(pdev);
5625 if (retval)
5626 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005627
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005628#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00005629 if (hw->mac.ops.stop_link_on_d3)
5630 hw->mac.ops.stop_link_on_d3(hw);
5631
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005632 if (wufc) {
5633 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005634
Emil Tantilovec74a472012-09-20 03:33:56 +00005635 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5636 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005637 hw->mac.ops.enable_tx_laser(hw);
5638
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005639 /* turn on all-multi mode if wake on multicast is enabled */
5640 if (wufc & IXGBE_WUFC_MC) {
5641 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5642 fctrl |= IXGBE_FCTRL_MPE;
5643 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5644 }
5645
5646 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5647 ctrl |= IXGBE_CTRL_GIO_DIS;
5648 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5649
5650 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5651 } else {
5652 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5653 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5654 }
5655
Alexander Duyckbd508172010-11-16 19:27:03 -08005656 switch (hw->mac.type) {
5657 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005658 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005659 break;
5660 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005661 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005662 pci_wake_from_d3(pdev, !!wufc);
5663 break;
5664 default:
5665 break;
5666 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005667
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005668 *enable_wake = !!wufc;
5669
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005670 ixgbe_release_hw_control(adapter);
5671
5672 pci_disable_device(pdev);
5673
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005674 return 0;
5675}
5676
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005677#ifdef CONFIG_PM
5678static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5679{
5680 int retval;
5681 bool wake;
5682
5683 retval = __ixgbe_shutdown(pdev, &wake);
5684 if (retval)
5685 return retval;
5686
5687 if (wake) {
5688 pci_prepare_to_sleep(pdev);
5689 } else {
5690 pci_wake_from_d3(pdev, false);
5691 pci_set_power_state(pdev, PCI_D3hot);
5692 }
5693
5694 return 0;
5695}
5696#endif /* CONFIG_PM */
5697
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005698static void ixgbe_shutdown(struct pci_dev *pdev)
5699{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005700 bool wake;
5701
5702 __ixgbe_shutdown(pdev, &wake);
5703
5704 if (system_state == SYSTEM_POWER_OFF) {
5705 pci_wake_from_d3(pdev, wake);
5706 pci_set_power_state(pdev, PCI_D3hot);
5707 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005708}
5709
5710/**
Auke Kok9a799d72007-09-15 14:07:45 -07005711 * ixgbe_update_stats - Update the board statistics counters.
5712 * @adapter: board private structure
5713 **/
5714void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5715{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005716 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005717 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005718 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005719 u64 total_mpc = 0;
5720 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005721 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5722 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005723 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005724
Don Skidmored08935c2010-06-11 13:20:29 +00005725 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5726 test_bit(__IXGBE_RESETTING, &adapter->state))
5727 return;
5728
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005729 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005730 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005731 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005732 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005733 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5734 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005735 }
5736 adapter->rsc_total_count = rsc_count;
5737 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005738 }
5739
Alexander Duyck5b7da512010-11-16 19:26:50 -08005740 for (i = 0; i < adapter->num_rx_queues; i++) {
5741 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5742 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5743 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5744 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005745 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005746 bytes += rx_ring->stats.bytes;
5747 packets += rx_ring->stats.packets;
5748 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005749 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005750 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5751 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005752 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005753 netdev->stats.rx_bytes = bytes;
5754 netdev->stats.rx_packets = packets;
5755
5756 bytes = 0;
5757 packets = 0;
5758 /* gather some stats to the adapter struct that are per queue */
5759 for (i = 0; i < adapter->num_tx_queues; i++) {
5760 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5761 restart_queue += tx_ring->tx_stats.restart_queue;
5762 tx_busy += tx_ring->tx_stats.tx_busy;
5763 bytes += tx_ring->stats.bytes;
5764 packets += tx_ring->stats.packets;
5765 }
5766 adapter->restart_queue = restart_queue;
5767 adapter->tx_busy = tx_busy;
5768 netdev->stats.tx_bytes = bytes;
5769 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005770
Joe Perches7ca647b2010-09-07 21:35:40 +00005771 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005772
5773 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005774 for (i = 0; i < 8; i++) {
5775 /* for packet buffers not used, the register should read 0 */
5776 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5777 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005778 hwstats->mpc[i] += mpc;
5779 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005780 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5781 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005782 switch (hw->mac.type) {
5783 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005784 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5785 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5786 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005787 hwstats->pxonrxc[i] +=
5788 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005789 break;
5790 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005791 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005792 hwstats->pxonrxc[i] +=
5793 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005794 break;
5795 default:
5796 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005797 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005798 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005799
5800 /*16 register reads */
5801 for (i = 0; i < 16; i++) {
5802 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5803 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5804 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5805 (hw->mac.type == ixgbe_mac_X540)) {
5806 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5807 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5808 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5809 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5810 }
5811 }
5812
Joe Perches7ca647b2010-09-07 21:35:40 +00005813 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005814 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005815 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005816
John Fastabendc84d3242010-11-16 19:27:12 -08005817 ixgbe_update_xoff_received(adapter);
5818
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005819 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005820 switch (hw->mac.type) {
5821 case ixgbe_mac_82598EB:
5822 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005823 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5824 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5825 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5826 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005827 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005828 /* OS2BMC stats are X540 only*/
5829 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5830 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5831 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5832 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5833 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005834 for (i = 0; i < 16; i++)
5835 adapter->hw_rx_no_dma_resources +=
5836 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005837 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005838 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005839 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005840 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005841 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005842 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005843 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005844 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5845 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005846#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005847 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5848 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5849 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5850 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5851 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5852 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005853 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005854 if (adapter->fcoe.ddp_pool) {
5855 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5856 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5857 unsigned int cpu;
5858 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005859 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005860 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5861 noddp += ddp_pool->noddp;
5862 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005863 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005864 hwstats->fcoe_noddp = noddp;
5865 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005866 }
Yi Zou6d455222009-05-13 13:12:16 +00005867#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005868 break;
5869 default:
5870 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005871 }
Auke Kok9a799d72007-09-15 14:07:45 -07005872 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005873 hwstats->bprc += bprc;
5874 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005875 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005876 hwstats->mprc -= bprc;
5877 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5878 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5879 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5880 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5881 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5882 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5883 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5884 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005885 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005886 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005887 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005888 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005889 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5890 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005891 /*
5892 * 82598 errata - tx of flow control packets is included in tx counters
5893 */
5894 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005895 hwstats->gptc -= xon_off_tot;
5896 hwstats->mptc -= xon_off_tot;
5897 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5898 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5899 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5900 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5901 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5902 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5903 hwstats->ptc64 -= xon_off_tot;
5904 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5905 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5906 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5907 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5908 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5909 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005910
5911 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005912 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005913
5914 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005915 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005916 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005917 netdev->stats.rx_length_errors = hwstats->rlec;
5918 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005919 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005920}
5921
5922/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005923 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005924 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005925 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005926static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005927{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005928 struct ixgbe_hw *hw = &adapter->hw;
5929 int i;
5930
Alexander Duyckd034acf2011-04-27 09:25:34 +00005931 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5932 return;
5933
5934 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5935
5936 /* if interface is down do nothing */
5937 if (test_bit(__IXGBE_DOWN, &adapter->state))
5938 return;
5939
5940 /* do nothing if we are not using signature filters */
5941 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5942 return;
5943
5944 adapter->fdir_overflow++;
5945
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005946 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5947 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005948 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005949 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005950 /* re-enable flow director interrupts */
5951 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005952 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005953 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005954 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005955 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005956}
5957
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005958/**
5959 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005960 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005961 *
5962 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005963 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005964 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005965 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005966 */
5967static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5968{
Auke Kok9a799d72007-09-15 14:07:45 -07005969 struct ixgbe_hw *hw = &adapter->hw;
5970 u64 eics = 0;
5971 int i;
5972
Mark Rustad09f40ae2014-01-14 18:53:11 -08005973 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005974 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08005975 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005976 test_bit(__IXGBE_RESETTING, &adapter->state))
5977 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005978
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005979 /* Force detection of hung controller */
5980 if (netif_carrier_ok(adapter->netdev)) {
5981 for (i = 0; i < adapter->num_tx_queues; i++)
5982 set_check_for_tx_hang(adapter->tx_ring[i]);
5983 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005984
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005985 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005986 /*
5987 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005988 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005989 * would set *both* EIMS and EICS for any bit in EIAM
5990 */
5991 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5992 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005993 } else {
5994 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005995 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005996 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005997 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005998 eics |= ((u64)1 << i);
5999 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006000 }
6001
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006002 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006003 ixgbe_irq_rearm_queues(adapter, eics);
6004
Alexander Duyckfe49f042009-06-04 16:00:09 +00006005}
6006
6007/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006008 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006009 * @adapter: pointer to the device adapter structure
6010 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006011 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006012static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006013{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006014 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006015 u32 link_speed = adapter->link_speed;
6016 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006017 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006018
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006019 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6020 return;
6021
6022 if (hw->mac.ops.check_link) {
6023 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006024 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006025 /* always assume link is up, if no check link function */
6026 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6027 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006028 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006029
6030 if (adapter->ixgbe_ieee_pfc)
6031 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6032
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006033 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006034 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006035 ixgbe_set_rx_drop_en(adapter);
6036 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006037
6038 if (link_up ||
6039 time_after(jiffies, (adapter->link_check_timeout +
6040 IXGBE_TRY_LINK_TIMEOUT))) {
6041 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6042 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6043 IXGBE_WRITE_FLUSH(hw);
6044 }
6045
6046 adapter->link_up = link_up;
6047 adapter->link_speed = link_speed;
6048}
6049
Alexander Duyck107d3012012-10-02 00:17:03 +00006050static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6051{
6052#ifdef CONFIG_IXGBE_DCB
6053 struct net_device *netdev = adapter->netdev;
6054 struct dcb_app app = {
6055 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6056 .protocol = 0,
6057 };
6058 u8 up = 0;
6059
6060 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6061 up = dcb_ieee_getapp_mask(netdev, &app);
6062
6063 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6064#endif
6065}
6066
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006067/**
6068 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6069 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006070 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006071 **/
6072static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6073{
6074 struct net_device *netdev = adapter->netdev;
6075 struct ixgbe_hw *hw = &adapter->hw;
6076 u32 link_speed = adapter->link_speed;
6077 bool flow_rx, flow_tx;
6078
6079 /* only continue if link was previously down */
6080 if (netif_carrier_ok(netdev))
6081 return;
6082
6083 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6084
6085 switch (hw->mac.type) {
6086 case ixgbe_mac_82598EB: {
6087 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6088 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6089 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6090 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6091 }
6092 break;
6093 case ixgbe_mac_X540:
6094 case ixgbe_mac_82599EB: {
6095 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6096 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6097 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6098 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6099 }
6100 break;
6101 default:
6102 flow_tx = false;
6103 flow_rx = false;
6104 break;
6105 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006106
Jacob Keller6cb562d2012-12-05 07:24:41 +00006107 adapter->last_rx_ptp_check = jiffies;
6108
Jacob Keller8fecf672013-06-21 08:14:32 +00006109 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006110 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006111
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006112 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6113 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6114 "10 Gbps" :
6115 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6116 "1 Gbps" :
6117 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6118 "100 Mbps" :
6119 "unknown speed"))),
6120 ((flow_rx && flow_tx) ? "RX/TX" :
6121 (flow_rx ? "RX" :
6122 (flow_tx ? "TX" : "None"))));
6123
6124 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006125 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006126
Alexander Duyck107d3012012-10-02 00:17:03 +00006127 /* update the default user priority for VFs */
6128 ixgbe_update_default_up(adapter);
6129
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006130 /* ping all the active vfs to let them know link has changed */
6131 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006132}
6133
6134/**
6135 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6136 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006137 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006138 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00006139static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006140{
6141 struct net_device *netdev = adapter->netdev;
6142 struct ixgbe_hw *hw = &adapter->hw;
6143
6144 adapter->link_up = false;
6145 adapter->link_speed = 0;
6146
6147 /* only continue if link was up previously */
6148 if (!netif_carrier_ok(netdev))
6149 return;
6150
6151 /* poll for SFP+ cable when link is down */
6152 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6153 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6154
Jacob Keller8fecf672013-06-21 08:14:32 +00006155 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006156 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006157
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006158 e_info(drv, "NIC Link is Down\n");
6159 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006160
6161 /* ping all the active vfs to let them know link has changed */
6162 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006163}
6164
6165/**
6166 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006167 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006168 **/
6169static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6170{
6171 int i;
6172 int some_tx_pending = 0;
6173
6174 if (!netif_carrier_ok(adapter->netdev)) {
6175 for (i = 0; i < adapter->num_tx_queues; i++) {
6176 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6177 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6178 some_tx_pending = 1;
6179 break;
6180 }
6181 }
6182
6183 if (some_tx_pending) {
6184 /* We've lost link, so the controller stops DMA,
6185 * but we've got queued Tx work that's never going
6186 * to get done, so reset controller to flush Tx.
6187 * (Do the reset outside of interrupt context).
6188 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00006189 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006190 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006191 }
6192 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006193}
6194
Greg Rosea985b6c32010-11-18 03:02:52 +00006195static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6196{
6197 u32 ssvpc;
6198
Greg Rose0584d992012-08-08 00:00:58 +00006199 /* Do not perform spoof check for 82598 or if not in IOV mode */
6200 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
6201 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00006202 return;
6203
6204 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6205
6206 /*
6207 * ssvpc register is cleared on read, if zero then no
6208 * spoofed packets in the last interval.
6209 */
6210 if (!ssvpc)
6211 return;
6212
Emil Tantilovd6ea0752012-08-08 06:28:37 +00006213 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00006214}
6215
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006216/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006217 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006218 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006219 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006220static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006221{
Mark Rustad09f40ae2014-01-14 18:53:11 -08006222 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006223 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006224 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00006225 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006226 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006227
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006228 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006229
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006230 if (adapter->link_up)
6231 ixgbe_watchdog_link_is_up(adapter);
6232 else
6233 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006234
Greg Rosea985b6c32010-11-18 03:02:52 +00006235 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006236 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006237
6238 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006239}
6240
Alexander Duyck70864002011-04-27 09:13:56 +00006241/**
6242 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006243 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00006244 **/
6245static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6246{
6247 struct ixgbe_hw *hw = &adapter->hw;
6248 s32 err;
6249
6250 /* not searching for SFP so there is nothing to do here */
6251 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6252 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6253 return;
6254
6255 /* someone else is in init, wait until next service event */
6256 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6257 return;
6258
6259 err = hw->phy.ops.identify_sfp(hw);
6260 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6261 goto sfp_out;
6262
6263 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6264 /* If no cable is present, then we need to reset
6265 * the next time we find a good cable. */
6266 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6267 }
6268
6269 /* exit on error */
6270 if (err)
6271 goto sfp_out;
6272
6273 /* exit if reset not needed */
6274 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6275 goto sfp_out;
6276
6277 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6278
6279 /*
6280 * A module may be identified correctly, but the EEPROM may not have
6281 * support for that module. setup_sfp() will fail in that case, so
6282 * we should not allow that module to load.
6283 */
6284 if (hw->mac.type == ixgbe_mac_82598EB)
6285 err = hw->phy.ops.reset(hw);
6286 else
6287 err = hw->mac.ops.setup_sfp(hw);
6288
6289 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6290 goto sfp_out;
6291
6292 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6293 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6294
6295sfp_out:
6296 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6297
6298 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6299 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6300 e_dev_err("failed to initialize because an unsupported "
6301 "SFP+ module type was detected.\n");
6302 e_dev_err("Reload the driver after installing a "
6303 "supported module.\n");
6304 unregister_netdev(adapter->netdev);
6305 }
6306}
6307
6308/**
6309 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006310 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00006311 **/
6312static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6313{
6314 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00006315 u32 speed;
6316 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00006317
6318 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6319 return;
6320
6321 /* someone else is in init, wait until next service event */
6322 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6323 return;
6324
6325 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6326
Josh Hay3d292262012-12-15 03:28:19 +00006327 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00006328 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00006329 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00006330
6331 /* setup the highest link when no autoneg */
6332 if (!autoneg) {
6333 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
6334 speed = IXGBE_LINK_SPEED_10GB_FULL;
6335 }
6336 }
6337
Alexander Duyck70864002011-04-27 09:13:56 +00006338 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00006339 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00006340
6341 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6342 adapter->link_check_timeout = jiffies;
6343 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6344}
6345
Greg Rose83c61fa2011-09-07 05:59:35 +00006346#ifdef CONFIG_PCI_IOV
6347static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6348{
6349 int vf;
6350 struct ixgbe_hw *hw = &adapter->hw;
6351 struct net_device *netdev = adapter->netdev;
6352 u32 gpc;
6353 u32 ciaa, ciad;
6354
6355 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6356 if (gpc) /* If incrementing then no need for the check below */
6357 return;
6358 /*
6359 * Check to see if a bad DMA write target from an errant or
6360 * malicious VF has caused a PCIe error. If so then we can
6361 * issue a VFLR to the offending VF(s) and then resume without
6362 * requesting a full slot reset.
6363 */
6364
6365 for (vf = 0; vf < adapter->num_vfs; vf++) {
6366 ciaa = (vf << 16) | 0x80000000;
6367 /* 32 bit read so align, we really want status at offset 6 */
6368 ciaa |= PCI_COMMAND;
6369 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6370 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6371 ciaa &= 0x7FFFFFFF;
6372 /* disable debug mode asap after reading data */
6373 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6374 /* Get the upper 16 bits which will be the PCI status reg */
6375 ciad >>= 16;
6376 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6377 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6378 /* Issue VFLR */
6379 ciaa = (vf << 16) | 0x80000000;
6380 ciaa |= 0xA8;
6381 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6382 ciad = 0x00008000; /* VFLR */
6383 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6384 ciaa &= 0x7FFFFFFF;
6385 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6386 }
6387 }
6388}
6389
6390#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006391/**
6392 * ixgbe_service_timer - Timer Call-back
6393 * @data: pointer to adapter cast into an unsigned long
6394 **/
6395static void ixgbe_service_timer(unsigned long data)
6396{
6397 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6398 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006399 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006400
6401 /* poll faster when waiting for link */
6402 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6403 next_event_offset = HZ / 10;
6404 else
6405 next_event_offset = HZ * 2;
6406
Greg Rose83c61fa2011-09-07 05:59:35 +00006407#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00006408 /*
6409 * don't bother with SR-IOV VF DMA hang check if there are
6410 * no VFs or the link is down
6411 */
6412 if (!adapter->num_vfs ||
6413 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6414 goto normal_timer_service;
6415
6416 /* If we have VFs allocated then we must check for DMA hangs */
6417 ixgbe_check_for_bad_vf(adapter);
6418 next_event_offset = HZ / 50;
6419 adapter->timer_event_accumulator++;
6420
6421 if (adapter->timer_event_accumulator >= 100)
6422 adapter->timer_event_accumulator = 0;
6423 else
6424 ready = false;
6425
6426normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00006427#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006428 /* Reset the timer */
6429 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6430
Greg Rose83c61fa2011-09-07 05:59:35 +00006431 if (ready)
6432 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006433}
6434
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006435static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6436{
6437 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6438 return;
6439
6440 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6441
Mark Rustad09f40ae2014-01-14 18:53:11 -08006442 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006443 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006444 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006445 test_bit(__IXGBE_RESETTING, &adapter->state))
6446 return;
6447
6448 ixgbe_dump(adapter);
6449 netdev_err(adapter->netdev, "Reset adapter\n");
6450 adapter->tx_timeout_count++;
6451
John Fastabend8f4c5c92014-01-16 02:30:05 -08006452 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006453 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08006454 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006455}
6456
Alexander Duyck70864002011-04-27 09:13:56 +00006457/**
6458 * ixgbe_service_task - manages and runs subtasks
6459 * @work: pointer to work_struct containing our data
6460 **/
6461static void ixgbe_service_task(struct work_struct *work)
6462{
6463 struct ixgbe_adapter *adapter = container_of(work,
6464 struct ixgbe_adapter,
6465 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08006466 if (ixgbe_removed(adapter->hw.hw_addr)) {
6467 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
6468 rtnl_lock();
6469 ixgbe_down(adapter);
6470 rtnl_unlock();
6471 }
6472 ixgbe_service_event_complete(adapter);
6473 return;
6474 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006475 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006476 ixgbe_sfp_detection_subtask(adapter);
6477 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006478 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006479 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006480 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006481 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00006482
Jacob Keller8fecf672013-06-21 08:14:32 +00006483 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00006484 ixgbe_ptp_overflow_check(adapter);
6485 ixgbe_ptp_rx_hang(adapter);
6486 }
Alexander Duyck70864002011-04-27 09:13:56 +00006487
6488 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006489}
6490
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006491static int ixgbe_tso(struct ixgbe_ring *tx_ring,
6492 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006493 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00006494{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006495 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006496 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006497 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006498
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00006499 if (skb->ip_summed != CHECKSUM_PARTIAL)
6500 return 0;
6501
Alexander Duyck897ab152011-05-27 05:31:47 +00006502 if (!skb_is_gso(skb))
6503 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006504
Alexander Duyck897ab152011-05-27 05:31:47 +00006505 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006506 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00006507 if (err)
6508 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006509 }
6510
Alexander Duyck897ab152011-05-27 05:31:47 +00006511 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6512 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6513
Alexander Duyck244e27a2012-02-08 07:51:11 +00006514 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006515 struct iphdr *iph = ip_hdr(skb);
6516 iph->tot_len = 0;
6517 iph->check = 0;
6518 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6519 iph->daddr, 0,
6520 IPPROTO_TCP,
6521 0);
6522 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006523 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6524 IXGBE_TX_FLAGS_CSUM |
6525 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006526 } else if (skb_is_gso_v6(skb)) {
6527 ipv6_hdr(skb)->payload_len = 0;
6528 tcp_hdr(skb)->check =
6529 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6530 &ipv6_hdr(skb)->daddr,
6531 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00006532 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6533 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00006534 }
6535
Alexander Duyck091a6242012-02-08 07:51:01 +00006536 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00006537 l4len = tcp_hdrlen(skb);
6538 *hdr_len = skb_transport_offset(skb) + l4len;
6539
Alexander Duyck091a6242012-02-08 07:51:01 +00006540 /* update gso size and bytecount with header size */
6541 first->gso_segs = skb_shinfo(skb)->gso_segs;
6542 first->bytecount += (first->gso_segs - 1) * *hdr_len;
6543
Alexander Duyckc44f5f52012-10-30 06:01:45 +00006544 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00006545 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6546 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00006547
6548 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6549 vlan_macip_lens = skb_network_header_len(skb);
6550 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006551 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006552
6553 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006554 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00006555
6556 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006557}
6558
Alexander Duyck244e27a2012-02-08 07:51:11 +00006559static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6560 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07006561{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006562 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006563 u32 vlan_macip_lens = 0;
6564 u32 mss_l4len_idx = 0;
6565 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006566
Alexander Duyck897ab152011-05-27 05:31:47 +00006567 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck472148c2012-11-07 02:34:28 +00006568 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6569 !(first->tx_flags & IXGBE_TX_FLAGS_CC))
6570 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00006571 } else {
6572 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006573 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006574 case __constant_htons(ETH_P_IP):
6575 vlan_macip_lens |= skb_network_header_len(skb);
6576 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6577 l4_hdr = ip_hdr(skb)->protocol;
6578 break;
6579 case __constant_htons(ETH_P_IPV6):
6580 vlan_macip_lens |= skb_network_header_len(skb);
6581 l4_hdr = ipv6_hdr(skb)->nexthdr;
6582 break;
6583 default:
6584 if (unlikely(net_ratelimit())) {
6585 dev_warn(tx_ring->dev,
6586 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006587 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00006588 }
6589 break;
6590 }
Auke Kok9a799d72007-09-15 14:07:45 -07006591
Alexander Duyck897ab152011-05-27 05:31:47 +00006592 switch (l4_hdr) {
6593 case IPPROTO_TCP:
6594 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6595 mss_l4len_idx = tcp_hdrlen(skb) <<
6596 IXGBE_ADVTXD_L4LEN_SHIFT;
6597 break;
6598 case IPPROTO_SCTP:
6599 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6600 mss_l4len_idx = sizeof(struct sctphdr) <<
6601 IXGBE_ADVTXD_L4LEN_SHIFT;
6602 break;
6603 case IPPROTO_UDP:
6604 mss_l4len_idx = sizeof(struct udphdr) <<
6605 IXGBE_ADVTXD_L4LEN_SHIFT;
6606 break;
6607 default:
6608 if (unlikely(net_ratelimit())) {
6609 dev_warn(tx_ring->dev,
6610 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006611 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006612 }
6613 break;
6614 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006615
6616 /* update TX checksum flag */
6617 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006618 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006619
Alexander Duyck244e27a2012-02-08 07:51:11 +00006620 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006621 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006622 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006623
6624 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6625 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006626}
6627
Alexander Duyck472148c2012-11-07 02:34:28 +00006628#define IXGBE_SET_FLAG(_input, _flag, _result) \
6629 ((_flag <= _result) ? \
6630 ((u32)(_input & _flag) * (_result / _flag)) : \
6631 ((u32)(_input & _flag) / (_flag / _result)))
6632
6633static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006634{
6635 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00006636 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
6637 IXGBE_ADVTXD_DCMD_DEXT |
6638 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006639
6640 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00006641 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
6642 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006643
Alexander Duyckd3d00232011-07-15 02:31:25 +00006644 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006645 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
6646 IXGBE_ADVTXD_DCMD_TSE);
6647
6648 /* set timestamp bit if present */
6649 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
6650 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006651
Alexander Duyck62748b72012-07-20 08:09:01 +00006652 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00006653 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00006654
Alexander Duyckd3d00232011-07-15 02:31:25 +00006655 return cmd_type;
6656}
6657
Alexander Duyck729739b2012-02-08 07:51:06 +00006658static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6659 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006660{
Alexander Duyck472148c2012-11-07 02:34:28 +00006661 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006662
6663 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00006664 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6665 IXGBE_TX_FLAGS_CSUM,
6666 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006667
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006668 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006669 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6670 IXGBE_TX_FLAGS_IPV4,
6671 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006672
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006673 /*
6674 * Check Context must be set if Tx switch is enabled, which it
6675 * always is for case where virtual functions are running
6676 */
Alexander Duyck472148c2012-11-07 02:34:28 +00006677 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6678 IXGBE_TX_FLAGS_CC,
6679 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006680
Alexander Duyck472148c2012-11-07 02:34:28 +00006681 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006682}
6683
6684#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6685 IXGBE_TXD_CMD_RS)
6686
6687static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006688 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006689 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006690{
Alexander Duyck729739b2012-02-08 07:51:06 +00006691 struct sk_buff *skb = first->skb;
6692 struct ixgbe_tx_buffer *tx_buffer;
6693 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00006694 struct skb_frag_struct *frag;
6695 dma_addr_t dma;
6696 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006697 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00006698 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006699 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006700
Alexander Duyck729739b2012-02-08 07:51:06 +00006701 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6702
Alexander Duyckec718252012-10-30 06:01:55 +00006703 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
6704
6705 size = skb_headlen(skb);
6706 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00006707
Alexander Duyckd3d00232011-07-15 02:31:25 +00006708#ifdef IXGBE_FCOE
6709 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006710 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006711 size -= sizeof(struct fcoe_crc_eof) - data_len;
6712 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006713 } else {
6714 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006715 }
Auke Kok9a799d72007-09-15 14:07:45 -07006716 }
6717
Alexander Duyckd3d00232011-07-15 02:31:25 +00006718#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006719 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006720
Alexander Duyckec718252012-10-30 06:01:55 +00006721 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006722
Alexander Duyckec718252012-10-30 06:01:55 +00006723 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
6724 if (dma_mapping_error(tx_ring->dev, dma))
6725 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006726
Alexander Duyckec718252012-10-30 06:01:55 +00006727 /* record length, and DMA address */
6728 dma_unmap_len_set(tx_buffer, len, size);
6729 dma_unmap_addr_set(tx_buffer, dma, dma);
6730
6731 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6732
Alexander Duyck729739b2012-02-08 07:51:06 +00006733 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006734 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00006735 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006736
Alexander Duyckd3d00232011-07-15 02:31:25 +00006737 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006738 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006739 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006740 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006741 i = 0;
6742 }
Alexander Duyckec718252012-10-30 06:01:55 +00006743 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006744
6745 dma += IXGBE_MAX_DATA_PER_TXD;
6746 size -= IXGBE_MAX_DATA_PER_TXD;
6747
6748 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006749 }
6750
Alexander Duyck729739b2012-02-08 07:51:06 +00006751 if (likely(!data_len))
6752 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006753
Alexander Duyck472148c2012-11-07 02:34:28 +00006754 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006755
Alexander Duyck729739b2012-02-08 07:51:06 +00006756 i++;
6757 tx_desc++;
6758 if (i == tx_ring->count) {
6759 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6760 i = 0;
6761 }
Alexander Duyckec718252012-10-30 06:01:55 +00006762 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006763
Alexander Duyckd3d00232011-07-15 02:31:25 +00006764#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006765 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006766#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006767 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006768#endif
6769 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006770
Alexander Duyck729739b2012-02-08 07:51:06 +00006771 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6772 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07006773
Alexander Duyck729739b2012-02-08 07:51:06 +00006774 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07006775 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006776
Alexander Duyck729739b2012-02-08 07:51:06 +00006777 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00006778 cmd_type |= size | IXGBE_TXD_CMD;
6779 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006780
Alexander Duyck091a6242012-02-08 07:51:01 +00006781 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006782
Alexander Duyckd3d00232011-07-15 02:31:25 +00006783 /* set the timestamp */
6784 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006785
6786 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006787 * Force memory writes to complete before letting h/w know there
6788 * are new descriptors to fetch. (Only applicable for weak-ordered
6789 * memory model archs, such as IA-64).
6790 *
6791 * We also need this memory barrier to make certain all of the
6792 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006793 */
6794 wmb();
6795
Alexander Duyckd3d00232011-07-15 02:31:25 +00006796 /* set next_to_watch value indicating a packet is present */
6797 first->next_to_watch = tx_desc;
6798
Alexander Duyck729739b2012-02-08 07:51:06 +00006799 i++;
6800 if (i == tx_ring->count)
6801 i = 0;
6802
6803 tx_ring->next_to_use = i;
6804
Alexander Duyckd3d00232011-07-15 02:31:25 +00006805 /* notify HW of packet */
Mark Rustad84227bc2014-01-14 18:53:13 -08006806 ixgbe_write_tail(tx_ring, i);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006807
6808 return;
6809dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006810 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006811
6812 /* clear dma mappings for failed tx_buffer_info map */
6813 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006814 tx_buffer = &tx_ring->tx_buffer_info[i];
6815 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6816 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006817 break;
6818 if (i == 0)
6819 i = tx_ring->count;
6820 i--;
6821 }
6822
Alexander Duyckd3d00232011-07-15 02:31:25 +00006823 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006824}
6825
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006826static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006827 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006828{
Alexander Duyck69830522011-01-06 14:29:58 +00006829 struct ixgbe_q_vector *q_vector = ring->q_vector;
6830 union ixgbe_atr_hash_dword input = { .dword = 0 };
6831 union ixgbe_atr_hash_dword common = { .dword = 0 };
6832 union {
6833 unsigned char *network;
6834 struct iphdr *ipv4;
6835 struct ipv6hdr *ipv6;
6836 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006837 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006838 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006839
Alexander Duyck69830522011-01-06 14:29:58 +00006840 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6841 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006842 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006843
Alexander Duyck69830522011-01-06 14:29:58 +00006844 /* do nothing if sampling is disabled */
6845 if (!ring->atr_sample_rate)
6846 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006847
Alexander Duyck69830522011-01-06 14:29:58 +00006848 ring->atr_count++;
6849
6850 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006851 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006852
6853 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006854 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006855 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006856 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006857 hdr.ipv4->protocol != IPPROTO_TCP))
6858 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006859
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006860 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006861
Alexander Duyck66f32a82011-06-29 05:43:22 +00006862 /* skip this packet since it is invalid or the socket is closing */
6863 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006864 return;
6865
6866 /* sample on all syn packets or once every atr sample count */
6867 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6868 return;
6869
6870 /* reset sample count */
6871 ring->atr_count = 0;
6872
Alexander Duyck244e27a2012-02-08 07:51:11 +00006873 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006874
6875 /*
6876 * src and dst are inverted, think how the receiver sees them
6877 *
6878 * The input is broken into two sections, a non-compressed section
6879 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6880 * is XORed together and stored in the compressed dword.
6881 */
6882 input.formatted.vlan_id = vlan_id;
6883
6884 /*
6885 * since src port and flex bytes occupy the same word XOR them together
6886 * and write the value to source port portion of compressed dword
6887 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006888 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006889 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6890 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006891 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006892 common.port.dst ^= th->source;
6893
Alexander Duyck244e27a2012-02-08 07:51:11 +00006894 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006895 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6896 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6897 } else {
6898 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6899 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6900 hdr.ipv6->saddr.s6_addr32[1] ^
6901 hdr.ipv6->saddr.s6_addr32[2] ^
6902 hdr.ipv6->saddr.s6_addr32[3] ^
6903 hdr.ipv6->daddr.s6_addr32[0] ^
6904 hdr.ipv6->daddr.s6_addr32[1] ^
6905 hdr.ipv6->daddr.s6_addr32[2] ^
6906 hdr.ipv6->daddr.s6_addr32[3];
6907 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006908
6909 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006910 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6911 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006912}
6913
Alexander Duyck63544e92011-05-27 05:31:42 +00006914static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006915{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006916 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006917 /* Herbert's original patch had:
6918 * smp_mb__after_netif_stop_queue();
6919 * but since that doesn't exist yet, just open code it. */
6920 smp_mb();
6921
6922 /* We need to check again in a case another CPU has just
6923 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006924 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006925 return -EBUSY;
6926
6927 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006928 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006929 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006930 return 0;
6931}
6932
Alexander Duyck82d4e462011-06-11 01:44:58 +00006933static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006934{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006935 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006936 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006937 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006938}
6939
Jason Wangf663dd92014-01-10 16:18:26 +08006940static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01006941 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006942{
Jason Wangf663dd92014-01-10 16:18:26 +08006943 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
6944#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00006945 struct ixgbe_adapter *adapter;
6946 struct ixgbe_ring_feature *f;
6947 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08006948#endif
6949
6950 if (fwd_adapter)
6951 return skb->queue_mapping + fwd_adapter->tx_base_queue;
6952
6953#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00006954
Alexander Duyck97488bd2013-01-12 06:33:37 +00006955 /*
6956 * only execute the code below if protocol is FCoE
6957 * or FIP and we have FCoE enabled on the adapter
6958 */
6959 switch (vlan_get_protocol(skb)) {
6960 case __constant_htons(ETH_P_FCOE):
6961 case __constant_htons(ETH_P_FIP):
6962 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00006963
Alexander Duyck97488bd2013-01-12 06:33:37 +00006964 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
6965 break;
6966 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01006967 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006968 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006969
Alexander Duyck97488bd2013-01-12 06:33:37 +00006970 f = &adapter->ring_feature[RING_F_FCOE];
6971
6972 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6973 smp_processor_id();
6974
6975 while (txq >= f->indices)
6976 txq -= f->indices;
6977
6978 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08006979#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01006980 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08006981#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006982}
6983
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006984netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006985 struct ixgbe_adapter *adapter,
6986 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006987{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006988 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006989 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006990 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006991 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00006992 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006993 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006994 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006995
Alexander Duycka535c302011-05-27 05:31:52 +00006996 /*
6997 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006998 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006999 * + 2 desc gap to keep tail from touching head,
7000 * + 1 desc for context descriptor,
7001 * otherwise try next time
7002 */
Alexander Duycka535c302011-05-27 05:31:52 +00007003 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7004 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00007005
Alexander Duycka535c302011-05-27 05:31:52 +00007006 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7007 tx_ring->tx_stats.tx_busy++;
7008 return NETDEV_TX_BUSY;
7009 }
7010
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007011 /* record the location of the first descriptor for this packet */
7012 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7013 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00007014 first->bytecount = skb->len;
7015 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007016
Alexander Duyck66f32a82011-06-29 05:43:22 +00007017 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007018 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007019 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7020 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7021 /* else if it is a SW VLAN check the next protocol and store the tag */
7022 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7023 struct vlan_hdr *vhdr, _vhdr;
7024 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7025 if (!vhdr)
7026 goto out_drop;
7027
7028 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007029 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7030 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007031 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007032 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007033
Jacob Kelleraa7bd462012-05-04 01:55:23 +00007034 skb_tx_timestamp(skb);
7035
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007036 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
7037 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
7038 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00007039
7040 /* schedule check for Tx timestamp */
7041 adapter->ptp_tx_skb = skb_get(skb);
7042 adapter->ptp_tx_start = jiffies;
7043 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007044 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007045
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007046#ifdef CONFIG_PCI_IOV
7047 /*
7048 * Use the l2switch_enable flag - would be false if the DMA
7049 * Tx switch had been disabled.
7050 */
7051 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00007052 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007053
7054#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007055 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007056 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007057 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7058 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007059 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007060 tx_flags |= (skb->priority & 0x7) <<
7061 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007062 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7063 struct vlan_ethhdr *vhdr;
7064 if (skb_header_cloned(skb) &&
7065 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7066 goto out_drop;
7067 vhdr = (struct vlan_ethhdr *)skb->data;
7068 vhdr->h_vlan_TCI = htons(tx_flags >>
7069 IXGBE_TX_FLAGS_VLAN_SHIFT);
7070 } else {
7071 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7072 }
7073 }
Alexander Duycka535c302011-05-27 05:31:52 +00007074
Alexander Duyck244e27a2012-02-08 07:51:11 +00007075 /* record initial flags and protocol */
7076 first->tx_flags = tx_flags;
7077 first->protocol = protocol;
7078
Yi Zoueacd73f2009-05-13 13:11:06 +00007079#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007080 /* setup tx offload for FCoE */
7081 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00007082 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00007083 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00007084 if (tso < 0)
7085 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07007086
Alexander Duyck66f32a82011-06-29 05:43:22 +00007087 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007088 }
Auke Kok9a799d72007-09-15 14:07:45 -07007089
Auke Kok9a799d72007-09-15 14:07:45 -07007090#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007091 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007092 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007093 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007094 else if (!tso)
7095 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007096
7097 /* add the ATR filter if ATR is on */
7098 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00007099 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007100
7101#ifdef IXGBE_FCOE
7102xmit_fcoe:
7103#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007104 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007105
7106 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007107
7108 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007109
7110out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007111 dev_kfree_skb_any(first->skb);
7112 first->skb = NULL;
7113
Alexander Duyck897ab152011-05-27 05:31:47 +00007114 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007115}
7116
John Fastabend2a47fa42013-11-06 09:54:52 -08007117static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
7118 struct net_device *netdev,
7119 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007120{
7121 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007122 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07007123
Alexander Duycka50c29d2012-02-08 07:50:40 +00007124 /*
7125 * The minimum packet size for olinfo paylen is 17 so pad the skb
7126 * in order to meet this minimum size requirement.
7127 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00007128 if (unlikely(skb->len < 17)) {
7129 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00007130 return NETDEV_TX_OK;
7131 skb->len = 17;
Tushar Dave71a49f72012-09-14 04:24:49 +00007132 skb_set_tail_pointer(skb, 17);
Alexander Duycka50c29d2012-02-08 07:50:40 +00007133 }
7134
John Fastabend2a47fa42013-11-06 09:54:52 -08007135 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
7136
Auke Kok9a799d72007-09-15 14:07:45 -07007137 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7138}
7139
John Fastabend2a47fa42013-11-06 09:54:52 -08007140static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7141 struct net_device *netdev)
7142{
7143 return __ixgbe_xmit_frame(skb, netdev, NULL);
7144}
7145
Auke Kok9a799d72007-09-15 14:07:45 -07007146/**
7147 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7148 * @netdev: network interface device structure
7149 * @p: pointer to an address structure
7150 *
7151 * Returns 0 on success, negative on failure
7152 **/
7153static int ixgbe_set_mac(struct net_device *netdev, void *p)
7154{
7155 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7156 struct ixgbe_hw *hw = &adapter->hw;
7157 struct sockaddr *addr = p;
7158
7159 if (!is_valid_ether_addr(addr->sa_data))
7160 return -EADDRNOTAVAIL;
7161
7162 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007163 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007164
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00007165 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07007166
7167 return 0;
7168}
7169
Ben Hutchings6b73e102009-04-29 08:08:58 +00007170static int
7171ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7172{
7173 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7174 struct ixgbe_hw *hw = &adapter->hw;
7175 u16 value;
7176 int rc;
7177
7178 if (prtad != hw->phy.mdio.prtad)
7179 return -EINVAL;
7180 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7181 if (!rc)
7182 rc = value;
7183 return rc;
7184}
7185
7186static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7187 u16 addr, u16 value)
7188{
7189 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7190 struct ixgbe_hw *hw = &adapter->hw;
7191
7192 if (prtad != hw->phy.mdio.prtad)
7193 return -EINVAL;
7194 return hw->phy.ops.write_reg(hw, addr, devad, value);
7195}
7196
7197static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7198{
7199 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7200
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007201 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007202 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08007203 return ixgbe_ptp_set_ts_config(adapter, req);
7204 case SIOCGHWTSTAMP:
7205 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007206 default:
7207 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7208 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00007209}
7210
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007211/**
7212 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007213 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007214 * @netdev: network interface device structure
7215 *
7216 * Returns non-zero on failure
7217 **/
7218static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7219{
7220 int err = 0;
7221 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007222 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007223
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007224 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007225 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007226 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007227 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007228
7229 /* update SAN MAC vmdq pool selection */
7230 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007231 }
7232 return err;
7233}
7234
7235/**
7236 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007237 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007238 * @netdev: network interface device structure
7239 *
7240 * Returns non-zero on failure
7241 **/
7242static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7243{
7244 int err = 0;
7245 struct ixgbe_adapter *adapter = netdev_priv(dev);
7246 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7247
7248 if (is_valid_ether_addr(mac->san_addr)) {
7249 rtnl_lock();
7250 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7251 rtnl_unlock();
7252 }
7253 return err;
7254}
7255
Auke Kok9a799d72007-09-15 14:07:45 -07007256#ifdef CONFIG_NET_POLL_CONTROLLER
7257/*
7258 * Polling 'interrupt' - used by things like netconsole to send skbs
7259 * without having to re-enable interrupts. It's not called while
7260 * the interrupt routine is executing.
7261 */
7262static void ixgbe_netpoll(struct net_device *netdev)
7263{
7264 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007265 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007266
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007267 /* if interface is down do nothing */
7268 if (test_bit(__IXGBE_DOWN, &adapter->state))
7269 return;
7270
Auke Kok9a799d72007-09-15 14:07:45 -07007271 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007272 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00007273 for (i = 0; i < adapter->num_q_vectors; i++)
7274 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007275 } else {
7276 ixgbe_intr(adapter->pdev->irq, netdev);
7277 }
Auke Kok9a799d72007-09-15 14:07:45 -07007278 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007279}
Auke Kok9a799d72007-09-15 14:07:45 -07007280
Alexander Duyck581330b2012-02-08 07:51:47 +00007281#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00007282static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7283 struct rtnl_link_stats64 *stats)
7284{
7285 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7286 int i;
7287
Eric Dumazet1a515022010-11-16 19:26:42 -08007288 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007289 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007290 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007291 u64 bytes, packets;
7292 unsigned int start;
7293
Eric Dumazet1a515022010-11-16 19:26:42 -08007294 if (ring) {
7295 do {
7296 start = u64_stats_fetch_begin_bh(&ring->syncp);
7297 packets = ring->stats.packets;
7298 bytes = ring->stats.bytes;
7299 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7300 stats->rx_packets += packets;
7301 stats->rx_bytes += bytes;
7302 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007303 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007304
7305 for (i = 0; i < adapter->num_tx_queues; i++) {
7306 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7307 u64 bytes, packets;
7308 unsigned int start;
7309
7310 if (ring) {
7311 do {
7312 start = u64_stats_fetch_begin_bh(&ring->syncp);
7313 packets = ring->stats.packets;
7314 bytes = ring->stats.bytes;
7315 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7316 stats->tx_packets += packets;
7317 stats->tx_bytes += bytes;
7318 }
7319 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007320 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007321 /* following stats updated by ixgbe_watchdog_task() */
7322 stats->multicast = netdev->stats.multicast;
7323 stats->rx_errors = netdev->stats.rx_errors;
7324 stats->rx_length_errors = netdev->stats.rx_length_errors;
7325 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7326 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7327 return stats;
7328}
7329
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007330#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007331/**
7332 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7333 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00007334 * @tc: number of traffic classes currently enabled
7335 *
7336 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7337 * 802.1Q priority maps to a packet buffer that exists.
7338 */
7339static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7340{
7341 struct ixgbe_hw *hw = &adapter->hw;
7342 u32 reg, rsave;
7343 int i;
7344
7345 /* 82598 have a static priority to TC mapping that can not
7346 * be changed so no validation is needed.
7347 */
7348 if (hw->mac.type == ixgbe_mac_82598EB)
7349 return;
7350
7351 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7352 rsave = reg;
7353
7354 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7355 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7356
7357 /* If up2tc is out of bounds default to zero */
7358 if (up2tc > tc)
7359 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7360 }
7361
7362 if (reg != rsave)
7363 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7364
7365 return;
7366}
7367
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007368/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00007369 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
7370 * @adapter: Pointer to adapter struct
7371 *
7372 * Populate the netdev user priority to tc map
7373 */
7374static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
7375{
7376 struct net_device *dev = adapter->netdev;
7377 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
7378 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
7379 u8 prio;
7380
7381 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
7382 u8 tc = 0;
7383
7384 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
7385 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
7386 else if (ets)
7387 tc = ets->prio_tc[prio];
7388
7389 netdev_set_prio_tc_map(dev, prio, tc);
7390 }
7391}
7392
Alexander Duyckcca73c52013-01-12 06:33:44 +00007393#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00007394/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007395 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00007396 *
7397 * @netdev: net device to configure
7398 * @tc: number of traffic classes to enable
7399 */
7400int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7401{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007402 struct ixgbe_adapter *adapter = netdev_priv(dev);
7403 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08007404 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007405
John Fastabend8b1c0b22011-05-03 02:26:48 +00007406 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007407 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00007408 (hw->mac.type == ixgbe_mac_82598EB &&
7409 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00007410 return -EINVAL;
7411
John Fastabend2a47fa42013-11-06 09:54:52 -08007412 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
7413 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
7414 return -EBUSY;
7415
John Fastabend8b1c0b22011-05-03 02:26:48 +00007416 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007417 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007418 * hardware is not flexible enough to do this dynamically.
7419 */
7420 if (netif_running(dev))
7421 ixgbe_close(dev);
7422 ixgbe_clear_interrupt_scheme(adapter);
7423
Alexander Duyckcca73c52013-01-12 06:33:44 +00007424#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00007425 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007426 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007427 ixgbe_set_prio_tc_map(adapter);
7428
John Fastabende7589ea2011-07-18 22:38:36 +00007429 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007430
Alexander Duyck943561d2012-05-09 22:14:44 -07007431 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
7432 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007433 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07007434 }
John Fastabende7589ea2011-07-18 22:38:36 +00007435 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007436 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007437
Alexander Duyck943561d2012-05-09 22:14:44 -07007438 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7439 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007440
7441 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007442
7443 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7444 adapter->dcb_cfg.pfc_mode_enable = false;
7445 }
7446
John Fastabend8b1c0b22011-05-03 02:26:48 +00007447 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00007448
7449#endif /* CONFIG_IXGBE_DCB */
7450 ixgbe_init_interrupt_scheme(adapter);
7451
John Fastabend8b1c0b22011-05-03 02:26:48 +00007452 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00007453 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00007454
7455 return 0;
7456}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007457
Greg Roseda36b642012-12-11 08:26:43 +00007458#ifdef CONFIG_PCI_IOV
7459void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
7460{
7461 struct net_device *netdev = adapter->netdev;
7462
7463 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00007464 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00007465 rtnl_unlock();
7466}
7467
7468#endif
Don Skidmore082757a2011-07-21 05:55:00 +00007469void ixgbe_do_reset(struct net_device *netdev)
7470{
7471 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7472
7473 if (netif_running(netdev))
7474 ixgbe_reinit_locked(adapter);
7475 else
7476 ixgbe_reset(adapter);
7477}
7478
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007479static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007480 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007481{
7482 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7483
Don Skidmore082757a2011-07-21 05:55:00 +00007484 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007485 if (!(features & NETIF_F_RXCSUM))
7486 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00007487
Alexander Duyck567d2de2012-02-11 07:18:57 +00007488 /* Turn off LRO if not RSC capable */
7489 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
7490 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007491
Alexander Duyck567d2de2012-02-11 07:18:57 +00007492 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00007493}
7494
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007495static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007496 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007497{
7498 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00007499 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00007500 bool need_reset = false;
7501
Don Skidmore082757a2011-07-21 05:55:00 +00007502 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007503 if (!(features & NETIF_F_LRO)) {
7504 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00007505 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00007506 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
7507 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
7508 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7509 if (adapter->rx_itr_setting == 1 ||
7510 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
7511 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
7512 need_reset = true;
7513 } else if ((changed ^ features) & NETIF_F_LRO) {
7514 e_info(probe, "rx-usecs set too low, "
7515 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00007516 }
7517 }
7518
7519 /*
7520 * Check if Flow Director n-tuple support was enabled or disabled. If
7521 * the state changed, we need to reset.
7522 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007523 switch (features & NETIF_F_NTUPLE) {
7524 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00007525 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007526 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
7527 need_reset = true;
7528
Alexander Duyck567d2de2012-02-11 07:18:57 +00007529 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7530 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00007531 break;
7532 default:
7533 /* turn off perfect filters, enable ATR and reset */
7534 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7535 need_reset = true;
7536
7537 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7538
7539 /* We cannot enable ATR if SR-IOV is enabled */
7540 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7541 break;
7542
7543 /* We cannot enable ATR if we have 2 or more traffic classes */
7544 if (netdev_get_num_tc(netdev) > 1)
7545 break;
7546
7547 /* We cannot enable ATR if RSS is disabled */
7548 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
7549 break;
7550
7551 /* A sample rate of 0 indicates ATR disabled */
7552 if (!adapter->atr_sample_rate)
7553 break;
7554
7555 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7556 break;
Don Skidmore082757a2011-07-21 05:55:00 +00007557 }
7558
Patrick McHardyf6469682013-04-19 02:04:27 +00007559 if (features & NETIF_F_HW_VLAN_CTAG_RX)
John Fastabend146d4cc2012-05-15 05:59:26 +00007560 ixgbe_vlan_strip_enable(adapter);
7561 else
7562 ixgbe_vlan_strip_disable(adapter);
7563
Ben Greear3f2d1c02012-03-08 08:28:41 +00007564 if (changed & NETIF_F_RXALL)
7565 need_reset = true;
7566
Alexander Duyck567d2de2012-02-11 07:18:57 +00007567 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00007568 if (need_reset)
7569 ixgbe_do_reset(netdev);
7570
7571 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00007572}
7573
stephen hemmingeredc7d572012-10-01 12:32:33 +00007574static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007575 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00007576 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007577 u16 flags)
7578{
7579 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend95447462012-05-31 12:42:26 +00007580 int err;
7581
7582 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
Vlad Yasevichfaaf02d2013-03-06 15:39:43 +00007583 return ndo_dflt_fdb_add(ndm, tb, dev, addr, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007584
John Fastabendb1ac1ef2012-11-01 05:00:44 +00007585 /* Hardware does not support aging addresses so if a
7586 * ndm_state is given only allow permanent addresses
7587 */
7588 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007589 pr_info("%s: FDB only supports static addresses\n",
7590 ixgbe_driver_name);
7591 return -EINVAL;
7592 }
7593
Ben Hutchings46acc462012-11-01 09:11:11 +00007594 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
John Fastabend95447462012-05-31 12:42:26 +00007595 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
7596
7597 if (netdev_uc_count(dev) < rar_uc_entries)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007598 err = dev_uc_add_excl(dev, addr);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007599 else
John Fastabend95447462012-05-31 12:42:26 +00007600 err = -ENOMEM;
7601 } else if (is_multicast_ether_addr(addr)) {
7602 err = dev_mc_add_excl(dev, addr);
7603 } else {
7604 err = -EINVAL;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007605 }
7606
7607 /* Only return duplicate errors if NLM_F_EXCL is set */
7608 if (err == -EEXIST && !(flags & NLM_F_EXCL))
7609 err = 0;
7610
7611 return err;
7612}
7613
John Fastabend815cccb2012-10-24 08:13:09 +00007614static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7615 struct nlmsghdr *nlh)
7616{
7617 struct ixgbe_adapter *adapter = netdev_priv(dev);
7618 struct nlattr *attr, *br_spec;
7619 int rem;
7620
7621 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7622 return -EOPNOTSUPP;
7623
7624 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7625
7626 nla_for_each_nested(attr, br_spec, rem) {
7627 __u16 mode;
7628 u32 reg = 0;
7629
7630 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7631 continue;
7632
7633 mode = nla_get_u16(attr);
Greg Rose9b735982012-11-08 02:41:35 +00007634 if (mode == BRIDGE_MODE_VEPA) {
John Fastabend815cccb2012-10-24 08:13:09 +00007635 reg = 0;
Greg Rose9b735982012-11-08 02:41:35 +00007636 adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB;
7637 } else if (mode == BRIDGE_MODE_VEB) {
John Fastabend815cccb2012-10-24 08:13:09 +00007638 reg = IXGBE_PFDTXGSWC_VT_LBEN;
Greg Rose9b735982012-11-08 02:41:35 +00007639 adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB;
7640 } else
John Fastabend815cccb2012-10-24 08:13:09 +00007641 return -EINVAL;
7642
7643 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7644
7645 e_info(drv, "enabling bridge mode: %s\n",
7646 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7647 }
7648
7649 return 0;
7650}
7651
7652static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00007653 struct net_device *dev,
7654 u32 filter_mask)
John Fastabend815cccb2012-10-24 08:13:09 +00007655{
7656 struct ixgbe_adapter *adapter = netdev_priv(dev);
7657 u16 mode;
7658
7659 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7660 return 0;
7661
Greg Rose9b735982012-11-08 02:41:35 +00007662 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
John Fastabend815cccb2012-10-24 08:13:09 +00007663 mode = BRIDGE_MODE_VEB;
7664 else
7665 mode = BRIDGE_MODE_VEPA;
7666
7667 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7668}
7669
John Fastabend2a47fa42013-11-06 09:54:52 -08007670static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
7671{
7672 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
7673 struct ixgbe_adapter *adapter = netdev_priv(pdev);
John Fastabend51f37732013-11-08 00:51:10 -08007674 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08007675 int pool, err;
7676
John Fastabend219354d2013-11-08 00:50:32 -08007677#ifdef CONFIG_RPS
7678 if (vdev->num_rx_queues != vdev->num_tx_queues) {
7679 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
7680 vdev->name);
7681 return ERR_PTR(-EINVAL);
7682 }
7683#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08007684 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08007685 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08007686 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
7687 netdev_info(pdev,
7688 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
7689 pdev->name);
7690 return ERR_PTR(-EINVAL);
7691 }
7692
7693 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
7694 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
7695 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
7696 return ERR_PTR(-EBUSY);
7697
7698 fwd_adapter = kcalloc(1, sizeof(struct ixgbe_fwd_adapter), GFP_KERNEL);
7699 if (!fwd_adapter)
7700 return ERR_PTR(-ENOMEM);
7701
7702 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
7703 adapter->num_rx_pools++;
7704 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08007705 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08007706
7707 /* Enable VMDq flag so device will be set in VM mode */
7708 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08007709 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08007710 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08007711
7712 /* Force reinit of ring allocation with VMDQ enabled */
7713 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
7714 if (err)
7715 goto fwd_add_err;
7716 fwd_adapter->pool = pool;
7717 fwd_adapter->real_adapter = adapter;
7718 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
7719 if (err)
7720 goto fwd_add_err;
7721 netif_tx_start_all_queues(vdev);
7722 return fwd_adapter;
7723fwd_add_err:
7724 /* unwind counter and free adapter struct */
7725 netdev_info(pdev,
7726 "%s: dfwd hardware acceleration failed\n", vdev->name);
7727 clear_bit(pool, &adapter->fwd_bitmask);
7728 adapter->num_rx_pools--;
7729 kfree(fwd_adapter);
7730 return ERR_PTR(err);
7731}
7732
7733static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
7734{
7735 struct ixgbe_fwd_adapter *fwd_adapter = priv;
7736 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08007737 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08007738
7739 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
7740 adapter->num_rx_pools--;
7741
John Fastabend51f37732013-11-08 00:51:10 -08007742 limit = find_last_bit(&adapter->fwd_bitmask, 32);
7743 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08007744 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
7745 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
7746 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
7747 fwd_adapter->pool, adapter->num_rx_pools,
7748 fwd_adapter->rx_base_queue,
7749 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
7750 adapter->fwd_bitmask);
7751 kfree(fwd_adapter);
7752}
7753
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007754static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007755 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007756 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007757 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007758 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00007759 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007760 .ndo_validate_addr = eth_validate_addr,
7761 .ndo_set_mac_address = ixgbe_set_mac,
7762 .ndo_change_mtu = ixgbe_change_mtu,
7763 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007764 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7765 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007766 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007767 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7768 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7769 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007770 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007771 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007772 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007773#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007774 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007775#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007776#ifdef CONFIG_NET_POLL_CONTROLLER
7777 .ndo_poll_controller = ixgbe_netpoll,
7778#endif
Cong Wange0d10952013-08-01 11:10:25 +08007779#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03007780 .ndo_busy_poll = ixgbe_low_latency_recv,
Eliezer Tamir5a85e732013-06-10 11:40:20 +03007781#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007782#ifdef IXGBE_FCOE
7783 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007784 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007785 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007786 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7787 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007788 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007789 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007790#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007791 .ndo_set_features = ixgbe_set_features,
7792 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007793 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00007794 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7795 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08007796 .ndo_dfwd_add_station = ixgbe_fwd_add,
7797 .ndo_dfwd_del_station = ixgbe_fwd_del,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007798};
7799
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007800/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00007801 * ixgbe_enumerate_functions - Get the number of ports this device has
7802 * @adapter: adapter structure
7803 *
7804 * This function enumerates the phsyical functions co-located on a single slot,
7805 * in order to determine how many ports a device has. This is most useful in
7806 * determining the required GT/s of PCIe bandwidth necessary for optimal
7807 * performance.
7808 **/
7809static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
7810{
Jacob Kellere027d1a2013-07-31 06:53:31 +00007811 struct list_head *entry;
7812 int physfns = 0;
7813
Jacob Kellerf1f96572013-08-31 02:45:38 +00007814 /* Some cards can not use the generic count PCIe functions method,
7815 * because they are behind a parent switch, so we hardcode these with
7816 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00007817 */
Jacob Kellerf1f96572013-08-31 02:45:38 +00007818 if (ixgbe_pcie_from_parent(&adapter->hw)) {
Jacob Kellere027d1a2013-07-31 06:53:31 +00007819 physfns = 4;
Jacob Kellerf1f96572013-08-31 02:45:38 +00007820 } else {
Jacob Kellere027d1a2013-07-31 06:53:31 +00007821 list_for_each(entry, &adapter->pdev->bus_list) {
7822 struct pci_dev *pdev =
7823 list_entry(entry, struct pci_dev, bus_list);
7824 /* don't count virtual functions */
7825 if (!pdev->is_virtfn)
7826 physfns++;
7827 }
7828 }
7829
7830 return physfns;
7831}
7832
7833/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007834 * ixgbe_wol_supported - Check whether device supports WoL
7835 * @hw: hw specific details
7836 * @device_id: the device ID
7837 * @subdev_id: the subsystem device ID
7838 *
7839 * This function is used by probe and ethtool to determine
7840 * which devices have WoL support
7841 *
7842 **/
7843int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7844 u16 subdevice_id)
7845{
7846 struct ixgbe_hw *hw = &adapter->hw;
7847 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7848 int is_wol_supported = 0;
7849
7850 switch (device_id) {
7851 case IXGBE_DEV_ID_82599_SFP:
7852 /* Only these subdevices could supports WOL */
7853 switch (subdevice_id) {
Mark Rustad87557442014-02-25 17:58:55 -08007854 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007855 case IXGBE_SUBDEV_ID_82599_560FLR:
7856 /* only support first port */
7857 if (hw->bus.func != 0)
7858 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00007859 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007860 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007861 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00007862 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller979fe5f2013-04-03 04:41:37 +00007863 case IXGBE_SUBDEV_ID_82599_LOM_SFP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007864 is_wol_supported = 1;
7865 break;
7866 }
7867 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00007868 case IXGBE_DEV_ID_82599EN_SFP:
7869 /* Only this subdevice supports WOL */
7870 switch (subdevice_id) {
7871 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
7872 is_wol_supported = 1;
7873 break;
7874 }
7875 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007876 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7877 /* All except this subdevice support WOL */
7878 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7879 is_wol_supported = 1;
7880 break;
7881 case IXGBE_DEV_ID_82599_KX4:
7882 is_wol_supported = 1;
7883 break;
7884 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007885 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007886 /* check eeprom to see if enabled wol */
7887 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7888 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7889 (hw->bus.func == 0))) {
7890 is_wol_supported = 1;
7891 }
7892 break;
7893 }
7894
7895 return is_wol_supported;
7896}
7897
7898/**
Auke Kok9a799d72007-09-15 14:07:45 -07007899 * ixgbe_probe - Device Initialization Routine
7900 * @pdev: PCI device information struct
7901 * @ent: entry in ixgbe_pci_tbl
7902 *
7903 * Returns 0 on success, negative on failure
7904 *
7905 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7906 * The OS initialization, configuring of the adapter private structure,
7907 * and a hardware reset occur.
7908 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00007909static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007910{
7911 struct net_device *netdev;
7912 struct ixgbe_adapter *adapter = NULL;
7913 struct ixgbe_hw *hw;
7914 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007915 static int cards_found;
Jacob Kellere027d1a2013-07-31 06:53:31 +00007916 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007917 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00007918 u8 part_str[IXGBE_PBANUM_LENGTH];
Yi Zoueacd73f2009-05-13 13:11:06 +00007919#ifdef IXGBE_FCOE
7920 u16 device_caps;
7921#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007922 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007923
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007924 /* Catch broken hardware that put the wrong VF device ID in
7925 * the PCIe SR-IOV capability.
7926 */
7927 if (pdev->is_virtfn) {
7928 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7929 pci_name(pdev), pdev->vendor, pdev->device);
7930 return -EINVAL;
7931 }
7932
gouji-new9ce77662009-05-06 10:44:45 +00007933 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007934 if (err)
7935 return err;
7936
Russell Kingf5f2eda2013-06-10 12:47:42 +01007937 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007938 pci_using_dac = 1;
7939 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01007940 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007941 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01007942 dev_err(&pdev->dev,
7943 "No usable DMA configuration, aborting\n");
7944 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07007945 }
7946 pci_using_dac = 0;
7947 }
7948
gouji-new9ce77662009-05-06 10:44:45 +00007949 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007950 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007951 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007952 dev_err(&pdev->dev,
7953 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007954 goto err_pci_reg;
7955 }
7956
Frans Pop19d5afd2009-10-02 10:04:12 -07007957 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007958
Auke Kok9a799d72007-09-15 14:07:45 -07007959 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007960 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007961
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007962 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00007963#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007964 /* 8 TC w/ 4 queues per TC */
7965 indices = 4 * MAX_TRAFFIC_CLASS;
7966#else
7967 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00007968#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007969 }
John Fastabende901acd2011-04-26 07:26:08 +00007970
John Fastabendc85a2612010-02-25 23:15:21 +00007971 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007972 if (!netdev) {
7973 err = -ENOMEM;
7974 goto err_alloc_etherdev;
7975 }
7976
Auke Kok9a799d72007-09-15 14:07:45 -07007977 SET_NETDEV_DEV(netdev, &pdev->dev);
7978
Auke Kok9a799d72007-09-15 14:07:45 -07007979 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007980 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007981
7982 adapter->netdev = netdev;
7983 adapter->pdev = pdev;
7984 hw = &adapter->hw;
7985 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007986 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007987
Jeff Kirsher05857982008-09-11 19:57:00 -07007988 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007989 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08007990 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07007991 if (!hw->hw_addr) {
7992 err = -EIO;
7993 goto err_ioremap;
7994 }
7995
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007996 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007997 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007998 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007999 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07008000
Auke Kok9a799d72007-09-15 14:07:45 -07008001 adapter->bd_number = cards_found;
8002
Auke Kok9a799d72007-09-15 14:07:45 -07008003 /* Setup hw api */
8004 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008005 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07008006
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008007 /* EEPROM */
8008 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
8009 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
8010 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
8011 if (!(eec & (1 << 8)))
8012 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
8013
8014 /* PHY */
8015 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08008016 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00008017 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
8018 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
8019 hw->phy.mdio.mmds = 0;
8020 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
8021 hw->phy.mdio.dev = netdev;
8022 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
8023 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08008024
Don Skidmore8ca783a2009-05-26 20:40:47 -07008025 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07008026
8027 /* setup the private structure */
8028 err = ixgbe_sw_init(adapter);
8029 if (err)
8030 goto err_sw_init;
8031
Don Skidmore0b2679d2013-02-21 03:00:04 +00008032 /* Cache if MNG FW is up so we don't have to read the REG later */
8033 if (hw->mac.ops.mng_fw_enabled)
8034 hw->mng_fw_enabled = hw->mac.ops.mng_fw_enabled(hw);
8035
Don Skidmoree86bff02010-02-11 04:14:08 +00008036 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08008037 switch (adapter->hw.mac.type) {
8038 case ixgbe_mac_82599EB:
8039 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00008040 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08008041 break;
8042 default:
8043 break;
8044 }
Don Skidmoree86bff02010-02-11 04:14:08 +00008045
Don Skidmorebf069c92009-05-07 10:39:54 +00008046 /*
8047 * If there is a fan on this device and it has failed log the
8048 * failure.
8049 */
8050 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
8051 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
8052 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00008053 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00008054 }
8055
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00008056 if (allow_unsupported_sfp)
8057 hw->allow_unsupported_sfp = allow_unsupported_sfp;
8058
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008059 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07008060 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008061 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07008062 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07008063 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
8064 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07008065 err = 0;
8066 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00008067 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
8068 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008069 goto err_sw_init;
8070 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008071 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008072 goto err_sw_init;
8073 }
8074
Alexander Duyck99d74482012-05-09 08:09:25 +00008075#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00008076 /* SR-IOV not supported on the 82598 */
8077 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8078 goto skip_sriov;
8079 /* Mailbox */
8080 ixgbe_init_mbx_params_pf(hw);
8081 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
ethan.zhaodcc23e32014-01-16 19:41:04 -08008082 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ethan.zhao31ac9102014-01-16 19:41:05 -08008083 ixgbe_enable_sriov(adapter);
Greg Rose60a1a682012-12-11 08:26:33 +00008084skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008085
Alexander Duyck99d74482012-05-09 08:09:25 +00008086#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00008087 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00008088 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00008089 NETIF_F_IPV6_CSUM |
Patrick McHardyf6469682013-04-19 02:04:27 +00008090 NETIF_F_HW_VLAN_CTAG_TX |
8091 NETIF_F_HW_VLAN_CTAG_RX |
8092 NETIF_F_HW_VLAN_CTAG_FILTER |
Don Skidmore082757a2011-07-21 05:55:00 +00008093 NETIF_F_TSO |
8094 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00008095 NETIF_F_RXHASH |
John Fastabend8bf12642013-11-12 12:13:29 +00008096 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07008097
John Fastabend8bf12642013-11-12 12:13:29 +00008098 netdev->hw_features = netdev->features | NETIF_F_HW_L2FW_DOFFLOAD;
Jeff Kirsherad31c402008-06-05 04:05:30 -07008099
Don Skidmore58be7662011-04-12 09:42:11 +00008100 switch (adapter->hw.mac.type) {
8101 case ixgbe_mac_82599EB:
8102 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00008103 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00008104 netdev->hw_features |= NETIF_F_SCTP_CSUM |
8105 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00008106 break;
8107 default:
8108 break;
8109 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00008110
Ben Greear3f2d1c02012-03-08 08:28:41 +00008111 netdev->hw_features |= NETIF_F_RXALL;
8112
Jeff Kirsherad31c402008-06-05 04:05:30 -07008113 netdev->vlan_features |= NETIF_F_TSO;
8114 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07008115 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00008116 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07008117 netdev->vlan_features |= NETIF_F_SG;
8118
Jiri Pirko01789342011-08-16 06:29:00 +00008119 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00008120 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00008121
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08008122#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08008123 netdev->dcbnl_ops = &dcbnl_ops;
8124#endif
8125
Yi Zoueacd73f2009-05-13 13:11:06 +00008126#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00008127 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008128 unsigned int fcoe_l;
8129
Yi Zoueacd73f2009-05-13 13:11:06 +00008130 if (hw->mac.ops.get_device_caps) {
8131 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00008132 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
8133 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00008134 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008135
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008136
8137 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
8138 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008139
Alexander Duycka58915c2012-05-25 06:38:18 +00008140 netdev->features |= NETIF_F_FSO |
8141 NETIF_F_FCOE_CRC;
8142
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008143 netdev->vlan_features |= NETIF_F_FSO |
8144 NETIF_F_FCOE_CRC |
8145 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00008146 }
Yi Zoueacd73f2009-05-13 13:11:06 +00008147#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00008148 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07008149 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00008150 netdev->vlan_features |= NETIF_F_HIGHDMA;
8151 }
Auke Kok9a799d72007-09-15 14:07:45 -07008152
Don Skidmore082757a2011-07-21 05:55:00 +00008153 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
8154 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00008155 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00008156 netdev->features |= NETIF_F_LRO;
8157
Auke Kok9a799d72007-09-15 14:07:45 -07008158 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008159 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008160 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07008161 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00008162 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008163 }
8164
8165 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008166
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00008167 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008168 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07008169 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00008170 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008171 }
8172
Alexander Duyck70864002011-04-27 09:13:56 +00008173 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00008174 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008175
Alexander Duyck70864002011-04-27 09:13:56 +00008176 INIT_WORK(&adapter->service_task, ixgbe_service_task);
8177 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07008178
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008179 err = ixgbe_init_interrupt_scheme(adapter);
8180 if (err)
8181 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008182
Jacob Keller8e2813f2012-04-21 06:05:40 +00008183 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00008184 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008185 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00008186 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00008187 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00008188 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00008189 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00008190
PJ Waskiewicze8e26352009-02-27 15:45:05 +00008191 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
8192
Emil Tantilov15e52092011-09-29 05:01:29 +00008193 /* save off EEPROM version number */
8194 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
8195 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
8196
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008197 /* pick up the PCI bus settings for reporting later */
8198 hw->mac.ops.get_bus_info(hw);
Jacob Kellere027d1a2013-07-31 06:53:31 +00008199 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00008200 ixgbe_get_parent_bus_info(adapter);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008201
Jacob Kellere027d1a2013-07-31 06:53:31 +00008202 /* calculate the expected PCIe bandwidth required for optimal
8203 * performance. Note that some older parts will never have enough
8204 * bandwidth due to being older generation PCIe parts. We clamp these
8205 * parts to ensure no warning is displayed if it can't be fixed.
8206 */
8207 switch (hw->mac.type) {
8208 case ixgbe_mac_82598EB:
8209 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
8210 break;
8211 default:
8212 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
8213 break;
Auke Kok0c254d82008-02-11 09:25:56 -08008214 }
Jacob Kellere027d1a2013-07-31 06:53:31 +00008215 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08008216
Jacob Keller6a2aae52013-10-18 05:09:24 +00008217 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
8218 if (err)
8219 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
8220 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
8221 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
8222 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
8223 part_str);
8224 else
8225 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
8226 hw->mac.type, hw->phy.type, part_str);
8227
8228 e_dev_info("%pM\n", netdev->dev_addr);
8229
Auke Kok9a799d72007-09-15 14:07:45 -07008230 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008231 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008232 if (err == IXGBE_ERR_EEPROM_VERSION) {
8233 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00008234 e_dev_warn("This device is a pre-production adapter/LOM. "
8235 "Please be aware there may be issues associated "
8236 "with your hardware. If you are experiencing "
8237 "problems please contact your Intel or hardware "
8238 "representative who provided you with this "
8239 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008240 }
Auke Kok9a799d72007-09-15 14:07:45 -07008241 strcpy(netdev->name, "eth%d");
8242 err = register_netdev(netdev);
8243 if (err)
8244 goto err_register;
8245
Emil Tantilovec74a472012-09-20 03:33:56 +00008246 /* power down the optics for 82599 SFP+ fiber */
8247 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00008248 hw->mac.ops.disable_tx_laser(hw);
8249
Jesse Brandeburg54386462009-04-17 20:44:27 +00008250 /* carrier off reporting is important to ethtool even BEFORE open */
8251 netif_carrier_off(netdev);
8252
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008253#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03008254 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008255 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008256 ixgbe_setup_dca(adapter);
8257 }
8258#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008259 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008260 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008261 for (i = 0; i < adapter->num_vfs; i++)
8262 ixgbe_vf_configuration(pdev, (i | 0x10000000));
8263 }
8264
Jacob Keller2466dd92011-09-08 03:50:54 +00008265 /* firmware requires driver version to be 0xFFFFFFFF
8266 * since os does not support feature
8267 */
Emil Tantilov9612de92011-05-07 07:40:20 +00008268 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00008269 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
8270 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00008271
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008272 /* add san mac addr to netdev */
8273 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008274
Neerav Parikhea818752012-01-04 20:23:40 +00008275 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07008276 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008277
Don Skidmore12109822012-05-04 06:07:08 +00008278#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008279 if (ixgbe_sysfs_init(adapter))
8280 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00008281#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008282
Catherine Sullivan00949162012-08-10 01:59:10 +00008283 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00008284
Don Skidmore0b2679d2013-02-21 03:00:04 +00008285 /* Need link setup for MNG FW, else wait for IXGBE_UP */
8286 if (hw->mng_fw_enabled && hw->mac.ops.setup_link)
8287 hw->mac.ops.setup_link(hw,
8288 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
8289 true);
8290
Auke Kok9a799d72007-09-15 14:07:45 -07008291 return 0;
8292
8293err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008294 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00008295 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008296err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00008297 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00008298 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -08008299 iounmap(adapter->io_addr);
Auke Kok9a799d72007-09-15 14:07:45 -07008300err_ioremap:
8301 free_netdev(netdev);
8302err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00008303 pci_release_selected_regions(pdev,
8304 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008305err_pci_reg:
8306err_dma:
8307 pci_disable_device(pdev);
8308 return err;
8309}
8310
8311/**
8312 * ixgbe_remove - Device Removal Routine
8313 * @pdev: PCI device information struct
8314 *
8315 * ixgbe_remove is called by the PCI subsystem to alert the driver
8316 * that it should release a PCI device. The could be caused by a
8317 * Hot-Plug event, or because the driver is going to be removed from
8318 * memory.
8319 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05008320static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07008321{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008322 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8323 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008324
Catherine Sullivan00949162012-08-10 01:59:10 +00008325 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00008326
Mark Rustad09f40ae2014-01-14 18:53:11 -08008327 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008328 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008329
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008330
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008331#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008332 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8333 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8334 dca_remove_requester(&pdev->dev);
8335 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8336 }
8337
8338#endif
Don Skidmore12109822012-05-04 06:07:08 +00008339#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008340 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00008341#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008342
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008343 /* remove the added san mac */
8344 ixgbe_del_sanmac_netdev(netdev);
8345
Donald Skidmorec4900be2008-11-20 21:11:42 -08008346 if (netdev->reg_state == NETREG_REGISTERED)
8347 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008348
Greg Roseda36b642012-12-11 08:26:43 +00008349#ifdef CONFIG_PCI_IOV
8350 /*
8351 * Only disable SR-IOV on unload if the user specified the now
8352 * deprecated max_vfs module parameter.
8353 */
8354 if (max_vfs)
8355 ixgbe_disable_sriov(adapter);
8356#endif
Alexander Duyck7a921c92009-05-06 10:43:28 +00008357 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008358
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008359 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008360
Alexander Duyck2b1588c2012-03-17 02:39:16 +00008361#ifdef CONFIG_DCB
8362 kfree(adapter->ixgbe_ieee_pfc);
8363 kfree(adapter->ixgbe_ieee_ets);
8364
8365#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -08008366 iounmap(adapter->io_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008367 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008368 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008369
Emil Tantilov849c4542010-06-03 16:53:41 +00008370 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008371
Auke Kok9a799d72007-09-15 14:07:45 -07008372 free_netdev(netdev);
8373
Frans Pop19d5afd2009-10-02 10:04:12 -07008374 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008375
Auke Kok9a799d72007-09-15 14:07:45 -07008376 pci_disable_device(pdev);
8377}
8378
8379/**
8380 * ixgbe_io_error_detected - called when PCI error is detected
8381 * @pdev: Pointer to PCI device
8382 * @state: The current pci connection state
8383 *
8384 * This function is called after a PCI bus error affecting
8385 * this device has been detected.
8386 */
8387static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008388 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008389{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008390 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8391 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008392
Greg Rose83c61fa2011-09-07 05:59:35 +00008393#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -08008394 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +00008395 struct pci_dev *bdev, *vfdev;
8396 u32 dw0, dw1, dw2, dw3;
8397 int vf, pos;
8398 u16 req_id, pf_func;
8399
8400 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8401 adapter->num_vfs == 0)
8402 goto skip_bad_vf_detection;
8403
8404 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08008405 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00008406 bdev = bdev->bus->self;
8407
8408 if (!bdev)
8409 goto skip_bad_vf_detection;
8410
8411 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8412 if (!pos)
8413 goto skip_bad_vf_detection;
8414
Mark Rustad14438462014-02-28 15:48:57 -08008415 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
8416 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
8417 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
8418 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
8419 if (ixgbe_removed(hw->hw_addr))
8420 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +00008421
8422 req_id = dw1 >> 16;
8423 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8424 if (!(req_id & 0x0080))
8425 goto skip_bad_vf_detection;
8426
8427 pf_func = req_id & 0x01;
8428 if ((pf_func & 1) == (pdev->devfn & 1)) {
8429 unsigned int device_id;
8430
8431 vf = (req_id & 0x7F) >> 1;
8432 e_dev_err("VF %d has caused a PCIe error\n", vf);
8433 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8434 "%8.8x\tdw3: %8.8x\n",
8435 dw0, dw1, dw2, dw3);
8436 switch (adapter->hw.mac.type) {
8437 case ixgbe_mac_82599EB:
8438 device_id = IXGBE_82599_VF_DEVICE_ID;
8439 break;
8440 case ixgbe_mac_X540:
8441 device_id = IXGBE_X540_VF_DEVICE_ID;
8442 break;
8443 default:
8444 device_id = 0;
8445 break;
8446 }
8447
8448 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00008449 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00008450 while (vfdev) {
8451 if (vfdev->devfn == (req_id & 0xFF))
8452 break;
Jon Mason36e90312012-07-19 21:02:09 +00008453 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00008454 device_id, vfdev);
8455 }
8456 /*
8457 * There's a slim chance the VF could have been hot plugged,
8458 * so if it is no longer present we don't need to issue the
8459 * VFLR. Just clean up the AER in that case.
8460 */
8461 if (vfdev) {
8462 e_dev_err("Issuing VFLR to VF %d\n", vf);
8463 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
Greg Roseb4fafbe2012-12-13 01:14:06 +00008464 /* Free device reference count */
8465 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +00008466 }
8467
8468 pci_cleanup_aer_uncorrect_error_status(pdev);
8469 }
8470
8471 /*
8472 * Even though the error may have occurred on the other port
8473 * we still need to increment the vf error reference count for
8474 * both ports because the I/O resume function will be called
8475 * for both of them.
8476 */
8477 adapter->vferr_refcount++;
8478
8479 return PCI_ERS_RESULT_RECOVERED;
8480
8481skip_bad_vf_detection:
8482#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008483 netif_device_detach(netdev);
8484
Breno Leitao3044b8d2009-05-06 10:44:26 +00008485 if (state == pci_channel_io_perm_failure)
8486 return PCI_ERS_RESULT_DISCONNECT;
8487
Auke Kok9a799d72007-09-15 14:07:45 -07008488 if (netif_running(netdev))
8489 ixgbe_down(adapter);
8490 pci_disable_device(pdev);
8491
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008492 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008493 return PCI_ERS_RESULT_NEED_RESET;
8494}
8495
8496/**
8497 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8498 * @pdev: Pointer to PCI device
8499 *
8500 * Restart the card from scratch, as if from a cold-boot.
8501 */
8502static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8503{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008504 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008505 pci_ers_result_t result;
8506 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008507
gouji-new9ce77662009-05-06 10:44:45 +00008508 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008509 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008510 result = PCI_ERS_RESULT_DISCONNECT;
8511 } else {
Mark Rustad0391bbe2014-02-28 15:48:55 -08008512 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008513 pci_set_master(pdev);
8514 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008515 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008516
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008517 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008518
8519 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008520 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008521 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008522 }
Auke Kok9a799d72007-09-15 14:07:45 -07008523
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008524 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8525 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008526 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8527 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008528 /* non-fatal, continue */
8529 }
Auke Kok9a799d72007-09-15 14:07:45 -07008530
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008531 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008532}
8533
8534/**
8535 * ixgbe_io_resume - called when traffic can start flowing again.
8536 * @pdev: Pointer to PCI device
8537 *
8538 * This callback is called when the error recovery driver tells us that
8539 * its OK to resume normal operation.
8540 */
8541static void ixgbe_io_resume(struct pci_dev *pdev)
8542{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008543 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8544 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008545
Greg Rose83c61fa2011-09-07 05:59:35 +00008546#ifdef CONFIG_PCI_IOV
8547 if (adapter->vferr_refcount) {
8548 e_info(drv, "Resuming after VF err\n");
8549 adapter->vferr_refcount--;
8550 return;
8551 }
8552
8553#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008554 if (netif_running(netdev))
8555 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008556
8557 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008558}
8559
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07008560static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07008561 .error_detected = ixgbe_io_error_detected,
8562 .slot_reset = ixgbe_io_slot_reset,
8563 .resume = ixgbe_io_resume,
8564};
8565
8566static struct pci_driver ixgbe_driver = {
8567 .name = ixgbe_driver_name,
8568 .id_table = ixgbe_pci_tbl,
8569 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05008570 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07008571#ifdef CONFIG_PM
8572 .suspend = ixgbe_suspend,
8573 .resume = ixgbe_resume,
8574#endif
8575 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +00008576 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -07008577 .err_handler = &ixgbe_err_handler
8578};
8579
8580/**
8581 * ixgbe_init_module - Driver Registration Routine
8582 *
8583 * ixgbe_init_module is the first routine called when the driver is
8584 * loaded. All it does is register with the PCI subsystem.
8585 **/
8586static int __init ixgbe_init_module(void)
8587{
8588 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008589 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008590 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008591
Catherine Sullivan00949162012-08-10 01:59:10 +00008592 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +00008593
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008594 ret = pci_register_driver(&ixgbe_driver);
8595 if (ret) {
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008596 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008597 return ret;
8598 }
8599
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008600#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008601 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008602#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008603
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008604 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008605}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008606
Auke Kok9a799d72007-09-15 14:07:45 -07008607module_init(ixgbe_init_module);
8608
8609/**
8610 * ixgbe_exit_module - Driver Exit Cleanup Routine
8611 *
8612 * ixgbe_exit_module is called just before the driver is removed
8613 * from memory.
8614 **/
8615static void __exit ixgbe_exit_module(void)
8616{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008617#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008618 dca_unregister_notify(&dca_notifier);
8619#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008620 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00008621
Catherine Sullivan00949162012-08-10 01:59:10 +00008622 ixgbe_dbg_exit();
Catherine Sullivan00949162012-08-10 01:59:10 +00008623
Eric Dumazet1a515022010-11-16 19:26:42 -08008624 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008625}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008626
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008627#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008628static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008629 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008630{
8631 int ret_val;
8632
8633 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008634 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008635
8636 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8637}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008638
Alexander Duyckb4533682009-03-31 21:32:42 +00008639#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008640
Auke Kok9a799d72007-09-15 14:07:45 -07008641module_exit(ixgbe_exit_module);
8642
8643/* ixgbe_main.c */