blob: 166dc0015a5e91b21ff2d03ac8cf7764732ecbdd [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 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020087static const struct pci_device_id 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 Rustad58cf6632014-03-12 00:38:40 +0000300 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
301 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800302}
303
Mark Rustadf8e24722014-03-18 07:03:40 +0000304static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800305{
306 u32 value;
307
308 /* The following check not only optimizes a bit by not
309 * performing a read on the status register when the
310 * register just read was a status register read that
311 * returned IXGBE_FAILED_READ_REG. It also blocks any
312 * potential recursion.
313 */
314 if (reg == IXGBE_STATUS) {
315 ixgbe_remove_adapter(hw);
316 return;
317 }
318 value = ixgbe_read_reg(hw, IXGBE_STATUS);
319 if (value == IXGBE_FAILED_READ_REG)
320 ixgbe_remove_adapter(hw);
321}
322
Mark Rustadf8e24722014-03-18 07:03:40 +0000323/**
324 * ixgbe_read_reg - Read from device register
325 * @hw: hw specific details
326 * @reg: offset of register to read
327 *
328 * Returns : value read or IXGBE_FAILED_READ_REG if removed
329 *
330 * This function is used to read device registers. It checks for device
331 * removal by confirming any read that returns all ones by checking the
332 * status register value for all ones. This function avoids reading from
333 * the hardware if a removal was previously detected in which case it
334 * returns IXGBE_FAILED_READ_REG (all ones).
335 */
336u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
337{
338 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
339 u32 value;
340
341 if (ixgbe_removed(reg_addr))
342 return IXGBE_FAILED_READ_REG;
343 value = readl(reg_addr + reg);
344 if (unlikely(value == IXGBE_FAILED_READ_REG))
345 ixgbe_check_remove(hw, reg);
346 return value;
347}
348
Mark Rustad14438462014-02-28 15:48:57 -0800349static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
350{
351 u16 value;
352
353 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
354 if (value == IXGBE_FAILED_READ_CFG_WORD) {
355 ixgbe_remove_adapter(hw);
356 return true;
357 }
358 return false;
359}
360
361u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
362{
363 struct ixgbe_adapter *adapter = hw->back;
364 u16 value;
365
366 if (ixgbe_removed(hw->hw_addr))
367 return IXGBE_FAILED_READ_CFG_WORD;
368 pci_read_config_word(adapter->pdev, reg, &value);
369 if (value == IXGBE_FAILED_READ_CFG_WORD &&
370 ixgbe_check_cfg_remove(hw, adapter->pdev))
371 return IXGBE_FAILED_READ_CFG_WORD;
372 return value;
373}
374
375#ifdef CONFIG_PCI_IOV
376static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
377{
378 struct ixgbe_adapter *adapter = hw->back;
379 u32 value;
380
381 if (ixgbe_removed(hw->hw_addr))
382 return IXGBE_FAILED_READ_CFG_DWORD;
383 pci_read_config_dword(adapter->pdev, reg, &value);
384 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
385 ixgbe_check_cfg_remove(hw, adapter->pdev))
386 return IXGBE_FAILED_READ_CFG_DWORD;
387 return value;
388}
389#endif /* CONFIG_PCI_IOV */
390
Jacob Kellered192312014-02-22 01:23:53 +0000391void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
392{
393 struct ixgbe_adapter *adapter = hw->back;
394
395 if (ixgbe_removed(hw->hw_addr))
396 return;
397 pci_write_config_word(adapter->pdev, reg, value);
398}
399
Alexander Duyck70864002011-04-27 09:13:56 +0000400static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
401{
402 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
403
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000404 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100405 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000406 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
407}
408
Taku Izumidcd79ae2010-04-27 14:39:53 +0000409struct ixgbe_reg_info {
410 u32 ofs;
411 char *name;
412};
413
414static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
415
416 /* General Registers */
417 {IXGBE_CTRL, "CTRL"},
418 {IXGBE_STATUS, "STATUS"},
419 {IXGBE_CTRL_EXT, "CTRL_EXT"},
420
421 /* Interrupt Registers */
422 {IXGBE_EICR, "EICR"},
423
424 /* RX Registers */
425 {IXGBE_SRRCTL(0), "SRRCTL"},
426 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
427 {IXGBE_RDLEN(0), "RDLEN"},
428 {IXGBE_RDH(0), "RDH"},
429 {IXGBE_RDT(0), "RDT"},
430 {IXGBE_RXDCTL(0), "RXDCTL"},
431 {IXGBE_RDBAL(0), "RDBAL"},
432 {IXGBE_RDBAH(0), "RDBAH"},
433
434 /* TX Registers */
435 {IXGBE_TDBAL(0), "TDBAL"},
436 {IXGBE_TDBAH(0), "TDBAH"},
437 {IXGBE_TDLEN(0), "TDLEN"},
438 {IXGBE_TDH(0), "TDH"},
439 {IXGBE_TDT(0), "TDT"},
440 {IXGBE_TXDCTL(0), "TXDCTL"},
441
442 /* List Terminator */
443 {}
444};
445
446
447/*
448 * ixgbe_regdump - register printout routine
449 */
450static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
451{
452 int i = 0, j = 0;
453 char rname[16];
454 u32 regs[64];
455
456 switch (reginfo->ofs) {
457 case IXGBE_SRRCTL(0):
458 for (i = 0; i < 64; i++)
459 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
460 break;
461 case IXGBE_DCA_RXCTRL(0):
462 for (i = 0; i < 64; i++)
463 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
464 break;
465 case IXGBE_RDLEN(0):
466 for (i = 0; i < 64; i++)
467 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
468 break;
469 case IXGBE_RDH(0):
470 for (i = 0; i < 64; i++)
471 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
472 break;
473 case IXGBE_RDT(0):
474 for (i = 0; i < 64; i++)
475 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
476 break;
477 case IXGBE_RXDCTL(0):
478 for (i = 0; i < 64; i++)
479 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
480 break;
481 case IXGBE_RDBAL(0):
482 for (i = 0; i < 64; i++)
483 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
484 break;
485 case IXGBE_RDBAH(0):
486 for (i = 0; i < 64; i++)
487 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
488 break;
489 case IXGBE_TDBAL(0):
490 for (i = 0; i < 64; i++)
491 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
492 break;
493 case IXGBE_TDBAH(0):
494 for (i = 0; i < 64; i++)
495 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
496 break;
497 case IXGBE_TDLEN(0):
498 for (i = 0; i < 64; i++)
499 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
500 break;
501 case IXGBE_TDH(0):
502 for (i = 0; i < 64; i++)
503 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
504 break;
505 case IXGBE_TDT(0):
506 for (i = 0; i < 64; i++)
507 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
508 break;
509 case IXGBE_TXDCTL(0):
510 for (i = 0; i < 64; i++)
511 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
512 break;
513 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000514 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000515 IXGBE_READ_REG(hw, reginfo->ofs));
516 return;
517 }
518
519 for (i = 0; i < 8; i++) {
520 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000521 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000522 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000523 pr_cont(" %08x", regs[i*8+j]);
524 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000525 }
526
527}
528
529/*
530 * ixgbe_dump - Print registers, tx-rings and rx-rings
531 */
532static void ixgbe_dump(struct ixgbe_adapter *adapter)
533{
534 struct net_device *netdev = adapter->netdev;
535 struct ixgbe_hw *hw = &adapter->hw;
536 struct ixgbe_reg_info *reginfo;
537 int n = 0;
538 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000539 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000540 union ixgbe_adv_tx_desc *tx_desc;
541 struct my_u0 { u64 a; u64 b; } *u0;
542 struct ixgbe_ring *rx_ring;
543 union ixgbe_adv_rx_desc *rx_desc;
544 struct ixgbe_rx_buffer *rx_buffer_info;
545 u32 staterr;
546 int i = 0;
547
548 if (!netif_msg_hw(adapter))
549 return;
550
551 /* Print netdevice Info */
552 if (netdev) {
553 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000554 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000555 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000556 pr_info("%-15s %016lX %016lX %016lX\n",
557 netdev->name,
558 netdev->state,
559 netdev->trans_start,
560 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000561 }
562
563 /* Print Registers */
564 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000565 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000566 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
567 reginfo->name; reginfo++) {
568 ixgbe_regdump(hw, reginfo);
569 }
570
571 /* Print TX Ring Summary */
572 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000573 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000574
575 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000576 pr_info(" %s %s %s %s\n",
577 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
578 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000579 for (n = 0; n < adapter->num_tx_queues; n++) {
580 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000581 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000582 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000583 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000584 (u64)dma_unmap_addr(tx_buffer, dma),
585 dma_unmap_len(tx_buffer, len),
586 tx_buffer->next_to_watch,
587 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000588 }
589
590 /* Print TX Rings */
591 if (!netif_msg_tx_done(adapter))
592 goto rx_ring_summary;
593
594 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
595
596 /* Transmit Descriptor Formats
597 *
Josh Hay39ac8682012-09-26 05:59:36 +0000598 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000599 * +--------------------------------------------------------------+
600 * 0 | Buffer Address [63:0] |
601 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000602 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000603 * +--------------------------------------------------------------+
604 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000605 *
606 * 82598 Advanced Transmit Descriptor (Write-Back Format)
607 * +--------------------------------------------------------------+
608 * 0 | RSV [63:0] |
609 * +--------------------------------------------------------------+
610 * 8 | RSV | STA | NXTSEQ |
611 * +--------------------------------------------------------------+
612 * 63 36 35 32 31 0
613 *
614 * 82599+ Advanced Transmit Descriptor
615 * +--------------------------------------------------------------+
616 * 0 | Buffer Address [63:0] |
617 * +--------------------------------------------------------------+
618 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
619 * +--------------------------------------------------------------+
620 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
621 *
622 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
623 * +--------------------------------------------------------------+
624 * 0 | RSV [63:0] |
625 * +--------------------------------------------------------------+
626 * 8 | RSV | STA | RSV |
627 * +--------------------------------------------------------------+
628 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000629 */
630
631 for (n = 0; n < adapter->num_tx_queues; n++) {
632 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000633 pr_info("------------------------------------\n");
634 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
635 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000636 pr_info("%s%s %s %s %s %s\n",
637 "T [desc] [address 63:0 ] ",
638 "[PlPOIdStDDt Ln] [bi->dma ] ",
639 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000640
641 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000642 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000643 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000644 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000645 if (dma_unmap_len(tx_buffer, len) > 0) {
646 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
647 i,
648 le64_to_cpu(u0->a),
649 le64_to_cpu(u0->b),
650 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000651 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000652 tx_buffer->next_to_watch,
653 (u64)tx_buffer->time_stamp,
654 tx_buffer->skb);
655 if (i == tx_ring->next_to_use &&
656 i == tx_ring->next_to_clean)
657 pr_cont(" NTC/U\n");
658 else if (i == tx_ring->next_to_use)
659 pr_cont(" NTU\n");
660 else if (i == tx_ring->next_to_clean)
661 pr_cont(" NTC\n");
662 else
663 pr_cont("\n");
664
665 if (netif_msg_pktdata(adapter) &&
666 tx_buffer->skb)
667 print_hex_dump(KERN_INFO, "",
668 DUMP_PREFIX_ADDRESS, 16, 1,
669 tx_buffer->skb->data,
670 dma_unmap_len(tx_buffer, len),
671 true);
672 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000673 }
674 }
675
676 /* Print RX Rings Summary */
677rx_ring_summary:
678 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000679 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000680 for (n = 0; n < adapter->num_rx_queues; n++) {
681 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000682 pr_info("%5d %5X %5X\n",
683 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000684 }
685
686 /* Print RX Rings */
687 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000688 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000689
690 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
691
Josh Hay39ac8682012-09-26 05:59:36 +0000692 /* Receive Descriptor Formats
693 *
694 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000695 * 63 1 0
696 * +-----------------------------------------------------+
697 * 0 | Packet Buffer Address [63:1] |A0/NSE|
698 * +----------------------------------------------+------+
699 * 8 | Header Buffer Address [63:1] | DD |
700 * +-----------------------------------------------------+
701 *
702 *
Josh Hay39ac8682012-09-26 05:59:36 +0000703 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000704 *
705 * 63 48 47 32 31 30 21 20 16 15 4 3 0
706 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000707 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
708 * | Packet | IP | | | | Type | Type |
709 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000710 * +------------------------------------------------------+
711 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
712 * +------------------------------------------------------+
713 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000714 *
715 * 82599+ Advanced Receive Descriptor (Read) Format
716 * 63 1 0
717 * +-----------------------------------------------------+
718 * 0 | Packet Buffer Address [63:1] |A0/NSE|
719 * +----------------------------------------------+------+
720 * 8 | Header Buffer Address [63:1] | DD |
721 * +-----------------------------------------------------+
722 *
723 *
724 * 82599+ Advanced Receive Descriptor (Write-Back) Format
725 *
726 * 63 48 47 32 31 30 21 20 17 16 4 3 0
727 * +------------------------------------------------------+
728 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
729 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
730 * |/ Flow Dir Flt ID | | | | | |
731 * +------------------------------------------------------+
732 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
733 * +------------------------------------------------------+
734 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000735 */
Josh Hay39ac8682012-09-26 05:59:36 +0000736
Taku Izumidcd79ae2010-04-27 14:39:53 +0000737 for (n = 0; n < adapter->num_rx_queues; n++) {
738 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000739 pr_info("------------------------------------\n");
740 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
741 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000742 pr_info("%s%s%s",
743 "R [desc] [ PktBuf A0] ",
744 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000745 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000746 pr_info("%s%s%s",
747 "RWB[desc] [PcsmIpSHl PtRs] ",
748 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000749 "<-- Adv Rx Write-Back format\n");
750
751 for (i = 0; i < rx_ring->count; i++) {
752 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000753 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000754 u0 = (struct my_u0 *)rx_desc;
755 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
756 if (staterr & IXGBE_RXD_STAT_DD) {
757 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000758 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000759 "%016llX ---------------- %p", i,
760 le64_to_cpu(u0->a),
761 le64_to_cpu(u0->b),
762 rx_buffer_info->skb);
763 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000764 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000765 "%016llX %016llX %p", i,
766 le64_to_cpu(u0->a),
767 le64_to_cpu(u0->b),
768 (u64)rx_buffer_info->dma,
769 rx_buffer_info->skb);
770
Emil Tantilov9c50c032012-07-26 01:21:24 +0000771 if (netif_msg_pktdata(adapter) &&
772 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000773 print_hex_dump(KERN_INFO, "",
774 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000775 page_address(rx_buffer_info->page) +
776 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000777 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000778 }
779 }
780
781 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000782 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000783 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000784 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000785 else
Joe Perchesc7689572010-09-07 21:35:17 +0000786 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000787
788 }
789 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000790}
791
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800792static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
793{
794 u32 ctrl_ext;
795
796 /* Let firmware take over control of h/w */
797 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
798 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000799 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800800}
801
802static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
803{
804 u32 ctrl_ext;
805
806 /* Let firmware know the driver has taken over */
807 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
808 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000809 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800810}
Auke Kok9a799d72007-09-15 14:07:45 -0700811
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000812/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000813 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
814 * @adapter: pointer to adapter struct
815 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
816 * @queue: queue to map the corresponding interrupt to
817 * @msix_vector: the vector to map to the corresponding queue
818 *
819 */
820static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000821 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700822{
823 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000824 struct ixgbe_hw *hw = &adapter->hw;
825 switch (hw->mac.type) {
826 case ixgbe_mac_82598EB:
827 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
828 if (direction == -1)
829 direction = 0;
830 index = (((direction * 64) + queue) >> 2) & 0x1F;
831 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
832 ivar &= ~(0xFF << (8 * (queue & 0x3)));
833 ivar |= (msix_vector << (8 * (queue & 0x3)));
834 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
835 break;
836 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800837 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000838 if (direction == -1) {
839 /* other causes */
840 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
841 index = ((queue & 1) * 8);
842 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
843 ivar &= ~(0xFF << index);
844 ivar |= (msix_vector << index);
845 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
846 break;
847 } else {
848 /* tx or rx causes */
849 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
850 index = ((16 * (queue & 1)) + (8 * direction));
851 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
852 ivar &= ~(0xFF << index);
853 ivar |= (msix_vector << index);
854 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
855 break;
856 }
857 default:
858 break;
859 }
Auke Kok9a799d72007-09-15 14:07:45 -0700860}
861
Alexander Duyckfe49f042009-06-04 16:00:09 +0000862static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000863 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000864{
865 u32 mask;
866
Alexander Duyckbd508172010-11-16 19:27:03 -0800867 switch (adapter->hw.mac.type) {
868 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000869 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
870 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800871 break;
872 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800873 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000874 mask = (qmask & 0xFFFFFFFF);
875 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
876 mask = (qmask >> 32);
877 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800878 break;
879 default:
880 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000881 }
882}
883
Alexander Duyck729739b2012-02-08 07:51:06 +0000884void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
885 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000886{
Alexander Duyck729739b2012-02-08 07:51:06 +0000887 if (tx_buffer->skb) {
888 dev_kfree_skb_any(tx_buffer->skb);
889 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000890 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000891 dma_unmap_addr(tx_buffer, dma),
892 dma_unmap_len(tx_buffer, len),
893 DMA_TO_DEVICE);
894 } else if (dma_unmap_len(tx_buffer, len)) {
895 dma_unmap_page(ring->dev,
896 dma_unmap_addr(tx_buffer, dma),
897 dma_unmap_len(tx_buffer, len),
898 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000899 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000900 tx_buffer->next_to_watch = NULL;
901 tx_buffer->skb = NULL;
902 dma_unmap_len_set(tx_buffer, len, 0);
903 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700904}
905
Alexander Duyck943561d2012-05-09 22:14:44 -0700906static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
907{
908 struct ixgbe_hw *hw = &adapter->hw;
909 struct ixgbe_hw_stats *hwstats = &adapter->stats;
910 int i;
911 u32 data;
912
913 if ((hw->fc.current_mode != ixgbe_fc_full) &&
914 (hw->fc.current_mode != ixgbe_fc_rx_pause))
915 return;
916
917 switch (hw->mac.type) {
918 case ixgbe_mac_82598EB:
919 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
920 break;
921 default:
922 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
923 }
924 hwstats->lxoffrxc += data;
925
926 /* refill credits (no tx hang) if we received xoff */
927 if (!data)
928 return;
929
930 for (i = 0; i < adapter->num_tx_queues; i++)
931 clear_bit(__IXGBE_HANG_CHECK_ARMED,
932 &adapter->tx_ring[i]->state);
933}
934
John Fastabendc84d3242010-11-16 19:27:12 -0800935static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700936{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700937 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800938 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800939 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000940 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800941 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700942 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700943
Alexander Duyck943561d2012-05-09 22:14:44 -0700944 if (adapter->ixgbe_ieee_pfc)
945 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800946
Alexander Duyck943561d2012-05-09 22:14:44 -0700947 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
948 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800949 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700950 }
John Fastabendc84d3242010-11-16 19:27:12 -0800951
952 /* update stats for each tc, only valid with PFC enabled */
953 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000954 u32 pxoffrxc;
955
John Fastabendc84d3242010-11-16 19:27:12 -0800956 switch (hw->mac.type) {
957 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000958 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800959 break;
960 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000961 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800962 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000963 hwstats->pxoffrxc[i] += pxoffrxc;
964 /* Get the TC for given UP */
965 tc = netdev_get_prio_tc_map(adapter->netdev, i);
966 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -0700967 }
968
John Fastabendc84d3242010-11-16 19:27:12 -0800969 /* disarm tx queues that have received xoff frames */
970 for (i = 0; i < adapter->num_tx_queues; i++) {
971 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -0800972
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000973 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800974 if (xoff[tc])
975 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
976 }
977}
978
979static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
980{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000981 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800982}
983
984static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
985{
John Fastabend2a47fa42013-11-06 09:54:52 -0800986 struct ixgbe_adapter *adapter;
987 struct ixgbe_hw *hw;
988 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -0800989
John Fastabend2a47fa42013-11-06 09:54:52 -0800990 if (ring->l2_accel_priv)
991 adapter = ring->l2_accel_priv->real_adapter;
992 else
993 adapter = netdev_priv(ring->netdev);
994
995 hw = &adapter->hw;
996 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
997 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -0800998
999 if (head != tail)
1000 return (head < tail) ?
1001 tail - head : (tail + ring->count - head);
1002
1003 return 0;
1004}
1005
1006static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1007{
1008 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1009 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1010 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001011
1012 clear_check_for_tx_hang(tx_ring);
1013
1014 /*
1015 * Check for a hung queue, but be thorough. This verifies
1016 * that a transmit has been completed since the previous
1017 * check AND there is at least one packet pending. The
1018 * ARMED bit is set to indicate a potential hang. The
1019 * bit is cleared if a pause frame is received to remove
1020 * false hang detection due to PFC or 802.3x frames. By
1021 * requiring this to fail twice we avoid races with
1022 * pfc clearing the ARMED bit and conditions where we
1023 * run the check_tx_hang logic with a transmit completion
1024 * pending but without time to complete it yet.
1025 */
Mark Rustade90dd262014-07-22 06:51:08 +00001026 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001027 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001028 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1029 &tx_ring->state);
1030 /* update completed stats and continue */
1031 tx_ring->tx_stats.tx_done_old = tx_done;
1032 /* reset the countdown */
1033 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001034
Mark Rustade90dd262014-07-22 06:51:08 +00001035 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001036}
1037
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001038/**
1039 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1040 * @adapter: driver private struct
1041 **/
1042static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1043{
1044
1045 /* Do the reset outside of interrupt context */
1046 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1047 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Jacob Keller12ff3f32012-12-01 07:57:17 +00001048 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001049 ixgbe_service_event_schedule(adapter);
1050 }
1051}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001052
Auke Kok9a799d72007-09-15 14:07:45 -07001053/**
1054 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001055 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001056 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -07001057 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001058static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001059 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07001060{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001061 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001062 struct ixgbe_tx_buffer *tx_buffer;
1063 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001064 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001065 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001066 unsigned int i = tx_ring->next_to_clean;
1067
1068 if (test_bit(__IXGBE_DOWN, &adapter->state))
1069 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001070
Alexander Duyckd3d00232011-07-15 02:31:25 +00001071 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001072 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001073 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001074
Alexander Duyck729739b2012-02-08 07:51:06 +00001075 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001076 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001077
Alexander Duyckd3d00232011-07-15 02:31:25 +00001078 /* if next_to_watch is not set then there is no work pending */
1079 if (!eop_desc)
1080 break;
1081
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001082 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001083 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001084
Alexander Duyckd3d00232011-07-15 02:31:25 +00001085 /* if DD is not set pending work has not been completed */
1086 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1087 break;
1088
Alexander Duyckd3d00232011-07-15 02:31:25 +00001089 /* clear next_to_watch to prevent false hangs */
1090 tx_buffer->next_to_watch = NULL;
1091
Alexander Duyck091a6242012-02-08 07:51:01 +00001092 /* update the statistics for this packet */
1093 total_bytes += tx_buffer->bytecount;
1094 total_packets += tx_buffer->gso_segs;
1095
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001096 /* free the skb */
1097 dev_kfree_skb_any(tx_buffer->skb);
1098
Alexander Duyck729739b2012-02-08 07:51:06 +00001099 /* unmap skb header data */
1100 dma_unmap_single(tx_ring->dev,
1101 dma_unmap_addr(tx_buffer, dma),
1102 dma_unmap_len(tx_buffer, len),
1103 DMA_TO_DEVICE);
1104
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001105 /* clear tx_buffer data */
1106 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +00001107 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001108
Alexander Duyck729739b2012-02-08 07:51:06 +00001109 /* unmap remaining buffers */
1110 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001111 tx_buffer++;
1112 tx_desc++;
1113 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001114 if (unlikely(!i)) {
1115 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001116 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001117 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001118 }
1119
Alexander Duyck729739b2012-02-08 07:51:06 +00001120 /* unmap any remaining paged data */
1121 if (dma_unmap_len(tx_buffer, len)) {
1122 dma_unmap_page(tx_ring->dev,
1123 dma_unmap_addr(tx_buffer, dma),
1124 dma_unmap_len(tx_buffer, len),
1125 DMA_TO_DEVICE);
1126 dma_unmap_len_set(tx_buffer, len, 0);
1127 }
1128 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001129
Alexander Duyck729739b2012-02-08 07:51:06 +00001130 /* move us one more past the eop_desc for start of next pkt */
1131 tx_buffer++;
1132 tx_desc++;
1133 i++;
1134 if (unlikely(!i)) {
1135 i -= tx_ring->count;
1136 tx_buffer = tx_ring->tx_buffer_info;
1137 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1138 }
1139
1140 /* issue prefetch for next Tx descriptor */
1141 prefetch(tx_desc);
1142
1143 /* update budget accounting */
1144 budget--;
1145 } while (likely(budget));
1146
1147 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001148 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001149 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001150 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001151 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001152 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001153 q_vector->tx.total_bytes += total_bytes;
1154 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001155
John Fastabendc84d3242010-11-16 19:27:12 -08001156 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001157 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001158 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001159 e_err(drv, "Detected Tx Unit Hang\n"
1160 " Tx Queue <%d>\n"
1161 " TDH, TDT <%x>, <%x>\n"
1162 " next_to_use <%x>\n"
1163 " next_to_clean <%x>\n"
1164 "tx_buffer_info[next_to_clean]\n"
1165 " time_stamp <%lx>\n"
1166 " jiffies <%lx>\n",
1167 tx_ring->queue_index,
1168 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1169 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001170 tx_ring->next_to_use, i,
1171 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001172
1173 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1174
1175 e_info(probe,
1176 "tx hang %d detected on queue %d, resetting adapter\n",
1177 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1178
1179 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001180 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001181
1182 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001183 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001184 }
Auke Kok9a799d72007-09-15 14:07:45 -07001185
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001186 netdev_tx_completed_queue(txring_txq(tx_ring),
1187 total_packets, total_bytes);
1188
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001189#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001190 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001191 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001192 /* Make sure that anybody stopping the queue after this
1193 * sees the new next_to_clean.
1194 */
1195 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001196 if (__netif_subqueue_stopped(tx_ring->netdev,
1197 tx_ring->queue_index)
1198 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1199 netif_wake_subqueue(tx_ring->netdev,
1200 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001201 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001202 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001203 }
Auke Kok9a799d72007-09-15 14:07:45 -07001204
Alexander Duyck59224552011-08-31 00:01:06 +00001205 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001206}
1207
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001208#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001209static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001210 struct ixgbe_ring *tx_ring,
1211 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001212{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001213 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001214 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1215 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001216
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001217 switch (hw->mac.type) {
1218 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001219 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001220 break;
1221 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001222 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001223 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1224 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1225 break;
1226 default:
1227 /* for unknown hardware do not write register */
1228 return;
1229 }
1230
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 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1237 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1238 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1239
1240 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1241}
1242
1243static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1244 struct ixgbe_ring *rx_ring,
1245 int cpu)
1246{
1247 struct ixgbe_hw *hw = &adapter->hw;
1248 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1249 u8 reg_idx = rx_ring->reg_idx;
1250
1251
1252 switch (hw->mac.type) {
1253 case ixgbe_mac_82599EB:
1254 case ixgbe_mac_X540:
1255 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001256 break;
1257 default:
1258 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001259 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001260
1261 /*
1262 * We can enable relaxed ordering for reads, but not writes when
1263 * DCA is enabled. This is due to a known issue in some chipsets
1264 * which will cause the DCA tag to be cleared.
1265 */
1266 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001267 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1268
1269 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001270}
1271
1272static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1273{
1274 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001275 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001276 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001277
1278 if (q_vector->cpu == cpu)
1279 goto out_no_update;
1280
Alexander Duycka5579282012-02-08 07:50:04 +00001281 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001282 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001283
Alexander Duycka5579282012-02-08 07:50:04 +00001284 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001285 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001286
1287 q_vector->cpu = cpu;
1288out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001289 put_cpu();
1290}
1291
1292static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1293{
1294 int i;
1295
1296 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1297 return;
1298
Alexander Duycke35ec122009-05-21 13:07:12 +00001299 /* always use CB2 mode, difference is masked in the CB driver */
1300 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1301
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001302 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001303 adapter->q_vector[i]->cpu = -1;
1304 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001305 }
1306}
1307
1308static int __ixgbe_notify_dca(struct device *dev, void *data)
1309{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001310 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001311 unsigned long event = *(unsigned long *)data;
1312
Don Skidmore2a72c312011-07-20 02:27:05 +00001313 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001314 return 0;
1315
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001316 switch (event) {
1317 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001318 /* if we're already enabled, don't do it again */
1319 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1320 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001321 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001322 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001323 ixgbe_setup_dca(adapter);
1324 break;
1325 }
1326 /* Fall Through since DCA is disabled. */
1327 case DCA_PROVIDER_REMOVE:
1328 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1329 dca_remove_requester(dev);
1330 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1331 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1332 }
1333 break;
1334 }
1335
Denis V. Lunev652f0932008-03-27 14:39:17 +03001336 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001337}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001338
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001339#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001340static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1341 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001342 struct sk_buff *skb)
1343{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001344 if (ring->netdev->features & NETIF_F_RXHASH)
Tom Herbert38da9852013-12-18 16:47:04 +00001345 skb_set_hash(skb,
1346 le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1347 PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001348}
1349
Alexander Duyckf8003262012-03-03 02:35:52 +00001350#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001351/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001352 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001353 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001354 * @rx_desc: advanced rx descriptor
1355 *
1356 * Returns : true if it is FCoE pkt
1357 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001358static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001359 union ixgbe_adv_rx_desc *rx_desc)
1360{
1361 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1362
Alexander Duyck57efd442012-06-25 21:54:46 +00001363 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001364 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1365 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1366 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1367}
1368
Alexander Duyckf8003262012-03-03 02:35:52 +00001369#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001370/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001371 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001372 * @ring: structure containing ring specific data
1373 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001374 * @skb: skb currently being received and modified
1375 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001376static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001377 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001378 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001379{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001380 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001381
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001382 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001383 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001384 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001385
1386 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001387 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1388 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001389 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001390 return;
1391 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001392
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001393 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001394 return;
1395
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001396 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001397 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001398
1399 /*
1400 * 82599 errata, UDP frames with a 0 checksum can be marked as
1401 * checksum errors.
1402 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001403 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1404 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001405 return;
1406
Alexander Duyck8a0da212012-01-31 02:59:49 +00001407 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001408 return;
1409 }
1410
Auke Kok9a799d72007-09-15 14:07:45 -07001411 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001412 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001413}
1414
Alexander Duyck84ea2592010-11-16 19:26:49 -08001415static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001416{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001417 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001418
1419 /* update next to alloc since we have filled the ring */
1420 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001421 /*
1422 * Force memory writes to complete before letting h/w
1423 * know there are new descriptors to fetch. (Only
1424 * applicable for weak-ordered memory model archs,
1425 * such as IA-64).
1426 */
1427 wmb();
Mark Rustad84227bc2014-01-14 18:53:13 -08001428 ixgbe_write_tail(rx_ring, val);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001429}
1430
Alexander Duyckf990b792012-01-31 02:59:34 +00001431static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1432 struct ixgbe_rx_buffer *bi)
1433{
1434 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001435 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001436
Alexander Duyckf8003262012-03-03 02:35:52 +00001437 /* since we are recycling buffers we should seldom need to alloc */
1438 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001439 return true;
1440
Alexander Duyckf8003262012-03-03 02:35:52 +00001441 /* alloc new page for storage */
1442 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001443 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1444 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001445 if (unlikely(!page)) {
1446 rx_ring->rx_stats.alloc_rx_page_failed++;
1447 return false;
1448 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001449 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001450 }
1451
Alexander Duyckf8003262012-03-03 02:35:52 +00001452 /* map page for use */
1453 dma = dma_map_page(rx_ring->dev, page, 0,
1454 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001455
Alexander Duyckf8003262012-03-03 02:35:52 +00001456 /*
1457 * if mapping failed free memory back to system since
1458 * there isn't much point in holding memory we can't use
1459 */
1460 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001461 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001462 bi->page = NULL;
1463
Alexander Duyckf990b792012-01-31 02:59:34 +00001464 rx_ring->rx_stats.alloc_rx_page_failed++;
1465 return false;
1466 }
1467
Alexander Duyckf8003262012-03-03 02:35:52 +00001468 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001469 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001470
Alexander Duyckf990b792012-01-31 02:59:34 +00001471 return true;
1472}
1473
Auke Kok9a799d72007-09-15 14:07:45 -07001474/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001475 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001476 * @rx_ring: ring to place buffers on
1477 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001478 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001479void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001480{
Auke Kok9a799d72007-09-15 14:07:45 -07001481 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001482 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001483 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001484
Alexander Duyckf8003262012-03-03 02:35:52 +00001485 /* nothing to do */
1486 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001487 return;
1488
Alexander Duycke4f74022012-01-31 02:59:44 +00001489 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001490 bi = &rx_ring->rx_buffer_info[i];
1491 i -= rx_ring->count;
1492
Alexander Duyckf8003262012-03-03 02:35:52 +00001493 do {
1494 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001495 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001496
Alexander Duyckf8003262012-03-03 02:35:52 +00001497 /*
1498 * Refresh the desc even if buffer_addrs didn't change
1499 * because each write-back erases this info.
1500 */
1501 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001502
Alexander Duyckf990b792012-01-31 02:59:34 +00001503 rx_desc++;
1504 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001505 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001506 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001507 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001508 bi = rx_ring->rx_buffer_info;
1509 i -= rx_ring->count;
1510 }
1511
1512 /* clear the hdr_addr for the next_to_use descriptor */
1513 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001514
1515 cleaned_count--;
1516 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001517
Alexander Duyckf990b792012-01-31 02:59:34 +00001518 i += rx_ring->count;
1519
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001520 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001521 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001522}
1523
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001524static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1525 struct sk_buff *skb)
1526{
Alexander Duyckf8003262012-03-03 02:35:52 +00001527 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001528
1529 /* set gso_size to avoid messing up TCP MSS */
1530 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1531 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001532 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001533}
1534
1535static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1536 struct sk_buff *skb)
1537{
1538 /* if append_cnt is 0 then frame is not RSC */
1539 if (!IXGBE_CB(skb)->append_cnt)
1540 return;
1541
1542 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1543 rx_ring->rx_stats.rsc_flush++;
1544
1545 ixgbe_set_rsc_gso_size(rx_ring, skb);
1546
1547 /* gso_size is computed using append_cnt so always clear it last */
1548 IXGBE_CB(skb)->append_cnt = 0;
1549}
1550
Alexander Duyck8a0da212012-01-31 02:59:49 +00001551/**
1552 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1553 * @rx_ring: rx descriptor ring packet is being transacted on
1554 * @rx_desc: pointer to the EOP Rx descriptor
1555 * @skb: pointer to current skb being populated
1556 *
1557 * This function checks the ring, descriptor, and packet information in
1558 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1559 * other fields within the skb.
1560 **/
1561static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1562 union ixgbe_adv_rx_desc *rx_desc,
1563 struct sk_buff *skb)
1564{
John Fastabend43e95f12012-05-15 06:12:17 +00001565 struct net_device *dev = rx_ring->netdev;
1566
Alexander Duyck8a0da212012-01-31 02:59:49 +00001567 ixgbe_update_rsc_stats(rx_ring, skb);
1568
1569 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1570
1571 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1572
Jakub Kicinskieda183c2014-04-02 10:33:28 +00001573 if (unlikely(ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_TS)))
1574 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector->adapter, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001575
Patrick McHardyf6469682013-04-19 02:04:27 +00001576 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001577 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001578 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001579 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001580 }
1581
1582 skb_record_rx_queue(skb, rx_ring->queue_index);
1583
John Fastabend43e95f12012-05-15 06:12:17 +00001584 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001585}
1586
1587static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1588 struct sk_buff *skb)
1589{
1590 struct ixgbe_adapter *adapter = q_vector->adapter;
1591
Jacob Kellerb4640032013-10-01 04:33:54 -07001592 if (ixgbe_qv_busy_polling(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001593 netif_receive_skb(skb);
1594 else if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
Alexander Duyck8a0da212012-01-31 02:59:49 +00001595 napi_gro_receive(&q_vector->napi, skb);
1596 else
1597 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001598}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001599
Alexander Duyckf8003262012-03-03 02:35:52 +00001600/**
1601 * ixgbe_is_non_eop - process handling of non-EOP buffers
1602 * @rx_ring: Rx ring being processed
1603 * @rx_desc: Rx descriptor for current buffer
1604 * @skb: Current socket buffer containing buffer in progress
1605 *
1606 * This function updates next to clean. If the buffer is an EOP buffer
1607 * this function exits returning false, otherwise it will place the
1608 * sk_buff in the next buffer to be chained and return true indicating
1609 * that this is in fact a non-EOP buffer.
1610 **/
1611static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1612 union ixgbe_adv_rx_desc *rx_desc,
1613 struct sk_buff *skb)
1614{
1615 u32 ntc = rx_ring->next_to_clean + 1;
1616
1617 /* fetch, update, and store next to clean */
1618 ntc = (ntc < rx_ring->count) ? ntc : 0;
1619 rx_ring->next_to_clean = ntc;
1620
1621 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1622
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001623 /* update RSC append count if present */
1624 if (ring_is_rsc_enabled(rx_ring)) {
1625 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1626 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1627
1628 if (unlikely(rsc_enabled)) {
1629 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1630
1631 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1632 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1633
1634 /* update ntc based on RSC value */
1635 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1636 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1637 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1638 }
1639 }
1640
1641 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001642 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1643 return false;
1644
Alexander Duyckf8003262012-03-03 02:35:52 +00001645 /* place skb in next buffer to be received */
1646 rx_ring->rx_buffer_info[ntc].skb = skb;
1647 rx_ring->rx_stats.non_eop_descs++;
1648
1649 return true;
1650}
1651
1652/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001653 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1654 * @rx_ring: rx descriptor ring packet is being transacted on
1655 * @skb: pointer to current skb being adjusted
1656 *
1657 * This function is an ixgbe specific version of __pskb_pull_tail. The
1658 * main difference between this version and the original function is that
1659 * this function can make several assumptions about the state of things
1660 * that allow for significant optimizations versus the standard function.
1661 * As a result we can do things like drop a frag and maintain an accurate
1662 * truesize for the skb.
1663 */
1664static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1665 struct sk_buff *skb)
1666{
1667 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1668 unsigned char *va;
1669 unsigned int pull_len;
1670
1671 /*
1672 * it is valid to use page_address instead of kmap since we are
1673 * working with pages allocated out of the lomem pool per
1674 * alloc_page(GFP_ATOMIC)
1675 */
1676 va = skb_frag_address(frag);
1677
1678 /*
1679 * we need the header to contain the greater of either ETH_HLEN or
1680 * 60 bytes if the skb->len is less than 60 for skb_pad.
1681 */
Alexander Duyck8496e3382014-09-05 19:22:18 -04001682 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001683
1684 /* align pull length to size of long to optimize memcpy performance */
1685 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1686
1687 /* update all of the pointers */
1688 skb_frag_size_sub(frag, pull_len);
1689 frag->page_offset += pull_len;
1690 skb->data_len -= pull_len;
1691 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001692}
1693
1694/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001695 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1696 * @rx_ring: rx descriptor ring packet is being transacted on
1697 * @skb: pointer to current skb being updated
1698 *
1699 * This function provides a basic DMA sync up for the first fragment of an
1700 * skb. The reason for doing this is that the first fragment cannot be
1701 * unmapped until we have reached the end of packet descriptor for a buffer
1702 * chain.
1703 */
1704static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1705 struct sk_buff *skb)
1706{
1707 /* if the page was released unmap it, else just sync our portion */
1708 if (unlikely(IXGBE_CB(skb)->page_released)) {
1709 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1710 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1711 IXGBE_CB(skb)->page_released = false;
1712 } else {
1713 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1714
1715 dma_sync_single_range_for_cpu(rx_ring->dev,
1716 IXGBE_CB(skb)->dma,
1717 frag->page_offset,
1718 ixgbe_rx_bufsz(rx_ring),
1719 DMA_FROM_DEVICE);
1720 }
1721 IXGBE_CB(skb)->dma = 0;
1722}
1723
1724/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001725 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1726 * @rx_ring: rx descriptor ring packet is being transacted on
1727 * @rx_desc: pointer to the EOP Rx descriptor
1728 * @skb: pointer to current skb being fixed
1729 *
1730 * Check for corrupted packet headers caused by senders on the local L2
1731 * embedded NIC switch not setting up their Tx Descriptors right. These
1732 * should be very rare.
1733 *
1734 * Also address the case where we are pulling data in on pages only
1735 * and as such no data is present in the skb header.
1736 *
1737 * In addition if skb is not at least 60 bytes we need to pad it so that
1738 * it is large enough to qualify as a valid Ethernet frame.
1739 *
1740 * Returns true if an error was encountered and skb was freed.
1741 **/
1742static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1743 union ixgbe_adv_rx_desc *rx_desc,
1744 struct sk_buff *skb)
1745{
Alexander Duyckf8003262012-03-03 02:35:52 +00001746 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001747
1748 /* verify that the packet does not have any known errors */
1749 if (unlikely(ixgbe_test_staterr(rx_desc,
1750 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1751 !(netdev->features & NETIF_F_RXALL))) {
1752 dev_kfree_skb_any(skb);
1753 return true;
1754 }
1755
Alexander Duyck19861ce2012-07-20 08:08:33 +00001756 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001757 if (skb_is_nonlinear(skb))
1758 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001759
Alexander Duyck57efd442012-06-25 21:54:46 +00001760#ifdef IXGBE_FCOE
1761 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1762 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1763 return false;
1764
1765#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001766 /* if skb_pad returns an error the skb was freed */
1767 if (unlikely(skb->len < 60)) {
1768 int pad_len = 60 - skb->len;
1769
1770 if (skb_pad(skb, pad_len))
1771 return true;
1772 __skb_put(skb, pad_len);
1773 }
1774
1775 return false;
1776}
1777
1778/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001779 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1780 * @rx_ring: rx descriptor ring to store buffers on
1781 * @old_buff: donor buffer to have page reused
1782 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001783 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001784 **/
1785static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1786 struct ixgbe_rx_buffer *old_buff)
1787{
1788 struct ixgbe_rx_buffer *new_buff;
1789 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001790
1791 new_buff = &rx_ring->rx_buffer_info[nta];
1792
1793 /* update, and store next to alloc */
1794 nta++;
1795 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1796
1797 /* transfer page from old buffer to new buffer */
1798 new_buff->page = old_buff->page;
1799 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001800 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001801
1802 /* sync the buffer for use by the device */
1803 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001804 new_buff->page_offset,
1805 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001806 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001807}
1808
1809/**
1810 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1811 * @rx_ring: rx descriptor ring to transact packets on
1812 * @rx_buffer: buffer containing page to add
1813 * @rx_desc: descriptor containing length of buffer written by hardware
1814 * @skb: sk_buff to place the data into
1815 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001816 * This function will add the data contained in rx_buffer->page to the skb.
1817 * This is done either through a direct copy if the data in the buffer is
1818 * less than the skb header size, otherwise it will just attach the page as
1819 * a frag to the skb.
1820 *
1821 * The function will then update the page offset if necessary and return
1822 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001823 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001824static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001825 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001826 union ixgbe_adv_rx_desc *rx_desc,
1827 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001828{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001829 struct page *page = rx_buffer->page;
1830 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001831#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001832 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001833#else
1834 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1835 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1836 ixgbe_rx_bufsz(rx_ring);
1837#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001838
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001839 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1840 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1841
1842 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1843
1844 /* we can reuse buffer as-is, just make sure it is local */
1845 if (likely(page_to_nid(page) == numa_node_id()))
1846 return true;
1847
1848 /* this page cannot be reused so discard it */
1849 put_page(page);
1850 return false;
1851 }
1852
Alexander Duyck0549ae22012-07-20 08:08:18 +00001853 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1854 rx_buffer->page_offset, size, truesize);
1855
Alexander Duyck09816fb2012-07-20 08:08:23 +00001856 /* avoid re-using remote pages */
1857 if (unlikely(page_to_nid(page) != numa_node_id()))
1858 return false;
1859
1860#if (PAGE_SIZE < 8192)
1861 /* if we are only owner of page we can reuse it */
1862 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001863 return false;
1864
1865 /* flip page offset to other buffer */
1866 rx_buffer->page_offset ^= truesize;
1867
Alexander Duyck09816fb2012-07-20 08:08:23 +00001868 /*
1869 * since we are the only owner of the page and we need to
1870 * increment it, just set the value to 2 in order to avoid
1871 * an unecessary locked operation
1872 */
1873 atomic_set(&page->_count, 2);
1874#else
1875 /* move offset up to the next cache line */
1876 rx_buffer->page_offset += truesize;
1877
1878 if (rx_buffer->page_offset > last_offset)
1879 return false;
1880
Alexander Duyck0549ae22012-07-20 08:08:18 +00001881 /* bump ref count on page before it is given to the stack */
1882 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001883#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001884
1885 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001886}
1887
Alexander Duyck18806c92012-07-20 08:08:44 +00001888static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1889 union ixgbe_adv_rx_desc *rx_desc)
1890{
1891 struct ixgbe_rx_buffer *rx_buffer;
1892 struct sk_buff *skb;
1893 struct page *page;
1894
1895 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1896 page = rx_buffer->page;
1897 prefetchw(page);
1898
1899 skb = rx_buffer->skb;
1900
1901 if (likely(!skb)) {
1902 void *page_addr = page_address(page) +
1903 rx_buffer->page_offset;
1904
1905 /* prefetch first cache line of first page */
1906 prefetch(page_addr);
1907#if L1_CACHE_BYTES < 128
1908 prefetch(page_addr + L1_CACHE_BYTES);
1909#endif
1910
1911 /* allocate a skb to store the frags */
1912 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1913 IXGBE_RX_HDR_SIZE);
1914 if (unlikely(!skb)) {
1915 rx_ring->rx_stats.alloc_rx_buff_failed++;
1916 return NULL;
1917 }
1918
1919 /*
1920 * we will be copying header into skb->data in
1921 * pskb_may_pull so it is in our interest to prefetch
1922 * it now to avoid a possible cache miss
1923 */
1924 prefetchw(skb->data);
1925
1926 /*
1927 * Delay unmapping of the first packet. It carries the
1928 * header information, HW may still access the header
1929 * after the writeback. Only unmap it when EOP is
1930 * reached
1931 */
1932 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1933 goto dma_sync;
1934
1935 IXGBE_CB(skb)->dma = rx_buffer->dma;
1936 } else {
1937 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1938 ixgbe_dma_sync_frag(rx_ring, skb);
1939
1940dma_sync:
1941 /* we are reusing so sync this buffer for CPU use */
1942 dma_sync_single_range_for_cpu(rx_ring->dev,
1943 rx_buffer->dma,
1944 rx_buffer->page_offset,
1945 ixgbe_rx_bufsz(rx_ring),
1946 DMA_FROM_DEVICE);
1947 }
1948
1949 /* pull page into skb */
1950 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1951 /* hand second half of page back to the ring */
1952 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1953 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1954 /* the page has been released from the ring */
1955 IXGBE_CB(skb)->page_released = true;
1956 } else {
1957 /* we are not reusing the buffer so unmap it */
1958 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1959 ixgbe_rx_pg_size(rx_ring),
1960 DMA_FROM_DEVICE);
1961 }
1962
1963 /* clear contents of buffer_info */
1964 rx_buffer->skb = NULL;
1965 rx_buffer->dma = 0;
1966 rx_buffer->page = NULL;
1967
1968 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001969}
1970
1971/**
1972 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1973 * @q_vector: structure containing interrupt and ring information
1974 * @rx_ring: rx descriptor ring to transact packets on
1975 * @budget: Total limit on number of packets to process
1976 *
1977 * This function provides a "bounce buffer" approach to Rx interrupt
1978 * processing. The advantage to this is that on systems that have
1979 * expensive overhead for IOMMU access this provides a means of avoiding
1980 * it by maintaining the mapping of the page to the syste.
1981 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001982 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00001983 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001984static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001985 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001986 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001987{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001988 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001989#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001990 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00001991 int ddp_bytes;
1992 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00001993#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001994 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001995
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07001996 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001997 union ixgbe_adv_rx_desc *rx_desc;
1998 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001999
Alexander Duyckf8003262012-03-03 02:35:52 +00002000 /* return some buffers to hardware, one at a time is too slow */
2001 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2002 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2003 cleaned_count = 0;
2004 }
Auke Kok9a799d72007-09-15 14:07:45 -07002005
Alexander Duyck18806c92012-07-20 08:08:44 +00002006 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07002007
Alexander Duyckf8003262012-03-03 02:35:52 +00002008 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
2009 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002010
Alexander Duyckf8003262012-03-03 02:35:52 +00002011 /*
2012 * This memory barrier is needed to keep us from reading
2013 * any other fields out of the rx_desc until we know the
2014 * RXD_STAT_DD bit is set
2015 */
2016 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002017
Alexander Duyck18806c92012-07-20 08:08:44 +00002018 /* retrieve a buffer from the ring */
2019 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00002020
Alexander Duyck18806c92012-07-20 08:08:44 +00002021 /* exit if we failed to retrieve a buffer */
2022 if (!skb)
2023 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002024
Auke Kok9a799d72007-09-15 14:07:45 -07002025 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002026
Alexander Duyckf8003262012-03-03 02:35:52 +00002027 /* place incomplete frames back on ring for completion */
2028 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2029 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002030
Alexander Duyckf8003262012-03-03 02:35:52 +00002031 /* verify the packet layout is correct */
2032 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2033 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002034
2035 /* probably a little skewed due to removing CRC */
2036 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002037
Alexander Duyck8a0da212012-01-31 02:59:49 +00002038 /* populate checksum, timestamp, VLAN, and protocol */
2039 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2040
Yi Zou332d4a72009-05-13 13:11:53 +00002041#ifdef IXGBE_FCOE
2042 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002043 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002044 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002045 /* include DDPed FCoE data */
2046 if (ddp_bytes > 0) {
2047 if (!mss) {
2048 mss = rx_ring->netdev->mtu -
2049 sizeof(struct fcoe_hdr) -
2050 sizeof(struct fc_frame_header) -
2051 sizeof(struct fcoe_crc_eof);
2052 if (mss > 512)
2053 mss &= ~511;
2054 }
2055 total_rx_bytes += ddp_bytes;
2056 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2057 mss);
2058 }
David S. Miller823dcd22011-08-20 10:39:12 -07002059 if (!ddp_bytes) {
2060 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002061 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002062 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002063 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002064
Yi Zou332d4a72009-05-13 13:11:53 +00002065#endif /* IXGBE_FCOE */
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03002066 skb_mark_napi_id(skb, &q_vector->napi);
Alexander Duyck8a0da212012-01-31 02:59:49 +00002067 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002068
Alexander Duyckf8003262012-03-03 02:35:52 +00002069 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002070 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002071 }
Auke Kok9a799d72007-09-15 14:07:45 -07002072
Alexander Duyckc267fc12010-11-16 19:27:00 -08002073 u64_stats_update_begin(&rx_ring->syncp);
2074 rx_ring->stats.packets += total_rx_packets;
2075 rx_ring->stats.bytes += total_rx_bytes;
2076 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002077 q_vector->rx.total_packets += total_rx_packets;
2078 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002079
Alexander Duyckf8003262012-03-03 02:35:52 +00002080 if (cleaned_count)
2081 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2082
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002083 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002084}
2085
Cong Wange0d10952013-08-01 11:10:25 +08002086#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002087/* must be called with local_bh_disable()d */
2088static int ixgbe_low_latency_recv(struct napi_struct *napi)
2089{
2090 struct ixgbe_q_vector *q_vector =
2091 container_of(napi, struct ixgbe_q_vector, napi);
2092 struct ixgbe_adapter *adapter = q_vector->adapter;
2093 struct ixgbe_ring *ring;
2094 int found = 0;
2095
2096 if (test_bit(__IXGBE_DOWN, &adapter->state))
2097 return LL_FLUSH_FAILED;
2098
2099 if (!ixgbe_qv_lock_poll(q_vector))
2100 return LL_FLUSH_BUSY;
2101
2102 ixgbe_for_each_ring(ring, q_vector->rx) {
2103 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
Jacob Kellerb4640032013-10-01 04:33:54 -07002104#ifdef BP_EXTENDED_STATS
Eliezer Tamir7e15b902013-06-10 11:40:31 +03002105 if (found)
2106 ring->stats.cleaned += found;
2107 else
2108 ring->stats.misses++;
2109#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002110 if (found)
2111 break;
2112 }
2113
2114 ixgbe_qv_unlock_poll(q_vector);
2115
2116 return found;
2117}
Cong Wange0d10952013-08-01 11:10:25 +08002118#endif /* CONFIG_NET_RX_BUSY_POLL */
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002119
Auke Kok9a799d72007-09-15 14:07:45 -07002120/**
2121 * ixgbe_configure_msix - Configure MSI-X hardware
2122 * @adapter: board private structure
2123 *
2124 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2125 * interrupts.
2126 **/
2127static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2128{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002129 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002130 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002131 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002132
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002133 /* Populate MSIX to EITR Select */
2134 if (adapter->num_vfs > 32) {
2135 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2136 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2137 }
2138
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002139 /*
2140 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002141 * corresponding register.
2142 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002143 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002144 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002145 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002146
Alexander Duycka5579282012-02-08 07:50:04 +00002147 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002148 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002149
Alexander Duycka5579282012-02-08 07:50:04 +00002150 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002151 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002152
Alexander Duyckfe49f042009-06-04 16:00:09 +00002153 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002154 }
2155
Alexander Duyckbd508172010-11-16 19:27:03 -08002156 switch (adapter->hw.mac.type) {
2157 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002158 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002159 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002160 break;
2161 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002162 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002163 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002164 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002165 default:
2166 break;
2167 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002168 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002169
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002170 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002171 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002172 mask &= ~(IXGBE_EIMS_OTHER |
2173 IXGBE_EIMS_MAILBOX |
2174 IXGBE_EIMS_LSC);
2175
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002176 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002177}
2178
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002179enum latency_range {
2180 lowest_latency = 0,
2181 low_latency = 1,
2182 bulk_latency = 2,
2183 latency_invalid = 255
2184};
2185
2186/**
2187 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002188 * @q_vector: structure containing interrupt and ring information
2189 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002190 *
2191 * Stores a new ITR value based on packets and byte
2192 * counts during the last interrupt. The advantage of per interrupt
2193 * computation is faster updates and more accurate ITR for the current
2194 * traffic pattern. Constants in this function were computed
2195 * based on theoretical maximum wire speed and thresholds were set based
2196 * on testing data as well as attempting to minimize response time
2197 * while increasing bulk throughput.
2198 * this functionality is controlled by the InterruptThrottleRate module
2199 * parameter (see ixgbe_param.c)
2200 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002201static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2202 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002203{
Alexander Duyckbd198052011-06-11 01:45:08 +00002204 int bytes = ring_container->total_bytes;
2205 int packets = ring_container->total_packets;
2206 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002207 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002208 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002209
2210 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002211 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002212
2213 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002214 * 0-10MB/s lowest (100000 ints/s)
2215 * 10-20MB/s low (20000 ints/s)
2216 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002217 */
2218 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002219 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002220 if (timepassed_us == 0)
2221 return;
2222
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002223 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2224
2225 switch (itr_setting) {
2226 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002227 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002228 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002229 break;
2230 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002231 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002232 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002233 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002234 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002235 break;
2236 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002237 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002238 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002239 break;
2240 }
2241
Alexander Duyckbd198052011-06-11 01:45:08 +00002242 /* clear work counters since we have the values we need */
2243 ring_container->total_bytes = 0;
2244 ring_container->total_packets = 0;
2245
2246 /* write updated itr to ring container */
2247 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002248}
2249
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002250/**
2251 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002252 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002253 *
2254 * This function is made to be called by ethtool and by the driver
2255 * when it needs to update EITR registers at runtime. Hardware
2256 * specific quirks/differences are taken care of here.
2257 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002258void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002259{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002260 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002261 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002262 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002263 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002264
Alexander Duyckbd508172010-11-16 19:27:03 -08002265 switch (adapter->hw.mac.type) {
2266 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002267 /* must write high and low 16 bits to reset counter */
2268 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002269 break;
2270 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002271 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002272 /*
2273 * set the WDIS bit to not clear the timer bits and cause an
2274 * immediate assertion of the interrupt
2275 */
2276 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002277 break;
2278 default:
2279 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002280 }
2281 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2282}
2283
Alexander Duyckbd198052011-06-11 01:45:08 +00002284static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002285{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002286 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002287 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002288
Alexander Duyckbd198052011-06-11 01:45:08 +00002289 ixgbe_update_itr(q_vector, &q_vector->tx);
2290 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002291
Alexander Duyck08c88332011-06-11 01:45:03 +00002292 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002293
2294 switch (current_itr) {
2295 /* counts and packets in update_itr are dependent on these numbers */
2296 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002297 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002298 break;
2299 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002300 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002301 break;
2302 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002303 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002304 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002305 default:
2306 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002307 }
2308
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002309 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002310 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002311 new_itr = (10 * new_itr * q_vector->itr) /
2312 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002313
Alexander Duyckbd198052011-06-11 01:45:08 +00002314 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002315 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002316
2317 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002318 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002319}
2320
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002321/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002322 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002323 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002324 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002325static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002326{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002327 struct ixgbe_hw *hw = &adapter->hw;
2328 u32 eicr = adapter->interrupt_event;
2329
Alexander Duyckf0f97782011-04-22 04:08:09 +00002330 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002331 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002332
Alexander Duyckf0f97782011-04-22 04:08:09 +00002333 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2334 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2335 return;
2336
2337 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2338
Joe Perches7ca647b2010-09-07 21:35:40 +00002339 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002340 case IXGBE_DEV_ID_82599_T3_LOM:
2341 /*
2342 * Since the warning interrupt is for both ports
2343 * we don't have to check if:
2344 * - This interrupt wasn't for our port.
2345 * - We may have missed the interrupt so always have to
2346 * check if we got a LSC
2347 */
2348 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2349 !(eicr & IXGBE_EICR_LSC))
2350 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002351
Alexander Duyckf0f97782011-04-22 04:08:09 +00002352 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002353 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002354 bool link_up = false;
2355
Josh Hay3d292262012-12-15 03:28:19 +00002356 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002357
Alexander Duyckf0f97782011-04-22 04:08:09 +00002358 if (link_up)
2359 return;
2360 }
2361
2362 /* Check if this is not due to overtemp */
2363 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2364 return;
2365
2366 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002367 default:
2368 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2369 return;
2370 break;
2371 }
2372 e_crit(drv,
2373 "Network adapter has been stopped because it has over heated. "
2374 "Restart the computer. If the problem persists, "
2375 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002376
2377 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002378}
2379
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002380static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2381{
2382 struct ixgbe_hw *hw = &adapter->hw;
2383
2384 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2385 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002386 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002387 /* write to clear the interrupt */
2388 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2389 }
2390}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002391
Jacob Keller4f51bf72011-08-20 04:49:45 +00002392static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2393{
2394 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2395 return;
2396
2397 switch (adapter->hw.mac.type) {
2398 case ixgbe_mac_82599EB:
2399 /*
2400 * Need to check link state so complete overtemp check
2401 * on service task
2402 */
2403 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2404 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2405 adapter->interrupt_event = eicr;
2406 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2407 ixgbe_service_event_schedule(adapter);
2408 return;
2409 }
2410 return;
2411 case ixgbe_mac_X540:
2412 if (!(eicr & IXGBE_EICR_TS))
2413 return;
2414 break;
2415 default:
2416 return;
2417 }
2418
2419 e_crit(drv,
2420 "Network adapter has been stopped because it has over heated. "
2421 "Restart the computer. If the problem persists, "
2422 "power off the system and replace the adapter\n");
2423}
2424
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002425static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2426{
2427 struct ixgbe_hw *hw = &adapter->hw;
2428
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002429 if (eicr & IXGBE_EICR_GPI_SDP2) {
2430 /* Clear the interrupt */
2431 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002432 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2433 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2434 ixgbe_service_event_schedule(adapter);
2435 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002436 }
2437
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002438 if (eicr & IXGBE_EICR_GPI_SDP1) {
2439 /* Clear the interrupt */
2440 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002441 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2442 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2443 ixgbe_service_event_schedule(adapter);
2444 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002445 }
2446}
2447
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002448static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2449{
2450 struct ixgbe_hw *hw = &adapter->hw;
2451
2452 adapter->lsc_int++;
2453 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2454 adapter->link_check_timeout = jiffies;
2455 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2456 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002457 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002458 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002459 }
2460}
2461
Alexander Duyckfe49f042009-06-04 16:00:09 +00002462static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2463 u64 qmask)
2464{
2465 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002466 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002467
Alexander Duyckbd508172010-11-16 19:27:03 -08002468 switch (hw->mac.type) {
2469 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002470 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002471 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2472 break;
2473 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002474 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002475 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002476 if (mask)
2477 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002478 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002479 if (mask)
2480 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2481 break;
2482 default:
2483 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002484 }
2485 /* skip the flush */
2486}
2487
2488static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002489 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002490{
2491 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002492 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002493
Alexander Duyckbd508172010-11-16 19:27:03 -08002494 switch (hw->mac.type) {
2495 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002496 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002497 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2498 break;
2499 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002500 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002501 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002502 if (mask)
2503 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002504 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002505 if (mask)
2506 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2507 break;
2508 default:
2509 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002510 }
2511 /* skip the flush */
2512}
2513
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002514/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002515 * ixgbe_irq_enable - Enable default interrupt generation settings
2516 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002517 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002518static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2519 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002520{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002521 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002522
Alexander Duyck2c4af692011-07-15 07:29:55 +00002523 /* don't reenable LSC while waiting for link */
2524 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2525 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002526
Alexander Duyck2c4af692011-07-15 07:29:55 +00002527 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002528 switch (adapter->hw.mac.type) {
2529 case ixgbe_mac_82599EB:
2530 mask |= IXGBE_EIMS_GPI_SDP0;
2531 break;
2532 case ixgbe_mac_X540:
2533 mask |= IXGBE_EIMS_TS;
2534 break;
2535 default:
2536 break;
2537 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002538 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2539 mask |= IXGBE_EIMS_GPI_SDP1;
2540 switch (adapter->hw.mac.type) {
2541 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002542 mask |= IXGBE_EIMS_GPI_SDP1;
2543 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002544 case ixgbe_mac_X540:
2545 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002546 mask |= IXGBE_EIMS_MAILBOX;
2547 break;
2548 default:
2549 break;
2550 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002551
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002552 if (adapter->hw.mac.type == ixgbe_mac_X540)
2553 mask |= IXGBE_EIMS_TIMESYNC;
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002554
Alexander Duyck2c4af692011-07-15 07:29:55 +00002555 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2556 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2557 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002558
Alexander Duyck2c4af692011-07-15 07:29:55 +00002559 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2560 if (queues)
2561 ixgbe_irq_enable_queues(adapter, ~0);
2562 if (flush)
2563 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002564}
2565
Alexander Duyck2c4af692011-07-15 07:29:55 +00002566static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002567{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002568 struct ixgbe_adapter *adapter = data;
2569 struct ixgbe_hw *hw = &adapter->hw;
2570 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002571
Alexander Duyck2c4af692011-07-15 07:29:55 +00002572 /*
2573 * Workaround for Silicon errata. Use clear-by-write instead
2574 * of clear-by-read. Reading with EICS will return the
2575 * interrupt causes without clearing, which later be done
2576 * with the write to EICR.
2577 */
2578 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002579
2580 /* The lower 16bits of the EICR register are for the queue interrupts
2581 * which should be masked here in order to not accidently clear them if
2582 * the bits are high when ixgbe_msix_other is called. There is a race
2583 * condition otherwise which results in possible performance loss
2584 * especially if the ixgbe_msix_other interrupt is triggering
2585 * consistently (as it would when PPS is turned on for the X540 device)
2586 */
2587 eicr &= 0xFFFF0000;
2588
Alexander Duyck2c4af692011-07-15 07:29:55 +00002589 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002590
Alexander Duyck2c4af692011-07-15 07:29:55 +00002591 if (eicr & IXGBE_EICR_LSC)
2592 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002593
Alexander Duyck2c4af692011-07-15 07:29:55 +00002594 if (eicr & IXGBE_EICR_MAILBOX)
2595 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002596
Alexander Duyck2c4af692011-07-15 07:29:55 +00002597 switch (hw->mac.type) {
2598 case ixgbe_mac_82599EB:
2599 case ixgbe_mac_X540:
Don Skidmored773ce22014-02-25 17:58:53 -08002600 if (eicr & IXGBE_EICR_ECC) {
2601 e_info(link, "Received ECC Err, initiating reset\n");
2602 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2603 ixgbe_service_event_schedule(adapter);
2604 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2605 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002606 /* Handle Flow Director Full threshold interrupt */
2607 if (eicr & IXGBE_EICR_FLOW_DIR) {
2608 int reinit_count = 0;
2609 int i;
2610 for (i = 0; i < adapter->num_tx_queues; i++) {
2611 struct ixgbe_ring *ring = adapter->tx_ring[i];
2612 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2613 &ring->state))
2614 reinit_count++;
2615 }
2616 if (reinit_count) {
2617 /* no more flow director interrupts until after init */
2618 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2619 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2620 ixgbe_service_event_schedule(adapter);
2621 }
2622 }
2623 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002624 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002625 break;
2626 default:
2627 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002628 }
2629
Alexander Duyck2c4af692011-07-15 07:29:55 +00002630 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002631
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002632 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2633 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002634
Alexander Duyck2c4af692011-07-15 07:29:55 +00002635 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002636 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002637 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002638
Alexander Duyck2c4af692011-07-15 07:29:55 +00002639 return IRQ_HANDLED;
2640}
2641
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002642static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002643{
2644 struct ixgbe_q_vector *q_vector = data;
2645
Auke Kok9a799d72007-09-15 14:07:45 -07002646 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002647
2648 if (q_vector->rx.ring || q_vector->tx.ring)
2649 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002650
2651 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002652}
2653
Auke Kok9a799d72007-09-15 14:07:45 -07002654/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002655 * ixgbe_poll - NAPI Rx polling callback
2656 * @napi: structure for representing this polling device
2657 * @budget: how many packets driver is allowed to clean
2658 *
2659 * This function is used for legacy and MSI, NAPI mode
2660 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002661int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002662{
2663 struct ixgbe_q_vector *q_vector =
2664 container_of(napi, struct ixgbe_q_vector, napi);
2665 struct ixgbe_adapter *adapter = q_vector->adapter;
2666 struct ixgbe_ring *ring;
2667 int per_ring_budget;
2668 bool clean_complete = true;
2669
2670#ifdef CONFIG_IXGBE_DCA
2671 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2672 ixgbe_update_dca(q_vector);
2673#endif
2674
2675 ixgbe_for_each_ring(ring, q_vector->tx)
2676 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2677
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002678 if (!ixgbe_qv_lock_napi(q_vector))
2679 return budget;
2680
Alexander Duyckeb01b972012-02-08 07:51:27 +00002681 /* attempt to distribute budget to each queue fairly, but don't allow
2682 * the budget to go below 1 because we'll exit polling */
2683 if (q_vector->rx.count > 1)
2684 per_ring_budget = max(budget/q_vector->rx.count, 1);
2685 else
2686 per_ring_budget = budget;
2687
2688 ixgbe_for_each_ring(ring, q_vector->rx)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002689 clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring,
2690 per_ring_budget) < per_ring_budget);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002691
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002692 ixgbe_qv_unlock_napi(q_vector);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002693 /* If all work not completed, return budget and keep polling */
2694 if (!clean_complete)
2695 return budget;
2696
2697 /* all work done, exit the polling mode */
2698 napi_complete(napi);
2699 if (adapter->rx_itr_setting & 1)
2700 ixgbe_set_itr(q_vector);
2701 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2702 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2703
2704 return 0;
2705}
2706
2707/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002708 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2709 * @adapter: board private structure
2710 *
2711 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2712 * interrupts from the kernel.
2713 **/
2714static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2715{
2716 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002717 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002718 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002719
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002720 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002721 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002722 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002723
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002724 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002725 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002726 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002727 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002728 } else if (q_vector->rx.ring) {
2729 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2730 "%s-%s-%d", netdev->name, "rx", ri++);
2731 } else if (q_vector->tx.ring) {
2732 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2733 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002734 } else {
2735 /* skip this unused q_vector */
2736 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002737 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002738 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2739 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002740 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002741 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002742 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002743 goto free_queue_irqs;
2744 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002745 /* If Flow Director is enabled, set interrupt affinity */
2746 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2747 /* assign the mask for this irq */
2748 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002749 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002750 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002751 }
2752
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002753 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002754 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002755 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002756 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002757 goto free_queue_irqs;
2758 }
2759
2760 return 0;
2761
2762free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002763 while (vector) {
2764 vector--;
2765 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2766 NULL);
2767 free_irq(adapter->msix_entries[vector].vector,
2768 adapter->q_vector[vector]);
2769 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002770 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2771 pci_disable_msix(adapter->pdev);
2772 kfree(adapter->msix_entries);
2773 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002774 return err;
2775}
2776
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002777/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002778 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002779 * @irq: interrupt number
2780 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002781 **/
2782static irqreturn_t ixgbe_intr(int irq, void *data)
2783{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002784 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002785 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002786 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002787 u32 eicr;
2788
Don Skidmore54037502009-02-21 15:42:56 -08002789 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002790 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002791 * before the read of EICR.
2792 */
2793 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2794
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002795 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002796 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002797 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002798 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002799 /*
2800 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002801 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002802 * have disabled interrupts due to EIAM
2803 * finish the workaround of silicon errata on 82598. Unmask
2804 * the interrupt that we masked before the EICR read.
2805 */
2806 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2807 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002808 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002809 }
Auke Kok9a799d72007-09-15 14:07:45 -07002810
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002811 if (eicr & IXGBE_EICR_LSC)
2812 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002813
Alexander Duyckbd508172010-11-16 19:27:03 -08002814 switch (hw->mac.type) {
2815 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002816 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002817 /* Fall through */
2818 case ixgbe_mac_X540:
Don Skidmored773ce22014-02-25 17:58:53 -08002819 if (eicr & IXGBE_EICR_ECC) {
2820 e_info(link, "Received ECC Err, initiating reset\n");
2821 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2822 ixgbe_service_event_schedule(adapter);
2823 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2824 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00002825 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002826 break;
2827 default:
2828 break;
2829 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002830
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002831 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002832 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2833 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002834
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002835 /* would disable interrupts here but EIAM disabled it */
2836 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002837
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002838 /*
2839 * re-enable link(maybe) and non-queue interrupts, no flush.
2840 * ixgbe_poll will re-enable the queue interrupts
2841 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002842 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2843 ixgbe_irq_enable(adapter, false, false);
2844
Auke Kok9a799d72007-09-15 14:07:45 -07002845 return IRQ_HANDLED;
2846}
2847
2848/**
2849 * ixgbe_request_irq - initialize interrupts
2850 * @adapter: board private structure
2851 *
2852 * Attempts to configure interrupts using the best available
2853 * capabilities of the hardware and kernel.
2854 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002855static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002856{
2857 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002858 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002859
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002860 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002861 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002862 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002863 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002864 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002865 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002866 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002867 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002868
Alexander Duyckde88eee2012-02-08 07:49:59 +00002869 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002870 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002871
Auke Kok9a799d72007-09-15 14:07:45 -07002872 return err;
2873}
2874
2875static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2876{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002877 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002878
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002879 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002880 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002881 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002882 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002883
2884 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2885 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2886 struct msix_entry *entry = &adapter->msix_entries[vector];
2887
2888 /* free only the irqs that were actually requested */
2889 if (!q_vector->rx.ring && !q_vector->tx.ring)
2890 continue;
2891
2892 /* clear the affinity_mask in the IRQ descriptor */
2893 irq_set_affinity_hint(entry->vector, NULL);
2894
2895 free_irq(entry->vector, q_vector);
2896 }
2897
2898 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002899}
2900
2901/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002902 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2903 * @adapter: board private structure
2904 **/
2905static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2906{
Alexander Duyckbd508172010-11-16 19:27:03 -08002907 switch (adapter->hw.mac.type) {
2908 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002909 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002910 break;
2911 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002912 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002913 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2914 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002915 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002916 break;
2917 default:
2918 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002919 }
2920 IXGBE_WRITE_FLUSH(&adapter->hw);
2921 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002922 int vector;
2923
2924 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2925 synchronize_irq(adapter->msix_entries[vector].vector);
2926
2927 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002928 } else {
2929 synchronize_irq(adapter->pdev->irq);
2930 }
2931}
2932
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002933/**
Auke Kok9a799d72007-09-15 14:07:45 -07002934 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2935 *
2936 **/
2937static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2938{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002939 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002940
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002941 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002942
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002943 ixgbe_set_ivar(adapter, 0, 0, 0);
2944 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002945
Emil Tantilov396e7992010-07-01 20:05:12 +00002946 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002947}
2948
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002949/**
2950 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2951 * @adapter: board private structure
2952 * @ring: structure containing ring specific data
2953 *
2954 * Configure the Tx descriptor ring after a reset.
2955 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002956void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2957 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002958{
2959 struct ixgbe_hw *hw = &adapter->hw;
2960 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002961 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002962 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002963 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002964
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002965 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002966 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002967 IXGBE_WRITE_FLUSH(hw);
2968
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002969 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002970 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002971 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2972 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2973 ring->count * sizeof(union ixgbe_adv_tx_desc));
2974 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2975 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08002976 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002977
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002978 /*
2979 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00002980 * higher than 1 when:
2981 * - ITR is 0 as it could cause false TX hangs
2982 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002983 *
2984 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2985 * to or less than the number of on chip descriptors, which is
2986 * currently 40.
2987 */
Emil Tantilov67da0972013-01-25 06:19:20 +00002988#if IS_ENABLED(CONFIG_BQL)
2989 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
2990#else
Alexander Duycke954b372012-02-08 07:49:38 +00002991 if (!ring->q_vector || (ring->q_vector->itr < 8))
Emil Tantilov67da0972013-01-25 06:19:20 +00002992#endif
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002993 txdctl |= (1 << 16); /* WTHRESH = 1 */
2994 else
2995 txdctl |= (8 << 16); /* WTHRESH = 8 */
2996
Alexander Duycke954b372012-02-08 07:49:38 +00002997 /*
2998 * Setting PTHRESH to 32 both improves performance
2999 * and avoids a TX hang with DFP enabled
3000 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003001 txdctl |= (1 << 8) | /* HTHRESH = 1 */
3002 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003003
3004 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003005 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003006 ring->atr_sample_rate = adapter->atr_sample_rate;
3007 ring->atr_count = 0;
3008 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3009 } else {
3010 ring->atr_sample_rate = 0;
3011 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003012
Alexander Duyckfd786b72013-01-12 06:33:31 +00003013 /* initialize XPS */
3014 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3015 struct ixgbe_q_vector *q_vector = ring->q_vector;
3016
3017 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003018 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003019 &q_vector->affinity_mask,
3020 ring->queue_index);
3021 }
3022
John Fastabendc84d3242010-11-16 19:27:12 -08003023 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3024
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003025 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003026 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3027
3028 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3029 if (hw->mac.type == ixgbe_mac_82598EB &&
3030 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3031 return;
3032
3033 /* poll to verify queue is enabled */
3034 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003035 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003036 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3037 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3038 if (!wait_loop)
3039 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003040}
3041
Alexander Duyck120ff942010-08-19 13:34:50 +00003042static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3043{
3044 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003045 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003046 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003047
3048 if (hw->mac.type == ixgbe_mac_82598EB)
3049 return;
3050
3051 /* disable the arbiter while setting MTQC */
3052 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3053 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3054 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3055
3056 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003057 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3058 mtqc = IXGBE_MTQC_VT_ENA;
3059 if (tcs > 4)
3060 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3061 else if (tcs > 1)
3062 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3063 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3064 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003065 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003066 mtqc |= IXGBE_MTQC_64VF;
3067 } else {
3068 if (tcs > 4)
3069 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3070 else if (tcs > 1)
3071 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3072 else
3073 mtqc = IXGBE_MTQC_64Q_1PB;
3074 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003075
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003076 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003077
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003078 /* Enable Security TX Buffer IFG for multiple pb */
3079 if (tcs) {
3080 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3081 sectx |= IXGBE_SECTX_DCB;
3082 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003083 }
3084
3085 /* re-enable the arbiter */
3086 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3087 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3088}
3089
Auke Kok9a799d72007-09-15 14:07:45 -07003090/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003091 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003092 * @adapter: board private structure
3093 *
3094 * Configure the Tx unit of the MAC after a reset.
3095 **/
3096static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3097{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003098 struct ixgbe_hw *hw = &adapter->hw;
3099 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003100 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003101
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003102 ixgbe_setup_mtqc(adapter);
3103
3104 if (hw->mac.type != ixgbe_mac_82598EB) {
3105 /* DMATXCTL.EN must be before Tx queues are enabled */
3106 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3107 dmatxctl |= IXGBE_DMATXCTL_TE;
3108 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3109 }
3110
Auke Kok9a799d72007-09-15 14:07:45 -07003111 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003112 for (i = 0; i < adapter->num_tx_queues; i++)
3113 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003114}
3115
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003116static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3117 struct ixgbe_ring *ring)
3118{
3119 struct ixgbe_hw *hw = &adapter->hw;
3120 u8 reg_idx = ring->reg_idx;
3121 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3122
3123 srrctl |= IXGBE_SRRCTL_DROP_EN;
3124
3125 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3126}
3127
3128static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3129 struct ixgbe_ring *ring)
3130{
3131 struct ixgbe_hw *hw = &adapter->hw;
3132 u8 reg_idx = ring->reg_idx;
3133 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3134
3135 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3136
3137 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3138}
3139
3140#ifdef CONFIG_IXGBE_DCB
3141void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3142#else
3143static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3144#endif
3145{
3146 int i;
3147 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3148
3149 if (adapter->ixgbe_ieee_pfc)
3150 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3151
3152 /*
3153 * We should set the drop enable bit if:
3154 * SR-IOV is enabled
3155 * or
3156 * Number of Rx queues > 1 and flow control is disabled
3157 *
3158 * This allows us to avoid head of line blocking for security
3159 * and performance reasons.
3160 */
3161 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3162 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3163 for (i = 0; i < adapter->num_rx_queues; i++)
3164 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3165 } else {
3166 for (i = 0; i < adapter->num_rx_queues; i++)
3167 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3168 }
3169}
3170
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003171#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003172
Yi Zoua6616b42009-08-06 13:05:23 +00003173static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003174 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003175{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003176 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003177 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003178 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003179
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003180 if (hw->mac.type == ixgbe_mac_82598EB) {
3181 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3182
3183 /*
3184 * if VMDq is not active we must program one srrctl register
3185 * per RSS queue since we have enabled RDRXCTL.MVMEN
3186 */
3187 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003188 }
3189
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003190 /* configure header buffer length, needed for RSC */
3191 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003192
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003193 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00003194 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003195
3196 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003197 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003198
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003199 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003200}
3201
Alexander Duyck05abb122010-08-19 13:35:41 +00003202static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003203{
Alexander Duyck05abb122010-08-19 13:35:41 +00003204 struct ixgbe_hw *hw = &adapter->hw;
3205 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00003206 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
3207 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00003208 u32 mrqc = 0, reta = 0;
3209 u32 rxcsum;
3210 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003211 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00003212
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003213 /*
3214 * Program table for at least 2 queues w/ SR-IOV so that VFs can
3215 * make full use of any rings they may have. We will use the
3216 * PSRTYPE register to control how many rings we use within the PF.
3217 */
3218 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3219 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003220
Alexander Duyck05abb122010-08-19 13:35:41 +00003221 /* Fill out hash function seeds */
3222 for (i = 0; i < 10; i++)
3223 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003224
Alexander Duyck05abb122010-08-19 13:35:41 +00003225 /* Fill out redirection table */
3226 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003227 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003228 j = 0;
3229 /* reta = 4-byte sliding window of
3230 * 0x00..(indices-1)(indices-1)00..etc. */
3231 reta = (reta << 8) | (j * 0x11);
3232 if ((i & 3) == 3)
3233 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3234 }
3235
3236 /* Disable indicating checksum in descriptor, enables RSS hash */
3237 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3238 rxcsum |= IXGBE_RXCSUM_PCSD;
3239 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3240
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003241 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003242 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003243 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003244 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003245 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003246
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003247 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3248 if (tcs > 4)
3249 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3250 else if (tcs > 1)
3251 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3252 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3253 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3254 else
3255 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3256 } else {
3257 if (tcs > 4)
3258 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3259 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003260 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3261 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003262 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003263 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003264 }
3265
Alexander Duyck05abb122010-08-19 13:35:41 +00003266 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003267 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3268 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3269 IXGBE_MRQC_RSS_FIELD_IPV6 |
3270 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003271
Alexander Duyckef6afc02012-02-08 07:51:53 +00003272 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3273 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3274 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3275 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3276
Alexander Duyck05abb122010-08-19 13:35:41 +00003277 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003278}
3279
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003280/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003281 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3282 * @adapter: address of board private structure
3283 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003284 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003285static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003286 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003287{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003288 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003289 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003290 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003291
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003292 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003293 return;
3294
Alexander Duyck73670962010-08-19 13:38:34 +00003295 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003296 rscctrl |= IXGBE_RSCCTL_RSCEN;
3297 /*
3298 * we must limit the number of descriptors so that the
3299 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003300 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003301 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003302 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003303 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003304}
3305
Alexander Duyck9e10e042010-08-19 13:40:06 +00003306#define IXGBE_MAX_RX_DESC_POLL 10
3307static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3308 struct ixgbe_ring *ring)
3309{
3310 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003311 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3312 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003313 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003314
Mark Rustadb0483c82014-01-14 18:53:17 -08003315 if (ixgbe_removed(hw->hw_addr))
3316 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003317 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3318 if (hw->mac.type == ixgbe_mac_82598EB &&
3319 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3320 return;
3321
3322 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003323 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003324 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3325 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3326
3327 if (!wait_loop) {
3328 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3329 "the polling period\n", reg_idx);
3330 }
3331}
3332
Yi Zou2d39d572011-01-06 14:29:56 +00003333void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3334 struct ixgbe_ring *ring)
3335{
3336 struct ixgbe_hw *hw = &adapter->hw;
3337 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3338 u32 rxdctl;
3339 u8 reg_idx = ring->reg_idx;
3340
Mark Rustadb0483c82014-01-14 18:53:17 -08003341 if (ixgbe_removed(hw->hw_addr))
3342 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003343 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3344 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3345
3346 /* write value back with RXDCTL.ENABLE bit cleared */
3347 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3348
3349 if (hw->mac.type == ixgbe_mac_82598EB &&
3350 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3351 return;
3352
3353 /* the hardware may take up to 100us to really disable the rx queue */
3354 do {
3355 udelay(10);
3356 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3357 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3358
3359 if (!wait_loop) {
3360 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3361 "the polling period\n", reg_idx);
3362 }
3363}
3364
Alexander Duyck84418e32010-08-19 13:40:54 +00003365void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3366 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003367{
3368 struct ixgbe_hw *hw = &adapter->hw;
3369 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003370 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003371 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003372
Alexander Duyck9e10e042010-08-19 13:40:06 +00003373 /* disable queue to avoid issues while updating state */
3374 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003375 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003376
Alexander Duyckacd37172010-08-19 13:36:05 +00003377 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3378 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3379 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3380 ring->count * sizeof(union ixgbe_adv_rx_desc));
3381 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3382 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003383 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003384
3385 ixgbe_configure_srrctl(adapter, ring);
3386 ixgbe_configure_rscctl(adapter, ring);
3387
3388 if (hw->mac.type == ixgbe_mac_82598EB) {
3389 /*
3390 * enable cache line friendly hardware writes:
3391 * PTHRESH=32 descriptors (half the internal cache),
3392 * this also removes ugly rx_no_buffer_count increment
3393 * HTHRESH=4 descriptors (to minimize latency on fetch)
3394 * WTHRESH=8 burst writeback up to two cache lines
3395 */
3396 rxdctl &= ~0x3FFFFF;
3397 rxdctl |= 0x080420;
3398 }
3399
3400 /* enable receive descriptor ring */
3401 rxdctl |= IXGBE_RXDCTL_ENABLE;
3402 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3403
3404 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003405 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003406}
3407
Alexander Duyck48654522010-08-19 13:36:27 +00003408static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3409{
3410 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003411 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003412 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003413
3414 /* PSRTYPE must be initialized in non 82598 adapters */
3415 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003416 IXGBE_PSRTYPE_UDPHDR |
3417 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003418 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003419 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003420
3421 if (hw->mac.type == ixgbe_mac_82598EB)
3422 return;
3423
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003424 if (rss_i > 3)
3425 psrtype |= 2 << 29;
3426 else if (rss_i > 1)
3427 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003428
John Fastabend2a47fa42013-11-06 09:54:52 -08003429 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3430 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003431}
3432
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003433static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3434{
3435 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003436 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003437 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003438 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003439
3440 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3441 return;
3442
3443 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003444 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3445 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003446 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003447 vmdctl |= IXGBE_VT_CTL_REPLEN;
3448 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003449
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003450 vf_shift = VMDQ_P(0) % 32;
3451 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003452
3453 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003454 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3455 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3456 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3457 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Greg Rose9b735982012-11-08 02:41:35 +00003458 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
3459 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003460
3461 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003462 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003463
3464 /*
3465 * Set up VF register offsets for selected VT Mode,
3466 * i.e. 32 or 64 VFs for SR-IOV
3467 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003468 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3469 case IXGBE_82599_VMDQ_8Q_MASK:
3470 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3471 break;
3472 case IXGBE_82599_VMDQ_4Q_MASK:
3473 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3474 break;
3475 default:
3476 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3477 break;
3478 }
3479
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003480 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3481
Alexander Duyck435b19f2012-05-18 06:34:08 +00003482
Greg Rosea985b6c32010-11-18 03:02:52 +00003483 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003484 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003485 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003486 /* For VFs that have spoof checking turned off */
3487 for (i = 0; i < adapter->num_vfs; i++) {
3488 if (!adapter->vfinfo[i].spoofchk_enabled)
3489 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3490 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003491}
3492
Alexander Duyck477de6e2010-08-19 13:38:11 +00003493static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003494{
Auke Kok9a799d72007-09-15 14:07:45 -07003495 struct ixgbe_hw *hw = &adapter->hw;
3496 struct net_device *netdev = adapter->netdev;
3497 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003498 struct ixgbe_ring *rx_ring;
3499 int i;
3500 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003501
Alexander Duyck477de6e2010-08-19 13:38:11 +00003502#ifdef IXGBE_FCOE
3503 /* adjust max frame to be able to do baby jumbo for FCoE */
3504 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3505 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3506 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3507
3508#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003509
3510 /* adjust max frame to be at least the size of a standard frame */
3511 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3512 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3513
Alexander Duyck477de6e2010-08-19 13:38:11 +00003514 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3515 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3516 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3517 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3518
3519 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003520 }
3521
Auke Kok9a799d72007-09-15 14:07:45 -07003522 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003523 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3524 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003525 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3526
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003527 /*
3528 * Setup the HW Rx Head and Tail Descriptor Pointers and
3529 * the Base and Length of the Rx Descriptor Ring
3530 */
Auke Kok9a799d72007-09-15 14:07:45 -07003531 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003532 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003533 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3534 set_ring_rsc_enabled(rx_ring);
3535 else
3536 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003537 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003538}
3539
Alexander Duyck73670962010-08-19 13:38:34 +00003540static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3541{
3542 struct ixgbe_hw *hw = &adapter->hw;
3543 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3544
3545 switch (hw->mac.type) {
3546 case ixgbe_mac_82598EB:
3547 /*
3548 * For VMDq support of different descriptor types or
3549 * buffer sizes through the use of multiple SRRCTL
3550 * registers, RDRXCTL.MVMEN must be set to 1
3551 *
3552 * also, the manual doesn't mention it clearly but DCA hints
3553 * will only use queue 0's tags unless this bit is set. Side
3554 * effects of setting this bit are only that SRRCTL must be
3555 * fully programmed [0..15]
3556 */
3557 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3558 break;
3559 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003560 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003561 /* Disable RSC for ACK packets */
3562 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3563 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3564 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3565 /* hardware requires some bits to be set by default */
3566 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3567 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3568 break;
3569 default:
3570 /* We should do nothing since we don't know this hardware */
3571 return;
3572 }
3573
3574 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3575}
3576
Alexander Duyck477de6e2010-08-19 13:38:11 +00003577/**
3578 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3579 * @adapter: board private structure
3580 *
3581 * Configure the Rx unit of the MAC after a reset.
3582 **/
3583static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3584{
3585 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003586 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003587 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003588
3589 /* disable receives while setting up the descriptors */
3590 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3591 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3592
3593 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003594 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003595
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003596 /* RSC Setup */
3597 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
3598 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
3599 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
3600 rfctl |= IXGBE_RFCTL_RSC_DIS;
3601 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
3602
Alexander Duyck9e10e042010-08-19 13:40:06 +00003603 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003604 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003605
Alexander Duyck477de6e2010-08-19 13:38:11 +00003606 /* set_rx_buffer_len must be called before ring initialization */
3607 ixgbe_set_rx_buffer_len(adapter);
3608
3609 /*
3610 * Setup the HW Rx Head and Tail Descriptor Pointers and
3611 * the Base and Length of the Rx Descriptor Ring
3612 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003613 for (i = 0; i < adapter->num_rx_queues; i++)
3614 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003615
Alexander Duyck9e10e042010-08-19 13:40:06 +00003616 /* disable drop enable for 82598 parts */
3617 if (hw->mac.type == ixgbe_mac_82598EB)
3618 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3619
3620 /* enable all receives */
3621 rxctrl |= IXGBE_RXCTRL_RXEN;
3622 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003623}
3624
Patrick McHardy80d5c362013-04-19 02:04:28 +00003625static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3626 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003627{
3628 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003629 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003630
3631 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003632 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003633 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003634
3635 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003636}
3637
Patrick McHardy80d5c362013-04-19 02:04:28 +00003638static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
3639 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003640{
3641 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003642 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003643
Auke Kok9a799d72007-09-15 14:07:45 -07003644 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003645 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003646 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003647
3648 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003649}
3650
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003651/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003652 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3653 * @adapter: driver data
3654 */
3655static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3656{
3657 struct ixgbe_hw *hw = &adapter->hw;
3658 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003659 int i, j;
3660
3661 switch (hw->mac.type) {
3662 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003663 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3664 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003665 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3666 break;
3667 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003668 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003669 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08003670 struct ixgbe_ring *ring = adapter->rx_ring[i];
3671
3672 if (ring->l2_accel_priv)
3673 continue;
3674 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003675 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3676 vlnctrl &= ~IXGBE_RXDCTL_VME;
3677 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3678 }
3679 break;
3680 default:
3681 break;
3682 }
3683}
3684
3685/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003686 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003687 * @adapter: driver data
3688 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003689static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003690{
3691 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003692 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003693 int i, j;
3694
3695 switch (hw->mac.type) {
3696 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003697 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3698 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003699 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3700 break;
3701 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003702 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003703 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08003704 struct ixgbe_ring *ring = adapter->rx_ring[i];
3705
3706 if (ring->l2_accel_priv)
3707 continue;
3708 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003709 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3710 vlnctrl |= IXGBE_RXDCTL_VME;
3711 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3712 }
3713 break;
3714 default:
3715 break;
3716 }
3717}
3718
Auke Kok9a799d72007-09-15 14:07:45 -07003719static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3720{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003721 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003722
Patrick McHardy80d5c362013-04-19 02:04:28 +00003723 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003724
3725 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00003726 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003727}
3728
3729/**
Jacob Kellerb335e752014-03-25 07:45:27 +00003730 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
3731 * @netdev: network interface device structure
3732 *
3733 * Writes multicast address list to the MTA hash table.
3734 * Returns: -ENOMEM on failure
3735 * 0 on no addresses written
3736 * X on writing X addresses to MTA
3737 **/
3738static int ixgbe_write_mc_addr_list(struct net_device *netdev)
3739{
3740 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3741 struct ixgbe_hw *hw = &adapter->hw;
3742
3743 if (!netif_running(netdev))
3744 return 0;
3745
3746 if (hw->mac.ops.update_mc_addr_list)
3747 hw->mac.ops.update_mc_addr_list(hw, netdev);
3748 else
3749 return -ENOMEM;
3750
3751#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00003752 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00003753#endif
3754
3755 return netdev_mc_count(netdev);
3756}
3757
Jacob Keller5d7daa32014-03-29 06:51:25 +00003758#ifdef CONFIG_PCI_IOV
3759void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
3760{
3761 struct ixgbe_hw *hw = &adapter->hw;
3762 int i;
3763 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3764 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
3765 hw->mac.ops.set_rar(hw, i, adapter->mac_table[i].addr,
3766 adapter->mac_table[i].queue,
3767 IXGBE_RAH_AV);
3768 else
3769 hw->mac.ops.clear_rar(hw, i);
3770
3771 adapter->mac_table[i].state &= ~(IXGBE_MAC_STATE_MODIFIED);
3772 }
3773}
3774#endif
3775
3776static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
3777{
3778 struct ixgbe_hw *hw = &adapter->hw;
3779 int i;
3780 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3781 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_MODIFIED) {
3782 if (adapter->mac_table[i].state &
3783 IXGBE_MAC_STATE_IN_USE)
3784 hw->mac.ops.set_rar(hw, i,
3785 adapter->mac_table[i].addr,
3786 adapter->mac_table[i].queue,
3787 IXGBE_RAH_AV);
3788 else
3789 hw->mac.ops.clear_rar(hw, i);
3790
3791 adapter->mac_table[i].state &=
3792 ~(IXGBE_MAC_STATE_MODIFIED);
3793 }
3794 }
3795}
3796
3797static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
3798{
3799 int i;
3800 struct ixgbe_hw *hw = &adapter->hw;
3801
3802 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3803 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
3804 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
3805 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
3806 adapter->mac_table[i].queue = 0;
3807 }
3808 ixgbe_sync_mac_table(adapter);
3809}
3810
3811static int ixgbe_available_rars(struct ixgbe_adapter *adapter)
3812{
3813 struct ixgbe_hw *hw = &adapter->hw;
3814 int i, count = 0;
3815
3816 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3817 if (adapter->mac_table[i].state == 0)
3818 count++;
3819 }
3820 return count;
3821}
3822
3823/* this function destroys the first RAR entry */
3824static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter,
3825 u8 *addr)
3826{
3827 struct ixgbe_hw *hw = &adapter->hw;
3828
3829 memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN);
3830 adapter->mac_table[0].queue = VMDQ_P(0);
3831 adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
3832 IXGBE_MAC_STATE_IN_USE);
3833 hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
3834 adapter->mac_table[0].queue,
3835 IXGBE_RAH_AV);
3836}
3837
3838int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
3839{
3840 struct ixgbe_hw *hw = &adapter->hw;
3841 int i;
3842
3843 if (is_zero_ether_addr(addr))
3844 return -EINVAL;
3845
3846 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3847 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
3848 continue;
3849 adapter->mac_table[i].state |= (IXGBE_MAC_STATE_MODIFIED |
3850 IXGBE_MAC_STATE_IN_USE);
3851 ether_addr_copy(adapter->mac_table[i].addr, addr);
3852 adapter->mac_table[i].queue = queue;
3853 ixgbe_sync_mac_table(adapter);
3854 return i;
3855 }
3856 return -ENOMEM;
3857}
3858
3859int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
3860{
3861 /* search table for addr, if found, set to 0 and sync */
3862 int i;
3863 struct ixgbe_hw *hw = &adapter->hw;
3864
3865 if (is_zero_ether_addr(addr))
3866 return -EINVAL;
3867
3868 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3869 if (ether_addr_equal(addr, adapter->mac_table[i].addr) &&
3870 adapter->mac_table[i].queue == queue) {
3871 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
3872 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
3873 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
3874 adapter->mac_table[i].queue = 0;
3875 ixgbe_sync_mac_table(adapter);
3876 return 0;
3877 }
3878 }
3879 return -ENOMEM;
3880}
Jacob Kellerb335e752014-03-25 07:45:27 +00003881/**
Alexander Duyck28500622010-06-15 09:25:48 +00003882 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3883 * @netdev: network interface device structure
3884 *
3885 * Writes unicast address list to the RAR table.
3886 * Returns: -ENOMEM on failure/insufficient address space
3887 * 0 on no addresses written
3888 * X on writing X addresses to the RAR table
3889 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00003890static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00003891{
3892 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00003893 int count = 0;
3894
3895 /* return ENOMEM indicating insufficient memory for addresses */
Jacob Keller5d7daa32014-03-29 06:51:25 +00003896 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter))
Alexander Duyck28500622010-06-15 09:25:48 +00003897 return -ENOMEM;
3898
John Fastabend95447462012-05-31 12:42:26 +00003899 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003900 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00003901 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00003902 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
3903 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00003904 count++;
3905 }
3906 }
Alexander Duyck28500622010-06-15 09:25:48 +00003907 return count;
3908}
3909
3910/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003911 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003912 * @netdev: network interface device structure
3913 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003914 * The set_rx_method entry point is called whenever the unicast/multicast
3915 * address list or the network interface flags are updated. This routine is
3916 * responsible for configuring the hardware for proper unicast, multicast and
3917 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003918 **/
Greg Rose7f870472010-01-09 02:25:29 +00003919void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003920{
3921 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3922 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003923 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Jacob Kellera9b89432014-03-25 07:45:26 +00003924 u32 vlnctrl;
Alexander Duyck28500622010-06-15 09:25:48 +00003925 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003926
3927 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07003928 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Jacob Kellera9b89432014-03-25 07:45:26 +00003929 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07003930
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003931 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003932 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003933 fctrl |= IXGBE_FCTRL_BAM;
3934 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3935 fctrl |= IXGBE_FCTRL_PMCF;
3936
Alexander Duyck28500622010-06-15 09:25:48 +00003937 /* clear the bits we are changing the status of */
3938 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellera9b89432014-03-25 07:45:26 +00003939 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
Auke Kok9a799d72007-09-15 14:07:45 -07003940 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003941 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003942 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00003943 vmolr |= IXGBE_VMOLR_MPE;
Greg Rose670224f2013-02-22 02:14:39 +00003944 /* Only disable hardware filter vlans in promiscuous mode
3945 * if SR-IOV and VMDQ are disabled - otherwise ensure
3946 * that hardware VLAN filters remain enabled.
3947 */
3948 if (!(adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED |
3949 IXGBE_FLAG_SRIOV_ENABLED)))
Jacob Kellera9b89432014-03-25 07:45:26 +00003950 vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
Auke Kok9a799d72007-09-15 14:07:45 -07003951 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003952 if (netdev->flags & IFF_ALLMULTI) {
3953 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003954 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003955 }
Jacob Kellera9b89432014-03-25 07:45:26 +00003956 vlnctrl |= IXGBE_VLNCTRL_VFE;
Emil Tantilove433ea12010-05-13 17:33:00 +00003957 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003958 }
3959
3960 /*
3961 * Write addresses to available RAR registers, if there is not
3962 * sufficient space to store all the addresses then enable
3963 * unicast promiscuous mode
3964 */
Jacob Keller5d7daa32014-03-29 06:51:25 +00003965 count = ixgbe_write_uc_addr_list(netdev, VMDQ_P(0));
John Fastabend9dcb3732012-04-15 06:44:25 +00003966 if (count < 0) {
3967 fctrl |= IXGBE_FCTRL_UPE;
3968 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003969 }
3970
Emil Tantilovcf789592013-10-26 08:13:20 +00003971 /* Write addresses to the MTA, if the attempt fails
3972 * then we should just turn on promiscuous mode so
3973 * that we can at least receive multicast traffic
3974 */
Jacob Kellerb335e752014-03-25 07:45:27 +00003975 count = ixgbe_write_mc_addr_list(netdev);
3976 if (count < 0) {
3977 fctrl |= IXGBE_FCTRL_MPE;
3978 vmolr |= IXGBE_VMOLR_MPE;
3979 } else if (count) {
3980 vmolr |= IXGBE_VMOLR_ROMPE;
3981 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003982
3983 if (hw->mac.type != ixgbe_mac_82598EB) {
3984 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003985 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3986 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003987 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003988 }
3989
Ben Greear3f2d1c02012-03-08 08:28:41 +00003990 /* This is useful for sniffing bad packets. */
3991 if (adapter->netdev->features & NETIF_F_RXALL) {
3992 /* UPE and MPE will be handled by normal PROMISC logic
3993 * in e1000e_set_rx_mode */
3994 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3995 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3996 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3997
3998 fctrl &= ~(IXGBE_FCTRL_DPF);
3999 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4000 }
4001
Jacob Kellera9b89432014-03-25 07:45:26 +00004002 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004003 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004004
Patrick McHardyf6469682013-04-19 02:04:27 +00004005 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004006 ixgbe_vlan_strip_enable(adapter);
4007 else
4008 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004009}
4010
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004011static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4012{
4013 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004014
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004015 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
4016 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004017 napi_enable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004018 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004019}
4020
4021static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4022{
4023 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004024
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004025 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004026 napi_disable(&adapter->q_vector[q_idx]->napi);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004027 while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) {
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004028 pr_info("QV %d locked\n", q_idx);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004029 usleep_range(1000, 20000);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004030 }
4031 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004032}
4033
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004034#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004035/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004036 * ixgbe_configure_dcb - Configure DCB hardware
4037 * @adapter: ixgbe adapter struct
4038 *
4039 * This is called by the driver on open to configure the DCB hardware.
4040 * This is also called by the gennetlink interface when reconfiguring
4041 * the DCB state.
4042 */
4043static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4044{
4045 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00004046 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004047
Alexander Duyck67ebd792010-08-19 13:34:04 +00004048 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4049 if (hw->mac.type == ixgbe_mac_82598EB)
4050 netif_set_gso_max_size(adapter->netdev, 65536);
4051 return;
4052 }
4053
4054 if (hw->mac.type == ixgbe_mac_82598EB)
4055 netif_set_gso_max_size(adapter->netdev, 32768);
4056
John Fastabendb1208182011-10-15 05:00:10 +00004057#ifdef IXGBE_FCOE
4058 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4059 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4060#endif
4061
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004062 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004063 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004064 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4065 DCB_TX_CONFIG);
4066 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4067 DCB_RX_CONFIG);
4068 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004069 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4070 ixgbe_dcb_hw_ets(&adapter->hw,
4071 adapter->ixgbe_ieee_ets,
4072 max_frame);
4073 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4074 adapter->ixgbe_ieee_pfc->pfc_en,
4075 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004076 }
John Fastabend8187cd42011-02-23 05:58:08 +00004077
4078 /* Enable RSS Hash per TC */
4079 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004080 u32 msb = 0;
4081 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004082
Alexander Duyckd411a932012-06-30 00:14:01 +00004083 while (rss_i) {
4084 msb++;
4085 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004086 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004087
Alexander Duyck4ae63732012-06-22 06:46:33 +00004088 /* write msb to all 8 TCs in one write */
4089 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004090 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004091}
John Fastabend9da712d2011-08-23 03:14:22 +00004092#endif
4093
4094/* Additional bittime to account for IXGBE framing */
4095#define IXGBE_ETH_FRAMING 20
4096
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004097/**
John Fastabend9da712d2011-08-23 03:14:22 +00004098 * ixgbe_hpbthresh - calculate high water mark for flow control
4099 *
4100 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004101 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004102 */
4103static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4104{
4105 struct ixgbe_hw *hw = &adapter->hw;
4106 struct net_device *dev = adapter->netdev;
4107 int link, tc, kb, marker;
4108 u32 dv_id, rx_pba;
4109
4110 /* Calculate max LAN frame size */
4111 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4112
4113#ifdef IXGBE_FCOE
4114 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004115 if ((dev->features & NETIF_F_FCOE_MTU) &&
4116 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4117 (pb == ixgbe_fcoe_get_tc(adapter)))
4118 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004119#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004120
John Fastabend9da712d2011-08-23 03:14:22 +00004121 /* Calculate delay value for device */
4122 switch (hw->mac.type) {
4123 case ixgbe_mac_X540:
4124 dv_id = IXGBE_DV_X540(link, tc);
4125 break;
4126 default:
4127 dv_id = IXGBE_DV(link, tc);
4128 break;
4129 }
4130
4131 /* Loopback switch introduces additional latency */
4132 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4133 dv_id += IXGBE_B2BT(tc);
4134
4135 /* Delay value is calculated in bit times convert to KB */
4136 kb = IXGBE_BT2KB(dv_id);
4137 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4138
4139 marker = rx_pba - kb;
4140
4141 /* It is possible that the packet buffer is not large enough
4142 * to provide required headroom. In this case throw an error
4143 * to user and a do the best we can.
4144 */
4145 if (marker < 0) {
4146 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4147 "headroom to support flow control."
4148 "Decrease MTU or number of traffic classes\n", pb);
4149 marker = tc + 1;
4150 }
4151
4152 return marker;
4153}
4154
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004155/**
John Fastabend9da712d2011-08-23 03:14:22 +00004156 * ixgbe_lpbthresh - calculate low water mark for for flow control
4157 *
4158 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004159 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004160 */
Jacob Kellere5776622014-04-05 02:35:52 +00004161static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00004162{
4163 struct ixgbe_hw *hw = &adapter->hw;
4164 struct net_device *dev = adapter->netdev;
4165 int tc;
4166 u32 dv_id;
4167
4168 /* Calculate max LAN frame size */
4169 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4170
Jacob Kellere5776622014-04-05 02:35:52 +00004171#ifdef IXGBE_FCOE
4172 /* FCoE traffic class uses FCOE jumbo frames */
4173 if ((dev->features & NETIF_F_FCOE_MTU) &&
4174 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4175 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4176 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4177#endif
4178
John Fastabend9da712d2011-08-23 03:14:22 +00004179 /* Calculate delay value for device */
4180 switch (hw->mac.type) {
4181 case ixgbe_mac_X540:
4182 dv_id = IXGBE_LOW_DV_X540(tc);
4183 break;
4184 default:
4185 dv_id = IXGBE_LOW_DV(tc);
4186 break;
4187 }
4188
4189 /* Delay value is calculated in bit times convert to KB */
4190 return IXGBE_BT2KB(dv_id);
4191}
4192
4193/*
4194 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4195 */
4196static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4197{
4198 struct ixgbe_hw *hw = &adapter->hw;
4199 int num_tc = netdev_get_num_tc(adapter->netdev);
4200 int i;
4201
4202 if (!num_tc)
4203 num_tc = 1;
4204
John Fastabend9da712d2011-08-23 03:14:22 +00004205 for (i = 0; i < num_tc; i++) {
4206 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00004207 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00004208
4209 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00004210 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4211 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004212 }
Jacob Kellere5776622014-04-05 02:35:52 +00004213
4214 for (; i < MAX_TRAFFIC_CLASS; i++)
4215 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004216}
John Fastabend80605c652011-05-02 12:34:10 +00004217
4218static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4219{
John Fastabend80605c652011-05-02 12:34:10 +00004220 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004221 int hdrm;
4222 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004223
4224 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4225 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004226 hdrm = 32 << adapter->fdir_pballoc;
4227 else
4228 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004229
Alexander Duyckf7e10272011-07-21 00:40:35 +00004230 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004231 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004232}
4233
Alexander Duycke4911d52011-05-11 07:18:52 +00004234static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4235{
4236 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004237 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004238 struct ixgbe_fdir_filter *filter;
4239
4240 spin_lock(&adapter->fdir_perfect_lock);
4241
4242 if (!hlist_empty(&adapter->fdir_filter_list))
4243 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4244
Sasha Levinb67bfe02013-02-27 17:06:00 -08004245 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004246 &adapter->fdir_filter_list, fdir_node) {
4247 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004248 &filter->filter,
4249 filter->sw_idx,
4250 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4251 IXGBE_FDIR_DROP_QUEUE :
4252 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004253 }
4254
4255 spin_unlock(&adapter->fdir_perfect_lock);
4256}
4257
John Fastabend2a47fa42013-11-06 09:54:52 -08004258static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4259 struct ixgbe_adapter *adapter)
4260{
4261 struct ixgbe_hw *hw = &adapter->hw;
4262 u32 vmolr;
4263
4264 /* No unicast promiscuous support for VMDQ devices. */
4265 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4266 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4267
4268 /* clear the affected bit */
4269 vmolr &= ~IXGBE_VMOLR_MPE;
4270
4271 if (dev->flags & IFF_ALLMULTI) {
4272 vmolr |= IXGBE_VMOLR_MPE;
4273 } else {
4274 vmolr |= IXGBE_VMOLR_ROMPE;
4275 hw->mac.ops.update_mc_addr_list(hw, dev);
4276 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00004277 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08004278 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4279}
4280
John Fastabend2a47fa42013-11-06 09:54:52 -08004281static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4282{
4283 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004284 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004285 struct ixgbe_hw *hw = &adapter->hw;
4286 u16 pool = vadapter->pool;
4287 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4288 IXGBE_PSRTYPE_UDPHDR |
4289 IXGBE_PSRTYPE_IPV4HDR |
4290 IXGBE_PSRTYPE_L2HDR |
4291 IXGBE_PSRTYPE_IPV6HDR;
4292
4293 if (hw->mac.type == ixgbe_mac_82598EB)
4294 return;
4295
4296 if (rss_i > 3)
4297 psrtype |= 2 << 29;
4298 else if (rss_i > 1)
4299 psrtype |= 1 << 29;
4300
4301 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4302}
4303
4304/**
4305 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4306 * @rx_ring: ring to free buffers from
4307 **/
4308static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4309{
4310 struct device *dev = rx_ring->dev;
4311 unsigned long size;
4312 u16 i;
4313
4314 /* ring already cleared, nothing to do */
4315 if (!rx_ring->rx_buffer_info)
4316 return;
4317
4318 /* Free all the Rx ring sk_buffs */
4319 for (i = 0; i < rx_ring->count; i++) {
4320 struct ixgbe_rx_buffer *rx_buffer;
4321
4322 rx_buffer = &rx_ring->rx_buffer_info[i];
4323 if (rx_buffer->skb) {
4324 struct sk_buff *skb = rx_buffer->skb;
4325 if (IXGBE_CB(skb)->page_released) {
4326 dma_unmap_page(dev,
4327 IXGBE_CB(skb)->dma,
4328 ixgbe_rx_bufsz(rx_ring),
4329 DMA_FROM_DEVICE);
4330 IXGBE_CB(skb)->page_released = false;
4331 }
4332 dev_kfree_skb(skb);
4333 }
4334 rx_buffer->skb = NULL;
4335 if (rx_buffer->dma)
4336 dma_unmap_page(dev, rx_buffer->dma,
4337 ixgbe_rx_pg_size(rx_ring),
4338 DMA_FROM_DEVICE);
4339 rx_buffer->dma = 0;
4340 if (rx_buffer->page)
4341 __free_pages(rx_buffer->page,
4342 ixgbe_rx_pg_order(rx_ring));
4343 rx_buffer->page = NULL;
4344 }
4345
4346 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4347 memset(rx_ring->rx_buffer_info, 0, size);
4348
4349 /* Zero out the descriptor ring */
4350 memset(rx_ring->desc, 0, rx_ring->size);
4351
4352 rx_ring->next_to_alloc = 0;
4353 rx_ring->next_to_clean = 0;
4354 rx_ring->next_to_use = 0;
4355}
4356
4357static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
4358 struct ixgbe_ring *rx_ring)
4359{
4360 struct ixgbe_adapter *adapter = vadapter->real_adapter;
4361 int index = rx_ring->queue_index + vadapter->rx_base_queue;
4362
4363 /* shutdown specific queue receive and wait for dma to settle */
4364 ixgbe_disable_rx_queue(adapter, rx_ring);
4365 usleep_range(10000, 20000);
4366 ixgbe_irq_disable_queues(adapter, ((u64)1 << index));
4367 ixgbe_clean_rx_ring(rx_ring);
4368 rx_ring->l2_accel_priv = NULL;
4369}
4370
John Fastabendae72c8d2013-11-09 07:11:26 +00004371static int ixgbe_fwd_ring_down(struct net_device *vdev,
4372 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08004373{
4374 struct ixgbe_adapter *adapter = accel->real_adapter;
4375 unsigned int rxbase = accel->rx_base_queue;
4376 unsigned int txbase = accel->tx_base_queue;
4377 int i;
4378
4379 netif_tx_stop_all_queues(vdev);
4380
4381 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4382 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4383 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
4384 }
4385
4386 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4387 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
4388 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
4389 }
4390
4391
4392 return 0;
4393}
4394
4395static int ixgbe_fwd_ring_up(struct net_device *vdev,
4396 struct ixgbe_fwd_adapter *accel)
4397{
4398 struct ixgbe_adapter *adapter = accel->real_adapter;
4399 unsigned int rxbase, txbase, queues;
4400 int i, baseq, err = 0;
4401
4402 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
4403 return 0;
4404
4405 baseq = accel->pool * adapter->num_rx_queues_per_pool;
4406 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4407 accel->pool, adapter->num_rx_pools,
4408 baseq, baseq + adapter->num_rx_queues_per_pool,
4409 adapter->fwd_bitmask);
4410
4411 accel->netdev = vdev;
4412 accel->rx_base_queue = rxbase = baseq;
4413 accel->tx_base_queue = txbase = baseq;
4414
4415 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
4416 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4417
4418 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4419 adapter->rx_ring[rxbase + i]->netdev = vdev;
4420 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
4421 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
4422 }
4423
4424 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4425 adapter->tx_ring[txbase + i]->netdev = vdev;
4426 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
4427 }
4428
4429 queues = min_t(unsigned int,
4430 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
4431 err = netif_set_real_num_tx_queues(vdev, queues);
4432 if (err)
4433 goto fwd_queue_err;
4434
John Fastabend2a47fa42013-11-06 09:54:52 -08004435 err = netif_set_real_num_rx_queues(vdev, queues);
4436 if (err)
4437 goto fwd_queue_err;
4438
4439 if (is_valid_ether_addr(vdev->dev_addr))
4440 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
4441
4442 ixgbe_fwd_psrtype(accel);
4443 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
4444 return err;
4445fwd_queue_err:
4446 ixgbe_fwd_ring_down(vdev, accel);
4447 return err;
4448}
4449
4450static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
4451{
4452 struct net_device *upper;
4453 struct list_head *iter;
4454 int err;
4455
4456 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
4457 if (netif_is_macvlan(upper)) {
4458 struct macvlan_dev *dfwd = netdev_priv(upper);
4459 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
4460
4461 if (dfwd->fwd_priv) {
4462 err = ixgbe_fwd_ring_up(upper, vadapter);
4463 if (err)
4464 continue;
4465 }
4466 }
4467 }
4468}
4469
Auke Kok9a799d72007-09-15 14:07:45 -07004470static void ixgbe_configure(struct ixgbe_adapter *adapter)
4471{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004472 struct ixgbe_hw *hw = &adapter->hw;
4473
John Fastabend80605c652011-05-02 12:34:10 +00004474 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004475#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00004476 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004477#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00004478 /*
4479 * We must restore virtualization before VLANs or else
4480 * the VLVF registers will not be populated
4481 */
4482 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004483
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004484 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004485 ixgbe_restore_vlan(adapter);
4486
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004487 switch (hw->mac.type) {
4488 case ixgbe_mac_82599EB:
4489 case ixgbe_mac_X540:
4490 hw->mac.ops.disable_rx_buff(hw);
4491 break;
4492 default:
4493 break;
4494 }
4495
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004496 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004497 ixgbe_init_fdir_signature_82599(&adapter->hw,
4498 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00004499 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
4500 ixgbe_init_fdir_perfect_82599(&adapter->hw,
4501 adapter->fdir_pballoc);
4502 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004503 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004504
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004505 switch (hw->mac.type) {
4506 case ixgbe_mac_82599EB:
4507 case ixgbe_mac_X540:
4508 hw->mac.ops.enable_rx_buff(hw);
4509 break;
4510 default:
4511 break;
4512 }
4513
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004514#ifdef IXGBE_FCOE
4515 /* configure FCoE L2 filters, redirection table, and Rx control */
4516 ixgbe_configure_fcoe(adapter);
4517
4518#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07004519 ixgbe_configure_tx(adapter);
4520 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08004521 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004522}
4523
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004524static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
4525{
4526 switch (hw->phy.type) {
4527 case ixgbe_phy_sfp_avago:
4528 case ixgbe_phy_sfp_ftl:
4529 case ixgbe_phy_sfp_intel:
4530 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00004531 case ixgbe_phy_sfp_passive_tyco:
4532 case ixgbe_phy_sfp_passive_unknown:
4533 case ixgbe_phy_sfp_active_unknown:
4534 case ixgbe_phy_sfp_ftl_active:
Emil Tantilov987e1d52013-08-14 07:12:27 +00004535 case ixgbe_phy_qsfp_passive_unknown:
4536 case ixgbe_phy_qsfp_active_unknown:
4537 case ixgbe_phy_qsfp_intel:
4538 case ixgbe_phy_qsfp_unknown:
Emil Tantilovd9cd46c2014-05-15 07:16:53 +00004539 /* ixgbe_phy_none is set when no SFP module is present */
4540 case ixgbe_phy_none:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004541 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00004542 case ixgbe_phy_nl:
4543 if (hw->mac.type == ixgbe_mac_82598EB)
4544 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004545 default:
4546 return false;
4547 }
4548}
4549
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004550/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004551 * ixgbe_sfp_link_config - set up SFP+ link
4552 * @adapter: pointer to private adapter struct
4553 **/
4554static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
4555{
Alexander Duyck70864002011-04-27 09:13:56 +00004556 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004557 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00004558 * is that an SFP was inserted/removed after the reset
4559 * but before SFP detection was enabled. As such the best
4560 * solution is to just start searching as soon as we start
4561 */
4562 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
4563 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004564
Alexander Duyck70864002011-04-27 09:13:56 +00004565 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004566}
4567
4568/**
4569 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004570 * @hw: pointer to private hardware struct
4571 *
4572 * Returns 0 on success, negative on failure
4573 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004574static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004575{
Josh Hay3d292262012-12-15 03:28:19 +00004576 u32 speed;
4577 bool autoneg, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004578 u32 ret = IXGBE_ERR_LINK_SETUP;
4579
4580 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00004581 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004582
4583 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00004584 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004585
Josh Hay3d292262012-12-15 03:28:19 +00004586 speed = hw->phy.autoneg_advertised;
4587 if ((!speed) && (hw->mac.ops.get_link_capabilities))
4588 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
4589 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004590 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00004591 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004592
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004593 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00004594 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00004595
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004596 return ret;
4597}
4598
Alexander Duycka34bcff2010-08-19 13:39:20 +00004599static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004600{
Auke Kok9a799d72007-09-15 14:07:45 -07004601 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004602 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004603
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004604 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004605 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4606 IXGBE_GPIE_OCD;
4607 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004608 /*
4609 * use EIAM to auto-mask when MSI-X interrupt is asserted
4610 * this saves a register write for every interrupt
4611 */
4612 switch (hw->mac.type) {
4613 case ixgbe_mac_82598EB:
4614 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4615 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004616 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004617 case ixgbe_mac_X540:
4618 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004619 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4620 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4621 break;
4622 }
4623 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004624 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4625 * specifically only auto mask tx and rx interrupts */
4626 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004627 }
4628
Alexander Duycka34bcff2010-08-19 13:39:20 +00004629 /* XXX: to interrupt immediately for EICS writes, enable this */
4630 /* gpie |= IXGBE_GPIE_EIMEN; */
4631
4632 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4633 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004634
4635 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4636 case IXGBE_82599_VMDQ_8Q_MASK:
4637 gpie |= IXGBE_GPIE_VTMODE_16;
4638 break;
4639 case IXGBE_82599_VMDQ_4Q_MASK:
4640 gpie |= IXGBE_GPIE_VTMODE_32;
4641 break;
4642 default:
4643 gpie |= IXGBE_GPIE_VTMODE_64;
4644 break;
4645 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004646 }
4647
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004648 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004649 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4650 switch (adapter->hw.mac.type) {
4651 case ixgbe_mac_82599EB:
4652 gpie |= IXGBE_SDP0_GPIEN;
4653 break;
4654 case ixgbe_mac_X540:
4655 gpie |= IXGBE_EIMS_TS;
4656 break;
4657 default:
4658 break;
4659 }
4660 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004661
Alexander Duycka34bcff2010-08-19 13:39:20 +00004662 /* Enable fan failure interrupt */
4663 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004664 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004665
Don Skidmore2698b202011-04-13 07:01:52 +00004666 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004667 gpie |= IXGBE_SDP1_GPIEN;
4668 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004669 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004670
4671 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4672}
4673
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004674static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004675{
4676 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004677 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004678 u32 ctrl_ext;
4679
4680 ixgbe_get_hw_control(adapter);
4681 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004682
Auke Kok9a799d72007-09-15 14:07:45 -07004683 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4684 ixgbe_configure_msix(adapter);
4685 else
4686 ixgbe_configure_msi_and_legacy(adapter);
4687
Emil Tantilovec74a472012-09-20 03:33:56 +00004688 /* enable the optics for 82599 SFP+ fiber */
4689 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004690 hw->mac.ops.enable_tx_laser(hw);
4691
Peter Zijlstra4e857c52014-03-17 18:06:10 +01004692 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07004693 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004694 ixgbe_napi_enable_all(adapter);
4695
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004696 if (ixgbe_is_sfp(hw)) {
4697 ixgbe_sfp_link_config(adapter);
4698 } else {
4699 err = ixgbe_non_sfp_link_config(hw);
4700 if (err)
4701 e_err(probe, "link_config FAILED %d\n", err);
4702 }
4703
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004704 /* clear any pending interrupts, may auto mask */
4705 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004706 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004707
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004708 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004709 * If this adapter has a fan, check to see if we had a failure
4710 * before we enabled the interrupt.
4711 */
4712 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4713 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4714 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004715 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004716 }
4717
Auke Kok9a799d72007-09-15 14:07:45 -07004718 /* bring the link up in the watchdog, this could race with our first
4719 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004720 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4721 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004722 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004723
4724 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4725 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4726 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4727 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004728}
4729
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004730void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4731{
4732 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004733 /* put off any impending NetWatchDogTimeout */
4734 adapter->netdev->trans_start = jiffies;
4735
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004736 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004737 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004738 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004739 /*
4740 * If SR-IOV enabled then wait a bit before bringing the adapter
4741 * back up to give the VFs time to respond to the reset. The
4742 * two second wait is based upon the watchdog timer cycle in
4743 * the VF driver.
4744 */
4745 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4746 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004747 ixgbe_up(adapter);
4748 clear_bit(__IXGBE_RESETTING, &adapter->state);
4749}
4750
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004751void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004752{
4753 /* hardware has been reset, we need to reload some things */
4754 ixgbe_configure(adapter);
4755
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004756 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004757}
4758
4759void ixgbe_reset(struct ixgbe_adapter *adapter)
4760{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004761 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004762 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004763 int err;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004764 u8 old_addr[ETH_ALEN];
Don Skidmore8ca783a2009-05-26 20:40:47 -07004765
Mark Rustadb0483c82014-01-14 18:53:17 -08004766 if (ixgbe_removed(hw->hw_addr))
4767 return;
Alexander Duyck70864002011-04-27 09:13:56 +00004768 /* lock SFP init bit to prevent race conditions with the watchdog */
4769 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4770 usleep_range(1000, 2000);
4771
4772 /* clear all SFP and link config related flags while holding SFP_INIT */
4773 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4774 IXGBE_FLAG2_SFP_NEEDS_RESET);
4775 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4776
Don Skidmore8ca783a2009-05-26 20:40:47 -07004777 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004778 switch (err) {
4779 case 0:
4780 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004781 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004782 break;
4783 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004784 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004785 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004786 case IXGBE_ERR_EEPROM_VERSION:
4787 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004788 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004789 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004790 "your hardware. If you are experiencing problems "
4791 "please contact your Intel or hardware "
4792 "representative who provided you with this "
4793 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004794 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004795 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004796 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004797 }
Auke Kok9a799d72007-09-15 14:07:45 -07004798
Alexander Duyck70864002011-04-27 09:13:56 +00004799 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004800 /* do not flush user set addresses */
4801 memcpy(old_addr, &adapter->mac_table[0].addr, netdev->addr_len);
4802 ixgbe_flush_sw_mac_table(adapter);
4803 ixgbe_mac_set_default_filter(adapter, old_addr);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004804
4805 /* update SAN MAC vmdq pool selection */
4806 if (hw->mac.san_mac_rar_index)
4807 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004808
Jacob Keller8fecf672013-06-21 08:14:32 +00004809 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00004810 ixgbe_ptp_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004811}
4812
Auke Kok9a799d72007-09-15 14:07:45 -07004813/**
Auke Kok9a799d72007-09-15 14:07:45 -07004814 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004815 * @tx_ring: ring to be cleaned
4816 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004817static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004818{
4819 struct ixgbe_tx_buffer *tx_buffer_info;
4820 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004821 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004822
Alexander Duyck84418e32010-08-19 13:40:54 +00004823 /* ring already cleared, nothing to do */
4824 if (!tx_ring->tx_buffer_info)
4825 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004826
Alexander Duyck84418e32010-08-19 13:40:54 +00004827 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004828 for (i = 0; i < tx_ring->count; i++) {
4829 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004830 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004831 }
4832
John Fastabenddad8a3b2012-04-23 12:22:39 +00004833 netdev_tx_reset_queue(txring_txq(tx_ring));
4834
Auke Kok9a799d72007-09-15 14:07:45 -07004835 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4836 memset(tx_ring->tx_buffer_info, 0, size);
4837
4838 /* Zero out the descriptor ring */
4839 memset(tx_ring->desc, 0, tx_ring->size);
4840
4841 tx_ring->next_to_use = 0;
4842 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004843}
4844
4845/**
Auke Kok9a799d72007-09-15 14:07:45 -07004846 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4847 * @adapter: board private structure
4848 **/
4849static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4850{
4851 int i;
4852
4853 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004854 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004855}
4856
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004857/**
4858 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4859 * @adapter: board private structure
4860 **/
4861static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4862{
4863 int i;
4864
4865 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004866 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004867}
4868
Alexander Duycke4911d52011-05-11 07:18:52 +00004869static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4870{
Sasha Levinb67bfe02013-02-27 17:06:00 -08004871 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004872 struct ixgbe_fdir_filter *filter;
4873
4874 spin_lock(&adapter->fdir_perfect_lock);
4875
Sasha Levinb67bfe02013-02-27 17:06:00 -08004876 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004877 &adapter->fdir_filter_list, fdir_node) {
4878 hlist_del(&filter->fdir_node);
4879 kfree(filter);
4880 }
4881 adapter->fdir_filter_count = 0;
4882
4883 spin_unlock(&adapter->fdir_perfect_lock);
4884}
4885
Auke Kok9a799d72007-09-15 14:07:45 -07004886void ixgbe_down(struct ixgbe_adapter *adapter)
4887{
4888 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004889 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08004890 struct net_device *upper;
4891 struct list_head *iter;
Auke Kok9a799d72007-09-15 14:07:45 -07004892 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004893 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004894
4895 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08004896 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
4897 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07004898
4899 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004900 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4901 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004902
Yi Zou2d39d572011-01-06 14:29:56 +00004903 /* disable all enabled rx queues */
4904 for (i = 0; i < adapter->num_rx_queues; i++)
4905 /* this call also flushes the previous write */
4906 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4907
Don Skidmore032b4322011-03-18 09:32:53 +00004908 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004909
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004910 netif_tx_stop_all_queues(netdev);
4911
Alexander Duyck70864002011-04-27 09:13:56 +00004912 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004913 netif_carrier_off(netdev);
4914 netif_tx_disable(netdev);
4915
John Fastabend2a47fa42013-11-06 09:54:52 -08004916 /* disable any upper devices */
4917 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
4918 if (netif_is_macvlan(upper)) {
4919 struct macvlan_dev *vlan = netdev_priv(upper);
4920
4921 if (vlan->fwd_priv) {
4922 netif_tx_stop_all_queues(upper);
4923 netif_carrier_off(upper);
4924 netif_tx_disable(upper);
4925 }
4926 }
4927 }
4928
John Fastabendc0dfb902010-04-27 02:13:39 +00004929 ixgbe_irq_disable(adapter);
4930
4931 ixgbe_napi_disable_all(adapter);
4932
Alexander Duyckd034acf2011-04-27 09:25:34 +00004933 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4934 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004935 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4936
4937 del_timer_sync(&adapter->service_timer);
4938
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004939 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004940 /* Clear EITR Select mapping */
4941 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4942
4943 /* Mark all the VFs as inactive */
4944 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004945 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004946
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004947 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004948 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004949
Auke Kok9a799d72007-09-15 14:07:45 -07004950 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004951 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004952 }
4953
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004954 /* disable transmits in the hardware now that interrupts are off */
4955 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004956 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004957 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004958 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004959
4960 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004961 switch (hw->mac.type) {
4962 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004963 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004964 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004965 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4966 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004967 break;
4968 default:
4969 break;
4970 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004971
Paul Larson6f4a0e42008-06-24 17:00:56 -07004972 if (!pci_channel_offline(adapter->pdev))
4973 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004974
Emil Tantilovec74a472012-09-20 03:33:56 +00004975 /* power down the optics for 82599 SFP+ fiber */
4976 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00004977 hw->mac.ops.disable_tx_laser(hw);
4978
Auke Kok9a799d72007-09-15 14:07:45 -07004979 ixgbe_clean_all_tx_rings(adapter);
4980 ixgbe_clean_all_rx_rings(adapter);
4981
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004982#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004983 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004984 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004985#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004986}
4987
Auke Kok9a799d72007-09-15 14:07:45 -07004988/**
Auke Kok9a799d72007-09-15 14:07:45 -07004989 * ixgbe_tx_timeout - Respond to a Tx Hang
4990 * @netdev: network interface device structure
4991 **/
4992static void ixgbe_tx_timeout(struct net_device *netdev)
4993{
4994 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4995
4996 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004997 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004998}
4999
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005000/**
Auke Kok9a799d72007-09-15 14:07:45 -07005001 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5002 * @adapter: board private structure to initialize
5003 *
5004 * ixgbe_sw_init initializes the Adapter private data structure.
5005 * Fields are initialized based on PCI device information and
5006 * OS network device settings (MTU size).
5007 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05005008static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005009{
5010 struct ixgbe_hw *hw = &adapter->hw;
5011 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005012 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005013 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005014#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005015 int j;
5016 struct tc_configuration *tc;
5017#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005018
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005019 /* PCI config space info */
5020
5021 hw->vendor_id = pdev->vendor;
5022 hw->device_id = pdev->device;
5023 hw->revision_id = pdev->revision;
5024 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5025 hw->subsystem_device_id = pdev->subsystem_device;
5026
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005027 /* Set common capability flags and settings */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00005028 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005029 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005030 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5031 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005032 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5033 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005034 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5035 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005036 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5037#ifdef CONFIG_IXGBE_DCA
5038 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5039#endif
5040#ifdef IXGBE_FCOE
5041 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5042 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5043#ifdef CONFIG_IXGBE_DCB
5044 /* Default traffic class to use for FCoE */
5045 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5046#endif /* CONFIG_IXGBE_DCB */
5047#endif /* IXGBE_FCOE */
5048
Jacob Keller5d7daa32014-03-29 06:51:25 +00005049 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5050 hw->mac.num_rar_entries,
5051 GFP_ATOMIC);
5052
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005053 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005054 switch (hw->mac.type) {
5055 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005056 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
5057 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
5058
Don Skidmorebf069c92009-05-07 10:39:54 +00005059 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5060 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005061
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005062 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005063 adapter->ring_feature[RING_F_FDIR].limit = 0;
5064 adapter->atr_sample_rate = 0;
5065 adapter->fdir_pballoc = 0;
5066#ifdef IXGBE_FCOE
5067 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5068 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5069#ifdef CONFIG_IXGBE_DCB
5070 adapter->fcoe.up = 0;
5071#endif /* IXGBE_DCB */
5072#endif /* IXGBE_FCOE */
5073 break;
5074 case ixgbe_mac_82599EB:
5075 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5076 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005077 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005078 case ixgbe_mac_X540:
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005079 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
5080 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5081 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005082 break;
5083 default:
5084 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005085 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005086
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005087#ifdef IXGBE_FCOE
5088 /* FCoE support exists, always init the FCoE lock */
5089 spin_lock_init(&adapter->fcoe.lock);
5090
5091#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005092 /* n-tuple support exists, always init our spinlock */
5093 spin_lock_init(&adapter->fdir_perfect_lock);
5094
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005095#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005096 switch (hw->mac.type) {
5097 case ixgbe_mac_X540:
5098 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5099 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5100 break;
5101 default:
5102 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5103 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5104 break;
5105 }
5106
Alexander Duyck2f90b862008-11-20 20:52:10 -08005107 /* Configure DCB traffic classes */
5108 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5109 tc = &adapter->dcb_cfg.tc_config[j];
5110 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5111 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5112 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5113 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5114 tc->dcb_pfc = pfc_disabled;
5115 }
John Fastabend4de2a022011-09-27 03:52:01 +00005116
5117 /* Initialize default user to priority mapping, UPx->TC0 */
5118 tc = &adapter->dcb_cfg.tc_config[0];
5119 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5120 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5121
Alexander Duyck2f90b862008-11-20 20:52:10 -08005122 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5123 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005124 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005125 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005126 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00005127 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5128 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08005129
5130#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005131
5132 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005133 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005134 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005135 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005136 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5137 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005138 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005139
Alexander Duyck99d74482012-05-09 08:09:25 +00005140#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005141 if (max_vfs > 0)
5142 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 +00005143
Jacob Keller170e8542013-11-09 04:52:32 -08005144 /* assign number of SR-IOV VFs */
5145 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005146 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Jacob Keller170e8542013-11-09 04:52:32 -08005147 adapter->num_vfs = 0;
5148 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5149 } else {
5150 adapter->num_vfs = max_vfs;
5151 }
5152 }
5153#endif /* CONFIG_PCI_IOV */
5154
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005155 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005156 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005157 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005158
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005159 /* set default ring sizes */
5160 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5161 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5162
Alexander Duyckbd198052011-06-11 01:45:08 +00005163 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005164 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005165
Auke Kok9a799d72007-09-15 14:07:45 -07005166 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005167 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005168 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005169 return -EIO;
5170 }
5171
John Fastabend2a47fa42013-11-06 09:54:52 -08005172 /* PF holds first pool slot */
5173 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005174 set_bit(__IXGBE_DOWN, &adapter->state);
5175
5176 return 0;
5177}
5178
5179/**
5180 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005181 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005182 *
5183 * Return 0 on success, negative on failure
5184 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005185int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005186{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005187 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005188 int orig_node = dev_to_node(dev);
5189 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005190 int size;
5191
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005192 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005193
5194 if (tx_ring->q_vector)
5195 numa_node = tx_ring->q_vector->numa_node;
5196
5197 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005198 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005199 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005200 if (!tx_ring->tx_buffer_info)
5201 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005202
John Stultz827da442013-10-07 15:51:58 -07005203 u64_stats_init(&tx_ring->syncp);
5204
Auke Kok9a799d72007-09-15 14:07:45 -07005205 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005206 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005207 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005208
Alexander Duyckde88eee2012-02-08 07:49:59 +00005209 set_dev_node(dev, numa_node);
5210 tx_ring->desc = dma_alloc_coherent(dev,
5211 tx_ring->size,
5212 &tx_ring->dma,
5213 GFP_KERNEL);
5214 set_dev_node(dev, orig_node);
5215 if (!tx_ring->desc)
5216 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5217 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005218 if (!tx_ring->desc)
5219 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005220
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005221 tx_ring->next_to_use = 0;
5222 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005223 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005224
5225err:
5226 vfree(tx_ring->tx_buffer_info);
5227 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005228 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005229 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005230}
5231
5232/**
Alexander Duyck69888672008-09-11 20:05:39 -07005233 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5234 * @adapter: board private structure
5235 *
5236 * If this function returns with an error, then it's possible one or
5237 * more of the rings is populated (while the rest are not). It is the
5238 * callers duty to clean those orphaned rings.
5239 *
5240 * Return 0 on success, negative on failure
5241 **/
5242static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5243{
5244 int i, err = 0;
5245
5246 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005247 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005248 if (!err)
5249 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005250
Emil Tantilov396e7992010-07-01 20:05:12 +00005251 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005252 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07005253 }
5254
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005255 return 0;
5256err_setup_tx:
5257 /* rewind the index freeing the rings as we go */
5258 while (i--)
5259 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005260 return err;
5261}
5262
5263/**
Auke Kok9a799d72007-09-15 14:07:45 -07005264 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005265 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005266 *
5267 * Returns 0 on success, negative on failure
5268 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005269int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005270{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005271 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005272 int orig_node = dev_to_node(dev);
5273 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005274 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005275
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005276 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005277
5278 if (rx_ring->q_vector)
5279 numa_node = rx_ring->q_vector->numa_node;
5280
5281 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005282 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005283 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005284 if (!rx_ring->rx_buffer_info)
5285 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005286
John Stultz827da442013-10-07 15:51:58 -07005287 u64_stats_init(&rx_ring->syncp);
5288
Auke Kok9a799d72007-09-15 14:07:45 -07005289 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005290 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5291 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005292
Alexander Duyckde88eee2012-02-08 07:49:59 +00005293 set_dev_node(dev, numa_node);
5294 rx_ring->desc = dma_alloc_coherent(dev,
5295 rx_ring->size,
5296 &rx_ring->dma,
5297 GFP_KERNEL);
5298 set_dev_node(dev, orig_node);
5299 if (!rx_ring->desc)
5300 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5301 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005302 if (!rx_ring->desc)
5303 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005304
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005305 rx_ring->next_to_clean = 0;
5306 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005307
5308 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005309err:
5310 vfree(rx_ring->rx_buffer_info);
5311 rx_ring->rx_buffer_info = NULL;
5312 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005313 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005314}
5315
5316/**
Alexander Duyck69888672008-09-11 20:05:39 -07005317 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5318 * @adapter: board private structure
5319 *
5320 * If this function returns with an error, then it's possible one or
5321 * more of the rings is populated (while the rest are not). It is the
5322 * callers duty to clean those orphaned rings.
5323 *
5324 * Return 0 on success, negative on failure
5325 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005326static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5327{
5328 int i, err = 0;
5329
5330 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005331 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005332 if (!err)
5333 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005334
Emil Tantilov396e7992010-07-01 20:05:12 +00005335 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005336 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07005337 }
5338
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005339#ifdef IXGBE_FCOE
5340 err = ixgbe_setup_fcoe_ddp_resources(adapter);
5341 if (!err)
5342#endif
5343 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005344err_setup_rx:
5345 /* rewind the index freeing the rings as we go */
5346 while (i--)
5347 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005348 return err;
5349}
5350
5351/**
Auke Kok9a799d72007-09-15 14:07:45 -07005352 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005353 * @tx_ring: Tx descriptor ring for a specific queue
5354 *
5355 * Free all transmit software resources
5356 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005357void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005358{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005359 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005360
5361 vfree(tx_ring->tx_buffer_info);
5362 tx_ring->tx_buffer_info = NULL;
5363
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005364 /* if not set, then don't free */
5365 if (!tx_ring->desc)
5366 return;
5367
5368 dma_free_coherent(tx_ring->dev, tx_ring->size,
5369 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005370
5371 tx_ring->desc = NULL;
5372}
5373
5374/**
5375 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5376 * @adapter: board private structure
5377 *
5378 * Free all transmit software resources
5379 **/
5380static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5381{
5382 int i;
5383
5384 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005385 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005386 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005387}
5388
5389/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005390 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005391 * @rx_ring: ring to clean the resources from
5392 *
5393 * Free all receive software resources
5394 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005395void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005396{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005397 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005398
5399 vfree(rx_ring->rx_buffer_info);
5400 rx_ring->rx_buffer_info = NULL;
5401
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005402 /* if not set, then don't free */
5403 if (!rx_ring->desc)
5404 return;
5405
5406 dma_free_coherent(rx_ring->dev, rx_ring->size,
5407 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005408
5409 rx_ring->desc = NULL;
5410}
5411
5412/**
5413 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5414 * @adapter: board private structure
5415 *
5416 * Free all receive software resources
5417 **/
5418static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5419{
5420 int i;
5421
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005422#ifdef IXGBE_FCOE
5423 ixgbe_free_fcoe_ddp_resources(adapter);
5424
5425#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005426 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005427 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005428 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005429}
5430
5431/**
Auke Kok9a799d72007-09-15 14:07:45 -07005432 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5433 * @netdev: network interface device structure
5434 * @new_mtu: new value for maximum frame size
5435 *
5436 * Returns 0 on success, negative on failure
5437 **/
5438static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5439{
5440 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5441 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5442
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005443 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005444 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5445 return -EINVAL;
5446
5447 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00005448 * For 82599EB we cannot allow legacy VFs to enable their receive
5449 * paths when MTU greater than 1500 is configured. So display a
5450 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00005451 */
5452 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5453 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Alexander Duyckc5604512013-01-09 08:50:42 +00005454 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck872844d2012-08-15 02:10:43 +00005455 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005456
Emil Tantilov396e7992010-07-01 20:05:12 +00005457 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005458
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005459 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005460 netdev->mtu = new_mtu;
5461
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005462 if (netif_running(netdev))
5463 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005464
5465 return 0;
5466}
5467
5468/**
5469 * ixgbe_open - Called when a network interface is made active
5470 * @netdev: network interface device structure
5471 *
5472 * Returns 0 on success, negative value on failure
5473 *
5474 * The open entry point is called when a network interface is made
5475 * active by the system (IFF_UP). At this point all resources needed
5476 * for transmit and receive operations are allocated, the interrupt
5477 * handler is registered with the OS, the watchdog timer is started,
5478 * and the stack is notified that the interface is ready.
5479 **/
5480static int ixgbe_open(struct net_device *netdev)
5481{
5482 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend2a47fa42013-11-06 09:54:52 -08005483 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07005484
Auke Kok4bebfaa2008-02-11 09:26:01 -08005485 /* disallow open during test */
5486 if (test_bit(__IXGBE_TESTING, &adapter->state))
5487 return -EBUSY;
5488
Jesse Brandeburg54386462009-04-17 20:44:27 +00005489 netif_carrier_off(netdev);
5490
Auke Kok9a799d72007-09-15 14:07:45 -07005491 /* allocate transmit descriptors */
5492 err = ixgbe_setup_all_tx_resources(adapter);
5493 if (err)
5494 goto err_setup_tx;
5495
Auke Kok9a799d72007-09-15 14:07:45 -07005496 /* allocate receive descriptors */
5497 err = ixgbe_setup_all_rx_resources(adapter);
5498 if (err)
5499 goto err_setup_rx;
5500
5501 ixgbe_configure(adapter);
5502
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005503 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005504 if (err)
5505 goto err_req_irq;
5506
Alexander Duyckac802f52012-07-12 05:52:53 +00005507 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08005508 if (adapter->num_rx_pools > 1)
5509 queues = adapter->num_rx_queues_per_pool;
5510 else
5511 queues = adapter->num_tx_queues;
5512
5513 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00005514 if (err)
5515 goto err_set_queues;
5516
John Fastabend2a47fa42013-11-06 09:54:52 -08005517 if (adapter->num_rx_pools > 1 &&
5518 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
5519 queues = IXGBE_MAX_L2A_QUEUES;
5520 else
5521 queues = adapter->num_rx_queues;
5522 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00005523 if (err)
5524 goto err_set_queues;
5525
Jacob Keller1a71ab22012-08-25 03:54:19 +00005526 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005527
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005528 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005529
5530 return 0;
5531
Alexander Duyckac802f52012-07-12 05:52:53 +00005532err_set_queues:
5533 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005534err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005535 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005536err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005537 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005538err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07005539 ixgbe_reset(adapter);
5540
5541 return err;
5542}
5543
Jacob Kellera0cccce2014-05-16 05:12:29 +00005544static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
5545{
5546 ixgbe_ptp_suspend(adapter);
5547
5548 ixgbe_down(adapter);
5549 ixgbe_free_irq(adapter);
5550
5551 ixgbe_free_all_tx_resources(adapter);
5552 ixgbe_free_all_rx_resources(adapter);
5553}
5554
Auke Kok9a799d72007-09-15 14:07:45 -07005555/**
5556 * ixgbe_close - Disables a network interface
5557 * @netdev: network interface device structure
5558 *
5559 * Returns 0, this is not allowed to fail
5560 *
5561 * The close entry point is called when an interface is de-activated
5562 * by the OS. The hardware is still under the drivers control, but
5563 * needs to be disabled. A global MAC reset is issued to stop the
5564 * hardware, and all transmit and receive resources are freed.
5565 **/
5566static int ixgbe_close(struct net_device *netdev)
5567{
5568 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005569
Jacob Keller1a71ab22012-08-25 03:54:19 +00005570 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005571
Jacob Kellera0cccce2014-05-16 05:12:29 +00005572 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005573
Alexander Duycke4911d52011-05-11 07:18:52 +00005574 ixgbe_fdir_filter_exit(adapter);
5575
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005576 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005577
5578 return 0;
5579}
5580
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005581#ifdef CONFIG_PM
5582static int ixgbe_resume(struct pci_dev *pdev)
5583{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005584 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5585 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005586 u32 err;
5587
Mark Rustad0391bbe2014-02-28 15:48:55 -08005588 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005589 pci_set_power_state(pdev, PCI_D0);
5590 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005591 /*
5592 * pci_restore_state clears dev->state_saved so call
5593 * pci_save_state to restore it.
5594 */
5595 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005596
5597 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005598 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005599 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005600 return err;
5601 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005602 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00005603 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005604 pci_set_master(pdev);
5605
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005606 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005607
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005608 ixgbe_reset(adapter);
5609
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005610 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5611
Alexander Duyckac802f52012-07-12 05:52:53 +00005612 rtnl_lock();
5613 err = ixgbe_init_interrupt_scheme(adapter);
5614 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005615 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005616
5617 rtnl_unlock();
5618
5619 if (err)
5620 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005621
5622 netif_device_attach(netdev);
5623
5624 return 0;
5625}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005626#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005627
5628static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005629{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005630 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5631 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005632 struct ixgbe_hw *hw = &adapter->hw;
5633 u32 ctrl, fctrl;
5634 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005635#ifdef CONFIG_PM
5636 int retval = 0;
5637#endif
5638
5639 netif_device_detach(netdev);
5640
akepner499ab5c2013-03-13 14:54:58 +00005641 rtnl_lock();
Jacob Kellera0cccce2014-05-16 05:12:29 +00005642 if (netif_running(netdev))
5643 ixgbe_close_suspend(adapter);
akepner499ab5c2013-03-13 14:54:58 +00005644 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005645
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005646 ixgbe_clear_interrupt_scheme(adapter);
5647
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005648#ifdef CONFIG_PM
5649 retval = pci_save_state(pdev);
5650 if (retval)
5651 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005652
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005653#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00005654 if (hw->mac.ops.stop_link_on_d3)
5655 hw->mac.ops.stop_link_on_d3(hw);
5656
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005657 if (wufc) {
5658 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005659
Emil Tantilovec74a472012-09-20 03:33:56 +00005660 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5661 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005662 hw->mac.ops.enable_tx_laser(hw);
5663
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005664 /* turn on all-multi mode if wake on multicast is enabled */
5665 if (wufc & IXGBE_WUFC_MC) {
5666 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5667 fctrl |= IXGBE_FCTRL_MPE;
5668 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5669 }
5670
5671 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5672 ctrl |= IXGBE_CTRL_GIO_DIS;
5673 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5674
5675 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5676 } else {
5677 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5678 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5679 }
5680
Alexander Duyckbd508172010-11-16 19:27:03 -08005681 switch (hw->mac.type) {
5682 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005683 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005684 break;
5685 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005686 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005687 pci_wake_from_d3(pdev, !!wufc);
5688 break;
5689 default:
5690 break;
5691 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005692
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005693 *enable_wake = !!wufc;
5694
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005695 ixgbe_release_hw_control(adapter);
5696
Mark Rustad41c62842014-03-12 00:38:35 +00005697 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
5698 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005699
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005700 return 0;
5701}
5702
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005703#ifdef CONFIG_PM
5704static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5705{
5706 int retval;
5707 bool wake;
5708
5709 retval = __ixgbe_shutdown(pdev, &wake);
5710 if (retval)
5711 return retval;
5712
5713 if (wake) {
5714 pci_prepare_to_sleep(pdev);
5715 } else {
5716 pci_wake_from_d3(pdev, false);
5717 pci_set_power_state(pdev, PCI_D3hot);
5718 }
5719
5720 return 0;
5721}
5722#endif /* CONFIG_PM */
5723
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005724static void ixgbe_shutdown(struct pci_dev *pdev)
5725{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005726 bool wake;
5727
5728 __ixgbe_shutdown(pdev, &wake);
5729
5730 if (system_state == SYSTEM_POWER_OFF) {
5731 pci_wake_from_d3(pdev, wake);
5732 pci_set_power_state(pdev, PCI_D3hot);
5733 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005734}
5735
5736/**
Auke Kok9a799d72007-09-15 14:07:45 -07005737 * ixgbe_update_stats - Update the board statistics counters.
5738 * @adapter: board private structure
5739 **/
5740void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5741{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005742 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005743 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005744 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005745 u64 total_mpc = 0;
5746 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005747 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5748 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005749 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005750
Don Skidmored08935c2010-06-11 13:20:29 +00005751 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5752 test_bit(__IXGBE_RESETTING, &adapter->state))
5753 return;
5754
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005755 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005756 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005757 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005758 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005759 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5760 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005761 }
5762 adapter->rsc_total_count = rsc_count;
5763 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005764 }
5765
Alexander Duyck5b7da512010-11-16 19:26:50 -08005766 for (i = 0; i < adapter->num_rx_queues; i++) {
5767 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5768 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5769 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5770 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005771 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005772 bytes += rx_ring->stats.bytes;
5773 packets += rx_ring->stats.packets;
5774 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005775 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005776 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5777 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005778 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005779 netdev->stats.rx_bytes = bytes;
5780 netdev->stats.rx_packets = packets;
5781
5782 bytes = 0;
5783 packets = 0;
5784 /* gather some stats to the adapter struct that are per queue */
5785 for (i = 0; i < adapter->num_tx_queues; i++) {
5786 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5787 restart_queue += tx_ring->tx_stats.restart_queue;
5788 tx_busy += tx_ring->tx_stats.tx_busy;
5789 bytes += tx_ring->stats.bytes;
5790 packets += tx_ring->stats.packets;
5791 }
5792 adapter->restart_queue = restart_queue;
5793 adapter->tx_busy = tx_busy;
5794 netdev->stats.tx_bytes = bytes;
5795 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005796
Joe Perches7ca647b2010-09-07 21:35:40 +00005797 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005798
5799 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005800 for (i = 0; i < 8; i++) {
5801 /* for packet buffers not used, the register should read 0 */
5802 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5803 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005804 hwstats->mpc[i] += mpc;
5805 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005806 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5807 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005808 switch (hw->mac.type) {
5809 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005810 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5811 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5812 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005813 hwstats->pxonrxc[i] +=
5814 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005815 break;
5816 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005817 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005818 hwstats->pxonrxc[i] +=
5819 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005820 break;
5821 default:
5822 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005823 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005824 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005825
5826 /*16 register reads */
5827 for (i = 0; i < 16; i++) {
5828 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5829 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5830 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5831 (hw->mac.type == ixgbe_mac_X540)) {
5832 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5833 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5834 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5835 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5836 }
5837 }
5838
Joe Perches7ca647b2010-09-07 21:35:40 +00005839 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005840 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005841 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005842
John Fastabendc84d3242010-11-16 19:27:12 -08005843 ixgbe_update_xoff_received(adapter);
5844
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005845 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005846 switch (hw->mac.type) {
5847 case ixgbe_mac_82598EB:
5848 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005849 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5850 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5851 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5852 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005853 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005854 /* OS2BMC stats are X540 only*/
5855 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5856 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5857 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5858 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5859 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005860 for (i = 0; i < 16; i++)
5861 adapter->hw_rx_no_dma_resources +=
5862 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005863 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005864 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005865 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005866 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005867 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005868 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005869 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005870 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5871 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005872#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005873 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5874 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5875 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5876 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5877 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5878 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005879 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005880 if (adapter->fcoe.ddp_pool) {
5881 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5882 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5883 unsigned int cpu;
5884 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005885 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005886 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5887 noddp += ddp_pool->noddp;
5888 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005889 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005890 hwstats->fcoe_noddp = noddp;
5891 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005892 }
Yi Zou6d455222009-05-13 13:12:16 +00005893#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005894 break;
5895 default:
5896 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005897 }
Auke Kok9a799d72007-09-15 14:07:45 -07005898 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005899 hwstats->bprc += bprc;
5900 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005901 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005902 hwstats->mprc -= bprc;
5903 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5904 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5905 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5906 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5907 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5908 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5909 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5910 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005911 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005912 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005913 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005914 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005915 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5916 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005917 /*
5918 * 82598 errata - tx of flow control packets is included in tx counters
5919 */
5920 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005921 hwstats->gptc -= xon_off_tot;
5922 hwstats->mptc -= xon_off_tot;
5923 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5924 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5925 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5926 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5927 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5928 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5929 hwstats->ptc64 -= xon_off_tot;
5930 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5931 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5932 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5933 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5934 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5935 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005936
5937 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005938 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005939
5940 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005941 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005942 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005943 netdev->stats.rx_length_errors = hwstats->rlec;
5944 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005945 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005946}
5947
5948/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005949 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005950 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005951 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005952static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005953{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005954 struct ixgbe_hw *hw = &adapter->hw;
5955 int i;
5956
Alexander Duyckd034acf2011-04-27 09:25:34 +00005957 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5958 return;
5959
5960 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5961
5962 /* if interface is down do nothing */
5963 if (test_bit(__IXGBE_DOWN, &adapter->state))
5964 return;
5965
5966 /* do nothing if we are not using signature filters */
5967 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5968 return;
5969
5970 adapter->fdir_overflow++;
5971
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005972 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5973 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005974 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00005975 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005976 /* re-enable flow director interrupts */
5977 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005978 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005979 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005980 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005981 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005982}
5983
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005984/**
5985 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005986 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005987 *
5988 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005989 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005990 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005991 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005992 */
5993static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5994{
Auke Kok9a799d72007-09-15 14:07:45 -07005995 struct ixgbe_hw *hw = &adapter->hw;
5996 u64 eics = 0;
5997 int i;
5998
Mark Rustad09f40ae2014-01-14 18:53:11 -08005999 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006000 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006001 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006002 test_bit(__IXGBE_RESETTING, &adapter->state))
6003 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006004
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006005 /* Force detection of hung controller */
6006 if (netif_carrier_ok(adapter->netdev)) {
6007 for (i = 0; i < adapter->num_tx_queues; i++)
6008 set_check_for_tx_hang(adapter->tx_ring[i]);
6009 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006010
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006011 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006012 /*
6013 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006014 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006015 * would set *both* EIMS and EICS for any bit in EIAM
6016 */
6017 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6018 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006019 } else {
6020 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006021 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006022 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006023 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006024 eics |= ((u64)1 << i);
6025 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006026 }
6027
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006028 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006029 ixgbe_irq_rearm_queues(adapter, eics);
6030
Alexander Duyckfe49f042009-06-04 16:00:09 +00006031}
6032
6033/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006034 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006035 * @adapter: pointer to the device adapter structure
6036 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006037 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006038static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006039{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006040 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006041 u32 link_speed = adapter->link_speed;
6042 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006043 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006044
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006045 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6046 return;
6047
6048 if (hw->mac.ops.check_link) {
6049 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006050 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006051 /* always assume link is up, if no check link function */
6052 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6053 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006054 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006055
6056 if (adapter->ixgbe_ieee_pfc)
6057 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6058
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006059 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006060 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006061 ixgbe_set_rx_drop_en(adapter);
6062 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006063
6064 if (link_up ||
6065 time_after(jiffies, (adapter->link_check_timeout +
6066 IXGBE_TRY_LINK_TIMEOUT))) {
6067 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6068 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6069 IXGBE_WRITE_FLUSH(hw);
6070 }
6071
6072 adapter->link_up = link_up;
6073 adapter->link_speed = link_speed;
6074}
6075
Alexander Duyck107d3012012-10-02 00:17:03 +00006076static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6077{
6078#ifdef CONFIG_IXGBE_DCB
6079 struct net_device *netdev = adapter->netdev;
6080 struct dcb_app app = {
6081 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6082 .protocol = 0,
6083 };
6084 u8 up = 0;
6085
6086 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6087 up = dcb_ieee_getapp_mask(netdev, &app);
6088
6089 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6090#endif
6091}
6092
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006093/**
6094 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6095 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006096 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006097 **/
6098static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6099{
6100 struct net_device *netdev = adapter->netdev;
6101 struct ixgbe_hw *hw = &adapter->hw;
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006102 struct net_device *upper;
6103 struct list_head *iter;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006104 u32 link_speed = adapter->link_speed;
6105 bool flow_rx, flow_tx;
6106
6107 /* only continue if link was previously down */
6108 if (netif_carrier_ok(netdev))
6109 return;
6110
6111 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6112
6113 switch (hw->mac.type) {
6114 case ixgbe_mac_82598EB: {
6115 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6116 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6117 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6118 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6119 }
6120 break;
6121 case ixgbe_mac_X540:
6122 case ixgbe_mac_82599EB: {
6123 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6124 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6125 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6126 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6127 }
6128 break;
6129 default:
6130 flow_tx = false;
6131 flow_rx = false;
6132 break;
6133 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006134
Jacob Keller6cb562d2012-12-05 07:24:41 +00006135 adapter->last_rx_ptp_check = jiffies;
6136
Jacob Keller8fecf672013-06-21 08:14:32 +00006137 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006138 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006139
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006140 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6141 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6142 "10 Gbps" :
6143 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6144 "1 Gbps" :
6145 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6146 "100 Mbps" :
6147 "unknown speed"))),
6148 ((flow_rx && flow_tx) ? "RX/TX" :
6149 (flow_rx ? "RX" :
6150 (flow_tx ? "TX" : "None"))));
6151
6152 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006153 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006154
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006155 /* enable transmits */
6156 netif_tx_wake_all_queues(adapter->netdev);
6157
6158 /* enable any upper devices */
6159 rtnl_lock();
6160 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
6161 if (netif_is_macvlan(upper)) {
6162 struct macvlan_dev *vlan = netdev_priv(upper);
6163
6164 if (vlan->fwd_priv)
6165 netif_tx_wake_all_queues(upper);
6166 }
6167 }
6168 rtnl_unlock();
6169
Alexander Duyck107d3012012-10-02 00:17:03 +00006170 /* update the default user priority for VFs */
6171 ixgbe_update_default_up(adapter);
6172
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006173 /* ping all the active vfs to let them know link has changed */
6174 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006175}
6176
6177/**
6178 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6179 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006180 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006181 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00006182static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006183{
6184 struct net_device *netdev = adapter->netdev;
6185 struct ixgbe_hw *hw = &adapter->hw;
6186
6187 adapter->link_up = false;
6188 adapter->link_speed = 0;
6189
6190 /* only continue if link was up previously */
6191 if (!netif_carrier_ok(netdev))
6192 return;
6193
6194 /* poll for SFP+ cable when link is down */
6195 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6196 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6197
Jacob Keller8fecf672013-06-21 08:14:32 +00006198 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006199 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006200
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006201 e_info(drv, "NIC Link is Down\n");
6202 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006203
6204 /* ping all the active vfs to let them know link has changed */
6205 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006206}
6207
Emil Tantilov07923c12014-08-12 07:12:08 +00006208static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
6209{
6210 int i;
6211
6212 for (i = 0; i < adapter->num_tx_queues; i++) {
6213 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6214
6215 if (tx_ring->next_to_use != tx_ring->next_to_clean)
6216 return true;
6217 }
6218
6219 return false;
6220}
6221
6222static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
6223{
6224 struct ixgbe_hw *hw = &adapter->hw;
6225 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
6226 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
6227
6228 int i, j;
6229
6230 if (!adapter->num_vfs)
6231 return false;
6232
6233 for (i = 0; i < adapter->num_vfs; i++) {
6234 for (j = 0; j < q_per_pool; j++) {
6235 u32 h, t;
6236
6237 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
6238 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
6239
6240 if (h != t)
6241 return true;
6242 }
6243 }
6244
6245 return false;
6246}
6247
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006248/**
6249 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006250 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006251 **/
6252static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6253{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006254 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00006255 if (ixgbe_ring_tx_pending(adapter) ||
6256 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006257 /* We've lost link, so the controller stops DMA,
6258 * but we've got queued Tx work that's never going
6259 * to get done, so reset controller to flush Tx.
6260 * (Do the reset outside of interrupt context).
6261 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00006262 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006263 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006264 }
6265 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006266}
6267
Greg Rosea985b6c32010-11-18 03:02:52 +00006268static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6269{
6270 u32 ssvpc;
6271
Greg Rose0584d992012-08-08 00:00:58 +00006272 /* Do not perform spoof check for 82598 or if not in IOV mode */
6273 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
6274 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00006275 return;
6276
6277 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6278
6279 /*
6280 * ssvpc register is cleared on read, if zero then no
6281 * spoofed packets in the last interval.
6282 */
6283 if (!ssvpc)
6284 return;
6285
Emil Tantilovd6ea0752012-08-08 06:28:37 +00006286 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00006287}
6288
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006289/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006290 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006291 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006292 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006293static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006294{
Mark Rustad09f40ae2014-01-14 18:53:11 -08006295 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006296 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006297 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00006298 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006299 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006300
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006301 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006302
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006303 if (adapter->link_up)
6304 ixgbe_watchdog_link_is_up(adapter);
6305 else
6306 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006307
Greg Rosea985b6c32010-11-18 03:02:52 +00006308 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006309 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006310
6311 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006312}
6313
Alexander Duyck70864002011-04-27 09:13:56 +00006314/**
6315 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006316 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00006317 **/
6318static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6319{
6320 struct ixgbe_hw *hw = &adapter->hw;
6321 s32 err;
6322
6323 /* not searching for SFP so there is nothing to do here */
6324 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6325 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6326 return;
6327
6328 /* someone else is in init, wait until next service event */
6329 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6330 return;
6331
6332 err = hw->phy.ops.identify_sfp(hw);
6333 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6334 goto sfp_out;
6335
6336 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6337 /* If no cable is present, then we need to reset
6338 * the next time we find a good cable. */
6339 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6340 }
6341
6342 /* exit on error */
6343 if (err)
6344 goto sfp_out;
6345
6346 /* exit if reset not needed */
6347 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6348 goto sfp_out;
6349
6350 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6351
6352 /*
6353 * A module may be identified correctly, but the EEPROM may not have
6354 * support for that module. setup_sfp() will fail in that case, so
6355 * we should not allow that module to load.
6356 */
6357 if (hw->mac.type == ixgbe_mac_82598EB)
6358 err = hw->phy.ops.reset(hw);
6359 else
6360 err = hw->mac.ops.setup_sfp(hw);
6361
6362 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6363 goto sfp_out;
6364
6365 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6366 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6367
6368sfp_out:
6369 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6370
6371 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6372 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6373 e_dev_err("failed to initialize because an unsupported "
6374 "SFP+ module type was detected.\n");
6375 e_dev_err("Reload the driver after installing a "
6376 "supported module.\n");
6377 unregister_netdev(adapter->netdev);
6378 }
6379}
6380
6381/**
6382 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006383 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00006384 **/
6385static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6386{
6387 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00006388 u32 speed;
6389 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00006390
6391 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6392 return;
6393
6394 /* someone else is in init, wait until next service event */
6395 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6396 return;
6397
6398 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6399
Josh Hay3d292262012-12-15 03:28:19 +00006400 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00006401 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00006402 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00006403
6404 /* setup the highest link when no autoneg */
6405 if (!autoneg) {
6406 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
6407 speed = IXGBE_LINK_SPEED_10GB_FULL;
6408 }
6409 }
6410
Alexander Duyck70864002011-04-27 09:13:56 +00006411 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00006412 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00006413
6414 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6415 adapter->link_check_timeout = jiffies;
6416 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6417}
6418
Greg Rose83c61fa2011-09-07 05:59:35 +00006419#ifdef CONFIG_PCI_IOV
6420static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6421{
6422 int vf;
6423 struct ixgbe_hw *hw = &adapter->hw;
6424 struct net_device *netdev = adapter->netdev;
6425 u32 gpc;
6426 u32 ciaa, ciad;
6427
6428 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6429 if (gpc) /* If incrementing then no need for the check below */
6430 return;
6431 /*
6432 * Check to see if a bad DMA write target from an errant or
6433 * malicious VF has caused a PCIe error. If so then we can
6434 * issue a VFLR to the offending VF(s) and then resume without
6435 * requesting a full slot reset.
6436 */
6437
6438 for (vf = 0; vf < adapter->num_vfs; vf++) {
6439 ciaa = (vf << 16) | 0x80000000;
6440 /* 32 bit read so align, we really want status at offset 6 */
6441 ciaa |= PCI_COMMAND;
6442 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6443 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6444 ciaa &= 0x7FFFFFFF;
6445 /* disable debug mode asap after reading data */
6446 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6447 /* Get the upper 16 bits which will be the PCI status reg */
6448 ciad >>= 16;
6449 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6450 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6451 /* Issue VFLR */
6452 ciaa = (vf << 16) | 0x80000000;
6453 ciaa |= 0xA8;
6454 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6455 ciad = 0x00008000; /* VFLR */
6456 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6457 ciaa &= 0x7FFFFFFF;
6458 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6459 }
6460 }
6461}
6462
6463#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006464/**
6465 * ixgbe_service_timer - Timer Call-back
6466 * @data: pointer to adapter cast into an unsigned long
6467 **/
6468static void ixgbe_service_timer(unsigned long data)
6469{
6470 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6471 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006472 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006473
6474 /* poll faster when waiting for link */
6475 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6476 next_event_offset = HZ / 10;
6477 else
6478 next_event_offset = HZ * 2;
6479
Greg Rose83c61fa2011-09-07 05:59:35 +00006480#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00006481 /*
6482 * don't bother with SR-IOV VF DMA hang check if there are
6483 * no VFs or the link is down
6484 */
6485 if (!adapter->num_vfs ||
6486 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6487 goto normal_timer_service;
6488
6489 /* If we have VFs allocated then we must check for DMA hangs */
6490 ixgbe_check_for_bad_vf(adapter);
6491 next_event_offset = HZ / 50;
6492 adapter->timer_event_accumulator++;
6493
6494 if (adapter->timer_event_accumulator >= 100)
6495 adapter->timer_event_accumulator = 0;
6496 else
6497 ready = false;
6498
6499normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00006500#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006501 /* Reset the timer */
6502 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6503
Greg Rose83c61fa2011-09-07 05:59:35 +00006504 if (ready)
6505 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006506}
6507
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006508static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6509{
6510 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6511 return;
6512
6513 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6514
Mark Rustad09f40ae2014-01-14 18:53:11 -08006515 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006516 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006517 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006518 test_bit(__IXGBE_RESETTING, &adapter->state))
6519 return;
6520
6521 ixgbe_dump(adapter);
6522 netdev_err(adapter->netdev, "Reset adapter\n");
6523 adapter->tx_timeout_count++;
6524
John Fastabend8f4c5c92014-01-16 02:30:05 -08006525 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006526 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08006527 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006528}
6529
Alexander Duyck70864002011-04-27 09:13:56 +00006530/**
6531 * ixgbe_service_task - manages and runs subtasks
6532 * @work: pointer to work_struct containing our data
6533 **/
6534static void ixgbe_service_task(struct work_struct *work)
6535{
6536 struct ixgbe_adapter *adapter = container_of(work,
6537 struct ixgbe_adapter,
6538 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08006539 if (ixgbe_removed(adapter->hw.hw_addr)) {
6540 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
6541 rtnl_lock();
6542 ixgbe_down(adapter);
6543 rtnl_unlock();
6544 }
6545 ixgbe_service_event_complete(adapter);
6546 return;
6547 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006548 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006549 ixgbe_sfp_detection_subtask(adapter);
6550 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006551 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006552 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006553 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006554 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00006555
Jacob Keller8fecf672013-06-21 08:14:32 +00006556 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00006557 ixgbe_ptp_overflow_check(adapter);
6558 ixgbe_ptp_rx_hang(adapter);
6559 }
Alexander Duyck70864002011-04-27 09:13:56 +00006560
6561 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006562}
6563
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006564static int ixgbe_tso(struct ixgbe_ring *tx_ring,
6565 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006566 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00006567{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006568 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006569 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006570 u32 mss_l4len_idx, l4len;
Francois Romieu2049e1f2014-03-30 03:14:27 +00006571 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07006572
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00006573 if (skb->ip_summed != CHECKSUM_PARTIAL)
6574 return 0;
6575
Alexander Duyck897ab152011-05-27 05:31:47 +00006576 if (!skb_is_gso(skb))
6577 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006578
Francois Romieu2049e1f2014-03-30 03:14:27 +00006579 err = skb_cow_head(skb, 0);
6580 if (err < 0)
6581 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006582
Alexander Duyck897ab152011-05-27 05:31:47 +00006583 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6584 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6585
Joe Perchesa1108ff2014-03-13 05:19:25 +00006586 if (first->protocol == htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006587 struct iphdr *iph = ip_hdr(skb);
6588 iph->tot_len = 0;
6589 iph->check = 0;
6590 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6591 iph->daddr, 0,
6592 IPPROTO_TCP,
6593 0);
6594 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006595 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6596 IXGBE_TX_FLAGS_CSUM |
6597 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006598 } else if (skb_is_gso_v6(skb)) {
6599 ipv6_hdr(skb)->payload_len = 0;
6600 tcp_hdr(skb)->check =
6601 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6602 &ipv6_hdr(skb)->daddr,
6603 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00006604 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6605 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00006606 }
6607
Alexander Duyck091a6242012-02-08 07:51:01 +00006608 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00006609 l4len = tcp_hdrlen(skb);
6610 *hdr_len = skb_transport_offset(skb) + l4len;
6611
Alexander Duyck091a6242012-02-08 07:51:01 +00006612 /* update gso size and bytecount with header size */
6613 first->gso_segs = skb_shinfo(skb)->gso_segs;
6614 first->bytecount += (first->gso_segs - 1) * *hdr_len;
6615
Alexander Duyckc44f5f52012-10-30 06:01:45 +00006616 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00006617 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6618 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00006619
6620 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6621 vlan_macip_lens = skb_network_header_len(skb);
6622 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006623 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006624
6625 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006626 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00006627
6628 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006629}
6630
Alexander Duyck244e27a2012-02-08 07:51:11 +00006631static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6632 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07006633{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006634 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006635 u32 vlan_macip_lens = 0;
6636 u32 mss_l4len_idx = 0;
6637 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006638
Alexander Duyck897ab152011-05-27 05:31:47 +00006639 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck472148c2012-11-07 02:34:28 +00006640 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6641 !(first->tx_flags & IXGBE_TX_FLAGS_CC))
6642 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00006643 } else {
6644 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006645 switch (first->protocol) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00006646 case htons(ETH_P_IP):
Alexander Duyck897ab152011-05-27 05:31:47 +00006647 vlan_macip_lens |= skb_network_header_len(skb);
6648 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6649 l4_hdr = ip_hdr(skb)->protocol;
6650 break;
Joe Perchesa1108ff2014-03-13 05:19:25 +00006651 case htons(ETH_P_IPV6):
Alexander Duyck897ab152011-05-27 05:31:47 +00006652 vlan_macip_lens |= skb_network_header_len(skb);
6653 l4_hdr = ipv6_hdr(skb)->nexthdr;
6654 break;
6655 default:
6656 if (unlikely(net_ratelimit())) {
6657 dev_warn(tx_ring->dev,
6658 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006659 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00006660 }
6661 break;
6662 }
Auke Kok9a799d72007-09-15 14:07:45 -07006663
Alexander Duyck897ab152011-05-27 05:31:47 +00006664 switch (l4_hdr) {
6665 case IPPROTO_TCP:
6666 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6667 mss_l4len_idx = tcp_hdrlen(skb) <<
6668 IXGBE_ADVTXD_L4LEN_SHIFT;
6669 break;
6670 case IPPROTO_SCTP:
6671 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6672 mss_l4len_idx = sizeof(struct sctphdr) <<
6673 IXGBE_ADVTXD_L4LEN_SHIFT;
6674 break;
6675 case IPPROTO_UDP:
6676 mss_l4len_idx = sizeof(struct udphdr) <<
6677 IXGBE_ADVTXD_L4LEN_SHIFT;
6678 break;
6679 default:
6680 if (unlikely(net_ratelimit())) {
6681 dev_warn(tx_ring->dev,
6682 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006683 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006684 }
6685 break;
6686 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006687
6688 /* update TX checksum flag */
6689 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006690 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006691
Alexander Duyck244e27a2012-02-08 07:51:11 +00006692 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006693 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006694 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006695
6696 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6697 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006698}
6699
Alexander Duyck472148c2012-11-07 02:34:28 +00006700#define IXGBE_SET_FLAG(_input, _flag, _result) \
6701 ((_flag <= _result) ? \
6702 ((u32)(_input & _flag) * (_result / _flag)) : \
6703 ((u32)(_input & _flag) / (_flag / _result)))
6704
6705static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006706{
6707 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00006708 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
6709 IXGBE_ADVTXD_DCMD_DEXT |
6710 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006711
6712 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00006713 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
6714 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006715
Alexander Duyckd3d00232011-07-15 02:31:25 +00006716 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006717 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
6718 IXGBE_ADVTXD_DCMD_TSE);
6719
6720 /* set timestamp bit if present */
6721 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
6722 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006723
Alexander Duyck62748b72012-07-20 08:09:01 +00006724 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00006725 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00006726
Alexander Duyckd3d00232011-07-15 02:31:25 +00006727 return cmd_type;
6728}
6729
Alexander Duyck729739b2012-02-08 07:51:06 +00006730static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6731 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006732{
Alexander Duyck472148c2012-11-07 02:34:28 +00006733 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006734
6735 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00006736 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6737 IXGBE_TX_FLAGS_CSUM,
6738 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006739
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006740 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006741 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6742 IXGBE_TX_FLAGS_IPV4,
6743 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006744
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006745 /*
6746 * Check Context must be set if Tx switch is enabled, which it
6747 * always is for case where virtual functions are running
6748 */
Alexander Duyck472148c2012-11-07 02:34:28 +00006749 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6750 IXGBE_TX_FLAGS_CC,
6751 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006752
Alexander Duyck472148c2012-11-07 02:34:28 +00006753 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006754}
6755
Daniel Borkmann2367a172014-08-26 19:34:18 +02006756static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6757{
6758 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
6759
6760 /* Herbert's original patch had:
6761 * smp_mb__after_netif_stop_queue();
6762 * but since that doesn't exist yet, just open code it.
6763 */
6764 smp_mb();
6765
6766 /* We need to check again in a case another CPU has just
6767 * made room available.
6768 */
6769 if (likely(ixgbe_desc_unused(tx_ring) < size))
6770 return -EBUSY;
6771
6772 /* A reprieve! - use start_queue because it doesn't call schedule */
6773 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
6774 ++tx_ring->tx_stats.restart_queue;
6775 return 0;
6776}
6777
6778static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6779{
6780 if (likely(ixgbe_desc_unused(tx_ring) >= size))
6781 return 0;
6782
6783 return __ixgbe_maybe_stop_tx(tx_ring, size);
6784}
6785
Alexander Duyckd3d00232011-07-15 02:31:25 +00006786#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6787 IXGBE_TXD_CMD_RS)
6788
6789static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006790 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006791 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006792{
Alexander Duyck729739b2012-02-08 07:51:06 +00006793 struct sk_buff *skb = first->skb;
6794 struct ixgbe_tx_buffer *tx_buffer;
6795 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00006796 struct skb_frag_struct *frag;
6797 dma_addr_t dma;
6798 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006799 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00006800 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006801 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006802
Alexander Duyck729739b2012-02-08 07:51:06 +00006803 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6804
Alexander Duyckec718252012-10-30 06:01:55 +00006805 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
6806
6807 size = skb_headlen(skb);
6808 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00006809
Alexander Duyckd3d00232011-07-15 02:31:25 +00006810#ifdef IXGBE_FCOE
6811 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006812 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006813 size -= sizeof(struct fcoe_crc_eof) - data_len;
6814 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006815 } else {
6816 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006817 }
Auke Kok9a799d72007-09-15 14:07:45 -07006818 }
6819
Alexander Duyckd3d00232011-07-15 02:31:25 +00006820#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006821 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006822
Alexander Duyckec718252012-10-30 06:01:55 +00006823 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006824
Alexander Duyckec718252012-10-30 06:01:55 +00006825 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
6826 if (dma_mapping_error(tx_ring->dev, dma))
6827 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006828
Alexander Duyckec718252012-10-30 06:01:55 +00006829 /* record length, and DMA address */
6830 dma_unmap_len_set(tx_buffer, len, size);
6831 dma_unmap_addr_set(tx_buffer, dma, dma);
6832
6833 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6834
Alexander Duyck729739b2012-02-08 07:51:06 +00006835 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006836 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00006837 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006838
Alexander Duyckd3d00232011-07-15 02:31:25 +00006839 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006840 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006841 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006842 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006843 i = 0;
6844 }
Alexander Duyckec718252012-10-30 06:01:55 +00006845 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006846
6847 dma += IXGBE_MAX_DATA_PER_TXD;
6848 size -= IXGBE_MAX_DATA_PER_TXD;
6849
6850 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006851 }
6852
Alexander Duyck729739b2012-02-08 07:51:06 +00006853 if (likely(!data_len))
6854 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006855
Alexander Duyck472148c2012-11-07 02:34:28 +00006856 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006857
Alexander Duyck729739b2012-02-08 07:51:06 +00006858 i++;
6859 tx_desc++;
6860 if (i == tx_ring->count) {
6861 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6862 i = 0;
6863 }
Alexander Duyckec718252012-10-30 06:01:55 +00006864 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006865
Alexander Duyckd3d00232011-07-15 02:31:25 +00006866#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006867 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006868#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006869 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006870#endif
6871 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006872
Alexander Duyck729739b2012-02-08 07:51:06 +00006873 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6874 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07006875
Alexander Duyck729739b2012-02-08 07:51:06 +00006876 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07006877 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006878
Alexander Duyck729739b2012-02-08 07:51:06 +00006879 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00006880 cmd_type |= size | IXGBE_TXD_CMD;
6881 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006882
Alexander Duyck091a6242012-02-08 07:51:01 +00006883 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006884
Alexander Duyckd3d00232011-07-15 02:31:25 +00006885 /* set the timestamp */
6886 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006887
6888 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006889 * Force memory writes to complete before letting h/w know there
6890 * are new descriptors to fetch. (Only applicable for weak-ordered
6891 * memory model archs, such as IA-64).
6892 *
6893 * We also need this memory barrier to make certain all of the
6894 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006895 */
6896 wmb();
6897
Alexander Duyckd3d00232011-07-15 02:31:25 +00006898 /* set next_to_watch value indicating a packet is present */
6899 first->next_to_watch = tx_desc;
6900
Alexander Duyck729739b2012-02-08 07:51:06 +00006901 i++;
6902 if (i == tx_ring->count)
6903 i = 0;
6904
6905 tx_ring->next_to_use = i;
6906
Daniel Borkmann2367a172014-08-26 19:34:18 +02006907 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
6908
6909 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02006910 /* notify HW of packet */
6911 ixgbe_write_tail(tx_ring, i);
6912 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02006913
Alexander Duyckd3d00232011-07-15 02:31:25 +00006914 return;
6915dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006916 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006917
6918 /* clear dma mappings for failed tx_buffer_info map */
6919 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006920 tx_buffer = &tx_ring->tx_buffer_info[i];
6921 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6922 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006923 break;
6924 if (i == 0)
6925 i = tx_ring->count;
6926 i--;
6927 }
6928
Alexander Duyckd3d00232011-07-15 02:31:25 +00006929 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006930}
6931
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006932static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006933 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006934{
Alexander Duyck69830522011-01-06 14:29:58 +00006935 struct ixgbe_q_vector *q_vector = ring->q_vector;
6936 union ixgbe_atr_hash_dword input = { .dword = 0 };
6937 union ixgbe_atr_hash_dword common = { .dword = 0 };
6938 union {
6939 unsigned char *network;
6940 struct iphdr *ipv4;
6941 struct ipv6hdr *ipv6;
6942 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006943 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006944 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006945
Alexander Duyck69830522011-01-06 14:29:58 +00006946 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6947 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006948 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006949
Alexander Duyck69830522011-01-06 14:29:58 +00006950 /* do nothing if sampling is disabled */
6951 if (!ring->atr_sample_rate)
6952 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006953
Alexander Duyck69830522011-01-06 14:29:58 +00006954 ring->atr_count++;
6955
6956 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006957 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006958
6959 /* Currently only IPv4/IPv6 with TCP is supported */
Joe Perchesa1108ff2014-03-13 05:19:25 +00006960 if ((first->protocol != htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006961 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Joe Perchesa1108ff2014-03-13 05:19:25 +00006962 (first->protocol != htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006963 hdr.ipv4->protocol != IPPROTO_TCP))
6964 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006965
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006966 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006967
Alexander Duyck66f32a82011-06-29 05:43:22 +00006968 /* skip this packet since it is invalid or the socket is closing */
6969 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006970 return;
6971
6972 /* sample on all syn packets or once every atr sample count */
6973 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6974 return;
6975
6976 /* reset sample count */
6977 ring->atr_count = 0;
6978
Alexander Duyck244e27a2012-02-08 07:51:11 +00006979 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006980
6981 /*
6982 * src and dst are inverted, think how the receiver sees them
6983 *
6984 * The input is broken into two sections, a non-compressed section
6985 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6986 * is XORed together and stored in the compressed dword.
6987 */
6988 input.formatted.vlan_id = vlan_id;
6989
6990 /*
6991 * since src port and flex bytes occupy the same word XOR them together
6992 * and write the value to source port portion of compressed dword
6993 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006994 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00006995 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00006996 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006997 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006998 common.port.dst ^= th->source;
6999
Joe Perchesa1108ff2014-03-13 05:19:25 +00007000 if (first->protocol == htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00007001 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7002 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
7003 } else {
7004 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7005 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7006 hdr.ipv6->saddr.s6_addr32[1] ^
7007 hdr.ipv6->saddr.s6_addr32[2] ^
7008 hdr.ipv6->saddr.s6_addr32[3] ^
7009 hdr.ipv6->daddr.s6_addr32[0] ^
7010 hdr.ipv6->daddr.s6_addr32[1] ^
7011 hdr.ipv6->daddr.s6_addr32[2] ^
7012 hdr.ipv6->daddr.s6_addr32[3];
7013 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007014
7015 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007016 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7017 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007018}
7019
Jason Wangf663dd92014-01-10 16:18:26 +08007020static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01007021 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007022{
Jason Wangf663dd92014-01-10 16:18:26 +08007023 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7024#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00007025 struct ixgbe_adapter *adapter;
7026 struct ixgbe_ring_feature *f;
7027 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08007028#endif
7029
7030 if (fwd_adapter)
7031 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7032
7033#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00007034
Alexander Duyck97488bd2013-01-12 06:33:37 +00007035 /*
7036 * only execute the code below if protocol is FCoE
7037 * or FIP and we have FCoE enabled on the adapter
7038 */
7039 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00007040 case htons(ETH_P_FCOE):
7041 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00007042 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00007043
Alexander Duyck97488bd2013-01-12 06:33:37 +00007044 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7045 break;
7046 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01007047 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007048 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007049
Alexander Duyck97488bd2013-01-12 06:33:37 +00007050 f = &adapter->ring_feature[RING_F_FCOE];
7051
7052 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7053 smp_processor_id();
7054
7055 while (txq >= f->indices)
7056 txq -= f->indices;
7057
7058 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08007059#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01007060 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08007061#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007062}
7063
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007064netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007065 struct ixgbe_adapter *adapter,
7066 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007067{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007068 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007069 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007070 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007071 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00007072 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007073 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007074 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007075
Alexander Duycka535c302011-05-27 05:31:52 +00007076 /*
7077 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007078 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007079 * + 2 desc gap to keep tail from touching head,
7080 * + 1 desc for context descriptor,
7081 * otherwise try next time
7082 */
Alexander Duycka535c302011-05-27 05:31:52 +00007083 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7084 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00007085
Alexander Duycka535c302011-05-27 05:31:52 +00007086 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7087 tx_ring->tx_stats.tx_busy++;
7088 return NETDEV_TX_BUSY;
7089 }
7090
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007091 /* record the location of the first descriptor for this packet */
7092 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7093 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00007094 first->bytecount = skb->len;
7095 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007096
Alexander Duyck66f32a82011-06-29 05:43:22 +00007097 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007098 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007099 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7100 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7101 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007102 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007103 struct vlan_hdr *vhdr, _vhdr;
7104 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7105 if (!vhdr)
7106 goto out_drop;
7107
7108 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007109 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7110 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007111 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007112 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007113
Jakub Kicinski151b260c2014-03-15 14:55:21 +00007114 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
7115 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
7116 &adapter->state))) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007117 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
7118 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00007119
7120 /* schedule check for Tx timestamp */
7121 adapter->ptp_tx_skb = skb_get(skb);
7122 adapter->ptp_tx_start = jiffies;
7123 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007124 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007125
Jakub Kicinskiff29a862014-03-15 14:55:16 +00007126 skb_tx_timestamp(skb);
7127
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007128#ifdef CONFIG_PCI_IOV
7129 /*
7130 * Use the l2switch_enable flag - would be false if the DMA
7131 * Tx switch had been disabled.
7132 */
7133 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00007134 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007135
7136#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007137 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007138 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007139 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7140 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007141 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007142 tx_flags |= (skb->priority & 0x7) <<
7143 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007144 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7145 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007146
7147 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00007148 goto out_drop;
7149 vhdr = (struct vlan_ethhdr *)skb->data;
7150 vhdr->h_vlan_TCI = htons(tx_flags >>
7151 IXGBE_TX_FLAGS_VLAN_SHIFT);
7152 } else {
7153 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7154 }
7155 }
Alexander Duycka535c302011-05-27 05:31:52 +00007156
Alexander Duyck244e27a2012-02-08 07:51:11 +00007157 /* record initial flags and protocol */
7158 first->tx_flags = tx_flags;
7159 first->protocol = protocol;
7160
Yi Zoueacd73f2009-05-13 13:11:06 +00007161#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007162 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007163 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00007164 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00007165 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00007166 if (tso < 0)
7167 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07007168
Alexander Duyck66f32a82011-06-29 05:43:22 +00007169 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007170 }
Auke Kok9a799d72007-09-15 14:07:45 -07007171
Auke Kok9a799d72007-09-15 14:07:45 -07007172#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007173 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007174 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007175 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007176 else if (!tso)
7177 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007178
7179 /* add the ATR filter if ATR is on */
7180 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00007181 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007182
7183#ifdef IXGBE_FCOE
7184xmit_fcoe:
7185#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007186 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007187
Auke Kok9a799d72007-09-15 14:07:45 -07007188 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007189
7190out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007191 dev_kfree_skb_any(first->skb);
7192 first->skb = NULL;
7193
Alexander Duyck897ab152011-05-27 05:31:47 +00007194 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007195}
7196
John Fastabend2a47fa42013-11-06 09:54:52 -08007197static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
7198 struct net_device *netdev,
7199 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007200{
7201 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007202 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07007203
Alexander Duycka50c29d2012-02-08 07:50:40 +00007204 /*
7205 * The minimum packet size for olinfo paylen is 17 so pad the skb
7206 * in order to meet this minimum size requirement.
7207 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00007208 if (unlikely(skb->len < 17)) {
7209 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00007210 return NETDEV_TX_OK;
7211 skb->len = 17;
Tushar Dave71a49f72012-09-14 04:24:49 +00007212 skb_set_tail_pointer(skb, 17);
Alexander Duycka50c29d2012-02-08 07:50:40 +00007213 }
7214
John Fastabend2a47fa42013-11-06 09:54:52 -08007215 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
7216
Auke Kok9a799d72007-09-15 14:07:45 -07007217 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7218}
7219
John Fastabend2a47fa42013-11-06 09:54:52 -08007220static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7221 struct net_device *netdev)
7222{
7223 return __ixgbe_xmit_frame(skb, netdev, NULL);
7224}
7225
Auke Kok9a799d72007-09-15 14:07:45 -07007226/**
7227 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7228 * @netdev: network interface device structure
7229 * @p: pointer to an address structure
7230 *
7231 * Returns 0 on success, negative on failure
7232 **/
7233static int ixgbe_set_mac(struct net_device *netdev, void *p)
7234{
7235 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7236 struct ixgbe_hw *hw = &adapter->hw;
7237 struct sockaddr *addr = p;
Jacob Keller5d7daa32014-03-29 06:51:25 +00007238 int ret;
Auke Kok9a799d72007-09-15 14:07:45 -07007239
7240 if (!is_valid_ether_addr(addr->sa_data))
7241 return -EADDRNOTAVAIL;
7242
Jacob Keller5d7daa32014-03-29 06:51:25 +00007243 ixgbe_del_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
Auke Kok9a799d72007-09-15 14:07:45 -07007244 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007245 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007246
Jacob Keller5d7daa32014-03-29 06:51:25 +00007247 ret = ixgbe_add_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
7248 return ret > 0 ? 0 : ret;
Auke Kok9a799d72007-09-15 14:07:45 -07007249}
7250
Ben Hutchings6b73e102009-04-29 08:08:58 +00007251static int
7252ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7253{
7254 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7255 struct ixgbe_hw *hw = &adapter->hw;
7256 u16 value;
7257 int rc;
7258
7259 if (prtad != hw->phy.mdio.prtad)
7260 return -EINVAL;
7261 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7262 if (!rc)
7263 rc = value;
7264 return rc;
7265}
7266
7267static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7268 u16 addr, u16 value)
7269{
7270 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7271 struct ixgbe_hw *hw = &adapter->hw;
7272
7273 if (prtad != hw->phy.mdio.prtad)
7274 return -EINVAL;
7275 return hw->phy.ops.write_reg(hw, addr, devad, value);
7276}
7277
7278static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7279{
7280 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7281
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007282 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007283 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08007284 return ixgbe_ptp_set_ts_config(adapter, req);
7285 case SIOCGHWTSTAMP:
7286 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007287 default:
7288 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7289 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00007290}
7291
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007292/**
7293 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007294 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007295 * @netdev: network interface device structure
7296 *
7297 * Returns non-zero on failure
7298 **/
7299static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7300{
7301 int err = 0;
7302 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007303 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007304
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007305 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007306 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007307 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007308 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007309
7310 /* update SAN MAC vmdq pool selection */
7311 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007312 }
7313 return err;
7314}
7315
7316/**
7317 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007318 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007319 * @netdev: network interface device structure
7320 *
7321 * Returns non-zero on failure
7322 **/
7323static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7324{
7325 int err = 0;
7326 struct ixgbe_adapter *adapter = netdev_priv(dev);
7327 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7328
7329 if (is_valid_ether_addr(mac->san_addr)) {
7330 rtnl_lock();
7331 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7332 rtnl_unlock();
7333 }
7334 return err;
7335}
7336
Auke Kok9a799d72007-09-15 14:07:45 -07007337#ifdef CONFIG_NET_POLL_CONTROLLER
7338/*
7339 * Polling 'interrupt' - used by things like netconsole to send skbs
7340 * without having to re-enable interrupts. It's not called while
7341 * the interrupt routine is executing.
7342 */
7343static void ixgbe_netpoll(struct net_device *netdev)
7344{
7345 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007346 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007347
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007348 /* if interface is down do nothing */
7349 if (test_bit(__IXGBE_DOWN, &adapter->state))
7350 return;
7351
Auke Kok9a799d72007-09-15 14:07:45 -07007352 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007353 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00007354 for (i = 0; i < adapter->num_q_vectors; i++)
7355 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007356 } else {
7357 ixgbe_intr(adapter->pdev->irq, netdev);
7358 }
Auke Kok9a799d72007-09-15 14:07:45 -07007359 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007360}
Auke Kok9a799d72007-09-15 14:07:45 -07007361
Alexander Duyck581330b2012-02-08 07:51:47 +00007362#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00007363static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7364 struct rtnl_link_stats64 *stats)
7365{
7366 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7367 int i;
7368
Eric Dumazet1a515022010-11-16 19:26:42 -08007369 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007370 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007371 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007372 u64 bytes, packets;
7373 unsigned int start;
7374
Eric Dumazet1a515022010-11-16 19:26:42 -08007375 if (ring) {
7376 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07007377 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08007378 packets = ring->stats.packets;
7379 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07007380 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08007381 stats->rx_packets += packets;
7382 stats->rx_bytes += bytes;
7383 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007384 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007385
7386 for (i = 0; i < adapter->num_tx_queues; i++) {
7387 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7388 u64 bytes, packets;
7389 unsigned int start;
7390
7391 if (ring) {
7392 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07007393 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007394 packets = ring->stats.packets;
7395 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07007396 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007397 stats->tx_packets += packets;
7398 stats->tx_bytes += bytes;
7399 }
7400 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007401 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007402 /* following stats updated by ixgbe_watchdog_task() */
7403 stats->multicast = netdev->stats.multicast;
7404 stats->rx_errors = netdev->stats.rx_errors;
7405 stats->rx_length_errors = netdev->stats.rx_length_errors;
7406 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7407 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7408 return stats;
7409}
7410
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007411#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007412/**
7413 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7414 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00007415 * @tc: number of traffic classes currently enabled
7416 *
7417 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7418 * 802.1Q priority maps to a packet buffer that exists.
7419 */
7420static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7421{
7422 struct ixgbe_hw *hw = &adapter->hw;
7423 u32 reg, rsave;
7424 int i;
7425
7426 /* 82598 have a static priority to TC mapping that can not
7427 * be changed so no validation is needed.
7428 */
7429 if (hw->mac.type == ixgbe_mac_82598EB)
7430 return;
7431
7432 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7433 rsave = reg;
7434
7435 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7436 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7437
7438 /* If up2tc is out of bounds default to zero */
7439 if (up2tc > tc)
7440 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7441 }
7442
7443 if (reg != rsave)
7444 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7445
7446 return;
7447}
7448
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007449/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00007450 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
7451 * @adapter: Pointer to adapter struct
7452 *
7453 * Populate the netdev user priority to tc map
7454 */
7455static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
7456{
7457 struct net_device *dev = adapter->netdev;
7458 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
7459 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
7460 u8 prio;
7461
7462 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
7463 u8 tc = 0;
7464
7465 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
7466 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
7467 else if (ets)
7468 tc = ets->prio_tc[prio];
7469
7470 netdev_set_prio_tc_map(dev, prio, tc);
7471 }
7472}
7473
Alexander Duyckcca73c52013-01-12 06:33:44 +00007474#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00007475/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007476 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00007477 *
7478 * @netdev: net device to configure
7479 * @tc: number of traffic classes to enable
7480 */
7481int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7482{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007483 struct ixgbe_adapter *adapter = netdev_priv(dev);
7484 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08007485 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007486
John Fastabend8b1c0b22011-05-03 02:26:48 +00007487 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007488 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00007489 (hw->mac.type == ixgbe_mac_82598EB &&
7490 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00007491 return -EINVAL;
7492
John Fastabend2a47fa42013-11-06 09:54:52 -08007493 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
7494 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
7495 return -EBUSY;
7496
John Fastabend8b1c0b22011-05-03 02:26:48 +00007497 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007498 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007499 * hardware is not flexible enough to do this dynamically.
7500 */
7501 if (netif_running(dev))
7502 ixgbe_close(dev);
7503 ixgbe_clear_interrupt_scheme(adapter);
7504
Alexander Duyckcca73c52013-01-12 06:33:44 +00007505#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00007506 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007507 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007508 ixgbe_set_prio_tc_map(adapter);
7509
John Fastabende7589ea2011-07-18 22:38:36 +00007510 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007511
Alexander Duyck943561d2012-05-09 22:14:44 -07007512 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
7513 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007514 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07007515 }
John Fastabende7589ea2011-07-18 22:38:36 +00007516 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007517 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007518
Alexander Duyck943561d2012-05-09 22:14:44 -07007519 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7520 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007521
7522 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007523
7524 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7525 adapter->dcb_cfg.pfc_mode_enable = false;
7526 }
7527
John Fastabend8b1c0b22011-05-03 02:26:48 +00007528 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00007529
7530#endif /* CONFIG_IXGBE_DCB */
7531 ixgbe_init_interrupt_scheme(adapter);
7532
John Fastabend8b1c0b22011-05-03 02:26:48 +00007533 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00007534 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00007535
7536 return 0;
7537}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007538
Greg Roseda36b642012-12-11 08:26:43 +00007539#ifdef CONFIG_PCI_IOV
7540void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
7541{
7542 struct net_device *netdev = adapter->netdev;
7543
7544 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00007545 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00007546 rtnl_unlock();
7547}
7548
7549#endif
Don Skidmore082757a2011-07-21 05:55:00 +00007550void ixgbe_do_reset(struct net_device *netdev)
7551{
7552 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7553
7554 if (netif_running(netdev))
7555 ixgbe_reinit_locked(adapter);
7556 else
7557 ixgbe_reset(adapter);
7558}
7559
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007560static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007561 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007562{
7563 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7564
Don Skidmore082757a2011-07-21 05:55:00 +00007565 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007566 if (!(features & NETIF_F_RXCSUM))
7567 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00007568
Alexander Duyck567d2de2012-02-11 07:18:57 +00007569 /* Turn off LRO if not RSC capable */
7570 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
7571 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007572
Alexander Duyck567d2de2012-02-11 07:18:57 +00007573 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00007574}
7575
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007576static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007577 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007578{
7579 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00007580 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00007581 bool need_reset = false;
7582
Don Skidmore082757a2011-07-21 05:55:00 +00007583 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007584 if (!(features & NETIF_F_LRO)) {
7585 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00007586 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00007587 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
7588 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
7589 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7590 if (adapter->rx_itr_setting == 1 ||
7591 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
7592 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
7593 need_reset = true;
7594 } else if ((changed ^ features) & NETIF_F_LRO) {
7595 e_info(probe, "rx-usecs set too low, "
7596 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00007597 }
7598 }
7599
7600 /*
7601 * Check if Flow Director n-tuple support was enabled or disabled. If
7602 * the state changed, we need to reset.
7603 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007604 switch (features & NETIF_F_NTUPLE) {
7605 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00007606 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007607 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
7608 need_reset = true;
7609
Alexander Duyck567d2de2012-02-11 07:18:57 +00007610 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7611 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00007612 break;
7613 default:
7614 /* turn off perfect filters, enable ATR and reset */
7615 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7616 need_reset = true;
7617
7618 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7619
7620 /* We cannot enable ATR if SR-IOV is enabled */
7621 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7622 break;
7623
7624 /* We cannot enable ATR if we have 2 or more traffic classes */
7625 if (netdev_get_num_tc(netdev) > 1)
7626 break;
7627
7628 /* We cannot enable ATR if RSS is disabled */
7629 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
7630 break;
7631
7632 /* A sample rate of 0 indicates ATR disabled */
7633 if (!adapter->atr_sample_rate)
7634 break;
7635
7636 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7637 break;
Don Skidmore082757a2011-07-21 05:55:00 +00007638 }
7639
Patrick McHardyf6469682013-04-19 02:04:27 +00007640 if (features & NETIF_F_HW_VLAN_CTAG_RX)
John Fastabend146d4cc2012-05-15 05:59:26 +00007641 ixgbe_vlan_strip_enable(adapter);
7642 else
7643 ixgbe_vlan_strip_disable(adapter);
7644
Ben Greear3f2d1c02012-03-08 08:28:41 +00007645 if (changed & NETIF_F_RXALL)
7646 need_reset = true;
7647
Alexander Duyck567d2de2012-02-11 07:18:57 +00007648 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00007649 if (need_reset)
7650 ixgbe_do_reset(netdev);
7651
7652 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00007653}
7654
stephen hemmingeredc7d572012-10-01 12:32:33 +00007655static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007656 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00007657 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007658 u16 flags)
7659{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00007660 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00007661 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyckbcfd3432014-07-17 02:11:22 +00007662 if (IXGBE_MAX_PF_MACVLANS <= netdev_uc_count(dev))
7663 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007664 }
7665
Alexander Duyckbcfd3432014-07-17 02:11:22 +00007666 return ndo_dflt_fdb_add(ndm, tb, dev, addr, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007667}
7668
John Fastabend815cccb2012-10-24 08:13:09 +00007669static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7670 struct nlmsghdr *nlh)
7671{
7672 struct ixgbe_adapter *adapter = netdev_priv(dev);
7673 struct nlattr *attr, *br_spec;
7674 int rem;
7675
7676 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7677 return -EOPNOTSUPP;
7678
7679 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7680
7681 nla_for_each_nested(attr, br_spec, rem) {
7682 __u16 mode;
7683 u32 reg = 0;
7684
7685 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7686 continue;
7687
7688 mode = nla_get_u16(attr);
Greg Rose9b735982012-11-08 02:41:35 +00007689 if (mode == BRIDGE_MODE_VEPA) {
John Fastabend815cccb2012-10-24 08:13:09 +00007690 reg = 0;
Greg Rose9b735982012-11-08 02:41:35 +00007691 adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB;
7692 } else if (mode == BRIDGE_MODE_VEB) {
John Fastabend815cccb2012-10-24 08:13:09 +00007693 reg = IXGBE_PFDTXGSWC_VT_LBEN;
Greg Rose9b735982012-11-08 02:41:35 +00007694 adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB;
7695 } else
John Fastabend815cccb2012-10-24 08:13:09 +00007696 return -EINVAL;
7697
7698 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7699
7700 e_info(drv, "enabling bridge mode: %s\n",
7701 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7702 }
7703
7704 return 0;
7705}
7706
7707static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00007708 struct net_device *dev,
7709 u32 filter_mask)
John Fastabend815cccb2012-10-24 08:13:09 +00007710{
7711 struct ixgbe_adapter *adapter = netdev_priv(dev);
7712 u16 mode;
7713
7714 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7715 return 0;
7716
Greg Rose9b735982012-11-08 02:41:35 +00007717 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
John Fastabend815cccb2012-10-24 08:13:09 +00007718 mode = BRIDGE_MODE_VEB;
7719 else
7720 mode = BRIDGE_MODE_VEPA;
7721
7722 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7723}
7724
John Fastabend2a47fa42013-11-06 09:54:52 -08007725static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
7726{
7727 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
7728 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00007729 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08007730 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08007731 int pool, err;
7732
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00007733 /* Hardware has a limited number of available pools. Each VF, and the
7734 * PF require a pool. Check to ensure we don't attempt to use more
7735 * then the available number of pools.
7736 */
7737 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
7738 return ERR_PTR(-EINVAL);
7739
John Fastabend219354d2013-11-08 00:50:32 -08007740#ifdef CONFIG_RPS
7741 if (vdev->num_rx_queues != vdev->num_tx_queues) {
7742 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
7743 vdev->name);
7744 return ERR_PTR(-EINVAL);
7745 }
7746#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08007747 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08007748 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08007749 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
7750 netdev_info(pdev,
7751 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
7752 pdev->name);
7753 return ERR_PTR(-EINVAL);
7754 }
7755
7756 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
7757 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
7758 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
7759 return ERR_PTR(-EBUSY);
7760
7761 fwd_adapter = kcalloc(1, sizeof(struct ixgbe_fwd_adapter), GFP_KERNEL);
7762 if (!fwd_adapter)
7763 return ERR_PTR(-ENOMEM);
7764
7765 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
7766 adapter->num_rx_pools++;
7767 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08007768 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08007769
7770 /* Enable VMDq flag so device will be set in VM mode */
7771 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08007772 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08007773 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08007774
7775 /* Force reinit of ring allocation with VMDQ enabled */
7776 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
7777 if (err)
7778 goto fwd_add_err;
7779 fwd_adapter->pool = pool;
7780 fwd_adapter->real_adapter = adapter;
7781 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
7782 if (err)
7783 goto fwd_add_err;
7784 netif_tx_start_all_queues(vdev);
7785 return fwd_adapter;
7786fwd_add_err:
7787 /* unwind counter and free adapter struct */
7788 netdev_info(pdev,
7789 "%s: dfwd hardware acceleration failed\n", vdev->name);
7790 clear_bit(pool, &adapter->fwd_bitmask);
7791 adapter->num_rx_pools--;
7792 kfree(fwd_adapter);
7793 return ERR_PTR(err);
7794}
7795
7796static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
7797{
7798 struct ixgbe_fwd_adapter *fwd_adapter = priv;
7799 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08007800 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08007801
7802 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
7803 adapter->num_rx_pools--;
7804
John Fastabend51f37732013-11-08 00:51:10 -08007805 limit = find_last_bit(&adapter->fwd_bitmask, 32);
7806 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08007807 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
7808 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
7809 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
7810 fwd_adapter->pool, adapter->num_rx_pools,
7811 fwd_adapter->rx_base_queue,
7812 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
7813 adapter->fwd_bitmask);
7814 kfree(fwd_adapter);
7815}
7816
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007817static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007818 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007819 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007820 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007821 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00007822 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007823 .ndo_validate_addr = eth_validate_addr,
7824 .ndo_set_mac_address = ixgbe_set_mac,
7825 .ndo_change_mtu = ixgbe_change_mtu,
7826 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007827 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7828 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007829 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007830 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7831 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04007832 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007833 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007834 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007835 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007836#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007837 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007838#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007839#ifdef CONFIG_NET_POLL_CONTROLLER
7840 .ndo_poll_controller = ixgbe_netpoll,
7841#endif
Cong Wange0d10952013-08-01 11:10:25 +08007842#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03007843 .ndo_busy_poll = ixgbe_low_latency_recv,
Eliezer Tamir5a85e732013-06-10 11:40:20 +03007844#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007845#ifdef IXGBE_FCOE
7846 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007847 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007848 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007849 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7850 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007851 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007852 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007853#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007854 .ndo_set_features = ixgbe_set_features,
7855 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007856 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00007857 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7858 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08007859 .ndo_dfwd_add_station = ixgbe_fwd_add,
7860 .ndo_dfwd_del_station = ixgbe_fwd_del,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007861};
7862
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007863/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00007864 * ixgbe_enumerate_functions - Get the number of ports this device has
7865 * @adapter: adapter structure
7866 *
7867 * This function enumerates the phsyical functions co-located on a single slot,
7868 * in order to determine how many ports a device has. This is most useful in
7869 * determining the required GT/s of PCIe bandwidth necessary for optimal
7870 * performance.
7871 **/
7872static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
7873{
Jacob Kellercaafb952014-07-19 07:17:17 +00007874 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00007875 int physfns = 0;
7876
Jacob Kellerf1f96572013-08-31 02:45:38 +00007877 /* Some cards can not use the generic count PCIe functions method,
7878 * because they are behind a parent switch, so we hardcode these with
7879 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00007880 */
Jacob Keller88189702014-07-19 07:17:16 +00007881 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00007882 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00007883
7884 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
7885 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00007886 if (entry->is_virtfn)
7887 continue;
7888
7889 /* When the devices on the bus don't all match our device ID,
7890 * we can't reliably determine the correct number of
7891 * functions. This can occur if a function has been direct
7892 * attached to a virtual machine using VT-d, for example. In
7893 * this case, simply return -1 to indicate this.
7894 */
7895 if ((entry->vendor != pdev->vendor) ||
7896 (entry->device != pdev->device))
7897 return -1;
7898
7899 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00007900 }
7901
7902 return physfns;
7903}
7904
7905/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007906 * ixgbe_wol_supported - Check whether device supports WoL
7907 * @hw: hw specific details
7908 * @device_id: the device ID
7909 * @subdev_id: the subsystem device ID
7910 *
7911 * This function is used by probe and ethtool to determine
7912 * which devices have WoL support
7913 *
7914 **/
7915int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7916 u16 subdevice_id)
7917{
7918 struct ixgbe_hw *hw = &adapter->hw;
7919 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7920 int is_wol_supported = 0;
7921
7922 switch (device_id) {
7923 case IXGBE_DEV_ID_82599_SFP:
7924 /* Only these subdevices could supports WOL */
7925 switch (subdevice_id) {
Mark Rustad87557442014-02-25 17:58:55 -08007926 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007927 case IXGBE_SUBDEV_ID_82599_560FLR:
7928 /* only support first port */
7929 if (hw->bus.func != 0)
7930 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00007931 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007932 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007933 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00007934 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller979fe5f2013-04-03 04:41:37 +00007935 case IXGBE_SUBDEV_ID_82599_LOM_SFP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007936 is_wol_supported = 1;
7937 break;
7938 }
7939 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00007940 case IXGBE_DEV_ID_82599EN_SFP:
7941 /* Only this subdevice supports WOL */
7942 switch (subdevice_id) {
7943 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
7944 is_wol_supported = 1;
7945 break;
7946 }
7947 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007948 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7949 /* All except this subdevice support WOL */
7950 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7951 is_wol_supported = 1;
7952 break;
7953 case IXGBE_DEV_ID_82599_KX4:
7954 is_wol_supported = 1;
7955 break;
7956 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007957 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007958 /* check eeprom to see if enabled wol */
7959 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7960 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7961 (hw->bus.func == 0))) {
7962 is_wol_supported = 1;
7963 }
7964 break;
7965 }
7966
7967 return is_wol_supported;
7968}
7969
7970/**
Auke Kok9a799d72007-09-15 14:07:45 -07007971 * ixgbe_probe - Device Initialization Routine
7972 * @pdev: PCI device information struct
7973 * @ent: entry in ixgbe_pci_tbl
7974 *
7975 * Returns 0 on success, negative on failure
7976 *
7977 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7978 * The OS initialization, configuring of the adapter private structure,
7979 * and a hardware reset occur.
7980 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00007981static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007982{
7983 struct net_device *netdev;
7984 struct ixgbe_adapter *adapter = NULL;
7985 struct ixgbe_hw *hw;
7986 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007987 static int cards_found;
Jacob Kellere027d1a2013-07-31 06:53:31 +00007988 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007989 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00007990 u8 part_str[IXGBE_PBANUM_LENGTH];
Yi Zoueacd73f2009-05-13 13:11:06 +00007991#ifdef IXGBE_FCOE
7992 u16 device_caps;
7993#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007994 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007995
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007996 /* Catch broken hardware that put the wrong VF device ID in
7997 * the PCIe SR-IOV capability.
7998 */
7999 if (pdev->is_virtfn) {
8000 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
8001 pci_name(pdev), pdev->vendor, pdev->device);
8002 return -EINVAL;
8003 }
8004
gouji-new9ce77662009-05-06 10:44:45 +00008005 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008006 if (err)
8007 return err;
8008
Russell Kingf5f2eda2013-06-10 12:47:42 +01008009 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07008010 pci_using_dac = 1;
8011 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01008012 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07008013 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01008014 dev_err(&pdev->dev,
8015 "No usable DMA configuration, aborting\n");
8016 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07008017 }
8018 pci_using_dac = 0;
8019 }
8020
gouji-new9ce77662009-05-06 10:44:45 +00008021 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008022 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07008023 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00008024 dev_err(&pdev->dev,
8025 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07008026 goto err_pci_reg;
8027 }
8028
Frans Pop19d5afd2009-10-02 10:04:12 -07008029 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008030
Auke Kok9a799d72007-09-15 14:07:45 -07008031 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07008032 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008033
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008034 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00008035#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008036 /* 8 TC w/ 4 queues per TC */
8037 indices = 4 * MAX_TRAFFIC_CLASS;
8038#else
8039 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00008040#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008041 }
John Fastabende901acd2011-04-26 07:26:08 +00008042
John Fastabendc85a2612010-02-25 23:15:21 +00008043 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07008044 if (!netdev) {
8045 err = -ENOMEM;
8046 goto err_alloc_etherdev;
8047 }
8048
Auke Kok9a799d72007-09-15 14:07:45 -07008049 SET_NETDEV_DEV(netdev, &pdev->dev);
8050
Auke Kok9a799d72007-09-15 14:07:45 -07008051 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008052 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008053
8054 adapter->netdev = netdev;
8055 adapter->pdev = pdev;
8056 hw = &adapter->hw;
8057 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00008058 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07008059
Jeff Kirsher05857982008-09-11 19:57:00 -07008060 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00008061 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08008062 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07008063 if (!hw->hw_addr) {
8064 err = -EIO;
8065 goto err_ioremap;
8066 }
8067
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008068 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07008069 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008070 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +00008071 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -07008072
Auke Kok9a799d72007-09-15 14:07:45 -07008073 adapter->bd_number = cards_found;
8074
Auke Kok9a799d72007-09-15 14:07:45 -07008075 /* Setup hw api */
8076 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008077 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07008078
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008079 /* EEPROM */
8080 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
8081 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
Mark Rustad58cf6632014-03-12 00:38:40 +00008082 if (ixgbe_removed(hw->hw_addr)) {
8083 err = -EIO;
8084 goto err_ioremap;
8085 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008086 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
8087 if (!(eec & (1 << 8)))
8088 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
8089
8090 /* PHY */
8091 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08008092 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00008093 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
8094 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
8095 hw->phy.mdio.mmds = 0;
8096 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
8097 hw->phy.mdio.dev = netdev;
8098 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
8099 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08008100
Don Skidmore8ca783a2009-05-26 20:40:47 -07008101 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07008102
8103 /* setup the private structure */
8104 err = ixgbe_sw_init(adapter);
8105 if (err)
8106 goto err_sw_init;
8107
Don Skidmoree86bff02010-02-11 04:14:08 +00008108 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08008109 switch (adapter->hw.mac.type) {
8110 case ixgbe_mac_82599EB:
8111 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00008112 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08008113 break;
8114 default:
8115 break;
8116 }
Don Skidmoree86bff02010-02-11 04:14:08 +00008117
Don Skidmorebf069c92009-05-07 10:39:54 +00008118 /*
8119 * If there is a fan on this device and it has failed log the
8120 * failure.
8121 */
8122 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
8123 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
8124 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00008125 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00008126 }
8127
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00008128 if (allow_unsupported_sfp)
8129 hw->allow_unsupported_sfp = allow_unsupported_sfp;
8130
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008131 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07008132 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008133 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07008134 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07008135 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
8136 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07008137 err = 0;
8138 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00008139 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
8140 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008141 goto err_sw_init;
8142 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008143 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008144 goto err_sw_init;
8145 }
8146
Alexander Duyck99d74482012-05-09 08:09:25 +00008147#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00008148 /* SR-IOV not supported on the 82598 */
8149 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8150 goto skip_sriov;
8151 /* Mailbox */
8152 ixgbe_init_mbx_params_pf(hw);
8153 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
ethan.zhaodcc23e32014-01-16 19:41:04 -08008154 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ethan.zhao31ac9102014-01-16 19:41:05 -08008155 ixgbe_enable_sriov(adapter);
Greg Rose60a1a682012-12-11 08:26:33 +00008156skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008157
Alexander Duyck99d74482012-05-09 08:09:25 +00008158#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00008159 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00008160 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00008161 NETIF_F_IPV6_CSUM |
Patrick McHardyf6469682013-04-19 02:04:27 +00008162 NETIF_F_HW_VLAN_CTAG_TX |
8163 NETIF_F_HW_VLAN_CTAG_RX |
8164 NETIF_F_HW_VLAN_CTAG_FILTER |
Don Skidmore082757a2011-07-21 05:55:00 +00008165 NETIF_F_TSO |
8166 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00008167 NETIF_F_RXHASH |
John Fastabend8bf12642013-11-12 12:13:29 +00008168 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07008169
John Fastabend8bf12642013-11-12 12:13:29 +00008170 netdev->hw_features = netdev->features | NETIF_F_HW_L2FW_DOFFLOAD;
Jeff Kirsherad31c402008-06-05 04:05:30 -07008171
Don Skidmore58be7662011-04-12 09:42:11 +00008172 switch (adapter->hw.mac.type) {
8173 case ixgbe_mac_82599EB:
8174 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00008175 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00008176 netdev->hw_features |= NETIF_F_SCTP_CSUM |
8177 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00008178 break;
8179 default:
8180 break;
8181 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00008182
Ben Greear3f2d1c02012-03-08 08:28:41 +00008183 netdev->hw_features |= NETIF_F_RXALL;
8184
Jeff Kirsherad31c402008-06-05 04:05:30 -07008185 netdev->vlan_features |= NETIF_F_TSO;
8186 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07008187 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00008188 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07008189 netdev->vlan_features |= NETIF_F_SG;
8190
Jiri Pirko01789342011-08-16 06:29:00 +00008191 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00008192 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00008193
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08008194#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08008195 netdev->dcbnl_ops = &dcbnl_ops;
8196#endif
8197
Yi Zoueacd73f2009-05-13 13:11:06 +00008198#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00008199 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008200 unsigned int fcoe_l;
8201
Yi Zoueacd73f2009-05-13 13:11:06 +00008202 if (hw->mac.ops.get_device_caps) {
8203 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00008204 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
8205 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00008206 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008207
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008208
8209 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
8210 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008211
Alexander Duycka58915c2012-05-25 06:38:18 +00008212 netdev->features |= NETIF_F_FSO |
8213 NETIF_F_FCOE_CRC;
8214
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008215 netdev->vlan_features |= NETIF_F_FSO |
8216 NETIF_F_FCOE_CRC |
8217 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00008218 }
Yi Zoueacd73f2009-05-13 13:11:06 +00008219#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00008220 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07008221 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00008222 netdev->vlan_features |= NETIF_F_HIGHDMA;
8223 }
Auke Kok9a799d72007-09-15 14:07:45 -07008224
Don Skidmore082757a2011-07-21 05:55:00 +00008225 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
8226 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00008227 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00008228 netdev->features |= NETIF_F_LRO;
8229
Auke Kok9a799d72007-09-15 14:07:45 -07008230 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008231 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008232 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07008233 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00008234 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008235 }
8236
8237 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008238
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00008239 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008240 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07008241 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00008242 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008243 }
8244
Jacob Keller5d7daa32014-03-29 06:51:25 +00008245 ixgbe_mac_set_default_filter(adapter, hw->mac.perm_addr);
8246
Alexander Duyck70864002011-04-27 09:13:56 +00008247 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00008248 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008249
Mark Rustad58cf6632014-03-12 00:38:40 +00008250 if (ixgbe_removed(hw->hw_addr)) {
8251 err = -EIO;
8252 goto err_sw_init;
8253 }
Alexander Duyck70864002011-04-27 09:13:56 +00008254 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +00008255 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008256 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07008257
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008258 err = ixgbe_init_interrupt_scheme(adapter);
8259 if (err)
8260 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008261
Jacob Keller8e2813f2012-04-21 06:05:40 +00008262 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00008263 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008264 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00008265 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00008266 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00008267 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00008268 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00008269
PJ Waskiewicze8e26352009-02-27 15:45:05 +00008270 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
8271
Emil Tantilov15e52092011-09-29 05:01:29 +00008272 /* save off EEPROM version number */
8273 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
8274 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
8275
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008276 /* pick up the PCI bus settings for reporting later */
8277 hw->mac.ops.get_bus_info(hw);
Jacob Kellere027d1a2013-07-31 06:53:31 +00008278 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00008279 ixgbe_get_parent_bus_info(adapter);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008280
Jacob Kellere027d1a2013-07-31 06:53:31 +00008281 /* calculate the expected PCIe bandwidth required for optimal
8282 * performance. Note that some older parts will never have enough
8283 * bandwidth due to being older generation PCIe parts. We clamp these
8284 * parts to ensure no warning is displayed if it can't be fixed.
8285 */
8286 switch (hw->mac.type) {
8287 case ixgbe_mac_82598EB:
8288 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
8289 break;
8290 default:
8291 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
8292 break;
Auke Kok0c254d82008-02-11 09:25:56 -08008293 }
Jacob Kellercaafb952014-07-19 07:17:17 +00008294
8295 /* don't check link if we failed to enumerate functions */
8296 if (expected_gts > 0)
8297 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08008298
Mark Rustad339de302014-06-06 01:57:06 +00008299 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00008300 if (err)
Mark Rustad339de302014-06-06 01:57:06 +00008301 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00008302 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
8303 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
8304 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +00008305 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +00008306 else
8307 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
8308 hw->mac.type, hw->phy.type, part_str);
8309
8310 e_dev_info("%pM\n", netdev->dev_addr);
8311
Auke Kok9a799d72007-09-15 14:07:45 -07008312 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008313 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008314 if (err == IXGBE_ERR_EEPROM_VERSION) {
8315 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00008316 e_dev_warn("This device is a pre-production adapter/LOM. "
8317 "Please be aware there may be issues associated "
8318 "with your hardware. If you are experiencing "
8319 "problems please contact your Intel or hardware "
8320 "representative who provided you with this "
8321 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008322 }
Auke Kok9a799d72007-09-15 14:07:45 -07008323 strcpy(netdev->name, "eth%d");
8324 err = register_netdev(netdev);
8325 if (err)
8326 goto err_register;
8327
Emil Tantilovec74a472012-09-20 03:33:56 +00008328 /* power down the optics for 82599 SFP+ fiber */
8329 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00008330 hw->mac.ops.disable_tx_laser(hw);
8331
Jesse Brandeburg54386462009-04-17 20:44:27 +00008332 /* carrier off reporting is important to ethtool even BEFORE open */
8333 netif_carrier_off(netdev);
8334
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008335#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03008336 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008337 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008338 ixgbe_setup_dca(adapter);
8339 }
8340#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008341 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008342 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008343 for (i = 0; i < adapter->num_vfs; i++)
8344 ixgbe_vf_configuration(pdev, (i | 0x10000000));
8345 }
8346
Jacob Keller2466dd92011-09-08 03:50:54 +00008347 /* firmware requires driver version to be 0xFFFFFFFF
8348 * since os does not support feature
8349 */
Emil Tantilov9612de92011-05-07 07:40:20 +00008350 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00008351 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
8352 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00008353
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008354 /* add san mac addr to netdev */
8355 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008356
Neerav Parikhea818752012-01-04 20:23:40 +00008357 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07008358 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008359
Don Skidmore12109822012-05-04 06:07:08 +00008360#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008361 if (ixgbe_sysfs_init(adapter))
8362 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00008363#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008364
Catherine Sullivan00949162012-08-10 01:59:10 +00008365 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00008366
Emil Tantilovd1a35ee2014-05-13 08:24:00 +00008367 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
8368 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +00008369 hw->mac.ops.setup_link(hw,
8370 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
8371 true);
8372
Auke Kok9a799d72007-09-15 14:07:45 -07008373 return 0;
8374
8375err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008376 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00008377 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008378err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00008379 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00008380 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -08008381 iounmap(adapter->io_addr);
Jacob Keller5d7daa32014-03-29 06:51:25 +00008382 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -07008383err_ioremap:
8384 free_netdev(netdev);
8385err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00008386 pci_release_selected_regions(pdev,
8387 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008388err_pci_reg:
8389err_dma:
Mark Rustad508a8c92014-06-06 01:57:00 +00008390 if (!adapter || !test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
Mark Rustad41c62842014-03-12 00:38:35 +00008391 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008392 return err;
8393}
8394
8395/**
8396 * ixgbe_remove - Device Removal Routine
8397 * @pdev: PCI device information struct
8398 *
8399 * ixgbe_remove is called by the PCI subsystem to alert the driver
8400 * that it should release a PCI device. The could be caused by a
8401 * Hot-Plug event, or because the driver is going to be removed from
8402 * memory.
8403 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05008404static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07008405{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008406 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8407 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008408
Catherine Sullivan00949162012-08-10 01:59:10 +00008409 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00008410
Mark Rustad09f40ae2014-01-14 18:53:11 -08008411 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008412 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008413
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008414
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008415#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008416 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8417 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8418 dca_remove_requester(&pdev->dev);
8419 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8420 }
8421
8422#endif
Don Skidmore12109822012-05-04 06:07:08 +00008423#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008424 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00008425#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008426
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008427 /* remove the added san mac */
8428 ixgbe_del_sanmac_netdev(netdev);
8429
Donald Skidmorec4900be2008-11-20 21:11:42 -08008430 if (netdev->reg_state == NETREG_REGISTERED)
8431 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008432
Greg Roseda36b642012-12-11 08:26:43 +00008433#ifdef CONFIG_PCI_IOV
8434 /*
8435 * Only disable SR-IOV on unload if the user specified the now
8436 * deprecated max_vfs module parameter.
8437 */
8438 if (max_vfs)
8439 ixgbe_disable_sriov(adapter);
8440#endif
Alexander Duyck7a921c92009-05-06 10:43:28 +00008441 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008442
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008443 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008444
Alexander Duyck2b1588c2012-03-17 02:39:16 +00008445#ifdef CONFIG_DCB
8446 kfree(adapter->ixgbe_ieee_pfc);
8447 kfree(adapter->ixgbe_ieee_ets);
8448
8449#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -08008450 iounmap(adapter->io_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008451 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008452 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008453
Emil Tantilov849c4542010-06-03 16:53:41 +00008454 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008455
Jacob Keller5d7daa32014-03-29 06:51:25 +00008456 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -07008457 free_netdev(netdev);
8458
Frans Pop19d5afd2009-10-02 10:04:12 -07008459 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008460
Mark Rustad41c62842014-03-12 00:38:35 +00008461 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
8462 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008463}
8464
8465/**
8466 * ixgbe_io_error_detected - called when PCI error is detected
8467 * @pdev: Pointer to PCI device
8468 * @state: The current pci connection state
8469 *
8470 * This function is called after a PCI bus error affecting
8471 * this device has been detected.
8472 */
8473static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008474 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008475{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008476 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8477 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008478
Greg Rose83c61fa2011-09-07 05:59:35 +00008479#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -08008480 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +00008481 struct pci_dev *bdev, *vfdev;
8482 u32 dw0, dw1, dw2, dw3;
8483 int vf, pos;
8484 u16 req_id, pf_func;
8485
8486 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8487 adapter->num_vfs == 0)
8488 goto skip_bad_vf_detection;
8489
8490 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08008491 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00008492 bdev = bdev->bus->self;
8493
8494 if (!bdev)
8495 goto skip_bad_vf_detection;
8496
8497 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8498 if (!pos)
8499 goto skip_bad_vf_detection;
8500
Mark Rustad14438462014-02-28 15:48:57 -08008501 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
8502 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
8503 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
8504 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
8505 if (ixgbe_removed(hw->hw_addr))
8506 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +00008507
8508 req_id = dw1 >> 16;
8509 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8510 if (!(req_id & 0x0080))
8511 goto skip_bad_vf_detection;
8512
8513 pf_func = req_id & 0x01;
8514 if ((pf_func & 1) == (pdev->devfn & 1)) {
8515 unsigned int device_id;
8516
8517 vf = (req_id & 0x7F) >> 1;
8518 e_dev_err("VF %d has caused a PCIe error\n", vf);
8519 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8520 "%8.8x\tdw3: %8.8x\n",
8521 dw0, dw1, dw2, dw3);
8522 switch (adapter->hw.mac.type) {
8523 case ixgbe_mac_82599EB:
8524 device_id = IXGBE_82599_VF_DEVICE_ID;
8525 break;
8526 case ixgbe_mac_X540:
8527 device_id = IXGBE_X540_VF_DEVICE_ID;
8528 break;
8529 default:
8530 device_id = 0;
8531 break;
8532 }
8533
8534 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00008535 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00008536 while (vfdev) {
8537 if (vfdev->devfn == (req_id & 0xFF))
8538 break;
Jon Mason36e90312012-07-19 21:02:09 +00008539 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00008540 device_id, vfdev);
8541 }
8542 /*
8543 * There's a slim chance the VF could have been hot plugged,
8544 * so if it is no longer present we don't need to issue the
8545 * VFLR. Just clean up the AER in that case.
8546 */
8547 if (vfdev) {
8548 e_dev_err("Issuing VFLR to VF %d\n", vf);
8549 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
Greg Roseb4fafbe2012-12-13 01:14:06 +00008550 /* Free device reference count */
8551 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +00008552 }
8553
8554 pci_cleanup_aer_uncorrect_error_status(pdev);
8555 }
8556
8557 /*
8558 * Even though the error may have occurred on the other port
8559 * we still need to increment the vf error reference count for
8560 * both ports because the I/O resume function will be called
8561 * for both of them.
8562 */
8563 adapter->vferr_refcount++;
8564
8565 return PCI_ERS_RESULT_RECOVERED;
8566
8567skip_bad_vf_detection:
8568#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +00008569 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
8570 return PCI_ERS_RESULT_DISCONNECT;
8571
Mark Rustad41c62842014-03-12 00:38:35 +00008572 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07008573 netif_device_detach(netdev);
8574
Mark Rustad41c62842014-03-12 00:38:35 +00008575 if (state == pci_channel_io_perm_failure) {
8576 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +00008577 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +00008578 }
Breno Leitao3044b8d2009-05-06 10:44:26 +00008579
Auke Kok9a799d72007-09-15 14:07:45 -07008580 if (netif_running(netdev))
8581 ixgbe_down(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +00008582
8583 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
8584 pci_disable_device(pdev);
8585 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -07008586
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008587 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008588 return PCI_ERS_RESULT_NEED_RESET;
8589}
8590
8591/**
8592 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8593 * @pdev: Pointer to PCI device
8594 *
8595 * Restart the card from scratch, as if from a cold-boot.
8596 */
8597static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8598{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008599 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008600 pci_ers_result_t result;
8601 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008602
gouji-new9ce77662009-05-06 10:44:45 +00008603 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008604 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008605 result = PCI_ERS_RESULT_DISCONNECT;
8606 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +01008607 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00008608 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -08008609 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008610 pci_set_master(pdev);
8611 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008612 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008613
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008614 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008615
8616 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008617 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008618 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008619 }
Auke Kok9a799d72007-09-15 14:07:45 -07008620
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008621 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8622 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008623 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8624 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008625 /* non-fatal, continue */
8626 }
Auke Kok9a799d72007-09-15 14:07:45 -07008627
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008628 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008629}
8630
8631/**
8632 * ixgbe_io_resume - called when traffic can start flowing again.
8633 * @pdev: Pointer to PCI device
8634 *
8635 * This callback is called when the error recovery driver tells us that
8636 * its OK to resume normal operation.
8637 */
8638static void ixgbe_io_resume(struct pci_dev *pdev)
8639{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008640 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8641 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008642
Greg Rose83c61fa2011-09-07 05:59:35 +00008643#ifdef CONFIG_PCI_IOV
8644 if (adapter->vferr_refcount) {
8645 e_info(drv, "Resuming after VF err\n");
8646 adapter->vferr_refcount--;
8647 return;
8648 }
8649
8650#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008651 if (netif_running(netdev))
8652 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008653
8654 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008655}
8656
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07008657static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07008658 .error_detected = ixgbe_io_error_detected,
8659 .slot_reset = ixgbe_io_slot_reset,
8660 .resume = ixgbe_io_resume,
8661};
8662
8663static struct pci_driver ixgbe_driver = {
8664 .name = ixgbe_driver_name,
8665 .id_table = ixgbe_pci_tbl,
8666 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05008667 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07008668#ifdef CONFIG_PM
8669 .suspend = ixgbe_suspend,
8670 .resume = ixgbe_resume,
8671#endif
8672 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +00008673 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -07008674 .err_handler = &ixgbe_err_handler
8675};
8676
8677/**
8678 * ixgbe_init_module - Driver Registration Routine
8679 *
8680 * ixgbe_init_module is the first routine called when the driver is
8681 * loaded. All it does is register with the PCI subsystem.
8682 **/
8683static int __init ixgbe_init_module(void)
8684{
8685 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008686 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008687 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008688
Catherine Sullivan00949162012-08-10 01:59:10 +00008689 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +00008690
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008691 ret = pci_register_driver(&ixgbe_driver);
8692 if (ret) {
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008693 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008694 return ret;
8695 }
8696
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008697#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008698 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008699#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008700
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008701 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008702}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008703
Auke Kok9a799d72007-09-15 14:07:45 -07008704module_init(ixgbe_init_module);
8705
8706/**
8707 * ixgbe_exit_module - Driver Exit Cleanup Routine
8708 *
8709 * ixgbe_exit_module is called just before the driver is removed
8710 * from memory.
8711 **/
8712static void __exit ixgbe_exit_module(void)
8713{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008714#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008715 dca_unregister_notify(&dca_notifier);
8716#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008717 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00008718
Catherine Sullivan00949162012-08-10 01:59:10 +00008719 ixgbe_dbg_exit();
Catherine Sullivan00949162012-08-10 01:59:10 +00008720
Eric Dumazet1a515022010-11-16 19:26:42 -08008721 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008722}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008723
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008724#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008725static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008726 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008727{
8728 int ret_val;
8729
8730 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008731 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008732
8733 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8734}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008735
Alexander Duyckb4533682009-03-31 21:32:42 +00008736#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008737
Auke Kok9a799d72007-09-15 14:07:45 -07008738module_exit(ixgbe_exit_module);
8739
8740/* ixgbe_main.c */