blob: 30adfb8f08145e0bdf3465eb368cf60fcef63a52 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Mark Rustad0391bbe2014-02-28 15:48:55 -08004 Copyright(c) 1999 - 2014 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Jacob Kellerb89aae72014-02-22 01:23:50 +000023 Linux NICS <linux.nics@intel.com>
Auke Kok9a799d72007-09-15 14:07:45 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include <linux/types.h>
30#include <linux/module.h>
31#include <linux/pci.h>
32#include <linux/netdevice.h>
33#include <linux/vmalloc.h>
34#include <linux/string.h>
35#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000036#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070037#include <linux/ip.h>
38#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000039#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000040#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070041#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070043#include <net/checksum.h>
44#include <net/ip6_checksum.h>
Martin K Petersenc762dff2014-11-15 14:24:51 +000045#include <linux/etherdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000047#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070048#include <linux/if_vlan.h>
John Fastabend2a47fa42013-11-06 09:54:52 -080049#include <linux/if_macvlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000050#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040051#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000052#include <scsi/fc/fc_fcoe.h>
Don Skidmore3f207802014-12-23 07:40:34 +000053#include <net/vxlan.h>
Auke Kok9a799d72007-09-15 14:07:45 -070054
Martin K Petersenc762dff2014-11-15 14:24:51 +000055#ifdef CONFIG_OF
56#include <linux/of_net.h>
57#endif
58
59#ifdef CONFIG_SPARC
60#include <asm/idprom.h>
61#include <asm/prom.h>
62#endif
63
Auke Kok9a799d72007-09-15 14:07:45 -070064#include "ixgbe.h"
65#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000066#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000067#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070068
69char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070070static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000071 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000072#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000073char ixgbe_default_device_descr[] =
74 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000075#else
76static char ixgbe_default_device_descr[] =
77 "Intel(R) 10 Gigabit Network Connection";
78#endif
Don Skidmore9be4a9b2014-11-29 05:22:58 +000079#define DRV_VERSION "4.0.1-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070080const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000081static const char ixgbe_copyright[] =
Mark Rustad0391bbe2014-02-28 15:48:55 -080082 "Copyright (c) 1999-2014 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070083
Don Skidmoref44e7512015-06-09 16:36:23 -070084static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter";
85
Auke Kok9a799d72007-09-15 14:07:45 -070086static const struct ixgbe_info *ixgbe_info_tbl[] = {
Don Skidmore6a14ee02014-12-05 03:59:50 +000087 [board_82598] = &ixgbe_82598_info,
88 [board_82599] = &ixgbe_82599_info,
89 [board_X540] = &ixgbe_X540_info,
90 [board_X550] = &ixgbe_X550_info,
91 [board_X550EM_x] = &ixgbe_X550EM_x_info,
Auke Kok9a799d72007-09-15 14:07:45 -070092};
93
94/* ixgbe_pci_tbl - PCI Device ID Table
95 *
96 * Wildcard entries (PCI_ANY_ID) should come last
97 * Last entry must be all 0s
98 *
99 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
100 * Class, Class Mask, private data (not used) }
101 */
Benoit Taine9baa3c32014-08-08 15:56:03 +0200102static const struct pci_device_id ixgbe_pci_tbl[] = {
Alexander Duyck54239c62011-07-15 03:06:06 +0000103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Don Skidmore8f583322013-07-27 06:25:38 +0000129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000132 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Don Skidmore6a14ee02014-12-05 03:59:50 +0000133 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
134 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
135 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
Auke Kok9a799d72007-09-15 14:07:45 -0700136 /* required last entry */
137 {0, }
138};
139MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
140
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400141#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800142static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000143 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800144static struct notifier_block dca_notifier = {
145 .notifier_call = ixgbe_notify_dca,
146 .next = NULL,
147 .priority = 0
148};
149#endif
150
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000151#ifdef CONFIG_PCI_IOV
152static unsigned int max_vfs;
153module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000154MODULE_PARM_DESC(max_vfs,
Jacob Keller170e8542013-11-09 04:52:32 -0800155 "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 +0000156#endif /* CONFIG_PCI_IOV */
157
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000158static unsigned int allow_unsupported_sfp;
159module_param(allow_unsupported_sfp, uint, 0);
160MODULE_PARM_DESC(allow_unsupported_sfp,
161 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
162
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000163#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
164static int debug = -1;
165module_param(debug, int, 0);
166MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
167
Auke Kok9a799d72007-09-15 14:07:45 -0700168MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
169MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
170MODULE_LICENSE("GPL");
171MODULE_VERSION(DRV_VERSION);
172
Mark Rustad14438462014-02-28 15:48:57 -0800173static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
174
Jacob Kellerb8e82002013-04-09 07:20:09 +0000175static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
176 u32 reg, u16 *value)
177{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000178 struct pci_dev *parent_dev;
179 struct pci_bus *parent_bus;
180
181 parent_bus = adapter->pdev->bus->parent;
182 if (!parent_bus)
183 return -1;
184
185 parent_dev = parent_bus->self;
186 if (!parent_dev)
187 return -1;
188
Yijing Wangc0798ed2013-09-04 17:30:08 +0000189 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000190 return -1;
191
Yijing Wangc0798ed2013-09-04 17:30:08 +0000192 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800193 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
194 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
195 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000196 return 0;
197}
198
199static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
200{
201 struct ixgbe_hw *hw = &adapter->hw;
202 u16 link_status = 0;
203 int err;
204
205 hw->bus.type = ixgbe_bus_type_pci_express;
206
207 /* Get the negotiated link width and speed from PCI config space of the
208 * parent, as this device is behind a switch
209 */
210 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
211
212 /* assume caller will handle error case */
213 if (err)
214 return err;
215
216 hw->bus.width = ixgbe_convert_bus_width(link_status);
217 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
218
219 return 0;
220}
221
Jacob Kellere027d1a2013-07-31 06:53:31 +0000222/**
223 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
224 * @hw: hw specific details
225 *
226 * This function is used by probe to determine whether a device's PCI-Express
227 * bandwidth details should be gathered from the parent bus instead of from the
228 * device. Used to ensure that various locations all have the correct device ID
229 * checks.
230 */
231static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
232{
233 switch (hw->device_id) {
234 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000235 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000236 return true;
237 default:
238 return false;
239 }
240}
241
242static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
243 int expected_gts)
244{
245 int max_gts = 0;
246 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
247 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
248 struct pci_dev *pdev;
249
250 /* determine whether to use the the parent device
251 */
252 if (ixgbe_pcie_from_parent(&adapter->hw))
253 pdev = adapter->pdev->bus->parent->self;
254 else
255 pdev = adapter->pdev;
256
257 if (pcie_get_minimum_link(pdev, &speed, &width) ||
258 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
259 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
260 return;
261 }
262
263 switch (speed) {
264 case PCIE_SPEED_2_5GT:
265 /* 8b/10b encoding reduces max throughput by 20% */
266 max_gts = 2 * width;
267 break;
268 case PCIE_SPEED_5_0GT:
269 /* 8b/10b encoding reduces max throughput by 20% */
270 max_gts = 4 * width;
271 break;
272 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000273 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000274 max_gts = 8 * width;
275 break;
276 default:
277 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
278 return;
279 }
280
281 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
282 max_gts);
283 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
284 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
285 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
286 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
287 "Unknown"),
288 width,
289 (speed == PCIE_SPEED_2_5GT ? "20%" :
290 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000291 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000292 "Unknown"));
293
294 if (max_gts < expected_gts) {
295 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
296 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
297 expected_gts);
298 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
299 }
300}
301
Alexander Duyck70864002011-04-27 09:13:56 +0000302static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
303{
304 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800305 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000306 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
307 schedule_work(&adapter->service_task);
308}
309
Mark Rustad2a1a0912014-01-14 18:53:15 -0800310static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
311{
312 struct ixgbe_adapter *adapter = hw->back;
313
314 if (!hw->hw_addr)
315 return;
316 hw->hw_addr = NULL;
317 e_dev_err("Adapter removed\n");
Mark Rustad58cf6632014-03-12 00:38:40 +0000318 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
319 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800320}
321
Mark Rustadf8e24722014-03-18 07:03:40 +0000322static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800323{
324 u32 value;
325
326 /* The following check not only optimizes a bit by not
327 * performing a read on the status register when the
328 * register just read was a status register read that
329 * returned IXGBE_FAILED_READ_REG. It also blocks any
330 * potential recursion.
331 */
332 if (reg == IXGBE_STATUS) {
333 ixgbe_remove_adapter(hw);
334 return;
335 }
336 value = ixgbe_read_reg(hw, IXGBE_STATUS);
337 if (value == IXGBE_FAILED_READ_REG)
338 ixgbe_remove_adapter(hw);
339}
340
Mark Rustadf8e24722014-03-18 07:03:40 +0000341/**
342 * ixgbe_read_reg - Read from device register
343 * @hw: hw specific details
344 * @reg: offset of register to read
345 *
346 * Returns : value read or IXGBE_FAILED_READ_REG if removed
347 *
348 * This function is used to read device registers. It checks for device
349 * removal by confirming any read that returns all ones by checking the
350 * status register value for all ones. This function avoids reading from
351 * the hardware if a removal was previously detected in which case it
352 * returns IXGBE_FAILED_READ_REG (all ones).
353 */
354u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
355{
356 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
357 u32 value;
358
359 if (ixgbe_removed(reg_addr))
360 return IXGBE_FAILED_READ_REG;
361 value = readl(reg_addr + reg);
362 if (unlikely(value == IXGBE_FAILED_READ_REG))
363 ixgbe_check_remove(hw, reg);
364 return value;
365}
366
Mark Rustad14438462014-02-28 15:48:57 -0800367static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
368{
369 u16 value;
370
371 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
372 if (value == IXGBE_FAILED_READ_CFG_WORD) {
373 ixgbe_remove_adapter(hw);
374 return true;
375 }
376 return false;
377}
378
379u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
380{
381 struct ixgbe_adapter *adapter = hw->back;
382 u16 value;
383
384 if (ixgbe_removed(hw->hw_addr))
385 return IXGBE_FAILED_READ_CFG_WORD;
386 pci_read_config_word(adapter->pdev, reg, &value);
387 if (value == IXGBE_FAILED_READ_CFG_WORD &&
388 ixgbe_check_cfg_remove(hw, adapter->pdev))
389 return IXGBE_FAILED_READ_CFG_WORD;
390 return value;
391}
392
393#ifdef CONFIG_PCI_IOV
394static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
395{
396 struct ixgbe_adapter *adapter = hw->back;
397 u32 value;
398
399 if (ixgbe_removed(hw->hw_addr))
400 return IXGBE_FAILED_READ_CFG_DWORD;
401 pci_read_config_dword(adapter->pdev, reg, &value);
402 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
403 ixgbe_check_cfg_remove(hw, adapter->pdev))
404 return IXGBE_FAILED_READ_CFG_DWORD;
405 return value;
406}
407#endif /* CONFIG_PCI_IOV */
408
Jacob Kellered192312014-02-22 01:23:53 +0000409void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
410{
411 struct ixgbe_adapter *adapter = hw->back;
412
413 if (ixgbe_removed(hw->hw_addr))
414 return;
415 pci_write_config_word(adapter->pdev, reg, value);
416}
417
Alexander Duyck70864002011-04-27 09:13:56 +0000418static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
419{
420 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
421
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000422 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100423 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000424 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
425}
426
Taku Izumidcd79ae2010-04-27 14:39:53 +0000427struct ixgbe_reg_info {
428 u32 ofs;
429 char *name;
430};
431
432static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
433
434 /* General Registers */
435 {IXGBE_CTRL, "CTRL"},
436 {IXGBE_STATUS, "STATUS"},
437 {IXGBE_CTRL_EXT, "CTRL_EXT"},
438
439 /* Interrupt Registers */
440 {IXGBE_EICR, "EICR"},
441
442 /* RX Registers */
443 {IXGBE_SRRCTL(0), "SRRCTL"},
444 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
445 {IXGBE_RDLEN(0), "RDLEN"},
446 {IXGBE_RDH(0), "RDH"},
447 {IXGBE_RDT(0), "RDT"},
448 {IXGBE_RXDCTL(0), "RXDCTL"},
449 {IXGBE_RDBAL(0), "RDBAL"},
450 {IXGBE_RDBAH(0), "RDBAH"},
451
452 /* TX Registers */
453 {IXGBE_TDBAL(0), "TDBAL"},
454 {IXGBE_TDBAH(0), "TDBAH"},
455 {IXGBE_TDLEN(0), "TDLEN"},
456 {IXGBE_TDH(0), "TDH"},
457 {IXGBE_TDT(0), "TDT"},
458 {IXGBE_TXDCTL(0), "TXDCTL"},
459
460 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000461 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000462};
463
464
465/*
466 * ixgbe_regdump - register printout routine
467 */
468static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
469{
470 int i = 0, j = 0;
471 char rname[16];
472 u32 regs[64];
473
474 switch (reginfo->ofs) {
475 case IXGBE_SRRCTL(0):
476 for (i = 0; i < 64; i++)
477 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
478 break;
479 case IXGBE_DCA_RXCTRL(0):
480 for (i = 0; i < 64; i++)
481 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
482 break;
483 case IXGBE_RDLEN(0):
484 for (i = 0; i < 64; i++)
485 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
486 break;
487 case IXGBE_RDH(0):
488 for (i = 0; i < 64; i++)
489 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
490 break;
491 case IXGBE_RDT(0):
492 for (i = 0; i < 64; i++)
493 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
494 break;
495 case IXGBE_RXDCTL(0):
496 for (i = 0; i < 64; i++)
497 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
498 break;
499 case IXGBE_RDBAL(0):
500 for (i = 0; i < 64; i++)
501 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
502 break;
503 case IXGBE_RDBAH(0):
504 for (i = 0; i < 64; i++)
505 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
506 break;
507 case IXGBE_TDBAL(0):
508 for (i = 0; i < 64; i++)
509 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
510 break;
511 case IXGBE_TDBAH(0):
512 for (i = 0; i < 64; i++)
513 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
514 break;
515 case IXGBE_TDLEN(0):
516 for (i = 0; i < 64; i++)
517 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
518 break;
519 case IXGBE_TDH(0):
520 for (i = 0; i < 64; i++)
521 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
522 break;
523 case IXGBE_TDT(0):
524 for (i = 0; i < 64; i++)
525 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
526 break;
527 case IXGBE_TXDCTL(0):
528 for (i = 0; i < 64; i++)
529 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
530 break;
531 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000532 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000533 IXGBE_READ_REG(hw, reginfo->ofs));
534 return;
535 }
536
537 for (i = 0; i < 8; i++) {
538 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000539 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000540 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000541 pr_cont(" %08x", regs[i*8+j]);
542 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000543 }
544
545}
546
547/*
548 * ixgbe_dump - Print registers, tx-rings and rx-rings
549 */
550static void ixgbe_dump(struct ixgbe_adapter *adapter)
551{
552 struct net_device *netdev = adapter->netdev;
553 struct ixgbe_hw *hw = &adapter->hw;
554 struct ixgbe_reg_info *reginfo;
555 int n = 0;
556 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000557 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000558 union ixgbe_adv_tx_desc *tx_desc;
559 struct my_u0 { u64 a; u64 b; } *u0;
560 struct ixgbe_ring *rx_ring;
561 union ixgbe_adv_rx_desc *rx_desc;
562 struct ixgbe_rx_buffer *rx_buffer_info;
563 u32 staterr;
564 int i = 0;
565
566 if (!netif_msg_hw(adapter))
567 return;
568
569 /* Print netdevice Info */
570 if (netdev) {
571 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000572 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000573 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000574 pr_info("%-15s %016lX %016lX %016lX\n",
575 netdev->name,
576 netdev->state,
577 netdev->trans_start,
578 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000579 }
580
581 /* Print Registers */
582 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000583 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000584 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
585 reginfo->name; reginfo++) {
586 ixgbe_regdump(hw, reginfo);
587 }
588
589 /* Print TX Ring Summary */
590 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000591 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000592
593 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000594 pr_info(" %s %s %s %s\n",
595 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
596 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000597 for (n = 0; n < adapter->num_tx_queues; n++) {
598 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000599 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000600 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000601 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000602 (u64)dma_unmap_addr(tx_buffer, dma),
603 dma_unmap_len(tx_buffer, len),
604 tx_buffer->next_to_watch,
605 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000606 }
607
608 /* Print TX Rings */
609 if (!netif_msg_tx_done(adapter))
610 goto rx_ring_summary;
611
612 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
613
614 /* Transmit Descriptor Formats
615 *
Josh Hay39ac8682012-09-26 05:59:36 +0000616 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000617 * +--------------------------------------------------------------+
618 * 0 | Buffer Address [63:0] |
619 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000620 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000621 * +--------------------------------------------------------------+
622 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000623 *
624 * 82598 Advanced Transmit Descriptor (Write-Back Format)
625 * +--------------------------------------------------------------+
626 * 0 | RSV [63:0] |
627 * +--------------------------------------------------------------+
628 * 8 | RSV | STA | NXTSEQ |
629 * +--------------------------------------------------------------+
630 * 63 36 35 32 31 0
631 *
632 * 82599+ Advanced Transmit Descriptor
633 * +--------------------------------------------------------------+
634 * 0 | Buffer Address [63:0] |
635 * +--------------------------------------------------------------+
636 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
637 * +--------------------------------------------------------------+
638 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
639 *
640 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
641 * +--------------------------------------------------------------+
642 * 0 | RSV [63:0] |
643 * +--------------------------------------------------------------+
644 * 8 | RSV | STA | RSV |
645 * +--------------------------------------------------------------+
646 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000647 */
648
649 for (n = 0; n < adapter->num_tx_queues; n++) {
650 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000651 pr_info("------------------------------------\n");
652 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
653 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000654 pr_info("%s%s %s %s %s %s\n",
655 "T [desc] [address 63:0 ] ",
656 "[PlPOIdStDDt Ln] [bi->dma ] ",
657 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000658
659 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000660 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000661 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000662 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000663 if (dma_unmap_len(tx_buffer, len) > 0) {
664 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
665 i,
666 le64_to_cpu(u0->a),
667 le64_to_cpu(u0->b),
668 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000669 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000670 tx_buffer->next_to_watch,
671 (u64)tx_buffer->time_stamp,
672 tx_buffer->skb);
673 if (i == tx_ring->next_to_use &&
674 i == tx_ring->next_to_clean)
675 pr_cont(" NTC/U\n");
676 else if (i == tx_ring->next_to_use)
677 pr_cont(" NTU\n");
678 else if (i == tx_ring->next_to_clean)
679 pr_cont(" NTC\n");
680 else
681 pr_cont("\n");
682
683 if (netif_msg_pktdata(adapter) &&
684 tx_buffer->skb)
685 print_hex_dump(KERN_INFO, "",
686 DUMP_PREFIX_ADDRESS, 16, 1,
687 tx_buffer->skb->data,
688 dma_unmap_len(tx_buffer, len),
689 true);
690 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000691 }
692 }
693
694 /* Print RX Rings Summary */
695rx_ring_summary:
696 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000697 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000698 for (n = 0; n < adapter->num_rx_queues; n++) {
699 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000700 pr_info("%5d %5X %5X\n",
701 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000702 }
703
704 /* Print RX Rings */
705 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000706 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000707
708 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
709
Josh Hay39ac8682012-09-26 05:59:36 +0000710 /* Receive Descriptor Formats
711 *
712 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000713 * 63 1 0
714 * +-----------------------------------------------------+
715 * 0 | Packet Buffer Address [63:1] |A0/NSE|
716 * +----------------------------------------------+------+
717 * 8 | Header Buffer Address [63:1] | DD |
718 * +-----------------------------------------------------+
719 *
720 *
Josh Hay39ac8682012-09-26 05:59:36 +0000721 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000722 *
723 * 63 48 47 32 31 30 21 20 16 15 4 3 0
724 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000725 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
726 * | Packet | IP | | | | Type | Type |
727 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000728 * +------------------------------------------------------+
729 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
730 * +------------------------------------------------------+
731 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000732 *
733 * 82599+ Advanced Receive Descriptor (Read) Format
734 * 63 1 0
735 * +-----------------------------------------------------+
736 * 0 | Packet Buffer Address [63:1] |A0/NSE|
737 * +----------------------------------------------+------+
738 * 8 | Header Buffer Address [63:1] | DD |
739 * +-----------------------------------------------------+
740 *
741 *
742 * 82599+ Advanced Receive Descriptor (Write-Back) Format
743 *
744 * 63 48 47 32 31 30 21 20 17 16 4 3 0
745 * +------------------------------------------------------+
746 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
747 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
748 * |/ Flow Dir Flt ID | | | | | |
749 * +------------------------------------------------------+
750 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
751 * +------------------------------------------------------+
752 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000753 */
Josh Hay39ac8682012-09-26 05:59:36 +0000754
Taku Izumidcd79ae2010-04-27 14:39:53 +0000755 for (n = 0; n < adapter->num_rx_queues; n++) {
756 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000757 pr_info("------------------------------------\n");
758 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
759 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000760 pr_info("%s%s%s",
761 "R [desc] [ PktBuf A0] ",
762 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000763 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000764 pr_info("%s%s%s",
765 "RWB[desc] [PcsmIpSHl PtRs] ",
766 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000767 "<-- Adv Rx Write-Back format\n");
768
769 for (i = 0; i < rx_ring->count; i++) {
770 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000771 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000772 u0 = (struct my_u0 *)rx_desc;
773 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
774 if (staterr & IXGBE_RXD_STAT_DD) {
775 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000776 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000777 "%016llX ---------------- %p", i,
778 le64_to_cpu(u0->a),
779 le64_to_cpu(u0->b),
780 rx_buffer_info->skb);
781 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000782 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000783 "%016llX %016llX %p", i,
784 le64_to_cpu(u0->a),
785 le64_to_cpu(u0->b),
786 (u64)rx_buffer_info->dma,
787 rx_buffer_info->skb);
788
Emil Tantilov9c50c032012-07-26 01:21:24 +0000789 if (netif_msg_pktdata(adapter) &&
790 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000791 print_hex_dump(KERN_INFO, "",
792 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000793 page_address(rx_buffer_info->page) +
794 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000795 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000796 }
797 }
798
799 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000800 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000801 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000802 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000803 else
Joe Perchesc7689572010-09-07 21:35:17 +0000804 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000805
806 }
807 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000808}
809
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800810static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
811{
812 u32 ctrl_ext;
813
814 /* Let firmware take over control of h/w */
815 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
816 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000817 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800818}
819
820static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
821{
822 u32 ctrl_ext;
823
824 /* Let firmware know the driver has taken over */
825 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
826 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000827 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800828}
Auke Kok9a799d72007-09-15 14:07:45 -0700829
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000830/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000831 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
832 * @adapter: pointer to adapter struct
833 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
834 * @queue: queue to map the corresponding interrupt to
835 * @msix_vector: the vector to map to the corresponding queue
836 *
837 */
838static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000839 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700840{
841 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000842 struct ixgbe_hw *hw = &adapter->hw;
843 switch (hw->mac.type) {
844 case ixgbe_mac_82598EB:
845 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
846 if (direction == -1)
847 direction = 0;
848 index = (((direction * 64) + queue) >> 2) & 0x1F;
849 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
850 ivar &= ~(0xFF << (8 * (queue & 0x3)));
851 ivar |= (msix_vector << (8 * (queue & 0x3)));
852 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
853 break;
854 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800855 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000856 case ixgbe_mac_X550:
857 case ixgbe_mac_X550EM_x:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000858 if (direction == -1) {
859 /* other causes */
860 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
861 index = ((queue & 1) * 8);
862 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
863 ivar &= ~(0xFF << index);
864 ivar |= (msix_vector << index);
865 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
866 break;
867 } else {
868 /* tx or rx causes */
869 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
870 index = ((16 * (queue & 1)) + (8 * direction));
871 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
872 ivar &= ~(0xFF << index);
873 ivar |= (msix_vector << index);
874 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
875 break;
876 }
877 default:
878 break;
879 }
Auke Kok9a799d72007-09-15 14:07:45 -0700880}
881
Alexander Duyckfe49f042009-06-04 16:00:09 +0000882static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000883 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000884{
885 u32 mask;
886
Alexander Duyckbd508172010-11-16 19:27:03 -0800887 switch (adapter->hw.mac.type) {
888 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000889 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
890 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800891 break;
892 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800893 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000894 case ixgbe_mac_X550:
895 case ixgbe_mac_X550EM_x:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000896 mask = (qmask & 0xFFFFFFFF);
897 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
898 mask = (qmask >> 32);
899 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800900 break;
901 default:
902 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000903 }
904}
905
Alexander Duyck729739b2012-02-08 07:51:06 +0000906void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
907 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000908{
Alexander Duyck729739b2012-02-08 07:51:06 +0000909 if (tx_buffer->skb) {
910 dev_kfree_skb_any(tx_buffer->skb);
911 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000912 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000913 dma_unmap_addr(tx_buffer, dma),
914 dma_unmap_len(tx_buffer, len),
915 DMA_TO_DEVICE);
916 } else if (dma_unmap_len(tx_buffer, len)) {
917 dma_unmap_page(ring->dev,
918 dma_unmap_addr(tx_buffer, dma),
919 dma_unmap_len(tx_buffer, len),
920 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000921 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000922 tx_buffer->next_to_watch = NULL;
923 tx_buffer->skb = NULL;
924 dma_unmap_len_set(tx_buffer, len, 0);
925 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700926}
927
Alexander Duyck943561d2012-05-09 22:14:44 -0700928static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
929{
930 struct ixgbe_hw *hw = &adapter->hw;
931 struct ixgbe_hw_stats *hwstats = &adapter->stats;
932 int i;
933 u32 data;
934
935 if ((hw->fc.current_mode != ixgbe_fc_full) &&
936 (hw->fc.current_mode != ixgbe_fc_rx_pause))
937 return;
938
939 switch (hw->mac.type) {
940 case ixgbe_mac_82598EB:
941 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
942 break;
943 default:
944 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
945 }
946 hwstats->lxoffrxc += data;
947
948 /* refill credits (no tx hang) if we received xoff */
949 if (!data)
950 return;
951
952 for (i = 0; i < adapter->num_tx_queues; i++)
953 clear_bit(__IXGBE_HANG_CHECK_ARMED,
954 &adapter->tx_ring[i]->state);
955}
956
John Fastabendc84d3242010-11-16 19:27:12 -0800957static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700958{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700959 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800960 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800961 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000962 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800963 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700964 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700965
Alexander Duyck943561d2012-05-09 22:14:44 -0700966 if (adapter->ixgbe_ieee_pfc)
967 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800968
Alexander Duyck943561d2012-05-09 22:14:44 -0700969 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
970 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800971 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700972 }
John Fastabendc84d3242010-11-16 19:27:12 -0800973
974 /* update stats for each tc, only valid with PFC enabled */
975 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000976 u32 pxoffrxc;
977
John Fastabendc84d3242010-11-16 19:27:12 -0800978 switch (hw->mac.type) {
979 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000980 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800981 break;
982 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000983 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800984 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000985 hwstats->pxoffrxc[i] += pxoffrxc;
986 /* Get the TC for given UP */
987 tc = netdev_get_prio_tc_map(adapter->netdev, i);
988 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -0700989 }
990
John Fastabendc84d3242010-11-16 19:27:12 -0800991 /* disarm tx queues that have received xoff frames */
992 for (i = 0; i < adapter->num_tx_queues; i++) {
993 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -0800994
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000995 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800996 if (xoff[tc])
997 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
998 }
999}
1000
1001static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1002{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001003 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001004}
1005
1006static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1007{
John Fastabend2a47fa42013-11-06 09:54:52 -08001008 struct ixgbe_adapter *adapter;
1009 struct ixgbe_hw *hw;
1010 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001011
John Fastabend2a47fa42013-11-06 09:54:52 -08001012 if (ring->l2_accel_priv)
1013 adapter = ring->l2_accel_priv->real_adapter;
1014 else
1015 adapter = netdev_priv(ring->netdev);
1016
1017 hw = &adapter->hw;
1018 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1019 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001020
1021 if (head != tail)
1022 return (head < tail) ?
1023 tail - head : (tail + ring->count - head);
1024
1025 return 0;
1026}
1027
1028static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1029{
1030 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1031 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1032 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001033
1034 clear_check_for_tx_hang(tx_ring);
1035
1036 /*
1037 * Check for a hung queue, but be thorough. This verifies
1038 * that a transmit has been completed since the previous
1039 * check AND there is at least one packet pending. The
1040 * ARMED bit is set to indicate a potential hang. The
1041 * bit is cleared if a pause frame is received to remove
1042 * false hang detection due to PFC or 802.3x frames. By
1043 * requiring this to fail twice we avoid races with
1044 * pfc clearing the ARMED bit and conditions where we
1045 * run the check_tx_hang logic with a transmit completion
1046 * pending but without time to complete it yet.
1047 */
Mark Rustade90dd262014-07-22 06:51:08 +00001048 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001049 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001050 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1051 &tx_ring->state);
1052 /* update completed stats and continue */
1053 tx_ring->tx_stats.tx_done_old = tx_done;
1054 /* reset the countdown */
1055 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001056
Mark Rustade90dd262014-07-22 06:51:08 +00001057 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001058}
1059
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001060/**
1061 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1062 * @adapter: driver private struct
1063 **/
1064static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1065{
1066
1067 /* Do the reset outside of interrupt context */
1068 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1069 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Jacob Keller12ff3f32012-12-01 07:57:17 +00001070 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001071 ixgbe_service_event_schedule(adapter);
1072 }
1073}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001074
Auke Kok9a799d72007-09-15 14:07:45 -07001075/**
1076 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001077 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001078 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -07001079 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001080static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001081 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07001082{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001083 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001084 struct ixgbe_tx_buffer *tx_buffer;
1085 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001086 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001087 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001088 unsigned int i = tx_ring->next_to_clean;
1089
1090 if (test_bit(__IXGBE_DOWN, &adapter->state))
1091 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001092
Alexander Duyckd3d00232011-07-15 02:31:25 +00001093 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001094 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001095 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001096
Alexander Duyck729739b2012-02-08 07:51:06 +00001097 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001098 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001099
Alexander Duyckd3d00232011-07-15 02:31:25 +00001100 /* if next_to_watch is not set then there is no work pending */
1101 if (!eop_desc)
1102 break;
1103
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001104 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001105 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001106
Alexander Duyckd3d00232011-07-15 02:31:25 +00001107 /* if DD is not set pending work has not been completed */
1108 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1109 break;
1110
Alexander Duyckd3d00232011-07-15 02:31:25 +00001111 /* clear next_to_watch to prevent false hangs */
1112 tx_buffer->next_to_watch = NULL;
1113
Alexander Duyck091a6242012-02-08 07:51:01 +00001114 /* update the statistics for this packet */
1115 total_bytes += tx_buffer->bytecount;
1116 total_packets += tx_buffer->gso_segs;
1117
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001118 /* free the skb */
Rick Jonesfe1f2a92014-09-12 17:44:06 +00001119 dev_consume_skb_any(tx_buffer->skb);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001120
Alexander Duyck729739b2012-02-08 07:51:06 +00001121 /* unmap skb header data */
1122 dma_unmap_single(tx_ring->dev,
1123 dma_unmap_addr(tx_buffer, dma),
1124 dma_unmap_len(tx_buffer, len),
1125 DMA_TO_DEVICE);
1126
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001127 /* clear tx_buffer data */
1128 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +00001129 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001130
Alexander Duyck729739b2012-02-08 07:51:06 +00001131 /* unmap remaining buffers */
1132 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001133 tx_buffer++;
1134 tx_desc++;
1135 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001136 if (unlikely(!i)) {
1137 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001138 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001139 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001140 }
1141
Alexander Duyck729739b2012-02-08 07:51:06 +00001142 /* unmap any remaining paged data */
1143 if (dma_unmap_len(tx_buffer, len)) {
1144 dma_unmap_page(tx_ring->dev,
1145 dma_unmap_addr(tx_buffer, dma),
1146 dma_unmap_len(tx_buffer, len),
1147 DMA_TO_DEVICE);
1148 dma_unmap_len_set(tx_buffer, len, 0);
1149 }
1150 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001151
Alexander Duyck729739b2012-02-08 07:51:06 +00001152 /* move us one more past the eop_desc for start of next pkt */
1153 tx_buffer++;
1154 tx_desc++;
1155 i++;
1156 if (unlikely(!i)) {
1157 i -= tx_ring->count;
1158 tx_buffer = tx_ring->tx_buffer_info;
1159 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1160 }
1161
1162 /* issue prefetch for next Tx descriptor */
1163 prefetch(tx_desc);
1164
1165 /* update budget accounting */
1166 budget--;
1167 } while (likely(budget));
1168
1169 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001170 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001171 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001172 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001173 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001174 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001175 q_vector->tx.total_bytes += total_bytes;
1176 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001177
John Fastabendc84d3242010-11-16 19:27:12 -08001178 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001179 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001180 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001181 e_err(drv, "Detected Tx Unit Hang\n"
1182 " Tx Queue <%d>\n"
1183 " TDH, TDT <%x>, <%x>\n"
1184 " next_to_use <%x>\n"
1185 " next_to_clean <%x>\n"
1186 "tx_buffer_info[next_to_clean]\n"
1187 " time_stamp <%lx>\n"
1188 " jiffies <%lx>\n",
1189 tx_ring->queue_index,
1190 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1191 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001192 tx_ring->next_to_use, i,
1193 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001194
1195 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1196
1197 e_info(probe,
1198 "tx hang %d detected on queue %d, resetting adapter\n",
1199 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1200
1201 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001202 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001203
1204 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001205 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001206 }
Auke Kok9a799d72007-09-15 14:07:45 -07001207
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001208 netdev_tx_completed_queue(txring_txq(tx_ring),
1209 total_packets, total_bytes);
1210
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001211#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001212 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001213 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001214 /* Make sure that anybody stopping the queue after this
1215 * sees the new next_to_clean.
1216 */
1217 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001218 if (__netif_subqueue_stopped(tx_ring->netdev,
1219 tx_ring->queue_index)
1220 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1221 netif_wake_subqueue(tx_ring->netdev,
1222 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001223 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001224 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001225 }
Auke Kok9a799d72007-09-15 14:07:45 -07001226
Alexander Duyck59224552011-08-31 00:01:06 +00001227 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001228}
1229
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001230#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001231static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001232 struct ixgbe_ring *tx_ring,
1233 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001234{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001235 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001236 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1237 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001238
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001239 switch (hw->mac.type) {
1240 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001241 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001242 break;
1243 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001244 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001245 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1246 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1247 break;
1248 default:
1249 /* for unknown hardware do not write register */
1250 return;
1251 }
1252
1253 /*
1254 * We can enable relaxed ordering for reads, but not writes when
1255 * DCA is enabled. This is due to a known issue in some chipsets
1256 * which will cause the DCA tag to be cleared.
1257 */
1258 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1259 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1260 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1261
1262 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1263}
1264
1265static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1266 struct ixgbe_ring *rx_ring,
1267 int cpu)
1268{
1269 struct ixgbe_hw *hw = &adapter->hw;
1270 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1271 u8 reg_idx = rx_ring->reg_idx;
1272
1273
1274 switch (hw->mac.type) {
1275 case ixgbe_mac_82599EB:
1276 case ixgbe_mac_X540:
1277 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001278 break;
1279 default:
1280 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001281 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001282
1283 /*
1284 * We can enable relaxed ordering for reads, but not writes when
1285 * DCA is enabled. This is due to a known issue in some chipsets
1286 * which will cause the DCA tag to be cleared.
1287 */
1288 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001289 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1290
1291 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001292}
1293
1294static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1295{
1296 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001297 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001298 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001299
1300 if (q_vector->cpu == cpu)
1301 goto out_no_update;
1302
Alexander Duycka5579282012-02-08 07:50:04 +00001303 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001304 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001305
Alexander Duycka5579282012-02-08 07:50:04 +00001306 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001307 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001308
1309 q_vector->cpu = cpu;
1310out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001311 put_cpu();
1312}
1313
1314static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1315{
1316 int i;
1317
1318 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1319 return;
1320
Alexander Duycke35ec122009-05-21 13:07:12 +00001321 /* always use CB2 mode, difference is masked in the CB driver */
1322 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1323
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001324 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001325 adapter->q_vector[i]->cpu = -1;
1326 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001327 }
1328}
1329
1330static int __ixgbe_notify_dca(struct device *dev, void *data)
1331{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001332 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001333 unsigned long event = *(unsigned long *)data;
1334
Don Skidmore2a72c312011-07-20 02:27:05 +00001335 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001336 return 0;
1337
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001338 switch (event) {
1339 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001340 /* if we're already enabled, don't do it again */
1341 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1342 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001343 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001344 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001345 ixgbe_setup_dca(adapter);
1346 break;
1347 }
1348 /* Fall Through since DCA is disabled. */
1349 case DCA_PROVIDER_REMOVE:
1350 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1351 dca_remove_requester(dev);
1352 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1353 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1354 }
1355 break;
1356 }
1357
Denis V. Lunev652f0932008-03-27 14:39:17 +03001358 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001359}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001360
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001361#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001362static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1363 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001364 struct sk_buff *skb)
1365{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001366 if (ring->netdev->features & NETIF_F_RXHASH)
Tom Herbert38da9852013-12-18 16:47:04 +00001367 skb_set_hash(skb,
1368 le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1369 PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001370}
1371
Alexander Duyckf8003262012-03-03 02:35:52 +00001372#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001373/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001374 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001375 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001376 * @rx_desc: advanced rx descriptor
1377 *
1378 * Returns : true if it is FCoE pkt
1379 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001380static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001381 union ixgbe_adv_rx_desc *rx_desc)
1382{
1383 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1384
Alexander Duyck57efd442012-06-25 21:54:46 +00001385 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001386 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1387 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1388 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1389}
1390
Alexander Duyckf8003262012-03-03 02:35:52 +00001391#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001392/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001393 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001394 * @ring: structure containing ring specific data
1395 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001396 * @skb: skb currently being received and modified
1397 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001398static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001399 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001400 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001401{
Don Skidmore3f207802014-12-23 07:40:34 +00001402 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1403 __le16 hdr_info = rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
1404 bool encap_pkt = false;
1405
Alexander Duyck8a0da212012-01-31 02:59:49 +00001406 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001407
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001408 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001409 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001410 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001411
Don Skidmore3f207802014-12-23 07:40:34 +00001412 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) &&
1413 (hdr_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL >> 16))) {
1414 encap_pkt = true;
1415 skb->encapsulation = 1;
1416 skb->ip_summed = CHECKSUM_NONE;
1417 }
1418
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001419 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001420 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1421 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001422 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001423 return;
1424 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001425
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001426 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001427 return;
1428
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001429 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001430 /*
1431 * 82599 errata, UDP frames with a 0 checksum can be marked as
1432 * checksum errors.
1433 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001434 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1435 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001436 return;
1437
Alexander Duyck8a0da212012-01-31 02:59:49 +00001438 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001439 return;
1440 }
1441
Auke Kok9a799d72007-09-15 14:07:45 -07001442 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001443 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001444 if (encap_pkt) {
1445 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1446 return;
1447
1448 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
1449 ring->rx_stats.csum_err++;
1450 return;
1451 }
1452 /* If we checked the outer header let the stack know */
1453 skb->csum_level = 1;
1454 }
Auke Kok9a799d72007-09-15 14:07:45 -07001455}
1456
Alexander Duyckf990b792012-01-31 02:59:34 +00001457static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1458 struct ixgbe_rx_buffer *bi)
1459{
1460 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001461 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001462
Alexander Duyckf8003262012-03-03 02:35:52 +00001463 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001464 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001465 return true;
1466
Alexander Duyckf8003262012-03-03 02:35:52 +00001467 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001468 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1469 if (unlikely(!page)) {
1470 rx_ring->rx_stats.alloc_rx_page_failed++;
1471 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001472 }
1473
Alexander Duyckf8003262012-03-03 02:35:52 +00001474 /* map page for use */
1475 dma = dma_map_page(rx_ring->dev, page, 0,
1476 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001477
Alexander Duyckf8003262012-03-03 02:35:52 +00001478 /*
1479 * if mapping failed free memory back to system since
1480 * there isn't much point in holding memory we can't use
1481 */
1482 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001483 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001484
Alexander Duyckf990b792012-01-31 02:59:34 +00001485 rx_ring->rx_stats.alloc_rx_page_failed++;
1486 return false;
1487 }
1488
Alexander Duyckf8003262012-03-03 02:35:52 +00001489 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001490 bi->page = page;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001491 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001492
Alexander Duyckf990b792012-01-31 02:59:34 +00001493 return true;
1494}
1495
Auke Kok9a799d72007-09-15 14:07:45 -07001496/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001497 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001498 * @rx_ring: ring to place buffers on
1499 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001500 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001501void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001502{
Auke Kok9a799d72007-09-15 14:07:45 -07001503 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001504 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001505 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001506
Alexander Duyckf8003262012-03-03 02:35:52 +00001507 /* nothing to do */
1508 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001509 return;
1510
Alexander Duycke4f74022012-01-31 02:59:44 +00001511 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001512 bi = &rx_ring->rx_buffer_info[i];
1513 i -= rx_ring->count;
1514
Alexander Duyckf8003262012-03-03 02:35:52 +00001515 do {
1516 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001517 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001518
Alexander Duyckf8003262012-03-03 02:35:52 +00001519 /*
1520 * Refresh the desc even if buffer_addrs didn't change
1521 * because each write-back erases this info.
1522 */
1523 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001524
Alexander Duyckf990b792012-01-31 02:59:34 +00001525 rx_desc++;
1526 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001527 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001528 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001529 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001530 bi = rx_ring->rx_buffer_info;
1531 i -= rx_ring->count;
1532 }
1533
Alexander Duyck18cb6522014-11-14 00:56:29 +00001534 /* clear the status bits for the next_to_use descriptor */
1535 rx_desc->wb.upper.status_error = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001536
1537 cleaned_count--;
1538 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001539
Alexander Duyckf990b792012-01-31 02:59:34 +00001540 i += rx_ring->count;
1541
Alexander Duyckad435ec2014-11-14 00:56:35 +00001542 if (rx_ring->next_to_use != i) {
1543 rx_ring->next_to_use = i;
1544
1545 /* update next to alloc since we have filled the ring */
1546 rx_ring->next_to_alloc = i;
1547
1548 /* Force memory writes to complete before letting h/w
1549 * know there are new descriptors to fetch. (Only
1550 * applicable for weak-ordered memory model archs,
1551 * such as IA-64).
1552 */
1553 wmb();
1554 writel(i, rx_ring->tail);
1555 }
Auke Kok9a799d72007-09-15 14:07:45 -07001556}
1557
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001558static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1559 struct sk_buff *skb)
1560{
Alexander Duyckf8003262012-03-03 02:35:52 +00001561 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001562
1563 /* set gso_size to avoid messing up TCP MSS */
1564 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1565 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001566 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001567}
1568
1569static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1570 struct sk_buff *skb)
1571{
1572 /* if append_cnt is 0 then frame is not RSC */
1573 if (!IXGBE_CB(skb)->append_cnt)
1574 return;
1575
1576 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1577 rx_ring->rx_stats.rsc_flush++;
1578
1579 ixgbe_set_rsc_gso_size(rx_ring, skb);
1580
1581 /* gso_size is computed using append_cnt so always clear it last */
1582 IXGBE_CB(skb)->append_cnt = 0;
1583}
1584
Alexander Duyck8a0da212012-01-31 02:59:49 +00001585/**
1586 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1587 * @rx_ring: rx descriptor ring packet is being transacted on
1588 * @rx_desc: pointer to the EOP Rx descriptor
1589 * @skb: pointer to current skb being populated
1590 *
1591 * This function checks the ring, descriptor, and packet information in
1592 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1593 * other fields within the skb.
1594 **/
1595static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1596 union ixgbe_adv_rx_desc *rx_desc,
1597 struct sk_buff *skb)
1598{
John Fastabend43e95f12012-05-15 06:12:17 +00001599 struct net_device *dev = rx_ring->netdev;
1600
Alexander Duyck8a0da212012-01-31 02:59:49 +00001601 ixgbe_update_rsc_stats(rx_ring, skb);
1602
1603 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1604
1605 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1606
Jakub Kicinskieda183c2014-04-02 10:33:28 +00001607 if (unlikely(ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_TS)))
1608 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector->adapter, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001609
Patrick McHardyf6469682013-04-19 02:04:27 +00001610 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001611 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001612 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001613 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001614 }
1615
1616 skb_record_rx_queue(skb, rx_ring->queue_index);
1617
John Fastabend43e95f12012-05-15 06:12:17 +00001618 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001619}
1620
1621static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1622 struct sk_buff *skb)
1623{
Jacob Kellerb4640032013-10-01 04:33:54 -07001624 if (ixgbe_qv_busy_polling(q_vector))
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001625 netif_receive_skb(skb);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001626 else
Alexander Duyck856f6062015-02-25 17:45:54 +00001627 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001628}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001629
Alexander Duyckf8003262012-03-03 02:35:52 +00001630/**
1631 * ixgbe_is_non_eop - process handling of non-EOP buffers
1632 * @rx_ring: Rx ring being processed
1633 * @rx_desc: Rx descriptor for current buffer
1634 * @skb: Current socket buffer containing buffer in progress
1635 *
1636 * This function updates next to clean. If the buffer is an EOP buffer
1637 * this function exits returning false, otherwise it will place the
1638 * sk_buff in the next buffer to be chained and return true indicating
1639 * that this is in fact a non-EOP buffer.
1640 **/
1641static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1642 union ixgbe_adv_rx_desc *rx_desc,
1643 struct sk_buff *skb)
1644{
1645 u32 ntc = rx_ring->next_to_clean + 1;
1646
1647 /* fetch, update, and store next to clean */
1648 ntc = (ntc < rx_ring->count) ? ntc : 0;
1649 rx_ring->next_to_clean = ntc;
1650
1651 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1652
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001653 /* update RSC append count if present */
1654 if (ring_is_rsc_enabled(rx_ring)) {
1655 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1656 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1657
1658 if (unlikely(rsc_enabled)) {
1659 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1660
1661 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1662 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1663
1664 /* update ntc based on RSC value */
1665 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1666 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1667 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1668 }
1669 }
1670
1671 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001672 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1673 return false;
1674
Alexander Duyckf8003262012-03-03 02:35:52 +00001675 /* place skb in next buffer to be received */
1676 rx_ring->rx_buffer_info[ntc].skb = skb;
1677 rx_ring->rx_stats.non_eop_descs++;
1678
1679 return true;
1680}
1681
1682/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001683 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1684 * @rx_ring: rx descriptor ring packet is being transacted on
1685 * @skb: pointer to current skb being adjusted
1686 *
1687 * This function is an ixgbe specific version of __pskb_pull_tail. The
1688 * main difference between this version and the original function is that
1689 * this function can make several assumptions about the state of things
1690 * that allow for significant optimizations versus the standard function.
1691 * As a result we can do things like drop a frag and maintain an accurate
1692 * truesize for the skb.
1693 */
1694static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1695 struct sk_buff *skb)
1696{
1697 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1698 unsigned char *va;
1699 unsigned int pull_len;
1700
1701 /*
1702 * it is valid to use page_address instead of kmap since we are
1703 * working with pages allocated out of the lomem pool per
1704 * alloc_page(GFP_ATOMIC)
1705 */
1706 va = skb_frag_address(frag);
1707
1708 /*
1709 * we need the header to contain the greater of either ETH_HLEN or
1710 * 60 bytes if the skb->len is less than 60 for skb_pad.
1711 */
Alexander Duyck8496e332014-09-05 19:22:18 -04001712 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001713
1714 /* align pull length to size of long to optimize memcpy performance */
1715 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1716
1717 /* update all of the pointers */
1718 skb_frag_size_sub(frag, pull_len);
1719 frag->page_offset += pull_len;
1720 skb->data_len -= pull_len;
1721 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001722}
1723
1724/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001725 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1726 * @rx_ring: rx descriptor ring packet is being transacted on
1727 * @skb: pointer to current skb being updated
1728 *
1729 * This function provides a basic DMA sync up for the first fragment of an
1730 * skb. The reason for doing this is that the first fragment cannot be
1731 * unmapped until we have reached the end of packet descriptor for a buffer
1732 * chain.
1733 */
1734static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1735 struct sk_buff *skb)
1736{
1737 /* if the page was released unmap it, else just sync our portion */
1738 if (unlikely(IXGBE_CB(skb)->page_released)) {
1739 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1740 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1741 IXGBE_CB(skb)->page_released = false;
1742 } else {
1743 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1744
1745 dma_sync_single_range_for_cpu(rx_ring->dev,
1746 IXGBE_CB(skb)->dma,
1747 frag->page_offset,
1748 ixgbe_rx_bufsz(rx_ring),
1749 DMA_FROM_DEVICE);
1750 }
1751 IXGBE_CB(skb)->dma = 0;
1752}
1753
1754/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001755 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1756 * @rx_ring: rx descriptor ring packet is being transacted on
1757 * @rx_desc: pointer to the EOP Rx descriptor
1758 * @skb: pointer to current skb being fixed
1759 *
1760 * Check for corrupted packet headers caused by senders on the local L2
1761 * embedded NIC switch not setting up their Tx Descriptors right. These
1762 * should be very rare.
1763 *
1764 * Also address the case where we are pulling data in on pages only
1765 * and as such no data is present in the skb header.
1766 *
1767 * In addition if skb is not at least 60 bytes we need to pad it so that
1768 * it is large enough to qualify as a valid Ethernet frame.
1769 *
1770 * Returns true if an error was encountered and skb was freed.
1771 **/
1772static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1773 union ixgbe_adv_rx_desc *rx_desc,
1774 struct sk_buff *skb)
1775{
Alexander Duyckf8003262012-03-03 02:35:52 +00001776 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001777
1778 /* verify that the packet does not have any known errors */
1779 if (unlikely(ixgbe_test_staterr(rx_desc,
1780 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1781 !(netdev->features & NETIF_F_RXALL))) {
1782 dev_kfree_skb_any(skb);
1783 return true;
1784 }
1785
Alexander Duyck19861ce2012-07-20 08:08:33 +00001786 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001787 if (skb_is_nonlinear(skb))
1788 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001789
Alexander Duyck57efd442012-06-25 21:54:46 +00001790#ifdef IXGBE_FCOE
1791 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1792 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1793 return false;
1794
1795#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001796 /* if eth_skb_pad returns an error the skb was freed */
1797 if (eth_skb_pad(skb))
1798 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001799
1800 return false;
1801}
1802
1803/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001804 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1805 * @rx_ring: rx descriptor ring to store buffers on
1806 * @old_buff: donor buffer to have page reused
1807 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001808 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001809 **/
1810static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1811 struct ixgbe_rx_buffer *old_buff)
1812{
1813 struct ixgbe_rx_buffer *new_buff;
1814 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001815
1816 new_buff = &rx_ring->rx_buffer_info[nta];
1817
1818 /* update, and store next to alloc */
1819 nta++;
1820 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1821
1822 /* transfer page from old buffer to new buffer */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001823 *new_buff = *old_buff;
Alexander Duyckf8003262012-03-03 02:35:52 +00001824
1825 /* sync the buffer for use by the device */
1826 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001827 new_buff->page_offset,
1828 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001829 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001830}
1831
Alexander Duyck18cb6522014-11-14 00:56:29 +00001832static inline bool ixgbe_page_is_reserved(struct page *page)
1833{
1834 return (page_to_nid(page) != numa_mem_id()) || page->pfmemalloc;
1835}
1836
Alexander Duyckf8003262012-03-03 02:35:52 +00001837/**
1838 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1839 * @rx_ring: rx descriptor ring to transact packets on
1840 * @rx_buffer: buffer containing page to add
1841 * @rx_desc: descriptor containing length of buffer written by hardware
1842 * @skb: sk_buff to place the data into
1843 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001844 * This function will add the data contained in rx_buffer->page to the skb.
1845 * This is done either through a direct copy if the data in the buffer is
1846 * less than the skb header size, otherwise it will just attach the page as
1847 * a frag to the skb.
1848 *
1849 * The function will then update the page offset if necessary and return
1850 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001851 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001852static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001853 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001854 union ixgbe_adv_rx_desc *rx_desc,
1855 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001856{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001857 struct page *page = rx_buffer->page;
1858 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001859#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001860 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001861#else
1862 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1863 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1864 ixgbe_rx_bufsz(rx_ring);
1865#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001866
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001867 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1868 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1869
1870 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1871
Alexander Duyck18cb6522014-11-14 00:56:29 +00001872 /* page is not reserved, we can reuse buffer as-is */
1873 if (likely(!ixgbe_page_is_reserved(page)))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001874 return true;
1875
1876 /* this page cannot be reused so discard it */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001877 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001878 return false;
1879 }
1880
Alexander Duyck0549ae22012-07-20 08:08:18 +00001881 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1882 rx_buffer->page_offset, size, truesize);
1883
Alexander Duyck09816fb2012-07-20 08:08:23 +00001884 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001885 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001886 return false;
1887
1888#if (PAGE_SIZE < 8192)
1889 /* if we are only owner of page we can reuse it */
1890 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001891 return false;
1892
1893 /* flip page offset to other buffer */
1894 rx_buffer->page_offset ^= truesize;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001895#else
1896 /* move offset up to the next cache line */
1897 rx_buffer->page_offset += truesize;
1898
1899 if (rx_buffer->page_offset > last_offset)
1900 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001901#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001902
Alexander Duyck18cb6522014-11-14 00:56:29 +00001903 /* Even if we own the page, we are not allowed to use atomic_set()
1904 * This would break get_page_unless_zero() users.
1905 */
1906 atomic_inc(&page->_count);
1907
Alexander Duyck0549ae22012-07-20 08:08:18 +00001908 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001909}
1910
Alexander Duyck18806c92012-07-20 08:08:44 +00001911static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1912 union ixgbe_adv_rx_desc *rx_desc)
1913{
1914 struct ixgbe_rx_buffer *rx_buffer;
1915 struct sk_buff *skb;
1916 struct page *page;
1917
1918 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1919 page = rx_buffer->page;
1920 prefetchw(page);
1921
1922 skb = rx_buffer->skb;
1923
1924 if (likely(!skb)) {
1925 void *page_addr = page_address(page) +
1926 rx_buffer->page_offset;
1927
1928 /* prefetch first cache line of first page */
1929 prefetch(page_addr);
1930#if L1_CACHE_BYTES < 128
1931 prefetch(page_addr + L1_CACHE_BYTES);
1932#endif
1933
1934 /* allocate a skb to store the frags */
Alexander Duyck67fd8932014-12-09 19:40:56 -08001935 skb = napi_alloc_skb(&rx_ring->q_vector->napi,
1936 IXGBE_RX_HDR_SIZE);
Alexander Duyck18806c92012-07-20 08:08:44 +00001937 if (unlikely(!skb)) {
1938 rx_ring->rx_stats.alloc_rx_buff_failed++;
1939 return NULL;
1940 }
1941
1942 /*
1943 * we will be copying header into skb->data in
1944 * pskb_may_pull so it is in our interest to prefetch
1945 * it now to avoid a possible cache miss
1946 */
1947 prefetchw(skb->data);
1948
1949 /*
1950 * Delay unmapping of the first packet. It carries the
1951 * header information, HW may still access the header
1952 * after the writeback. Only unmap it when EOP is
1953 * reached
1954 */
1955 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1956 goto dma_sync;
1957
1958 IXGBE_CB(skb)->dma = rx_buffer->dma;
1959 } else {
1960 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1961 ixgbe_dma_sync_frag(rx_ring, skb);
1962
1963dma_sync:
1964 /* we are reusing so sync this buffer for CPU use */
1965 dma_sync_single_range_for_cpu(rx_ring->dev,
1966 rx_buffer->dma,
1967 rx_buffer->page_offset,
1968 ixgbe_rx_bufsz(rx_ring),
1969 DMA_FROM_DEVICE);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001970
1971 rx_buffer->skb = NULL;
Alexander Duyck18806c92012-07-20 08:08:44 +00001972 }
1973
1974 /* pull page into skb */
1975 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1976 /* hand second half of page back to the ring */
1977 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1978 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1979 /* the page has been released from the ring */
1980 IXGBE_CB(skb)->page_released = true;
1981 } else {
1982 /* we are not reusing the buffer so unmap it */
1983 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1984 ixgbe_rx_pg_size(rx_ring),
1985 DMA_FROM_DEVICE);
1986 }
1987
1988 /* clear contents of buffer_info */
Alexander Duyck18806c92012-07-20 08:08:44 +00001989 rx_buffer->page = NULL;
1990
1991 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001992}
1993
1994/**
1995 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1996 * @q_vector: structure containing interrupt and ring information
1997 * @rx_ring: rx descriptor ring to transact packets on
1998 * @budget: Total limit on number of packets to process
1999 *
2000 * This function provides a "bounce buffer" approach to Rx interrupt
2001 * processing. The advantage to this is that on systems that have
2002 * expensive overhead for IOMMU access this provides a means of avoiding
2003 * it by maintaining the mapping of the page to the syste.
2004 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002005 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002006 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002007static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002008 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002009 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002010{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002011 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00002012#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00002013 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00002014 int ddp_bytes;
2015 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002016#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002017 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002018
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002019 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002020 union ixgbe_adv_rx_desc *rx_desc;
2021 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002022
Alexander Duyckf8003262012-03-03 02:35:52 +00002023 /* return some buffers to hardware, one at a time is too slow */
2024 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2025 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2026 cleaned_count = 0;
2027 }
Auke Kok9a799d72007-09-15 14:07:45 -07002028
Alexander Duyck18806c92012-07-20 08:08:44 +00002029 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07002030
Alexander Duyck124b74c2014-12-11 15:02:28 -08002031 if (!rx_desc->wb.upper.status_error)
Alexander Duyckf8003262012-03-03 02:35:52 +00002032 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002033
Alexander Duyck124b74c2014-12-11 15:02:28 -08002034 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002035 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002036 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002037 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002038 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002039
Alexander Duyck18806c92012-07-20 08:08:44 +00002040 /* retrieve a buffer from the ring */
2041 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00002042
Alexander Duyck18806c92012-07-20 08:08:44 +00002043 /* exit if we failed to retrieve a buffer */
2044 if (!skb)
2045 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002046
Auke Kok9a799d72007-09-15 14:07:45 -07002047 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002048
Alexander Duyckf8003262012-03-03 02:35:52 +00002049 /* place incomplete frames back on ring for completion */
2050 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2051 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002052
Alexander Duyckf8003262012-03-03 02:35:52 +00002053 /* verify the packet layout is correct */
2054 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2055 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002056
2057 /* probably a little skewed due to removing CRC */
2058 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002059
Alexander Duyck8a0da212012-01-31 02:59:49 +00002060 /* populate checksum, timestamp, VLAN, and protocol */
2061 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2062
Yi Zou332d4a72009-05-13 13:11:53 +00002063#ifdef IXGBE_FCOE
2064 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002065 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002066 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002067 /* include DDPed FCoE data */
2068 if (ddp_bytes > 0) {
2069 if (!mss) {
2070 mss = rx_ring->netdev->mtu -
2071 sizeof(struct fcoe_hdr) -
2072 sizeof(struct fc_frame_header) -
2073 sizeof(struct fcoe_crc_eof);
2074 if (mss > 512)
2075 mss &= ~511;
2076 }
2077 total_rx_bytes += ddp_bytes;
2078 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2079 mss);
2080 }
David S. Miller823dcd22011-08-20 10:39:12 -07002081 if (!ddp_bytes) {
2082 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002083 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002084 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002085 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002086
Yi Zou332d4a72009-05-13 13:11:53 +00002087#endif /* IXGBE_FCOE */
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03002088 skb_mark_napi_id(skb, &q_vector->napi);
Alexander Duyck8a0da212012-01-31 02:59:49 +00002089 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002090
Alexander Duyckf8003262012-03-03 02:35:52 +00002091 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002092 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002093 }
Auke Kok9a799d72007-09-15 14:07:45 -07002094
Alexander Duyckc267fc12010-11-16 19:27:00 -08002095 u64_stats_update_begin(&rx_ring->syncp);
2096 rx_ring->stats.packets += total_rx_packets;
2097 rx_ring->stats.bytes += total_rx_bytes;
2098 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002099 q_vector->rx.total_packets += total_rx_packets;
2100 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002101
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002102 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002103}
2104
Cong Wange0d10952013-08-01 11:10:25 +08002105#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002106/* must be called with local_bh_disable()d */
2107static int ixgbe_low_latency_recv(struct napi_struct *napi)
2108{
2109 struct ixgbe_q_vector *q_vector =
2110 container_of(napi, struct ixgbe_q_vector, napi);
2111 struct ixgbe_adapter *adapter = q_vector->adapter;
2112 struct ixgbe_ring *ring;
2113 int found = 0;
2114
2115 if (test_bit(__IXGBE_DOWN, &adapter->state))
2116 return LL_FLUSH_FAILED;
2117
2118 if (!ixgbe_qv_lock_poll(q_vector))
2119 return LL_FLUSH_BUSY;
2120
2121 ixgbe_for_each_ring(ring, q_vector->rx) {
2122 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
Jacob Kellerb4640032013-10-01 04:33:54 -07002123#ifdef BP_EXTENDED_STATS
Eliezer Tamir7e15b902013-06-10 11:40:31 +03002124 if (found)
2125 ring->stats.cleaned += found;
2126 else
2127 ring->stats.misses++;
2128#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002129 if (found)
2130 break;
2131 }
2132
2133 ixgbe_qv_unlock_poll(q_vector);
2134
2135 return found;
2136}
Cong Wange0d10952013-08-01 11:10:25 +08002137#endif /* CONFIG_NET_RX_BUSY_POLL */
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002138
Auke Kok9a799d72007-09-15 14:07:45 -07002139/**
2140 * ixgbe_configure_msix - Configure MSI-X hardware
2141 * @adapter: board private structure
2142 *
2143 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2144 * interrupts.
2145 **/
2146static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2147{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002148 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002149 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002150 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002151
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002152 /* Populate MSIX to EITR Select */
2153 if (adapter->num_vfs > 32) {
2154 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2155 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2156 }
2157
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002158 /*
2159 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002160 * corresponding register.
2161 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002162 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002163 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002164 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002165
Alexander Duycka5579282012-02-08 07:50:04 +00002166 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002167 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002168
Alexander Duycka5579282012-02-08 07:50:04 +00002169 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002170 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002171
Alexander Duyckfe49f042009-06-04 16:00:09 +00002172 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002173 }
2174
Alexander Duyckbd508172010-11-16 19:27:03 -08002175 switch (adapter->hw.mac.type) {
2176 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002177 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002178 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002179 break;
2180 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002181 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002182 case ixgbe_mac_X550:
2183 case ixgbe_mac_X550EM_x:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002184 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002185 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002186 default:
2187 break;
2188 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002189 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002190
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002191 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002192 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002193 mask &= ~(IXGBE_EIMS_OTHER |
2194 IXGBE_EIMS_MAILBOX |
2195 IXGBE_EIMS_LSC);
2196
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002197 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002198}
2199
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002200enum latency_range {
2201 lowest_latency = 0,
2202 low_latency = 1,
2203 bulk_latency = 2,
2204 latency_invalid = 255
2205};
2206
2207/**
2208 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002209 * @q_vector: structure containing interrupt and ring information
2210 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002211 *
2212 * Stores a new ITR value based on packets and byte
2213 * counts during the last interrupt. The advantage of per interrupt
2214 * computation is faster updates and more accurate ITR for the current
2215 * traffic pattern. Constants in this function were computed
2216 * based on theoretical maximum wire speed and thresholds were set based
2217 * on testing data as well as attempting to minimize response time
2218 * while increasing bulk throughput.
2219 * this functionality is controlled by the InterruptThrottleRate module
2220 * parameter (see ixgbe_param.c)
2221 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002222static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2223 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002224{
Alexander Duyckbd198052011-06-11 01:45:08 +00002225 int bytes = ring_container->total_bytes;
2226 int packets = ring_container->total_packets;
2227 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002228 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002229 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002230
2231 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002232 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002233
2234 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002235 * 0-10MB/s lowest (100000 ints/s)
2236 * 10-20MB/s low (20000 ints/s)
2237 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002238 */
2239 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002240 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002241 if (timepassed_us == 0)
2242 return;
2243
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002244 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2245
2246 switch (itr_setting) {
2247 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002248 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002249 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002250 break;
2251 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002252 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002253 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002254 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002255 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002256 break;
2257 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002258 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002259 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002260 break;
2261 }
2262
Alexander Duyckbd198052011-06-11 01:45:08 +00002263 /* clear work counters since we have the values we need */
2264 ring_container->total_bytes = 0;
2265 ring_container->total_packets = 0;
2266
2267 /* write updated itr to ring container */
2268 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002269}
2270
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002271/**
2272 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002273 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002274 *
2275 * This function is made to be called by ethtool and by the driver
2276 * when it needs to update EITR registers at runtime. Hardware
2277 * specific quirks/differences are taken care of here.
2278 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002279void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002280{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002281 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002282 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002283 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002284 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002285
Alexander Duyckbd508172010-11-16 19:27:03 -08002286 switch (adapter->hw.mac.type) {
2287 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002288 /* must write high and low 16 bits to reset counter */
2289 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002290 break;
2291 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002292 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002293 case ixgbe_mac_X550:
2294 case ixgbe_mac_X550EM_x:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002295 /*
2296 * set the WDIS bit to not clear the timer bits and cause an
2297 * immediate assertion of the interrupt
2298 */
2299 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002300 break;
2301 default:
2302 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002303 }
2304 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2305}
2306
Alexander Duyckbd198052011-06-11 01:45:08 +00002307static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002308{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002309 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002310 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002311
Alexander Duyckbd198052011-06-11 01:45:08 +00002312 ixgbe_update_itr(q_vector, &q_vector->tx);
2313 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002314
Alexander Duyck08c88332011-06-11 01:45:03 +00002315 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002316
2317 switch (current_itr) {
2318 /* counts and packets in update_itr are dependent on these numbers */
2319 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002320 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002321 break;
2322 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002323 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002324 break;
2325 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002326 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002327 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002328 default:
2329 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002330 }
2331
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002332 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002333 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002334 new_itr = (10 * new_itr * q_vector->itr) /
2335 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002336
Alexander Duyckbd198052011-06-11 01:45:08 +00002337 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002338 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002339
2340 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002341 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002342}
2343
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002344/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002345 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002346 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002347 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002348static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002349{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002350 struct ixgbe_hw *hw = &adapter->hw;
2351 u32 eicr = adapter->interrupt_event;
2352
Alexander Duyckf0f97782011-04-22 04:08:09 +00002353 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002354 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002355
Alexander Duyckf0f97782011-04-22 04:08:09 +00002356 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2357 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2358 return;
2359
2360 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2361
Joe Perches7ca647b2010-09-07 21:35:40 +00002362 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002363 case IXGBE_DEV_ID_82599_T3_LOM:
2364 /*
2365 * Since the warning interrupt is for both ports
2366 * we don't have to check if:
2367 * - This interrupt wasn't for our port.
2368 * - We may have missed the interrupt so always have to
2369 * check if we got a LSC
2370 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002371 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002372 !(eicr & IXGBE_EICR_LSC))
2373 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002374
Alexander Duyckf0f97782011-04-22 04:08:09 +00002375 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002376 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002377 bool link_up = false;
2378
Josh Hay3d292262012-12-15 03:28:19 +00002379 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002380
Alexander Duyckf0f97782011-04-22 04:08:09 +00002381 if (link_up)
2382 return;
2383 }
2384
2385 /* Check if this is not due to overtemp */
2386 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2387 return;
2388
2389 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002390 default:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002391 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002392 return;
2393 break;
2394 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002395 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002396
2397 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002398}
2399
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002400static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2401{
2402 struct ixgbe_hw *hw = &adapter->hw;
2403
2404 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002405 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002406 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002407 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002408 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002409 }
2410}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002411
Jacob Keller4f51bf72011-08-20 04:49:45 +00002412static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2413{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002414 struct ixgbe_hw *hw = &adapter->hw;
2415
Jacob Keller4f51bf72011-08-20 04:49:45 +00002416 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2417 return;
2418
2419 switch (adapter->hw.mac.type) {
2420 case ixgbe_mac_82599EB:
2421 /*
2422 * Need to check link state so complete overtemp check
2423 * on service task
2424 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002425 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2426 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002427 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2428 adapter->interrupt_event = eicr;
2429 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2430 ixgbe_service_event_schedule(adapter);
2431 return;
2432 }
2433 return;
2434 case ixgbe_mac_X540:
2435 if (!(eicr & IXGBE_EICR_TS))
2436 return;
2437 break;
2438 default:
2439 return;
2440 }
2441
Don Skidmoref44e7512015-06-09 16:36:23 -07002442 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002443}
2444
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002445static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2446{
2447 struct ixgbe_hw *hw = &adapter->hw;
2448
Don Skidmore9a900ec2015-06-09 17:15:01 -07002449 if (eicr & IXGBE_EICR_GPI_SDP2(hw)) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002450 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002451 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002452 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2453 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2454 ixgbe_service_event_schedule(adapter);
2455 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002456 }
2457
Don Skidmore9a900ec2015-06-09 17:15:01 -07002458 if (eicr & IXGBE_EICR_GPI_SDP1(hw)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002459 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002460 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002461 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2462 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2463 ixgbe_service_event_schedule(adapter);
2464 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002465 }
2466}
2467
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002468static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2469{
2470 struct ixgbe_hw *hw = &adapter->hw;
2471
2472 adapter->lsc_int++;
2473 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2474 adapter->link_check_timeout = jiffies;
2475 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2476 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002477 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002478 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002479 }
2480}
2481
Alexander Duyckfe49f042009-06-04 16:00:09 +00002482static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2483 u64 qmask)
2484{
2485 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002486 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002487
Alexander Duyckbd508172010-11-16 19:27:03 -08002488 switch (hw->mac.type) {
2489 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002490 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002491 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2492 break;
2493 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002494 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002495 case ixgbe_mac_X550:
2496 case ixgbe_mac_X550EM_x:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002497 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002498 if (mask)
2499 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002500 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002501 if (mask)
2502 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2503 break;
2504 default:
2505 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002506 }
2507 /* skip the flush */
2508}
2509
2510static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002511 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002512{
2513 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002514 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002515
Alexander Duyckbd508172010-11-16 19:27:03 -08002516 switch (hw->mac.type) {
2517 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002518 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002519 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2520 break;
2521 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002522 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002523 case ixgbe_mac_X550:
2524 case ixgbe_mac_X550EM_x:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002525 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002526 if (mask)
2527 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002528 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002529 if (mask)
2530 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2531 break;
2532 default:
2533 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002534 }
2535 /* skip the flush */
2536}
2537
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002538/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002539 * ixgbe_irq_enable - Enable default interrupt generation settings
2540 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002541 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002542static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2543 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002544{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002545 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002546 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002547
Alexander Duyck2c4af692011-07-15 07:29:55 +00002548 /* don't reenable LSC while waiting for link */
2549 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2550 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002551
Alexander Duyck2c4af692011-07-15 07:29:55 +00002552 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002553 switch (adapter->hw.mac.type) {
2554 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002555 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002556 break;
2557 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002558 case ixgbe_mac_X550:
2559 case ixgbe_mac_X550EM_x:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002560 mask |= IXGBE_EIMS_TS;
2561 break;
2562 default:
2563 break;
2564 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002565 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002566 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002567 switch (adapter->hw.mac.type) {
2568 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002569 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2570 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002571 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00002572 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002573 case ixgbe_mac_X550:
2574 case ixgbe_mac_X550EM_x:
Don Skidmore858bc082011-08-04 09:28:30 +00002575 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002576 mask |= IXGBE_EIMS_MAILBOX;
2577 break;
2578 default:
2579 break;
2580 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002581
Alexander Duyck2c4af692011-07-15 07:29:55 +00002582 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2583 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2584 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002585
Alexander Duyck2c4af692011-07-15 07:29:55 +00002586 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2587 if (queues)
2588 ixgbe_irq_enable_queues(adapter, ~0);
2589 if (flush)
2590 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002591}
2592
Alexander Duyck2c4af692011-07-15 07:29:55 +00002593static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002594{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002595 struct ixgbe_adapter *adapter = data;
2596 struct ixgbe_hw *hw = &adapter->hw;
2597 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002598
Alexander Duyck2c4af692011-07-15 07:29:55 +00002599 /*
2600 * Workaround for Silicon errata. Use clear-by-write instead
2601 * of clear-by-read. Reading with EICS will return the
2602 * interrupt causes without clearing, which later be done
2603 * with the write to EICR.
2604 */
2605 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002606
2607 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08002608 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00002609 * the bits are high when ixgbe_msix_other is called. There is a race
2610 * condition otherwise which results in possible performance loss
2611 * especially if the ixgbe_msix_other interrupt is triggering
2612 * consistently (as it would when PPS is turned on for the X540 device)
2613 */
2614 eicr &= 0xFFFF0000;
2615
Alexander Duyck2c4af692011-07-15 07:29:55 +00002616 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002617
Alexander Duyck2c4af692011-07-15 07:29:55 +00002618 if (eicr & IXGBE_EICR_LSC)
2619 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002620
Alexander Duyck2c4af692011-07-15 07:29:55 +00002621 if (eicr & IXGBE_EICR_MAILBOX)
2622 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002623
Alexander Duyck2c4af692011-07-15 07:29:55 +00002624 switch (hw->mac.type) {
2625 case ixgbe_mac_82599EB:
2626 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002627 case ixgbe_mac_X550:
2628 case ixgbe_mac_X550EM_x:
Don Skidmored773ce22014-02-25 17:58:53 -08002629 if (eicr & IXGBE_EICR_ECC) {
2630 e_info(link, "Received ECC Err, initiating reset\n");
2631 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2632 ixgbe_service_event_schedule(adapter);
2633 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2634 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002635 /* Handle Flow Director Full threshold interrupt */
2636 if (eicr & IXGBE_EICR_FLOW_DIR) {
2637 int reinit_count = 0;
2638 int i;
2639 for (i = 0; i < adapter->num_tx_queues; i++) {
2640 struct ixgbe_ring *ring = adapter->tx_ring[i];
2641 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2642 &ring->state))
2643 reinit_count++;
2644 }
2645 if (reinit_count) {
2646 /* no more flow director interrupts until after init */
2647 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2648 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2649 ixgbe_service_event_schedule(adapter);
2650 }
2651 }
2652 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002653 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002654 break;
2655 default:
2656 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002657 }
2658
Alexander Duyck2c4af692011-07-15 07:29:55 +00002659 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002660
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002661 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2662 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002663
Alexander Duyck2c4af692011-07-15 07:29:55 +00002664 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002665 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002666 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002667
Alexander Duyck2c4af692011-07-15 07:29:55 +00002668 return IRQ_HANDLED;
2669}
2670
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002671static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002672{
2673 struct ixgbe_q_vector *q_vector = data;
2674
Auke Kok9a799d72007-09-15 14:07:45 -07002675 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002676
2677 if (q_vector->rx.ring || q_vector->tx.ring)
2678 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002679
2680 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002681}
2682
Auke Kok9a799d72007-09-15 14:07:45 -07002683/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002684 * ixgbe_poll - NAPI Rx polling callback
2685 * @napi: structure for representing this polling device
2686 * @budget: how many packets driver is allowed to clean
2687 *
2688 * This function is used for legacy and MSI, NAPI mode
2689 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002690int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002691{
2692 struct ixgbe_q_vector *q_vector =
2693 container_of(napi, struct ixgbe_q_vector, napi);
2694 struct ixgbe_adapter *adapter = q_vector->adapter;
2695 struct ixgbe_ring *ring;
2696 int per_ring_budget;
2697 bool clean_complete = true;
2698
2699#ifdef CONFIG_IXGBE_DCA
2700 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2701 ixgbe_update_dca(q_vector);
2702#endif
2703
2704 ixgbe_for_each_ring(ring, q_vector->tx)
2705 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2706
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002707 if (!ixgbe_qv_lock_napi(q_vector))
2708 return budget;
2709
Alexander Duyckeb01b972012-02-08 07:51:27 +00002710 /* attempt to distribute budget to each queue fairly, but don't allow
2711 * the budget to go below 1 because we'll exit polling */
2712 if (q_vector->rx.count > 1)
2713 per_ring_budget = max(budget/q_vector->rx.count, 1);
2714 else
2715 per_ring_budget = budget;
2716
2717 ixgbe_for_each_ring(ring, q_vector->rx)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002718 clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring,
2719 per_ring_budget) < per_ring_budget);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002720
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002721 ixgbe_qv_unlock_napi(q_vector);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002722 /* If all work not completed, return budget and keep polling */
2723 if (!clean_complete)
2724 return budget;
2725
2726 /* all work done, exit the polling mode */
2727 napi_complete(napi);
2728 if (adapter->rx_itr_setting & 1)
2729 ixgbe_set_itr(q_vector);
2730 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2731 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2732
2733 return 0;
2734}
2735
2736/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002737 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2738 * @adapter: board private structure
2739 *
2740 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2741 * interrupts from the kernel.
2742 **/
2743static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2744{
2745 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002746 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002747 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002748
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002749 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002750 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002751 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002752
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002753 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002754 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002755 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002756 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002757 } else if (q_vector->rx.ring) {
2758 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2759 "%s-%s-%d", netdev->name, "rx", ri++);
2760 } else if (q_vector->tx.ring) {
2761 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2762 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002763 } else {
2764 /* skip this unused q_vector */
2765 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002766 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002767 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2768 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002769 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002770 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002771 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002772 goto free_queue_irqs;
2773 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002774 /* If Flow Director is enabled, set interrupt affinity */
2775 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2776 /* assign the mask for this irq */
2777 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002778 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002779 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002780 }
2781
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002782 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002783 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002784 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002785 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002786 goto free_queue_irqs;
2787 }
2788
2789 return 0;
2790
2791free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002792 while (vector) {
2793 vector--;
2794 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2795 NULL);
2796 free_irq(adapter->msix_entries[vector].vector,
2797 adapter->q_vector[vector]);
2798 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002799 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2800 pci_disable_msix(adapter->pdev);
2801 kfree(adapter->msix_entries);
2802 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002803 return err;
2804}
2805
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002806/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002807 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002808 * @irq: interrupt number
2809 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002810 **/
2811static irqreturn_t ixgbe_intr(int irq, void *data)
2812{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002813 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002814 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002815 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002816 u32 eicr;
2817
Don Skidmore54037502009-02-21 15:42:56 -08002818 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002819 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002820 * before the read of EICR.
2821 */
2822 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2823
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002824 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002825 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002826 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002827 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002828 /*
2829 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002830 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002831 * have disabled interrupts due to EIAM
2832 * finish the workaround of silicon errata on 82598. Unmask
2833 * the interrupt that we masked before the EICR read.
2834 */
2835 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2836 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002837 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002838 }
Auke Kok9a799d72007-09-15 14:07:45 -07002839
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002840 if (eicr & IXGBE_EICR_LSC)
2841 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002842
Alexander Duyckbd508172010-11-16 19:27:03 -08002843 switch (hw->mac.type) {
2844 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002845 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002846 /* Fall through */
2847 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002848 case ixgbe_mac_X550:
2849 case ixgbe_mac_X550EM_x:
Don Skidmored773ce22014-02-25 17:58:53 -08002850 if (eicr & IXGBE_EICR_ECC) {
2851 e_info(link, "Received ECC Err, initiating reset\n");
2852 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2853 ixgbe_service_event_schedule(adapter);
2854 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2855 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00002856 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002857 break;
2858 default:
2859 break;
2860 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002861
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002862 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002863 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2864 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002865
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002866 /* would disable interrupts here but EIAM disabled it */
2867 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002868
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002869 /*
2870 * re-enable link(maybe) and non-queue interrupts, no flush.
2871 * ixgbe_poll will re-enable the queue interrupts
2872 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002873 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2874 ixgbe_irq_enable(adapter, false, false);
2875
Auke Kok9a799d72007-09-15 14:07:45 -07002876 return IRQ_HANDLED;
2877}
2878
2879/**
2880 * ixgbe_request_irq - initialize interrupts
2881 * @adapter: board private structure
2882 *
2883 * Attempts to configure interrupts using the best available
2884 * capabilities of the hardware and kernel.
2885 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002886static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002887{
2888 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002889 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002890
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002891 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002892 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002893 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002894 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002895 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002896 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002897 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002898 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002899
Alexander Duyckde88eee2012-02-08 07:49:59 +00002900 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002901 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002902
Auke Kok9a799d72007-09-15 14:07:45 -07002903 return err;
2904}
2905
2906static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2907{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002908 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002909
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002910 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002911 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002912 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002913 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002914
2915 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2916 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2917 struct msix_entry *entry = &adapter->msix_entries[vector];
2918
2919 /* free only the irqs that were actually requested */
2920 if (!q_vector->rx.ring && !q_vector->tx.ring)
2921 continue;
2922
2923 /* clear the affinity_mask in the IRQ descriptor */
2924 irq_set_affinity_hint(entry->vector, NULL);
2925
2926 free_irq(entry->vector, q_vector);
2927 }
2928
2929 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002930}
2931
2932/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002933 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2934 * @adapter: board private structure
2935 **/
2936static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2937{
Alexander Duyckbd508172010-11-16 19:27:03 -08002938 switch (adapter->hw.mac.type) {
2939 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002940 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002941 break;
2942 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002943 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002944 case ixgbe_mac_X550:
2945 case ixgbe_mac_X550EM_x:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002946 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2947 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002948 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002949 break;
2950 default:
2951 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002952 }
2953 IXGBE_WRITE_FLUSH(&adapter->hw);
2954 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002955 int vector;
2956
2957 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2958 synchronize_irq(adapter->msix_entries[vector].vector);
2959
2960 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002961 } else {
2962 synchronize_irq(adapter->pdev->irq);
2963 }
2964}
2965
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002966/**
Auke Kok9a799d72007-09-15 14:07:45 -07002967 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2968 *
2969 **/
2970static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2971{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002972 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002973
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002974 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002975
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002976 ixgbe_set_ivar(adapter, 0, 0, 0);
2977 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002978
Emil Tantilov396e7992010-07-01 20:05:12 +00002979 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002980}
2981
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002982/**
2983 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2984 * @adapter: board private structure
2985 * @ring: structure containing ring specific data
2986 *
2987 * Configure the Tx descriptor ring after a reset.
2988 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002989void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2990 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002991{
2992 struct ixgbe_hw *hw = &adapter->hw;
2993 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002994 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002995 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002996 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002997
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002998 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002999 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003000 IXGBE_WRITE_FLUSH(hw);
3001
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003002 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003003 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003004 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3005 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3006 ring->count * sizeof(union ixgbe_adv_tx_desc));
3007 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3008 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003009 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003010
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003011 /*
3012 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003013 * higher than 1 when:
3014 * - ITR is 0 as it could cause false TX hangs
3015 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003016 *
3017 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3018 * to or less than the number of on chip descriptors, which is
3019 * currently 40.
3020 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003021 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003022 txdctl |= (1 << 16); /* WTHRESH = 1 */
3023 else
3024 txdctl |= (8 << 16); /* WTHRESH = 8 */
3025
Alexander Duycke954b372012-02-08 07:49:38 +00003026 /*
3027 * Setting PTHRESH to 32 both improves performance
3028 * and avoids a TX hang with DFP enabled
3029 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003030 txdctl |= (1 << 8) | /* HTHRESH = 1 */
3031 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003032
3033 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003034 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003035 ring->atr_sample_rate = adapter->atr_sample_rate;
3036 ring->atr_count = 0;
3037 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3038 } else {
3039 ring->atr_sample_rate = 0;
3040 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003041
Alexander Duyckfd786b72013-01-12 06:33:31 +00003042 /* initialize XPS */
3043 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3044 struct ixgbe_q_vector *q_vector = ring->q_vector;
3045
3046 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003047 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003048 &q_vector->affinity_mask,
3049 ring->queue_index);
3050 }
3051
John Fastabendc84d3242010-11-16 19:27:12 -08003052 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3053
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003054 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003055 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3056
3057 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3058 if (hw->mac.type == ixgbe_mac_82598EB &&
3059 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3060 return;
3061
3062 /* poll to verify queue is enabled */
3063 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003064 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003065 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3066 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3067 if (!wait_loop)
3068 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003069}
3070
Alexander Duyck120ff942010-08-19 13:34:50 +00003071static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3072{
3073 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003074 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003075 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003076
3077 if (hw->mac.type == ixgbe_mac_82598EB)
3078 return;
3079
3080 /* disable the arbiter while setting MTQC */
3081 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3082 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3083 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3084
3085 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003086 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3087 mtqc = IXGBE_MTQC_VT_ENA;
3088 if (tcs > 4)
3089 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3090 else if (tcs > 1)
3091 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3092 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3093 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003094 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003095 mtqc |= IXGBE_MTQC_64VF;
3096 } else {
3097 if (tcs > 4)
3098 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3099 else if (tcs > 1)
3100 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3101 else
3102 mtqc = IXGBE_MTQC_64Q_1PB;
3103 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003104
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003105 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003106
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003107 /* Enable Security TX Buffer IFG for multiple pb */
3108 if (tcs) {
3109 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3110 sectx |= IXGBE_SECTX_DCB;
3111 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003112 }
3113
3114 /* re-enable the arbiter */
3115 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3116 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3117}
3118
Auke Kok9a799d72007-09-15 14:07:45 -07003119/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003120 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003121 * @adapter: board private structure
3122 *
3123 * Configure the Tx unit of the MAC after a reset.
3124 **/
3125static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3126{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003127 struct ixgbe_hw *hw = &adapter->hw;
3128 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003129 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003130
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003131 ixgbe_setup_mtqc(adapter);
3132
3133 if (hw->mac.type != ixgbe_mac_82598EB) {
3134 /* DMATXCTL.EN must be before Tx queues are enabled */
3135 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3136 dmatxctl |= IXGBE_DMATXCTL_TE;
3137 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3138 }
3139
Auke Kok9a799d72007-09-15 14:07:45 -07003140 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003141 for (i = 0; i < adapter->num_tx_queues; i++)
3142 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003143}
3144
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003145static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3146 struct ixgbe_ring *ring)
3147{
3148 struct ixgbe_hw *hw = &adapter->hw;
3149 u8 reg_idx = ring->reg_idx;
3150 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3151
3152 srrctl |= IXGBE_SRRCTL_DROP_EN;
3153
3154 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3155}
3156
3157static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3158 struct ixgbe_ring *ring)
3159{
3160 struct ixgbe_hw *hw = &adapter->hw;
3161 u8 reg_idx = ring->reg_idx;
3162 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3163
3164 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3165
3166 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3167}
3168
3169#ifdef CONFIG_IXGBE_DCB
3170void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3171#else
3172static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3173#endif
3174{
3175 int i;
3176 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3177
3178 if (adapter->ixgbe_ieee_pfc)
3179 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3180
3181 /*
3182 * We should set the drop enable bit if:
3183 * SR-IOV is enabled
3184 * or
3185 * Number of Rx queues > 1 and flow control is disabled
3186 *
3187 * This allows us to avoid head of line blocking for security
3188 * and performance reasons.
3189 */
3190 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3191 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3192 for (i = 0; i < adapter->num_rx_queues; i++)
3193 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3194 } else {
3195 for (i = 0; i < adapter->num_rx_queues; i++)
3196 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3197 }
3198}
3199
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003200#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003201
Yi Zoua6616b42009-08-06 13:05:23 +00003202static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003203 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003204{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003205 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003206 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003207 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003208
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003209 if (hw->mac.type == ixgbe_mac_82598EB) {
3210 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3211
3212 /*
3213 * if VMDq is not active we must program one srrctl register
3214 * per RSS queue since we have enabled RDRXCTL.MVMEN
3215 */
3216 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003217 }
3218
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003219 /* configure header buffer length, needed for RSC */
3220 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003221
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003222 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00003223 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003224
3225 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003226 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003227
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003228 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003229}
3230
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003231/**
3232 * Return a number of entries in the RSS indirection table
3233 *
3234 * @adapter: device handle
3235 *
3236 * - 82598/82599/X540: 128
3237 * - X550(non-SRIOV mode): 512
3238 * - X550(SRIOV mode): 64
3239 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003240u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003241{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003242 if (adapter->hw.mac.type < ixgbe_mac_X550)
3243 return 128;
3244 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3245 return 64;
3246 else
3247 return 512;
3248}
3249
3250/**
3251 * Write the RETA table to HW
3252 *
3253 * @adapter: device handle
3254 *
3255 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3256 */
3257static void ixgbe_store_reta(struct ixgbe_adapter *adapter)
3258{
3259 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003260 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003261 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003262 u32 indices_multi;
3263 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003264
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003265 /* Fill out the redirection table as follows:
3266 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3267 * indices.
3268 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3269 * - X550: 8 bit wide entries containing 6 bit RSS index
3270 */
3271 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3272 indices_multi = 0x11;
3273 else
3274 indices_multi = 0x1;
3275
3276 /* Write redirection table to HW */
3277 for (i = 0; i < reta_entries; i++) {
3278 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3279 if ((i & 3) == 3) {
3280 if (i < 128)
3281 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3282 else
3283 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3284 reta);
3285 reta = 0;
3286 }
3287 }
3288}
3289
3290/**
3291 * Write the RETA table to HW (for x550 devices in SRIOV mode)
3292 *
3293 * @adapter: device handle
3294 *
3295 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3296 */
3297static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3298{
3299 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3300 struct ixgbe_hw *hw = &adapter->hw;
3301 u32 vfreta = 0;
3302 unsigned int pf_pool = adapter->num_vfs;
3303
3304 /* Write redirection table to HW */
3305 for (i = 0; i < reta_entries; i++) {
3306 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3307 if ((i & 3) == 3) {
3308 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3309 vfreta);
3310 vfreta = 0;
3311 }
3312 }
3313}
3314
3315static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3316{
3317 struct ixgbe_hw *hw = &adapter->hw;
3318 u32 i, j;
3319 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3320 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3321
3322 /* Program table for at least 2 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003323 * make full use of any rings they may have. We will use the
3324 * PSRTYPE register to control how many rings we use within the PF.
3325 */
3326 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3327 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003328
Alexander Duyck05abb122010-08-19 13:35:41 +00003329 /* Fill out hash function seeds */
3330 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003331 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003332
Alexander Duyck05abb122010-08-19 13:35:41 +00003333 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003334 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3335
Don Skidmore0f9b2322014-11-18 09:35:08 +00003336 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003337 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003338 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003339
3340 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003341 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003342
3343 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003344}
3345
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003346static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003347{
3348 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003349 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3350 unsigned int pf_pool = adapter->num_vfs;
3351 int i, j;
3352
3353 /* Fill out hash function seeds */
3354 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003355 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
3356 adapter->rss_key[i]);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003357
3358 /* Fill out the redirection table */
3359 for (i = 0, j = 0; i < 64; i++, j++) {
3360 if (j == rss_i)
3361 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003362
3363 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003364 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003365
3366 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003367}
3368
3369static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3370{
3371 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003372 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003373 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003374
3375 /* Disable indicating checksum in descriptor, enables RSS hash */
3376 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3377 rxcsum |= IXGBE_RXCSUM_PCSD;
3378 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3379
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003380 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003381 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003382 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003383 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003384 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003385
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003386 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3387 if (tcs > 4)
3388 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3389 else if (tcs > 1)
3390 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3391 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3392 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3393 else
3394 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3395 } else {
3396 if (tcs > 4)
3397 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3398 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003399 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3400 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003401 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003402 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003403 }
3404
Alexander Duyck05abb122010-08-19 13:35:41 +00003405 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003406 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3407 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3408 IXGBE_MRQC_RSS_FIELD_IPV6 |
3409 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003410
Alexander Duyckef6afc02012-02-08 07:51:53 +00003411 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003412 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003413 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003414 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003415
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003416 netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003417 if ((hw->mac.type >= ixgbe_mac_X550) &&
3418 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3419 unsigned int pf_pool = adapter->num_vfs;
3420
3421 /* Enable VF RSS mode */
3422 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3423 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3424
3425 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003426 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003427 vfmrqc = IXGBE_MRQC_RSSEN;
3428 vfmrqc |= rss_field;
3429 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3430 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003431 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003432 mrqc |= rss_field;
3433 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3434 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003435}
3436
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003437/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003438 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3439 * @adapter: address of board private structure
3440 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003441 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003442static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003443 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003444{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003445 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003446 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003447 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003448
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003449 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003450 return;
3451
Alexander Duyck73670962010-08-19 13:38:34 +00003452 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003453 rscctrl |= IXGBE_RSCCTL_RSCEN;
3454 /*
3455 * we must limit the number of descriptors so that the
3456 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003457 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003458 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003459 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003460 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003461}
3462
Alexander Duyck9e10e042010-08-19 13:40:06 +00003463#define IXGBE_MAX_RX_DESC_POLL 10
3464static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3465 struct ixgbe_ring *ring)
3466{
3467 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003468 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3469 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003470 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003471
Mark Rustadb0483c82014-01-14 18:53:17 -08003472 if (ixgbe_removed(hw->hw_addr))
3473 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003474 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3475 if (hw->mac.type == ixgbe_mac_82598EB &&
3476 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3477 return;
3478
3479 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003480 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003481 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3482 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3483
3484 if (!wait_loop) {
3485 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3486 "the polling period\n", reg_idx);
3487 }
3488}
3489
Yi Zou2d39d572011-01-06 14:29:56 +00003490void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3491 struct ixgbe_ring *ring)
3492{
3493 struct ixgbe_hw *hw = &adapter->hw;
3494 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3495 u32 rxdctl;
3496 u8 reg_idx = ring->reg_idx;
3497
Mark Rustadb0483c82014-01-14 18:53:17 -08003498 if (ixgbe_removed(hw->hw_addr))
3499 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003500 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3501 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3502
3503 /* write value back with RXDCTL.ENABLE bit cleared */
3504 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3505
3506 if (hw->mac.type == ixgbe_mac_82598EB &&
3507 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3508 return;
3509
3510 /* the hardware may take up to 100us to really disable the rx queue */
3511 do {
3512 udelay(10);
3513 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3514 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3515
3516 if (!wait_loop) {
3517 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3518 "the polling period\n", reg_idx);
3519 }
3520}
3521
Alexander Duyck84418e32010-08-19 13:40:54 +00003522void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3523 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003524{
3525 struct ixgbe_hw *hw = &adapter->hw;
3526 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003527 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003528 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003529
Alexander Duyck9e10e042010-08-19 13:40:06 +00003530 /* disable queue to avoid issues while updating state */
3531 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003532 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003533
Alexander Duyckacd37172010-08-19 13:36:05 +00003534 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3535 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3536 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3537 ring->count * sizeof(union ixgbe_adv_rx_desc));
3538 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3539 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003540 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003541
3542 ixgbe_configure_srrctl(adapter, ring);
3543 ixgbe_configure_rscctl(adapter, ring);
3544
3545 if (hw->mac.type == ixgbe_mac_82598EB) {
3546 /*
3547 * enable cache line friendly hardware writes:
3548 * PTHRESH=32 descriptors (half the internal cache),
3549 * this also removes ugly rx_no_buffer_count increment
3550 * HTHRESH=4 descriptors (to minimize latency on fetch)
3551 * WTHRESH=8 burst writeback up to two cache lines
3552 */
3553 rxdctl &= ~0x3FFFFF;
3554 rxdctl |= 0x080420;
3555 }
3556
3557 /* enable receive descriptor ring */
3558 rxdctl |= IXGBE_RXDCTL_ENABLE;
3559 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3560
3561 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003562 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003563}
3564
Alexander Duyck48654522010-08-19 13:36:27 +00003565static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3566{
3567 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003568 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08003569 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00003570
3571 /* PSRTYPE must be initialized in non 82598 adapters */
3572 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003573 IXGBE_PSRTYPE_UDPHDR |
3574 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003575 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003576 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003577
3578 if (hw->mac.type == ixgbe_mac_82598EB)
3579 return;
3580
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003581 if (rss_i > 3)
3582 psrtype |= 2 << 29;
3583 else if (rss_i > 1)
3584 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003585
John Fastabend2a47fa42013-11-06 09:54:52 -08003586 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3587 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00003588}
3589
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003590static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3591{
3592 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003593 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003594 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003595 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003596
3597 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3598 return;
3599
3600 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003601 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3602 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003603 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003604 vmdctl |= IXGBE_VT_CTL_REPLEN;
3605 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003606
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003607 vf_shift = VMDQ_P(0) % 32;
3608 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003609
3610 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003611 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3612 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3613 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3614 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07003615 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00003616 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003617
3618 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003619 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003620
3621 /*
3622 * Set up VF register offsets for selected VT Mode,
3623 * i.e. 32 or 64 VFs for SR-IOV
3624 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003625 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3626 case IXGBE_82599_VMDQ_8Q_MASK:
3627 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3628 break;
3629 case IXGBE_82599_VMDQ_4Q_MASK:
3630 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3631 break;
3632 default:
3633 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3634 break;
3635 }
3636
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003637 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3638
Alexander Duyck435b19f2012-05-18 06:34:08 +00003639
Greg Rosea985b6c32010-11-18 03:02:52 +00003640 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003641 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003642 adapter->num_vfs);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003643
3644 /* Ensure LLDP is set for Ethertype Antispoofing if we will be
3645 * calling set_ethertype_anti_spoofing for each VF in loop below
3646 */
3647 if (hw->mac.ops.set_ethertype_anti_spoofing)
3648 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP),
3649 (IXGBE_ETQF_FILTER_EN | /* enable filter */
3650 IXGBE_ETQF_TX_ANTISPOOF | /* tx antispoof */
3651 IXGBE_ETH_P_LLDP)); /* LLDP eth type */
3652
Greg Rosede4c7f62011-09-29 05:57:33 +00003653 /* For VFs that have spoof checking turned off */
3654 for (i = 0; i < adapter->num_vfs; i++) {
3655 if (!adapter->vfinfo[i].spoofchk_enabled)
3656 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003657
3658 /* enable ethertype anti spoofing if hw supports it */
3659 if (hw->mac.ops.set_ethertype_anti_spoofing)
3660 hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03003661
3662 /* Enable/Disable RSS query feature */
3663 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
3664 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00003665 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003666}
3667
Alexander Duyck477de6e2010-08-19 13:38:11 +00003668static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003669{
Auke Kok9a799d72007-09-15 14:07:45 -07003670 struct ixgbe_hw *hw = &adapter->hw;
3671 struct net_device *netdev = adapter->netdev;
3672 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003673 struct ixgbe_ring *rx_ring;
3674 int i;
3675 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003676
Alexander Duyck477de6e2010-08-19 13:38:11 +00003677#ifdef IXGBE_FCOE
3678 /* adjust max frame to be able to do baby jumbo for FCoE */
3679 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3680 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3681 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3682
3683#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003684
3685 /* adjust max frame to be at least the size of a standard frame */
3686 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3687 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3688
Alexander Duyck477de6e2010-08-19 13:38:11 +00003689 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3690 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3691 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3692 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3693
3694 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003695 }
3696
Auke Kok9a799d72007-09-15 14:07:45 -07003697 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003698 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3699 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003700 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3701
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003702 /*
3703 * Setup the HW Rx Head and Tail Descriptor Pointers and
3704 * the Base and Length of the Rx Descriptor Ring
3705 */
Auke Kok9a799d72007-09-15 14:07:45 -07003706 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003707 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003708 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3709 set_ring_rsc_enabled(rx_ring);
3710 else
3711 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003712 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003713}
3714
Alexander Duyck73670962010-08-19 13:38:34 +00003715static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3716{
3717 struct ixgbe_hw *hw = &adapter->hw;
3718 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3719
3720 switch (hw->mac.type) {
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003721 case ixgbe_mac_X550:
3722 case ixgbe_mac_X550EM_x:
Alexander Duyck73670962010-08-19 13:38:34 +00003723 case ixgbe_mac_82598EB:
3724 /*
3725 * For VMDq support of different descriptor types or
3726 * buffer sizes through the use of multiple SRRCTL
3727 * registers, RDRXCTL.MVMEN must be set to 1
3728 *
3729 * also, the manual doesn't mention it clearly but DCA hints
3730 * will only use queue 0's tags unless this bit is set. Side
3731 * effects of setting this bit are only that SRRCTL must be
3732 * fully programmed [0..15]
3733 */
3734 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3735 break;
3736 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003737 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003738 /* Disable RSC for ACK packets */
3739 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3740 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3741 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3742 /* hardware requires some bits to be set by default */
3743 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3744 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3745 break;
3746 default:
3747 /* We should do nothing since we don't know this hardware */
3748 return;
3749 }
3750
3751 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3752}
3753
Alexander Duyck477de6e2010-08-19 13:38:11 +00003754/**
3755 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3756 * @adapter: board private structure
3757 *
3758 * Configure the Rx unit of the MAC after a reset.
3759 **/
3760static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3761{
3762 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003763 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003764 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003765
3766 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07003767 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003768
3769 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003770 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003771
Jacob Keller6dcc28b2013-07-17 02:53:23 +00003772 /* RSC Setup */
3773 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
3774 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
3775 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
3776 rfctl |= IXGBE_RFCTL_RSC_DIS;
3777 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
3778
Alexander Duyck9e10e042010-08-19 13:40:06 +00003779 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003780 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003781
Alexander Duyck477de6e2010-08-19 13:38:11 +00003782 /* set_rx_buffer_len must be called before ring initialization */
3783 ixgbe_set_rx_buffer_len(adapter);
3784
3785 /*
3786 * Setup the HW Rx Head and Tail Descriptor Pointers and
3787 * the Base and Length of the Rx Descriptor Ring
3788 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003789 for (i = 0; i < adapter->num_rx_queues; i++)
3790 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003791
Don Skidmore1f9ac572015-03-13 13:54:30 -07003792 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003793 /* disable drop enable for 82598 parts */
3794 if (hw->mac.type == ixgbe_mac_82598EB)
3795 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3796
3797 /* enable all receives */
3798 rxctrl |= IXGBE_RXCTRL_RXEN;
3799 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003800}
3801
Patrick McHardy80d5c362013-04-19 02:04:28 +00003802static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3803 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003804{
3805 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003806 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003807
3808 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003809 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003810 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003811
3812 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003813}
3814
Patrick McHardy80d5c362013-04-19 02:04:28 +00003815static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
3816 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003817{
3818 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003819 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003820
Auke Kok9a799d72007-09-15 14:07:45 -07003821 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003822 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003823 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003824
3825 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003826}
3827
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003828/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003829 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3830 * @adapter: driver data
3831 */
3832static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3833{
3834 struct ixgbe_hw *hw = &adapter->hw;
3835 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003836 int i, j;
3837
3838 switch (hw->mac.type) {
3839 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003840 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3841 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003842 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3843 break;
3844 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003845 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003846 case ixgbe_mac_X550:
3847 case ixgbe_mac_X550EM_x:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003848 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08003849 struct ixgbe_ring *ring = adapter->rx_ring[i];
3850
3851 if (ring->l2_accel_priv)
3852 continue;
3853 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003854 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3855 vlnctrl &= ~IXGBE_RXDCTL_VME;
3856 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3857 }
3858 break;
3859 default:
3860 break;
3861 }
3862}
3863
3864/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003865 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003866 * @adapter: driver data
3867 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003868static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003869{
3870 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003871 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003872 int i, j;
3873
3874 switch (hw->mac.type) {
3875 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003876 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3877 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003878 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3879 break;
3880 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003881 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003882 case ixgbe_mac_X550:
3883 case ixgbe_mac_X550EM_x:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003884 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08003885 struct ixgbe_ring *ring = adapter->rx_ring[i];
3886
3887 if (ring->l2_accel_priv)
3888 continue;
3889 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003890 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3891 vlnctrl |= IXGBE_RXDCTL_VME;
3892 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3893 }
3894 break;
3895 default:
3896 break;
3897 }
3898}
3899
Auke Kok9a799d72007-09-15 14:07:45 -07003900static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3901{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003902 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003903
Patrick McHardy80d5c362013-04-19 02:04:28 +00003904 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003905
3906 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00003907 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003908}
3909
3910/**
Jacob Kellerb335e752014-03-25 07:45:27 +00003911 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
3912 * @netdev: network interface device structure
3913 *
3914 * Writes multicast address list to the MTA hash table.
3915 * Returns: -ENOMEM on failure
3916 * 0 on no addresses written
3917 * X on writing X addresses to MTA
3918 **/
3919static int ixgbe_write_mc_addr_list(struct net_device *netdev)
3920{
3921 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3922 struct ixgbe_hw *hw = &adapter->hw;
3923
3924 if (!netif_running(netdev))
3925 return 0;
3926
3927 if (hw->mac.ops.update_mc_addr_list)
3928 hw->mac.ops.update_mc_addr_list(hw, netdev);
3929 else
3930 return -ENOMEM;
3931
3932#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00003933 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00003934#endif
3935
3936 return netdev_mc_count(netdev);
3937}
3938
Jacob Keller5d7daa32014-03-29 06:51:25 +00003939#ifdef CONFIG_PCI_IOV
3940void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
3941{
3942 struct ixgbe_hw *hw = &adapter->hw;
3943 int i;
3944 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3945 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
3946 hw->mac.ops.set_rar(hw, i, adapter->mac_table[i].addr,
3947 adapter->mac_table[i].queue,
3948 IXGBE_RAH_AV);
3949 else
3950 hw->mac.ops.clear_rar(hw, i);
3951
3952 adapter->mac_table[i].state &= ~(IXGBE_MAC_STATE_MODIFIED);
3953 }
3954}
3955#endif
3956
3957static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
3958{
3959 struct ixgbe_hw *hw = &adapter->hw;
3960 int i;
3961 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3962 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_MODIFIED) {
3963 if (adapter->mac_table[i].state &
3964 IXGBE_MAC_STATE_IN_USE)
3965 hw->mac.ops.set_rar(hw, i,
3966 adapter->mac_table[i].addr,
3967 adapter->mac_table[i].queue,
3968 IXGBE_RAH_AV);
3969 else
3970 hw->mac.ops.clear_rar(hw, i);
3971
3972 adapter->mac_table[i].state &=
3973 ~(IXGBE_MAC_STATE_MODIFIED);
3974 }
3975 }
3976}
3977
3978static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
3979{
3980 int i;
3981 struct ixgbe_hw *hw = &adapter->hw;
3982
3983 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3984 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
3985 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
Joe Perchesc7bf7162015-03-02 19:54:47 -08003986 eth_zero_addr(adapter->mac_table[i].addr);
Jacob Keller5d7daa32014-03-29 06:51:25 +00003987 adapter->mac_table[i].queue = 0;
3988 }
3989 ixgbe_sync_mac_table(adapter);
3990}
3991
3992static int ixgbe_available_rars(struct ixgbe_adapter *adapter)
3993{
3994 struct ixgbe_hw *hw = &adapter->hw;
3995 int i, count = 0;
3996
3997 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3998 if (adapter->mac_table[i].state == 0)
3999 count++;
4000 }
4001 return count;
4002}
4003
4004/* this function destroys the first RAR entry */
4005static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter,
4006 u8 *addr)
4007{
4008 struct ixgbe_hw *hw = &adapter->hw;
4009
4010 memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN);
4011 adapter->mac_table[0].queue = VMDQ_P(0);
4012 adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
4013 IXGBE_MAC_STATE_IN_USE);
4014 hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
4015 adapter->mac_table[0].queue,
4016 IXGBE_RAH_AV);
4017}
4018
4019int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
4020{
4021 struct ixgbe_hw *hw = &adapter->hw;
4022 int i;
4023
4024 if (is_zero_ether_addr(addr))
4025 return -EINVAL;
4026
4027 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4028 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
4029 continue;
4030 adapter->mac_table[i].state |= (IXGBE_MAC_STATE_MODIFIED |
4031 IXGBE_MAC_STATE_IN_USE);
4032 ether_addr_copy(adapter->mac_table[i].addr, addr);
4033 adapter->mac_table[i].queue = queue;
4034 ixgbe_sync_mac_table(adapter);
4035 return i;
4036 }
4037 return -ENOMEM;
4038}
4039
4040int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
4041{
4042 /* search table for addr, if found, set to 0 and sync */
4043 int i;
4044 struct ixgbe_hw *hw = &adapter->hw;
4045
4046 if (is_zero_ether_addr(addr))
4047 return -EINVAL;
4048
4049 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4050 if (ether_addr_equal(addr, adapter->mac_table[i].addr) &&
4051 adapter->mac_table[i].queue == queue) {
4052 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
4053 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
Joe Perchesc7bf7162015-03-02 19:54:47 -08004054 eth_zero_addr(adapter->mac_table[i].addr);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004055 adapter->mac_table[i].queue = 0;
4056 ixgbe_sync_mac_table(adapter);
4057 return 0;
4058 }
4059 }
4060 return -ENOMEM;
4061}
Jacob Kellerb335e752014-03-25 07:45:27 +00004062/**
Alexander Duyck28500622010-06-15 09:25:48 +00004063 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4064 * @netdev: network interface device structure
4065 *
4066 * Writes unicast address list to the RAR table.
4067 * Returns: -ENOMEM on failure/insufficient address space
4068 * 0 on no addresses written
4069 * X on writing X addresses to the RAR table
4070 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004071static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004072{
4073 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004074 int count = 0;
4075
4076 /* return ENOMEM indicating insufficient memory for addresses */
Jacob Keller5d7daa32014-03-29 06:51:25 +00004077 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter))
Alexander Duyck28500622010-06-15 09:25:48 +00004078 return -ENOMEM;
4079
John Fastabend95447462012-05-31 12:42:26 +00004080 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004081 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004082 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004083 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4084 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004085 count++;
4086 }
4087 }
Alexander Duyck28500622010-06-15 09:25:48 +00004088 return count;
4089}
4090
4091/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004092 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004093 * @netdev: network interface device structure
4094 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004095 * The set_rx_method entry point is called whenever the unicast/multicast
4096 * address list or the network interface flags are updated. This routine is
4097 * responsible for configuring the hardware for proper unicast, multicast and
4098 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004099 **/
Greg Rose7f870472010-01-09 02:25:29 +00004100void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004101{
4102 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4103 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004104 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Jacob Kellera9b89432014-03-25 07:45:26 +00004105 u32 vlnctrl;
Alexander Duyck28500622010-06-15 09:25:48 +00004106 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004107
4108 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004109 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Jacob Kellera9b89432014-03-25 07:45:26 +00004110 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07004111
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004112 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004113 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004114 fctrl |= IXGBE_FCTRL_BAM;
4115 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4116 fctrl |= IXGBE_FCTRL_PMCF;
4117
Alexander Duyck28500622010-06-15 09:25:48 +00004118 /* clear the bits we are changing the status of */
4119 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellera9b89432014-03-25 07:45:26 +00004120 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004121 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004122 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004123 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004124 vmolr |= IXGBE_VMOLR_MPE;
Greg Rose670224f2013-02-22 02:14:39 +00004125 /* Only disable hardware filter vlans in promiscuous mode
4126 * if SR-IOV and VMDQ are disabled - otherwise ensure
4127 * that hardware VLAN filters remain enabled.
4128 */
Vlad Yasevich4556dc52014-11-21 23:52:52 -08004129 if (adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED |
4130 IXGBE_FLAG_SRIOV_ENABLED))
Jacob Kellera9b89432014-03-25 07:45:26 +00004131 vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004132 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004133 if (netdev->flags & IFF_ALLMULTI) {
4134 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004135 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004136 }
Jacob Kellera9b89432014-03-25 07:45:26 +00004137 vlnctrl |= IXGBE_VLNCTRL_VFE;
Emil Tantilove433ea12010-05-13 17:33:00 +00004138 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004139 }
4140
4141 /*
4142 * Write addresses to available RAR registers, if there is not
4143 * sufficient space to store all the addresses then enable
4144 * unicast promiscuous mode
4145 */
Jacob Keller5d7daa32014-03-29 06:51:25 +00004146 count = ixgbe_write_uc_addr_list(netdev, VMDQ_P(0));
John Fastabend9dcb3732012-04-15 06:44:25 +00004147 if (count < 0) {
4148 fctrl |= IXGBE_FCTRL_UPE;
4149 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004150 }
4151
Emil Tantilovcf789592013-10-26 08:13:20 +00004152 /* Write addresses to the MTA, if the attempt fails
4153 * then we should just turn on promiscuous mode so
4154 * that we can at least receive multicast traffic
4155 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004156 count = ixgbe_write_mc_addr_list(netdev);
4157 if (count < 0) {
4158 fctrl |= IXGBE_FCTRL_MPE;
4159 vmolr |= IXGBE_VMOLR_MPE;
4160 } else if (count) {
4161 vmolr |= IXGBE_VMOLR_ROMPE;
4162 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004163
4164 if (hw->mac.type != ixgbe_mac_82598EB) {
4165 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004166 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4167 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004168 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004169 }
4170
Ben Greear3f2d1c02012-03-08 08:28:41 +00004171 /* This is useful for sniffing bad packets. */
4172 if (adapter->netdev->features & NETIF_F_RXALL) {
4173 /* UPE and MPE will be handled by normal PROMISC logic
4174 * in e1000e_set_rx_mode */
4175 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4176 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4177 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4178
4179 fctrl &= ~(IXGBE_FCTRL_DPF);
4180 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4181 }
4182
Jacob Kellera9b89432014-03-25 07:45:26 +00004183 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004184 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004185
Patrick McHardyf6469682013-04-19 02:04:27 +00004186 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004187 ixgbe_vlan_strip_enable(adapter);
4188 else
4189 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004190}
4191
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004192static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4193{
4194 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004195
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004196 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
4197 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004198 napi_enable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004199 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004200}
4201
4202static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4203{
4204 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004205
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004206 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004207 napi_disable(&adapter->q_vector[q_idx]->napi);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004208 while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) {
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004209 pr_info("QV %d locked\n", q_idx);
Jacob Keller27d9ce42013-09-21 05:05:44 +00004210 usleep_range(1000, 20000);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03004211 }
4212 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004213}
4214
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004215#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004216/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004217 * ixgbe_configure_dcb - Configure DCB hardware
4218 * @adapter: ixgbe adapter struct
4219 *
4220 * This is called by the driver on open to configure the DCB hardware.
4221 * This is also called by the gennetlink interface when reconfiguring
4222 * the DCB state.
4223 */
4224static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4225{
4226 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00004227 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004228
Alexander Duyck67ebd792010-08-19 13:34:04 +00004229 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4230 if (hw->mac.type == ixgbe_mac_82598EB)
4231 netif_set_gso_max_size(adapter->netdev, 65536);
4232 return;
4233 }
4234
4235 if (hw->mac.type == ixgbe_mac_82598EB)
4236 netif_set_gso_max_size(adapter->netdev, 32768);
4237
John Fastabendb1208182011-10-15 05:00:10 +00004238#ifdef IXGBE_FCOE
4239 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4240 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4241#endif
4242
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004243 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004244 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004245 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4246 DCB_TX_CONFIG);
4247 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4248 DCB_RX_CONFIG);
4249 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004250 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4251 ixgbe_dcb_hw_ets(&adapter->hw,
4252 adapter->ixgbe_ieee_ets,
4253 max_frame);
4254 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4255 adapter->ixgbe_ieee_pfc->pfc_en,
4256 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004257 }
John Fastabend8187cd42011-02-23 05:58:08 +00004258
4259 /* Enable RSS Hash per TC */
4260 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004261 u32 msb = 0;
4262 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004263
Alexander Duyckd411a932012-06-30 00:14:01 +00004264 while (rss_i) {
4265 msb++;
4266 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004267 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004268
Alexander Duyck4ae63732012-06-22 06:46:33 +00004269 /* write msb to all 8 TCs in one write */
4270 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004271 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004272}
John Fastabend9da712d2011-08-23 03:14:22 +00004273#endif
4274
4275/* Additional bittime to account for IXGBE framing */
4276#define IXGBE_ETH_FRAMING 20
4277
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004278/**
John Fastabend9da712d2011-08-23 03:14:22 +00004279 * ixgbe_hpbthresh - calculate high water mark for flow control
4280 *
4281 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004282 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004283 */
4284static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4285{
4286 struct ixgbe_hw *hw = &adapter->hw;
4287 struct net_device *dev = adapter->netdev;
4288 int link, tc, kb, marker;
4289 u32 dv_id, rx_pba;
4290
4291 /* Calculate max LAN frame size */
4292 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4293
4294#ifdef IXGBE_FCOE
4295 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004296 if ((dev->features & NETIF_F_FCOE_MTU) &&
4297 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4298 (pb == ixgbe_fcoe_get_tc(adapter)))
4299 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004300#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004301
John Fastabend9da712d2011-08-23 03:14:22 +00004302 /* Calculate delay value for device */
4303 switch (hw->mac.type) {
4304 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004305 case ixgbe_mac_X550:
4306 case ixgbe_mac_X550EM_x:
John Fastabend9da712d2011-08-23 03:14:22 +00004307 dv_id = IXGBE_DV_X540(link, tc);
4308 break;
4309 default:
4310 dv_id = IXGBE_DV(link, tc);
4311 break;
4312 }
4313
4314 /* Loopback switch introduces additional latency */
4315 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4316 dv_id += IXGBE_B2BT(tc);
4317
4318 /* Delay value is calculated in bit times convert to KB */
4319 kb = IXGBE_BT2KB(dv_id);
4320 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4321
4322 marker = rx_pba - kb;
4323
4324 /* It is possible that the packet buffer is not large enough
4325 * to provide required headroom. In this case throw an error
4326 * to user and a do the best we can.
4327 */
4328 if (marker < 0) {
4329 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4330 "headroom to support flow control."
4331 "Decrease MTU or number of traffic classes\n", pb);
4332 marker = tc + 1;
4333 }
4334
4335 return marker;
4336}
4337
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004338/**
John Fastabend9da712d2011-08-23 03:14:22 +00004339 * ixgbe_lpbthresh - calculate low water mark for for flow control
4340 *
4341 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004342 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004343 */
Jacob Kellere5776622014-04-05 02:35:52 +00004344static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00004345{
4346 struct ixgbe_hw *hw = &adapter->hw;
4347 struct net_device *dev = adapter->netdev;
4348 int tc;
4349 u32 dv_id;
4350
4351 /* Calculate max LAN frame size */
4352 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4353
Jacob Kellere5776622014-04-05 02:35:52 +00004354#ifdef IXGBE_FCOE
4355 /* FCoE traffic class uses FCOE jumbo frames */
4356 if ((dev->features & NETIF_F_FCOE_MTU) &&
4357 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4358 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4359 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4360#endif
4361
John Fastabend9da712d2011-08-23 03:14:22 +00004362 /* Calculate delay value for device */
4363 switch (hw->mac.type) {
4364 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004365 case ixgbe_mac_X550:
4366 case ixgbe_mac_X550EM_x:
John Fastabend9da712d2011-08-23 03:14:22 +00004367 dv_id = IXGBE_LOW_DV_X540(tc);
4368 break;
4369 default:
4370 dv_id = IXGBE_LOW_DV(tc);
4371 break;
4372 }
4373
4374 /* Delay value is calculated in bit times convert to KB */
4375 return IXGBE_BT2KB(dv_id);
4376}
4377
4378/*
4379 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4380 */
4381static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4382{
4383 struct ixgbe_hw *hw = &adapter->hw;
4384 int num_tc = netdev_get_num_tc(adapter->netdev);
4385 int i;
4386
4387 if (!num_tc)
4388 num_tc = 1;
4389
John Fastabend9da712d2011-08-23 03:14:22 +00004390 for (i = 0; i < num_tc; i++) {
4391 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00004392 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00004393
4394 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00004395 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4396 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004397 }
Jacob Kellere5776622014-04-05 02:35:52 +00004398
4399 for (; i < MAX_TRAFFIC_CLASS; i++)
4400 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00004401}
John Fastabend80605c652011-05-02 12:34:10 +00004402
4403static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4404{
John Fastabend80605c652011-05-02 12:34:10 +00004405 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004406 int hdrm;
4407 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004408
4409 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4410 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004411 hdrm = 32 << adapter->fdir_pballoc;
4412 else
4413 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004414
Alexander Duyckf7e10272011-07-21 00:40:35 +00004415 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004416 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004417}
4418
Alexander Duycke4911d52011-05-11 07:18:52 +00004419static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4420{
4421 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004422 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004423 struct ixgbe_fdir_filter *filter;
4424
4425 spin_lock(&adapter->fdir_perfect_lock);
4426
4427 if (!hlist_empty(&adapter->fdir_filter_list))
4428 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4429
Sasha Levinb67bfe02013-02-27 17:06:00 -08004430 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004431 &adapter->fdir_filter_list, fdir_node) {
4432 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004433 &filter->filter,
4434 filter->sw_idx,
4435 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4436 IXGBE_FDIR_DROP_QUEUE :
4437 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004438 }
4439
4440 spin_unlock(&adapter->fdir_perfect_lock);
4441}
4442
John Fastabend2a47fa42013-11-06 09:54:52 -08004443static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4444 struct ixgbe_adapter *adapter)
4445{
4446 struct ixgbe_hw *hw = &adapter->hw;
4447 u32 vmolr;
4448
4449 /* No unicast promiscuous support for VMDQ devices. */
4450 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4451 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4452
4453 /* clear the affected bit */
4454 vmolr &= ~IXGBE_VMOLR_MPE;
4455
4456 if (dev->flags & IFF_ALLMULTI) {
4457 vmolr |= IXGBE_VMOLR_MPE;
4458 } else {
4459 vmolr |= IXGBE_VMOLR_ROMPE;
4460 hw->mac.ops.update_mc_addr_list(hw, dev);
4461 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00004462 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08004463 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4464}
4465
John Fastabend2a47fa42013-11-06 09:54:52 -08004466static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4467{
4468 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08004469 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08004470 struct ixgbe_hw *hw = &adapter->hw;
4471 u16 pool = vadapter->pool;
4472 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4473 IXGBE_PSRTYPE_UDPHDR |
4474 IXGBE_PSRTYPE_IPV4HDR |
4475 IXGBE_PSRTYPE_L2HDR |
4476 IXGBE_PSRTYPE_IPV6HDR;
4477
4478 if (hw->mac.type == ixgbe_mac_82598EB)
4479 return;
4480
4481 if (rss_i > 3)
4482 psrtype |= 2 << 29;
4483 else if (rss_i > 1)
4484 psrtype |= 1 << 29;
4485
4486 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4487}
4488
4489/**
4490 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4491 * @rx_ring: ring to free buffers from
4492 **/
4493static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4494{
4495 struct device *dev = rx_ring->dev;
4496 unsigned long size;
4497 u16 i;
4498
4499 /* ring already cleared, nothing to do */
4500 if (!rx_ring->rx_buffer_info)
4501 return;
4502
4503 /* Free all the Rx ring sk_buffs */
4504 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyck18cb6522014-11-14 00:56:29 +00004505 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08004506
John Fastabend2a47fa42013-11-06 09:54:52 -08004507 if (rx_buffer->skb) {
4508 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00004509 if (IXGBE_CB(skb)->page_released)
John Fastabend2a47fa42013-11-06 09:54:52 -08004510 dma_unmap_page(dev,
4511 IXGBE_CB(skb)->dma,
4512 ixgbe_rx_bufsz(rx_ring),
4513 DMA_FROM_DEVICE);
John Fastabend2a47fa42013-11-06 09:54:52 -08004514 dev_kfree_skb(skb);
Junwei Zhang4d2fcfb2014-10-22 15:29:03 +00004515 rx_buffer->skb = NULL;
John Fastabend2a47fa42013-11-06 09:54:52 -08004516 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00004517
4518 if (!rx_buffer->page)
4519 continue;
4520
4521 dma_unmap_page(dev, rx_buffer->dma,
4522 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
4523 __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring));
4524
John Fastabend2a47fa42013-11-06 09:54:52 -08004525 rx_buffer->page = NULL;
4526 }
4527
4528 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4529 memset(rx_ring->rx_buffer_info, 0, size);
4530
4531 /* Zero out the descriptor ring */
4532 memset(rx_ring->desc, 0, rx_ring->size);
4533
4534 rx_ring->next_to_alloc = 0;
4535 rx_ring->next_to_clean = 0;
4536 rx_ring->next_to_use = 0;
4537}
4538
4539static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
4540 struct ixgbe_ring *rx_ring)
4541{
4542 struct ixgbe_adapter *adapter = vadapter->real_adapter;
4543 int index = rx_ring->queue_index + vadapter->rx_base_queue;
4544
4545 /* shutdown specific queue receive and wait for dma to settle */
4546 ixgbe_disable_rx_queue(adapter, rx_ring);
4547 usleep_range(10000, 20000);
4548 ixgbe_irq_disable_queues(adapter, ((u64)1 << index));
4549 ixgbe_clean_rx_ring(rx_ring);
4550 rx_ring->l2_accel_priv = NULL;
4551}
4552
John Fastabendae72c8d2013-11-09 07:11:26 +00004553static int ixgbe_fwd_ring_down(struct net_device *vdev,
4554 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08004555{
4556 struct ixgbe_adapter *adapter = accel->real_adapter;
4557 unsigned int rxbase = accel->rx_base_queue;
4558 unsigned int txbase = accel->tx_base_queue;
4559 int i;
4560
4561 netif_tx_stop_all_queues(vdev);
4562
4563 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4564 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4565 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
4566 }
4567
4568 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4569 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
4570 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
4571 }
4572
4573
4574 return 0;
4575}
4576
4577static int ixgbe_fwd_ring_up(struct net_device *vdev,
4578 struct ixgbe_fwd_adapter *accel)
4579{
4580 struct ixgbe_adapter *adapter = accel->real_adapter;
4581 unsigned int rxbase, txbase, queues;
4582 int i, baseq, err = 0;
4583
4584 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
4585 return 0;
4586
4587 baseq = accel->pool * adapter->num_rx_queues_per_pool;
4588 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4589 accel->pool, adapter->num_rx_pools,
4590 baseq, baseq + adapter->num_rx_queues_per_pool,
4591 adapter->fwd_bitmask);
4592
4593 accel->netdev = vdev;
4594 accel->rx_base_queue = rxbase = baseq;
4595 accel->tx_base_queue = txbase = baseq;
4596
4597 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
4598 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4599
4600 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4601 adapter->rx_ring[rxbase + i]->netdev = vdev;
4602 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
4603 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
4604 }
4605
4606 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4607 adapter->tx_ring[txbase + i]->netdev = vdev;
4608 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
4609 }
4610
4611 queues = min_t(unsigned int,
4612 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
4613 err = netif_set_real_num_tx_queues(vdev, queues);
4614 if (err)
4615 goto fwd_queue_err;
4616
John Fastabend2a47fa42013-11-06 09:54:52 -08004617 err = netif_set_real_num_rx_queues(vdev, queues);
4618 if (err)
4619 goto fwd_queue_err;
4620
4621 if (is_valid_ether_addr(vdev->dev_addr))
4622 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
4623
4624 ixgbe_fwd_psrtype(accel);
4625 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
4626 return err;
4627fwd_queue_err:
4628 ixgbe_fwd_ring_down(vdev, accel);
4629 return err;
4630}
4631
4632static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
4633{
4634 struct net_device *upper;
4635 struct list_head *iter;
4636 int err;
4637
4638 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
4639 if (netif_is_macvlan(upper)) {
4640 struct macvlan_dev *dfwd = netdev_priv(upper);
4641 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
4642
4643 if (dfwd->fwd_priv) {
4644 err = ixgbe_fwd_ring_up(upper, vadapter);
4645 if (err)
4646 continue;
4647 }
4648 }
4649 }
4650}
4651
Auke Kok9a799d72007-09-15 14:07:45 -07004652static void ixgbe_configure(struct ixgbe_adapter *adapter)
4653{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004654 struct ixgbe_hw *hw = &adapter->hw;
4655
John Fastabend80605c652011-05-02 12:34:10 +00004656 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004657#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00004658 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004659#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00004660 /*
4661 * We must restore virtualization before VLANs or else
4662 * the VLVF registers will not be populated
4663 */
4664 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004665
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004666 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004667 ixgbe_restore_vlan(adapter);
4668
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004669 switch (hw->mac.type) {
4670 case ixgbe_mac_82599EB:
4671 case ixgbe_mac_X540:
4672 hw->mac.ops.disable_rx_buff(hw);
4673 break;
4674 default:
4675 break;
4676 }
4677
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004678 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004679 ixgbe_init_fdir_signature_82599(&adapter->hw,
4680 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00004681 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
4682 ixgbe_init_fdir_perfect_82599(&adapter->hw,
4683 adapter->fdir_pballoc);
4684 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004685 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004686
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004687 switch (hw->mac.type) {
4688 case ixgbe_mac_82599EB:
4689 case ixgbe_mac_X540:
4690 hw->mac.ops.enable_rx_buff(hw);
4691 break;
4692 default:
4693 break;
4694 }
4695
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004696#ifdef IXGBE_FCOE
4697 /* configure FCoE L2 filters, redirection table, and Rx control */
4698 ixgbe_configure_fcoe(adapter);
4699
4700#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07004701 ixgbe_configure_tx(adapter);
4702 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08004703 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004704}
4705
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004706static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
4707{
4708 switch (hw->phy.type) {
4709 case ixgbe_phy_sfp_avago:
4710 case ixgbe_phy_sfp_ftl:
4711 case ixgbe_phy_sfp_intel:
4712 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00004713 case ixgbe_phy_sfp_passive_tyco:
4714 case ixgbe_phy_sfp_passive_unknown:
4715 case ixgbe_phy_sfp_active_unknown:
4716 case ixgbe_phy_sfp_ftl_active:
Emil Tantilov987e1d52013-08-14 07:12:27 +00004717 case ixgbe_phy_qsfp_passive_unknown:
4718 case ixgbe_phy_qsfp_active_unknown:
4719 case ixgbe_phy_qsfp_intel:
4720 case ixgbe_phy_qsfp_unknown:
Emil Tantilovd9cd46c2014-05-15 07:16:53 +00004721 /* ixgbe_phy_none is set when no SFP module is present */
4722 case ixgbe_phy_none:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004723 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00004724 case ixgbe_phy_nl:
4725 if (hw->mac.type == ixgbe_mac_82598EB)
4726 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004727 default:
4728 return false;
4729 }
4730}
4731
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004732/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004733 * ixgbe_sfp_link_config - set up SFP+ link
4734 * @adapter: pointer to private adapter struct
4735 **/
4736static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
4737{
Alexander Duyck70864002011-04-27 09:13:56 +00004738 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004739 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00004740 * is that an SFP was inserted/removed after the reset
4741 * but before SFP detection was enabled. As such the best
4742 * solution is to just start searching as soon as we start
4743 */
4744 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
4745 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004746
Alexander Duyck70864002011-04-27 09:13:56 +00004747 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004748}
4749
4750/**
4751 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004752 * @hw: pointer to private hardware struct
4753 *
4754 * Returns 0 on success, negative on failure
4755 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004756static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004757{
Josh Hay3d292262012-12-15 03:28:19 +00004758 u32 speed;
4759 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07004760 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004761
4762 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00004763 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004764
4765 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00004766 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004767
Josh Hay3d292262012-12-15 03:28:19 +00004768 speed = hw->phy.autoneg_advertised;
4769 if ((!speed) && (hw->mac.ops.get_link_capabilities))
4770 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
4771 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004772 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00004773 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004774
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004775 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00004776 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00004777
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004778 return ret;
4779}
4780
Alexander Duycka34bcff2010-08-19 13:39:20 +00004781static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004782{
Auke Kok9a799d72007-09-15 14:07:45 -07004783 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004784 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004785
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004786 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004787 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4788 IXGBE_GPIE_OCD;
4789 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004790 /*
4791 * use EIAM to auto-mask when MSI-X interrupt is asserted
4792 * this saves a register write for every interrupt
4793 */
4794 switch (hw->mac.type) {
4795 case ixgbe_mac_82598EB:
4796 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4797 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004798 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004799 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004800 case ixgbe_mac_X550:
4801 case ixgbe_mac_X550EM_x:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004802 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004803 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4804 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4805 break;
4806 }
4807 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004808 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4809 * specifically only auto mask tx and rx interrupts */
4810 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004811 }
4812
Alexander Duycka34bcff2010-08-19 13:39:20 +00004813 /* XXX: to interrupt immediately for EICS writes, enable this */
4814 /* gpie |= IXGBE_GPIE_EIMEN; */
4815
4816 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4817 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004818
4819 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4820 case IXGBE_82599_VMDQ_8Q_MASK:
4821 gpie |= IXGBE_GPIE_VTMODE_16;
4822 break;
4823 case IXGBE_82599_VMDQ_4Q_MASK:
4824 gpie |= IXGBE_GPIE_VTMODE_32;
4825 break;
4826 default:
4827 gpie |= IXGBE_GPIE_VTMODE_64;
4828 break;
4829 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004830 }
4831
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004832 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004833 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4834 switch (adapter->hw.mac.type) {
4835 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07004836 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00004837 break;
4838 case ixgbe_mac_X540:
4839 gpie |= IXGBE_EIMS_TS;
4840 break;
4841 default:
4842 break;
4843 }
4844 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004845
Alexander Duycka34bcff2010-08-19 13:39:20 +00004846 /* Enable fan failure interrupt */
4847 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07004848 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004849
Don Skidmore2698b202011-04-13 07:01:52 +00004850 if (hw->mac.type == ixgbe_mac_82599EB) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07004851 gpie |= IXGBE_SDP1_GPIEN_8259X;
4852 gpie |= IXGBE_SDP2_GPIEN_8259X;
Don Skidmore2698b202011-04-13 07:01:52 +00004853 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004854
4855 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4856}
4857
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004858static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004859{
4860 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004861 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004862 u32 ctrl_ext;
4863
4864 ixgbe_get_hw_control(adapter);
4865 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004866
Auke Kok9a799d72007-09-15 14:07:45 -07004867 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4868 ixgbe_configure_msix(adapter);
4869 else
4870 ixgbe_configure_msi_and_legacy(adapter);
4871
Emil Tantilovec74a472012-09-20 03:33:56 +00004872 /* enable the optics for 82599 SFP+ fiber */
4873 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004874 hw->mac.ops.enable_tx_laser(hw);
4875
Don Skidmore961fac82015-06-09 16:09:47 -07004876 if (hw->phy.ops.set_phy_power)
4877 hw->phy.ops.set_phy_power(hw, true);
4878
Peter Zijlstra4e857c52014-03-17 18:06:10 +01004879 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07004880 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004881 ixgbe_napi_enable_all(adapter);
4882
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004883 if (ixgbe_is_sfp(hw)) {
4884 ixgbe_sfp_link_config(adapter);
4885 } else {
4886 err = ixgbe_non_sfp_link_config(hw);
4887 if (err)
4888 e_err(probe, "link_config FAILED %d\n", err);
4889 }
4890
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004891 /* clear any pending interrupts, may auto mask */
4892 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004893 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004894
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004895 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004896 * If this adapter has a fan, check to see if we had a failure
4897 * before we enabled the interrupt.
4898 */
4899 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4900 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4901 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004902 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004903 }
4904
Auke Kok9a799d72007-09-15 14:07:45 -07004905 /* bring the link up in the watchdog, this could race with our first
4906 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004907 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4908 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004909 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004910
4911 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4912 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4913 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4914 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004915}
4916
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004917void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4918{
4919 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004920 /* put off any impending NetWatchDogTimeout */
4921 adapter->netdev->trans_start = jiffies;
4922
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004923 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004924 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004925 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004926 /*
4927 * If SR-IOV enabled then wait a bit before bringing the adapter
4928 * back up to give the VFs time to respond to the reset. The
4929 * two second wait is based upon the watchdog timer cycle in
4930 * the VF driver.
4931 */
4932 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4933 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004934 ixgbe_up(adapter);
4935 clear_bit(__IXGBE_RESETTING, &adapter->state);
4936}
4937
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004938void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004939{
4940 /* hardware has been reset, we need to reload some things */
4941 ixgbe_configure(adapter);
4942
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004943 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004944}
4945
4946void ixgbe_reset(struct ixgbe_adapter *adapter)
4947{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004948 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004949 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004950 int err;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004951 u8 old_addr[ETH_ALEN];
Don Skidmore8ca783a2009-05-26 20:40:47 -07004952
Mark Rustadb0483c82014-01-14 18:53:17 -08004953 if (ixgbe_removed(hw->hw_addr))
4954 return;
Alexander Duyck70864002011-04-27 09:13:56 +00004955 /* lock SFP init bit to prevent race conditions with the watchdog */
4956 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4957 usleep_range(1000, 2000);
4958
4959 /* clear all SFP and link config related flags while holding SFP_INIT */
4960 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4961 IXGBE_FLAG2_SFP_NEEDS_RESET);
4962 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4963
Don Skidmore8ca783a2009-05-26 20:40:47 -07004964 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004965 switch (err) {
4966 case 0:
4967 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004968 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004969 break;
4970 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004971 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004972 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004973 case IXGBE_ERR_EEPROM_VERSION:
4974 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004975 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004976 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004977 "your hardware. If you are experiencing problems "
4978 "please contact your Intel or hardware "
4979 "representative who provided you with this "
4980 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004981 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004982 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004983 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004984 }
Auke Kok9a799d72007-09-15 14:07:45 -07004985
Alexander Duyck70864002011-04-27 09:13:56 +00004986 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004987 /* do not flush user set addresses */
4988 memcpy(old_addr, &adapter->mac_table[0].addr, netdev->addr_len);
4989 ixgbe_flush_sw_mac_table(adapter);
4990 ixgbe_mac_set_default_filter(adapter, old_addr);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004991
4992 /* update SAN MAC vmdq pool selection */
4993 if (hw->mac.san_mac_rar_index)
4994 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004995
Jacob Keller8fecf672013-06-21 08:14:32 +00004996 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00004997 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07004998
4999 if (hw->phy.ops.set_phy_power) {
5000 if (!netif_running(adapter->netdev) && !adapter->wol)
5001 hw->phy.ops.set_phy_power(hw, false);
5002 else
5003 hw->phy.ops.set_phy_power(hw, true);
5004 }
Auke Kok9a799d72007-09-15 14:07:45 -07005005}
5006
Auke Kok9a799d72007-09-15 14:07:45 -07005007/**
Auke Kok9a799d72007-09-15 14:07:45 -07005008 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005009 * @tx_ring: ring to be cleaned
5010 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005011static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005012{
5013 struct ixgbe_tx_buffer *tx_buffer_info;
5014 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005015 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07005016
Alexander Duyck84418e32010-08-19 13:40:54 +00005017 /* ring already cleared, nothing to do */
5018 if (!tx_ring->tx_buffer_info)
5019 return;
Auke Kok9a799d72007-09-15 14:07:45 -07005020
Alexander Duyck84418e32010-08-19 13:40:54 +00005021 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07005022 for (i = 0; i < tx_ring->count; i++) {
5023 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005024 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07005025 }
5026
John Fastabenddad8a3b2012-04-23 12:22:39 +00005027 netdev_tx_reset_queue(txring_txq(tx_ring));
5028
Auke Kok9a799d72007-09-15 14:07:45 -07005029 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5030 memset(tx_ring->tx_buffer_info, 0, size);
5031
5032 /* Zero out the descriptor ring */
5033 memset(tx_ring->desc, 0, tx_ring->size);
5034
5035 tx_ring->next_to_use = 0;
5036 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005037}
5038
5039/**
Auke Kok9a799d72007-09-15 14:07:45 -07005040 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5041 * @adapter: board private structure
5042 **/
5043static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5044{
5045 int i;
5046
5047 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005048 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005049}
5050
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005051/**
5052 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5053 * @adapter: board private structure
5054 **/
5055static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5056{
5057 int i;
5058
5059 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005060 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005061}
5062
Alexander Duycke4911d52011-05-11 07:18:52 +00005063static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5064{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005065 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005066 struct ixgbe_fdir_filter *filter;
5067
5068 spin_lock(&adapter->fdir_perfect_lock);
5069
Sasha Levinb67bfe02013-02-27 17:06:00 -08005070 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005071 &adapter->fdir_filter_list, fdir_node) {
5072 hlist_del(&filter->fdir_node);
5073 kfree(filter);
5074 }
5075 adapter->fdir_filter_count = 0;
5076
5077 spin_unlock(&adapter->fdir_perfect_lock);
5078}
5079
Auke Kok9a799d72007-09-15 14:07:45 -07005080void ixgbe_down(struct ixgbe_adapter *adapter)
5081{
5082 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005083 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08005084 struct net_device *upper;
5085 struct list_head *iter;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005086 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005087
5088 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005089 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5090 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005091
5092 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005093 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005094
Yi Zou2d39d572011-01-06 14:29:56 +00005095 /* disable all enabled rx queues */
5096 for (i = 0; i < adapter->num_rx_queues; i++)
5097 /* this call also flushes the previous write */
5098 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5099
Don Skidmore032b4322011-03-18 09:32:53 +00005100 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005101
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005102 netif_tx_stop_all_queues(netdev);
5103
Alexander Duyck70864002011-04-27 09:13:56 +00005104 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005105 netif_carrier_off(netdev);
5106 netif_tx_disable(netdev);
5107
John Fastabend2a47fa42013-11-06 09:54:52 -08005108 /* disable any upper devices */
5109 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
5110 if (netif_is_macvlan(upper)) {
5111 struct macvlan_dev *vlan = netdev_priv(upper);
5112
5113 if (vlan->fwd_priv) {
5114 netif_tx_stop_all_queues(upper);
5115 netif_carrier_off(upper);
5116 netif_tx_disable(upper);
5117 }
5118 }
5119 }
5120
John Fastabendc0dfb902010-04-27 02:13:39 +00005121 ixgbe_irq_disable(adapter);
5122
5123 ixgbe_napi_disable_all(adapter);
5124
Alexander Duyckd034acf2011-04-27 09:25:34 +00005125 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
5126 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00005127 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5128
5129 del_timer_sync(&adapter->service_timer);
5130
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005131 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005132 /* Clear EITR Select mapping */
5133 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5134
5135 /* Mark all the VFs as inactive */
5136 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005137 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005138
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005139 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005140 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005141
Auke Kok9a799d72007-09-15 14:07:45 -07005142 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005143 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005144 }
5145
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005146 /* disable transmits in the hardware now that interrupts are off */
5147 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005148 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005149 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005150 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005151
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005152 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005153 switch (hw->mac.type) {
5154 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005155 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005156 case ixgbe_mac_X550:
5157 case ixgbe_mac_X550EM_x:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005158 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005159 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5160 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005161 break;
5162 default:
5163 break;
5164 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005165
Paul Larson6f4a0e42008-06-24 17:00:56 -07005166 if (!pci_channel_offline(adapter->pdev))
5167 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005168
Emil Tantilovec74a472012-09-20 03:33:56 +00005169 /* power down the optics for 82599 SFP+ fiber */
5170 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005171 hw->mac.ops.disable_tx_laser(hw);
5172
Auke Kok9a799d72007-09-15 14:07:45 -07005173 ixgbe_clean_all_tx_rings(adapter);
5174 ixgbe_clean_all_rx_rings(adapter);
5175
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005176#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07005177 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00005178 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07005179#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005180}
5181
Auke Kok9a799d72007-09-15 14:07:45 -07005182/**
Auke Kok9a799d72007-09-15 14:07:45 -07005183 * ixgbe_tx_timeout - Respond to a Tx Hang
5184 * @netdev: network interface device structure
5185 **/
5186static void ixgbe_tx_timeout(struct net_device *netdev)
5187{
5188 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5189
5190 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005191 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005192}
5193
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005194/**
Auke Kok9a799d72007-09-15 14:07:45 -07005195 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5196 * @adapter: board private structure to initialize
5197 *
5198 * ixgbe_sw_init initializes the Adapter private data structure.
5199 * Fields are initialized based on PCI device information and
5200 * OS network device settings (MTU size).
5201 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05005202static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005203{
5204 struct ixgbe_hw *hw = &adapter->hw;
5205 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005206 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005207 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005208#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005209 int j;
5210 struct tc_configuration *tc;
5211#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005212
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005213 /* PCI config space info */
5214
5215 hw->vendor_id = pdev->vendor;
5216 hw->device_id = pdev->device;
5217 hw->revision_id = pdev->revision;
5218 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5219 hw->subsystem_device_id = pdev->subsystem_device;
5220
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005221 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00005222 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00005223 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005224 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5225 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005226 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5227 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005228 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5229 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005230 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5231#ifdef CONFIG_IXGBE_DCA
5232 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5233#endif
5234#ifdef IXGBE_FCOE
5235 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5236 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5237#ifdef CONFIG_IXGBE_DCB
5238 /* Default traffic class to use for FCoE */
5239 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5240#endif /* CONFIG_IXGBE_DCB */
5241#endif /* IXGBE_FCOE */
5242
Jacob Keller5d7daa32014-03-29 06:51:25 +00005243 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5244 hw->mac.num_rar_entries,
5245 GFP_ATOMIC);
5246
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005247 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08005248 switch (hw->mac.type) {
5249 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005250 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
5251 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
5252
Don Skidmorebf069c92009-05-07 10:39:54 +00005253 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5254 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005255
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005256 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00005257 adapter->ring_feature[RING_F_FDIR].limit = 0;
5258 adapter->atr_sample_rate = 0;
5259 adapter->fdir_pballoc = 0;
5260#ifdef IXGBE_FCOE
5261 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5262 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5263#ifdef CONFIG_IXGBE_DCB
5264 adapter->fcoe.up = 0;
5265#endif /* IXGBE_DCB */
5266#endif /* IXGBE_FCOE */
5267 break;
5268 case ixgbe_mac_82599EB:
5269 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5270 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005271 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005272 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005273 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005274 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5275 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08005276 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005277 case ixgbe_mac_X550EM_x:
5278 case ixgbe_mac_X550:
5279#ifdef CONFIG_IXGBE_DCA
5280 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
5281#endif
5282 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08005283 default:
5284 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005285 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005286
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005287#ifdef IXGBE_FCOE
5288 /* FCoE support exists, always init the FCoE lock */
5289 spin_lock_init(&adapter->fcoe.lock);
5290
5291#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005292 /* n-tuple support exists, always init our spinlock */
5293 spin_lock_init(&adapter->fdir_perfect_lock);
5294
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005295#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005296 switch (hw->mac.type) {
5297 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005298 case ixgbe_mac_X550:
5299 case ixgbe_mac_X550EM_x:
John Fastabend4de2a022011-09-27 03:52:01 +00005300 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5301 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5302 break;
5303 default:
5304 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5305 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5306 break;
5307 }
5308
Alexander Duyck2f90b862008-11-20 20:52:10 -08005309 /* Configure DCB traffic classes */
5310 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5311 tc = &adapter->dcb_cfg.tc_config[j];
5312 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5313 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5314 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5315 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5316 tc->dcb_pfc = pfc_disabled;
5317 }
John Fastabend4de2a022011-09-27 03:52:01 +00005318
5319 /* Initialize default user to priority mapping, UPx->TC0 */
5320 tc = &adapter->dcb_cfg.tc_config[0];
5321 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5322 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5323
Alexander Duyck2f90b862008-11-20 20:52:10 -08005324 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5325 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005326 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005327 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005328 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00005329 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5330 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08005331
5332#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005333
5334 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005335 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005336 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00005337 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005338 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5339 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00005340 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005341
Alexander Duyck99d74482012-05-09 08:09:25 +00005342#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08005343 if (max_vfs > 0)
5344 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 +00005345
Jacob Keller170e8542013-11-09 04:52:32 -08005346 /* assign number of SR-IOV VFs */
5347 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08005348 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Jacob Keller170e8542013-11-09 04:52:32 -08005349 adapter->num_vfs = 0;
5350 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5351 } else {
5352 adapter->num_vfs = max_vfs;
5353 }
5354 }
5355#endif /* CONFIG_PCI_IOV */
5356
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005357 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005358 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005359 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005360
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005361 /* set default ring sizes */
5362 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5363 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5364
Alexander Duyckbd198052011-06-11 01:45:08 +00005365 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005366 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005367
Auke Kok9a799d72007-09-15 14:07:45 -07005368 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005369 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005370 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005371 return -EIO;
5372 }
5373
John Fastabend2a47fa42013-11-06 09:54:52 -08005374 /* PF holds first pool slot */
5375 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07005376 set_bit(__IXGBE_DOWN, &adapter->state);
5377
5378 return 0;
5379}
5380
5381/**
5382 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005383 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005384 *
5385 * Return 0 on success, negative on failure
5386 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005387int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005388{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005389 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005390 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005391 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005392 int size;
5393
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005394 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005395
5396 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005397 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005398
Mark Rustadca8dfe22014-07-24 06:19:24 +00005399 tx_ring->tx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005400 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005401 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005402 if (!tx_ring->tx_buffer_info)
5403 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005404
John Stultz827da442013-10-07 15:51:58 -07005405 u64_stats_init(&tx_ring->syncp);
5406
Auke Kok9a799d72007-09-15 14:07:45 -07005407 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005408 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005409 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005410
Mark Rustadca8dfe22014-07-24 06:19:24 +00005411 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005412 tx_ring->desc = dma_alloc_coherent(dev,
5413 tx_ring->size,
5414 &tx_ring->dma,
5415 GFP_KERNEL);
5416 set_dev_node(dev, orig_node);
5417 if (!tx_ring->desc)
5418 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5419 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005420 if (!tx_ring->desc)
5421 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005422
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005423 tx_ring->next_to_use = 0;
5424 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005425 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005426
5427err:
5428 vfree(tx_ring->tx_buffer_info);
5429 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005430 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005431 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005432}
5433
5434/**
Alexander Duyck69888672008-09-11 20:05:39 -07005435 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5436 * @adapter: board private structure
5437 *
5438 * If this function returns with an error, then it's possible one or
5439 * more of the rings is populated (while the rest are not). It is the
5440 * callers duty to clean those orphaned rings.
5441 *
5442 * Return 0 on success, negative on failure
5443 **/
5444static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5445{
5446 int i, err = 0;
5447
5448 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005449 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005450 if (!err)
5451 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005452
Emil Tantilov396e7992010-07-01 20:05:12 +00005453 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005454 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07005455 }
5456
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005457 return 0;
5458err_setup_tx:
5459 /* rewind the index freeing the rings as we go */
5460 while (i--)
5461 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005462 return err;
5463}
5464
5465/**
Auke Kok9a799d72007-09-15 14:07:45 -07005466 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005467 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005468 *
5469 * Returns 0 on success, negative on failure
5470 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005471int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005472{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005473 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005474 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00005475 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005476 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005477
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005478 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005479
5480 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00005481 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005482
Mark Rustadca8dfe22014-07-24 06:19:24 +00005483 rx_ring->rx_buffer_info = vzalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005484 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005485 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005486 if (!rx_ring->rx_buffer_info)
5487 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005488
John Stultz827da442013-10-07 15:51:58 -07005489 u64_stats_init(&rx_ring->syncp);
5490
Auke Kok9a799d72007-09-15 14:07:45 -07005491 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005492 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5493 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005494
Mark Rustadca8dfe22014-07-24 06:19:24 +00005495 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00005496 rx_ring->desc = dma_alloc_coherent(dev,
5497 rx_ring->size,
5498 &rx_ring->dma,
5499 GFP_KERNEL);
5500 set_dev_node(dev, orig_node);
5501 if (!rx_ring->desc)
5502 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5503 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005504 if (!rx_ring->desc)
5505 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005506
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005507 rx_ring->next_to_clean = 0;
5508 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005509
5510 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005511err:
5512 vfree(rx_ring->rx_buffer_info);
5513 rx_ring->rx_buffer_info = NULL;
5514 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005515 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005516}
5517
5518/**
Alexander Duyck69888672008-09-11 20:05:39 -07005519 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5520 * @adapter: board private structure
5521 *
5522 * If this function returns with an error, then it's possible one or
5523 * more of the rings is populated (while the rest are not). It is the
5524 * callers duty to clean those orphaned rings.
5525 *
5526 * Return 0 on success, negative on failure
5527 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005528static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5529{
5530 int i, err = 0;
5531
5532 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005533 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005534 if (!err)
5535 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005536
Emil Tantilov396e7992010-07-01 20:05:12 +00005537 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005538 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07005539 }
5540
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005541#ifdef IXGBE_FCOE
5542 err = ixgbe_setup_fcoe_ddp_resources(adapter);
5543 if (!err)
5544#endif
5545 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005546err_setup_rx:
5547 /* rewind the index freeing the rings as we go */
5548 while (i--)
5549 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005550 return err;
5551}
5552
5553/**
Auke Kok9a799d72007-09-15 14:07:45 -07005554 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005555 * @tx_ring: Tx descriptor ring for a specific queue
5556 *
5557 * Free all transmit software resources
5558 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005559void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005560{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005561 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005562
5563 vfree(tx_ring->tx_buffer_info);
5564 tx_ring->tx_buffer_info = NULL;
5565
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005566 /* if not set, then don't free */
5567 if (!tx_ring->desc)
5568 return;
5569
5570 dma_free_coherent(tx_ring->dev, tx_ring->size,
5571 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005572
5573 tx_ring->desc = NULL;
5574}
5575
5576/**
5577 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5578 * @adapter: board private structure
5579 *
5580 * Free all transmit software resources
5581 **/
5582static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5583{
5584 int i;
5585
5586 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005587 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005588 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005589}
5590
5591/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005592 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005593 * @rx_ring: ring to clean the resources from
5594 *
5595 * Free all receive software resources
5596 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005597void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005598{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005599 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005600
5601 vfree(rx_ring->rx_buffer_info);
5602 rx_ring->rx_buffer_info = NULL;
5603
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005604 /* if not set, then don't free */
5605 if (!rx_ring->desc)
5606 return;
5607
5608 dma_free_coherent(rx_ring->dev, rx_ring->size,
5609 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005610
5611 rx_ring->desc = NULL;
5612}
5613
5614/**
5615 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5616 * @adapter: board private structure
5617 *
5618 * Free all receive software resources
5619 **/
5620static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5621{
5622 int i;
5623
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005624#ifdef IXGBE_FCOE
5625 ixgbe_free_fcoe_ddp_resources(adapter);
5626
5627#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005628 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005629 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005630 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005631}
5632
5633/**
Auke Kok9a799d72007-09-15 14:07:45 -07005634 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5635 * @netdev: network interface device structure
5636 * @new_mtu: new value for maximum frame size
5637 *
5638 * Returns 0 on success, negative on failure
5639 **/
5640static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5641{
5642 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5643 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5644
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005645 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005646 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5647 return -EINVAL;
5648
5649 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00005650 * For 82599EB we cannot allow legacy VFs to enable their receive
5651 * paths when MTU greater than 1500 is configured. So display a
5652 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00005653 */
5654 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5655 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Alexander Duyckc5604512013-01-09 08:50:42 +00005656 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck872844d2012-08-15 02:10:43 +00005657 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005658
Emil Tantilov396e7992010-07-01 20:05:12 +00005659 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005660
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005661 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005662 netdev->mtu = new_mtu;
5663
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005664 if (netif_running(netdev))
5665 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005666
5667 return 0;
5668}
5669
5670/**
5671 * ixgbe_open - Called when a network interface is made active
5672 * @netdev: network interface device structure
5673 *
5674 * Returns 0 on success, negative value on failure
5675 *
5676 * The open entry point is called when a network interface is made
5677 * active by the system (IFF_UP). At this point all resources needed
5678 * for transmit and receive operations are allocated, the interrupt
5679 * handler is registered with the OS, the watchdog timer is started,
5680 * and the stack is notified that the interface is ready.
5681 **/
5682static int ixgbe_open(struct net_device *netdev)
5683{
5684 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07005685 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08005686 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07005687
Auke Kok4bebfaa2008-02-11 09:26:01 -08005688 /* disallow open during test */
5689 if (test_bit(__IXGBE_TESTING, &adapter->state))
5690 return -EBUSY;
5691
Jesse Brandeburg54386462009-04-17 20:44:27 +00005692 netif_carrier_off(netdev);
5693
Auke Kok9a799d72007-09-15 14:07:45 -07005694 /* allocate transmit descriptors */
5695 err = ixgbe_setup_all_tx_resources(adapter);
5696 if (err)
5697 goto err_setup_tx;
5698
Auke Kok9a799d72007-09-15 14:07:45 -07005699 /* allocate receive descriptors */
5700 err = ixgbe_setup_all_rx_resources(adapter);
5701 if (err)
5702 goto err_setup_rx;
5703
5704 ixgbe_configure(adapter);
5705
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005706 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005707 if (err)
5708 goto err_req_irq;
5709
Alexander Duyckac802f52012-07-12 05:52:53 +00005710 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08005711 if (adapter->num_rx_pools > 1)
5712 queues = adapter->num_rx_queues_per_pool;
5713 else
5714 queues = adapter->num_tx_queues;
5715
5716 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00005717 if (err)
5718 goto err_set_queues;
5719
John Fastabend2a47fa42013-11-06 09:54:52 -08005720 if (adapter->num_rx_pools > 1 &&
5721 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
5722 queues = IXGBE_MAX_L2A_QUEUES;
5723 else
5724 queues = adapter->num_rx_queues;
5725 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00005726 if (err)
5727 goto err_set_queues;
5728
Jacob Keller1a71ab22012-08-25 03:54:19 +00005729 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005730
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005731 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005732
Don Skidmore3f207802014-12-23 07:40:34 +00005733#if IS_ENABLED(CONFIG_IXGBE_VXLAN)
5734 vxlan_get_rx_port(netdev);
5735
5736#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005737 return 0;
5738
Alexander Duyckac802f52012-07-12 05:52:53 +00005739err_set_queues:
5740 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005741err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005742 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005743 if (hw->phy.ops.set_phy_power && !adapter->wol)
5744 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005745err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005746 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005747err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07005748 ixgbe_reset(adapter);
5749
5750 return err;
5751}
5752
Jacob Kellera0cccce2014-05-16 05:12:29 +00005753static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
5754{
5755 ixgbe_ptp_suspend(adapter);
5756
5757 ixgbe_down(adapter);
5758 ixgbe_free_irq(adapter);
5759
5760 ixgbe_free_all_tx_resources(adapter);
5761 ixgbe_free_all_rx_resources(adapter);
5762}
5763
Auke Kok9a799d72007-09-15 14:07:45 -07005764/**
5765 * ixgbe_close - Disables a network interface
5766 * @netdev: network interface device structure
5767 *
5768 * Returns 0, this is not allowed to fail
5769 *
5770 * The close entry point is called when an interface is de-activated
5771 * by the OS. The hardware is still under the drivers control, but
5772 * needs to be disabled. A global MAC reset is issued to stop the
5773 * hardware, and all transmit and receive resources are freed.
5774 **/
5775static int ixgbe_close(struct net_device *netdev)
5776{
5777 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005778
Jacob Keller1a71ab22012-08-25 03:54:19 +00005779 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005780
Jacob Kellera0cccce2014-05-16 05:12:29 +00005781 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005782
Alexander Duycke4911d52011-05-11 07:18:52 +00005783 ixgbe_fdir_filter_exit(adapter);
5784
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005785 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005786
5787 return 0;
5788}
5789
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005790#ifdef CONFIG_PM
5791static int ixgbe_resume(struct pci_dev *pdev)
5792{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005793 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5794 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005795 u32 err;
5796
Mark Rustad0391bbe2014-02-28 15:48:55 -08005797 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005798 pci_set_power_state(pdev, PCI_D0);
5799 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005800 /*
5801 * pci_restore_state clears dev->state_saved so call
5802 * pci_save_state to restore it.
5803 */
5804 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005805
5806 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005807 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005808 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005809 return err;
5810 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005811 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00005812 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005813 pci_set_master(pdev);
5814
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005815 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005816
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005817 ixgbe_reset(adapter);
5818
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005819 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5820
Alexander Duyckac802f52012-07-12 05:52:53 +00005821 rtnl_lock();
5822 err = ixgbe_init_interrupt_scheme(adapter);
5823 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005824 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005825
5826 rtnl_unlock();
5827
5828 if (err)
5829 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005830
5831 netif_device_attach(netdev);
5832
5833 return 0;
5834}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005835#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005836
5837static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005838{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005839 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5840 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005841 struct ixgbe_hw *hw = &adapter->hw;
5842 u32 ctrl, fctrl;
5843 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005844#ifdef CONFIG_PM
5845 int retval = 0;
5846#endif
5847
5848 netif_device_detach(netdev);
5849
akepner499ab5c2013-03-13 14:54:58 +00005850 rtnl_lock();
Jacob Kellera0cccce2014-05-16 05:12:29 +00005851 if (netif_running(netdev))
5852 ixgbe_close_suspend(adapter);
akepner499ab5c2013-03-13 14:54:58 +00005853 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005854
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005855 ixgbe_clear_interrupt_scheme(adapter);
5856
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005857#ifdef CONFIG_PM
5858 retval = pci_save_state(pdev);
5859 if (retval)
5860 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005861
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005862#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00005863 if (hw->mac.ops.stop_link_on_d3)
5864 hw->mac.ops.stop_link_on_d3(hw);
5865
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005866 if (wufc) {
5867 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005868
Emil Tantilovec74a472012-09-20 03:33:56 +00005869 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5870 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005871 hw->mac.ops.enable_tx_laser(hw);
5872
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005873 /* turn on all-multi mode if wake on multicast is enabled */
5874 if (wufc & IXGBE_WUFC_MC) {
5875 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5876 fctrl |= IXGBE_FCTRL_MPE;
5877 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5878 }
5879
5880 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5881 ctrl |= IXGBE_CTRL_GIO_DIS;
5882 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5883
5884 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5885 } else {
5886 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5887 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5888 }
5889
Alexander Duyckbd508172010-11-16 19:27:03 -08005890 switch (hw->mac.type) {
5891 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005892 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005893 break;
5894 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005895 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005896 case ixgbe_mac_X550:
5897 case ixgbe_mac_X550EM_x:
Alexander Duyckbd508172010-11-16 19:27:03 -08005898 pci_wake_from_d3(pdev, !!wufc);
5899 break;
5900 default:
5901 break;
5902 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005903
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005904 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07005905 if (hw->phy.ops.set_phy_power && !*enable_wake)
5906 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005907
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005908 ixgbe_release_hw_control(adapter);
5909
Mark Rustad41c62842014-03-12 00:38:35 +00005910 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
5911 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005912
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005913 return 0;
5914}
5915
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005916#ifdef CONFIG_PM
5917static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5918{
5919 int retval;
5920 bool wake;
5921
5922 retval = __ixgbe_shutdown(pdev, &wake);
5923 if (retval)
5924 return retval;
5925
5926 if (wake) {
5927 pci_prepare_to_sleep(pdev);
5928 } else {
5929 pci_wake_from_d3(pdev, false);
5930 pci_set_power_state(pdev, PCI_D3hot);
5931 }
5932
5933 return 0;
5934}
5935#endif /* CONFIG_PM */
5936
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005937static void ixgbe_shutdown(struct pci_dev *pdev)
5938{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005939 bool wake;
5940
5941 __ixgbe_shutdown(pdev, &wake);
5942
5943 if (system_state == SYSTEM_POWER_OFF) {
5944 pci_wake_from_d3(pdev, wake);
5945 pci_set_power_state(pdev, PCI_D3hot);
5946 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005947}
5948
5949/**
Auke Kok9a799d72007-09-15 14:07:45 -07005950 * ixgbe_update_stats - Update the board statistics counters.
5951 * @adapter: board private structure
5952 **/
5953void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5954{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005955 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005956 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005957 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005958 u64 total_mpc = 0;
5959 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005960 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5961 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005962 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005963
Don Skidmored08935c2010-06-11 13:20:29 +00005964 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5965 test_bit(__IXGBE_RESETTING, &adapter->state))
5966 return;
5967
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005968 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005969 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005970 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005971 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005972 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5973 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005974 }
5975 adapter->rsc_total_count = rsc_count;
5976 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005977 }
5978
Alexander Duyck5b7da512010-11-16 19:26:50 -08005979 for (i = 0; i < adapter->num_rx_queues; i++) {
5980 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5981 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5982 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5983 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005984 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005985 bytes += rx_ring->stats.bytes;
5986 packets += rx_ring->stats.packets;
5987 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005988 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005989 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5990 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005991 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005992 netdev->stats.rx_bytes = bytes;
5993 netdev->stats.rx_packets = packets;
5994
5995 bytes = 0;
5996 packets = 0;
5997 /* gather some stats to the adapter struct that are per queue */
5998 for (i = 0; i < adapter->num_tx_queues; i++) {
5999 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6000 restart_queue += tx_ring->tx_stats.restart_queue;
6001 tx_busy += tx_ring->tx_stats.tx_busy;
6002 bytes += tx_ring->stats.bytes;
6003 packets += tx_ring->stats.packets;
6004 }
6005 adapter->restart_queue = restart_queue;
6006 adapter->tx_busy = tx_busy;
6007 netdev->stats.tx_bytes = bytes;
6008 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006009
Joe Perches7ca647b2010-09-07 21:35:40 +00006010 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006011
6012 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006013 for (i = 0; i < 8; i++) {
6014 /* for packet buffers not used, the register should read 0 */
6015 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6016 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006017 hwstats->mpc[i] += mpc;
6018 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006019 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6020 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006021 switch (hw->mac.type) {
6022 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006023 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6024 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6025 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006026 hwstats->pxonrxc[i] +=
6027 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006028 break;
6029 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006030 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006031 case ixgbe_mac_X550:
6032 case ixgbe_mac_X550EM_x:
Alexander Duyckbd508172010-11-16 19:27:03 -08006033 hwstats->pxonrxc[i] +=
6034 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006035 break;
6036 default:
6037 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006038 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006039 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006040
6041 /*16 register reads */
6042 for (i = 0; i < 16; i++) {
6043 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6044 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6045 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006046 (hw->mac.type == ixgbe_mac_X540) ||
6047 (hw->mac.type == ixgbe_mac_X550) ||
6048 (hw->mac.type == ixgbe_mac_X550EM_x)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006049 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6050 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6051 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6052 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6053 }
6054 }
6055
Joe Perches7ca647b2010-09-07 21:35:40 +00006056 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006057 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006058 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006059
John Fastabendc84d3242010-11-16 19:27:12 -08006060 ixgbe_update_xoff_received(adapter);
6061
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006062 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006063 switch (hw->mac.type) {
6064 case ixgbe_mac_82598EB:
6065 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006066 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6067 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6068 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6069 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006070 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006071 case ixgbe_mac_X550:
6072 case ixgbe_mac_X550EM_x:
6073 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006074 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6075 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6076 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6077 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6078 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006079 for (i = 0; i < 16; i++)
6080 adapter->hw_rx_no_dma_resources +=
6081 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006082 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006083 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006084 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006085 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006086 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006087 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006088 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006089 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6090 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006091#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006092 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6093 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6094 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6095 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6096 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6097 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006098 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006099 if (adapter->fcoe.ddp_pool) {
6100 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6101 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6102 unsigned int cpu;
6103 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006104 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006105 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6106 noddp += ddp_pool->noddp;
6107 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006108 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006109 hwstats->fcoe_noddp = noddp;
6110 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006111 }
Yi Zou6d455222009-05-13 13:12:16 +00006112#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006113 break;
6114 default:
6115 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006116 }
Auke Kok9a799d72007-09-15 14:07:45 -07006117 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006118 hwstats->bprc += bprc;
6119 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006120 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006121 hwstats->mprc -= bprc;
6122 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6123 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6124 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6125 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6126 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6127 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6128 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6129 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006130 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006131 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006132 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006133 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006134 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6135 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006136 /*
6137 * 82598 errata - tx of flow control packets is included in tx counters
6138 */
6139 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006140 hwstats->gptc -= xon_off_tot;
6141 hwstats->mptc -= xon_off_tot;
6142 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6143 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6144 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6145 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6146 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6147 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6148 hwstats->ptc64 -= xon_off_tot;
6149 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6150 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6151 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6152 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6153 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6154 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006155
6156 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006157 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006158
6159 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006160 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006161 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006162 netdev->stats.rx_length_errors = hwstats->rlec;
6163 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006164 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006165}
6166
6167/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006168 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006169 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006170 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006171static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006172{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006173 struct ixgbe_hw *hw = &adapter->hw;
6174 int i;
6175
Alexander Duyckd034acf2011-04-27 09:25:34 +00006176 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6177 return;
6178
6179 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6180
6181 /* if interface is down do nothing */
6182 if (test_bit(__IXGBE_DOWN, &adapter->state))
6183 return;
6184
6185 /* do nothing if we are not using signature filters */
6186 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6187 return;
6188
6189 adapter->fdir_overflow++;
6190
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006191 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6192 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006193 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00006194 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006195 /* re-enable flow director interrupts */
6196 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006197 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006198 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006199 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006200 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006201}
6202
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006203/**
6204 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006205 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006206 *
6207 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006208 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006209 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006210 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006211 */
6212static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6213{
Auke Kok9a799d72007-09-15 14:07:45 -07006214 struct ixgbe_hw *hw = &adapter->hw;
6215 u64 eics = 0;
6216 int i;
6217
Mark Rustad09f40ae2014-01-14 18:53:11 -08006218 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006219 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006220 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006221 test_bit(__IXGBE_RESETTING, &adapter->state))
6222 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006223
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006224 /* Force detection of hung controller */
6225 if (netif_carrier_ok(adapter->netdev)) {
6226 for (i = 0; i < adapter->num_tx_queues; i++)
6227 set_check_for_tx_hang(adapter->tx_ring[i]);
6228 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006229
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006230 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006231 /*
6232 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006233 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006234 * would set *both* EIMS and EICS for any bit in EIAM
6235 */
6236 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6237 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006238 } else {
6239 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006240 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006241 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006242 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006243 eics |= ((u64)1 << i);
6244 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006245 }
6246
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006247 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006248 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00006249}
6250
6251/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006252 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006253 * @adapter: pointer to the device adapter structure
6254 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006255 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006256static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006257{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006258 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006259 u32 link_speed = adapter->link_speed;
6260 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00006261 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006262
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006263 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6264 return;
6265
6266 if (hw->mac.ops.check_link) {
6267 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006268 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006269 /* always assume link is up, if no check link function */
6270 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6271 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006272 }
Alexander Duyck041441d2012-04-19 17:48:48 +00006273
6274 if (adapter->ixgbe_ieee_pfc)
6275 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6276
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006277 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00006278 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00006279 ixgbe_set_rx_drop_en(adapter);
6280 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006281
6282 if (link_up ||
6283 time_after(jiffies, (adapter->link_check_timeout +
6284 IXGBE_TRY_LINK_TIMEOUT))) {
6285 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6286 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6287 IXGBE_WRITE_FLUSH(hw);
6288 }
6289
6290 adapter->link_up = link_up;
6291 adapter->link_speed = link_speed;
6292}
6293
Alexander Duyck107d3012012-10-02 00:17:03 +00006294static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6295{
6296#ifdef CONFIG_IXGBE_DCB
6297 struct net_device *netdev = adapter->netdev;
6298 struct dcb_app app = {
6299 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6300 .protocol = 0,
6301 };
6302 u8 up = 0;
6303
6304 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6305 up = dcb_ieee_getapp_mask(netdev, &app);
6306
6307 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6308#endif
6309}
6310
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006311/**
6312 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6313 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006314 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006315 **/
6316static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6317{
6318 struct net_device *netdev = adapter->netdev;
6319 struct ixgbe_hw *hw = &adapter->hw;
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006320 struct net_device *upper;
6321 struct list_head *iter;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006322 u32 link_speed = adapter->link_speed;
6323 bool flow_rx, flow_tx;
6324
6325 /* only continue if link was previously down */
6326 if (netif_carrier_ok(netdev))
6327 return;
6328
6329 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6330
6331 switch (hw->mac.type) {
6332 case ixgbe_mac_82598EB: {
6333 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6334 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6335 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6336 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6337 }
6338 break;
6339 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006340 case ixgbe_mac_X550:
6341 case ixgbe_mac_X550EM_x:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006342 case ixgbe_mac_82599EB: {
6343 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6344 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6345 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6346 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6347 }
6348 break;
6349 default:
6350 flow_tx = false;
6351 flow_rx = false;
6352 break;
6353 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006354
Jacob Keller6cb562d2012-12-05 07:24:41 +00006355 adapter->last_rx_ptp_check = jiffies;
6356
Jacob Keller8fecf672013-06-21 08:14:32 +00006357 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006358 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006359
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006360 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6361 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6362 "10 Gbps" :
6363 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6364 "1 Gbps" :
6365 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6366 "100 Mbps" :
6367 "unknown speed"))),
6368 ((flow_rx && flow_tx) ? "RX/TX" :
6369 (flow_rx ? "RX" :
6370 (flow_tx ? "TX" : "None"))));
6371
6372 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006373 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006374
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00006375 /* enable transmits */
6376 netif_tx_wake_all_queues(adapter->netdev);
6377
6378 /* enable any upper devices */
6379 rtnl_lock();
6380 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
6381 if (netif_is_macvlan(upper)) {
6382 struct macvlan_dev *vlan = netdev_priv(upper);
6383
6384 if (vlan->fwd_priv)
6385 netif_tx_wake_all_queues(upper);
6386 }
6387 }
6388 rtnl_unlock();
6389
Alexander Duyck107d3012012-10-02 00:17:03 +00006390 /* update the default user priority for VFs */
6391 ixgbe_update_default_up(adapter);
6392
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006393 /* ping all the active vfs to let them know link has changed */
6394 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006395}
6396
6397/**
6398 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6399 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006400 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006401 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00006402static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006403{
6404 struct net_device *netdev = adapter->netdev;
6405 struct ixgbe_hw *hw = &adapter->hw;
6406
6407 adapter->link_up = false;
6408 adapter->link_speed = 0;
6409
6410 /* only continue if link was up previously */
6411 if (!netif_carrier_ok(netdev))
6412 return;
6413
6414 /* poll for SFP+ cable when link is down */
6415 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6416 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6417
Jacob Keller8fecf672013-06-21 08:14:32 +00006418 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00006419 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006420
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006421 e_info(drv, "NIC Link is Down\n");
6422 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00006423
6424 /* ping all the active vfs to let them know link has changed */
6425 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006426}
6427
Emil Tantilov07923c12014-08-12 07:12:08 +00006428static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
6429{
6430 int i;
6431
6432 for (i = 0; i < adapter->num_tx_queues; i++) {
6433 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6434
6435 if (tx_ring->next_to_use != tx_ring->next_to_clean)
6436 return true;
6437 }
6438
6439 return false;
6440}
6441
6442static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
6443{
6444 struct ixgbe_hw *hw = &adapter->hw;
6445 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
6446 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
6447
6448 int i, j;
6449
6450 if (!adapter->num_vfs)
6451 return false;
6452
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006453 /* resetting the PF is only needed for MAC before X550 */
6454 if (hw->mac.type >= ixgbe_mac_X550)
6455 return false;
6456
Emil Tantilov07923c12014-08-12 07:12:08 +00006457 for (i = 0; i < adapter->num_vfs; i++) {
6458 for (j = 0; j < q_per_pool; j++) {
6459 u32 h, t;
6460
6461 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
6462 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
6463
6464 if (h != t)
6465 return true;
6466 }
6467 }
6468
6469 return false;
6470}
6471
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006472/**
6473 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006474 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006475 **/
6476static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6477{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006478 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00006479 if (ixgbe_ring_tx_pending(adapter) ||
6480 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006481 /* We've lost link, so the controller stops DMA,
6482 * but we've got queued Tx work that's never going
6483 * to get done, so reset controller to flush Tx.
6484 * (Do the reset outside of interrupt context).
6485 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00006486 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006487 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006488 }
6489 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006490}
6491
Emil Tantilov9079e412014-11-19 03:18:19 +00006492#ifdef CONFIG_PCI_IOV
6493static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
6494 struct pci_dev *vfdev)
6495{
6496 if (!pci_wait_for_pending_transaction(vfdev))
6497 e_dev_warn("Issuing VFLR with pending transactions\n");
6498
6499 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
6500 pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
6501
6502 msleep(100);
6503}
6504
6505static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6506{
6507 struct ixgbe_hw *hw = &adapter->hw;
6508 struct pci_dev *pdev = adapter->pdev;
6509 struct pci_dev *vfdev;
6510 u32 gpc;
6511 int pos;
6512 unsigned short vf_id;
6513
6514 if (!(netif_carrier_ok(adapter->netdev)))
6515 return;
6516
6517 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6518 if (gpc) /* If incrementing then no need for the check below */
6519 return;
6520 /* Check to see if a bad DMA write target from an errant or
6521 * malicious VF has caused a PCIe error. If so then we can
6522 * issue a VFLR to the offending VF(s) and then resume without
6523 * requesting a full slot reset.
6524 */
6525
6526 if (!pdev)
6527 return;
6528
6529 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
6530 if (!pos)
6531 return;
6532
6533 /* get the device ID for the VF */
6534 pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID, &vf_id);
6535
6536 /* check status reg for all VFs owned by this PF */
6537 vfdev = pci_get_device(pdev->vendor, vf_id, NULL);
6538 while (vfdev) {
6539 if (vfdev->is_virtfn && (vfdev->physfn == pdev)) {
6540 u16 status_reg;
6541
6542 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
6543 if (status_reg & PCI_STATUS_REC_MASTER_ABORT)
6544 /* issue VFLR */
6545 ixgbe_issue_vf_flr(adapter, vfdev);
6546 }
6547
6548 vfdev = pci_get_device(pdev->vendor, vf_id, vfdev);
6549 }
6550}
6551
Greg Rosea985b6c32010-11-18 03:02:52 +00006552static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6553{
6554 u32 ssvpc;
6555
Greg Rose0584d992012-08-08 00:00:58 +00006556 /* Do not perform spoof check for 82598 or if not in IOV mode */
6557 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
6558 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00006559 return;
6560
6561 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6562
6563 /*
6564 * ssvpc register is cleared on read, if zero then no
6565 * spoofed packets in the last interval.
6566 */
6567 if (!ssvpc)
6568 return;
6569
Emil Tantilovd6ea0752012-08-08 06:28:37 +00006570 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00006571}
Emil Tantilov9079e412014-11-19 03:18:19 +00006572#else
6573static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
6574{
6575}
6576
6577static void
6578ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
6579{
6580}
6581#endif /* CONFIG_PCI_IOV */
6582
Greg Rosea985b6c32010-11-18 03:02:52 +00006583
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006584/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006585 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006586 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006587 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006588static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006589{
Mark Rustad09f40ae2014-01-14 18:53:11 -08006590 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006591 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006592 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00006593 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006594 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006595
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006596 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006597
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006598 if (adapter->link_up)
6599 ixgbe_watchdog_link_is_up(adapter);
6600 else
6601 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006602
Emil Tantilov9079e412014-11-19 03:18:19 +00006603 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00006604 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006605 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006606
6607 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006608}
6609
Alexander Duyck70864002011-04-27 09:13:56 +00006610/**
6611 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006612 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00006613 **/
6614static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6615{
6616 struct ixgbe_hw *hw = &adapter->hw;
6617 s32 err;
6618
6619 /* not searching for SFP so there is nothing to do here */
6620 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6621 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6622 return;
6623
6624 /* someone else is in init, wait until next service event */
6625 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6626 return;
6627
6628 err = hw->phy.ops.identify_sfp(hw);
6629 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6630 goto sfp_out;
6631
6632 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6633 /* If no cable is present, then we need to reset
6634 * the next time we find a good cable. */
6635 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6636 }
6637
6638 /* exit on error */
6639 if (err)
6640 goto sfp_out;
6641
6642 /* exit if reset not needed */
6643 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6644 goto sfp_out;
6645
6646 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6647
6648 /*
6649 * A module may be identified correctly, but the EEPROM may not have
6650 * support for that module. setup_sfp() will fail in that case, so
6651 * we should not allow that module to load.
6652 */
6653 if (hw->mac.type == ixgbe_mac_82598EB)
6654 err = hw->phy.ops.reset(hw);
6655 else
6656 err = hw->mac.ops.setup_sfp(hw);
6657
6658 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6659 goto sfp_out;
6660
6661 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6662 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6663
6664sfp_out:
6665 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6666
6667 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6668 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6669 e_dev_err("failed to initialize because an unsupported "
6670 "SFP+ module type was detected.\n");
6671 e_dev_err("Reload the driver after installing a "
6672 "supported module.\n");
6673 unregister_netdev(adapter->netdev);
6674 }
6675}
6676
6677/**
6678 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006679 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00006680 **/
6681static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6682{
6683 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00006684 u32 speed;
6685 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00006686
6687 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6688 return;
6689
6690 /* someone else is in init, wait until next service event */
6691 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6692 return;
6693
6694 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6695
Josh Hay3d292262012-12-15 03:28:19 +00006696 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00006697 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00006698 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00006699
6700 /* setup the highest link when no autoneg */
6701 if (!autoneg) {
6702 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
6703 speed = IXGBE_LINK_SPEED_10GB_FULL;
6704 }
6705 }
6706
Alexander Duyck70864002011-04-27 09:13:56 +00006707 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00006708 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00006709
6710 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6711 adapter->link_check_timeout = jiffies;
6712 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6713}
6714
6715/**
6716 * ixgbe_service_timer - Timer Call-back
6717 * @data: pointer to adapter cast into an unsigned long
6718 **/
6719static void ixgbe_service_timer(unsigned long data)
6720{
6721 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6722 unsigned long next_event_offset;
6723
6724 /* poll faster when waiting for link */
6725 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6726 next_event_offset = HZ / 10;
6727 else
6728 next_event_offset = HZ * 2;
6729
6730 /* Reset the timer */
6731 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6732
Emil Tantilov9079e412014-11-19 03:18:19 +00006733 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006734}
6735
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006736static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6737{
6738 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6739 return;
6740
6741 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6742
Mark Rustad09f40ae2014-01-14 18:53:11 -08006743 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006744 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08006745 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006746 test_bit(__IXGBE_RESETTING, &adapter->state))
6747 return;
6748
6749 ixgbe_dump(adapter);
6750 netdev_err(adapter->netdev, "Reset adapter\n");
6751 adapter->tx_timeout_count++;
6752
John Fastabend8f4c5c92014-01-16 02:30:05 -08006753 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006754 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08006755 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006756}
6757
Alexander Duyck70864002011-04-27 09:13:56 +00006758/**
6759 * ixgbe_service_task - manages and runs subtasks
6760 * @work: pointer to work_struct containing our data
6761 **/
6762static void ixgbe_service_task(struct work_struct *work)
6763{
6764 struct ixgbe_adapter *adapter = container_of(work,
6765 struct ixgbe_adapter,
6766 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08006767 if (ixgbe_removed(adapter->hw.hw_addr)) {
6768 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
6769 rtnl_lock();
6770 ixgbe_down(adapter);
6771 rtnl_unlock();
6772 }
6773 ixgbe_service_event_complete(adapter);
6774 return;
6775 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006776 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006777 ixgbe_sfp_detection_subtask(adapter);
6778 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006779 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006780 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006781 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006782 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00006783
Jacob Keller8fecf672013-06-21 08:14:32 +00006784 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00006785 ixgbe_ptp_overflow_check(adapter);
6786 ixgbe_ptp_rx_hang(adapter);
6787 }
Alexander Duyck70864002011-04-27 09:13:56 +00006788
6789 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006790}
6791
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006792static int ixgbe_tso(struct ixgbe_ring *tx_ring,
6793 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006794 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00006795{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006796 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006797 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006798 u32 mss_l4len_idx, l4len;
Francois Romieu2049e1f2014-03-30 03:14:27 +00006799 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07006800
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00006801 if (skb->ip_summed != CHECKSUM_PARTIAL)
6802 return 0;
6803
Alexander Duyck897ab152011-05-27 05:31:47 +00006804 if (!skb_is_gso(skb))
6805 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006806
Francois Romieu2049e1f2014-03-30 03:14:27 +00006807 err = skb_cow_head(skb, 0);
6808 if (err < 0)
6809 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006810
Alexander Duyck897ab152011-05-27 05:31:47 +00006811 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6812 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6813
Joe Perchesa1108ff2014-03-13 05:19:25 +00006814 if (first->protocol == htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006815 struct iphdr *iph = ip_hdr(skb);
6816 iph->tot_len = 0;
6817 iph->check = 0;
6818 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6819 iph->daddr, 0,
6820 IPPROTO_TCP,
6821 0);
6822 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006823 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6824 IXGBE_TX_FLAGS_CSUM |
6825 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006826 } else if (skb_is_gso_v6(skb)) {
6827 ipv6_hdr(skb)->payload_len = 0;
6828 tcp_hdr(skb)->check =
6829 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6830 &ipv6_hdr(skb)->daddr,
6831 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00006832 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6833 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00006834 }
6835
Alexander Duyck091a6242012-02-08 07:51:01 +00006836 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00006837 l4len = tcp_hdrlen(skb);
6838 *hdr_len = skb_transport_offset(skb) + l4len;
6839
Alexander Duyck091a6242012-02-08 07:51:01 +00006840 /* update gso size and bytecount with header size */
6841 first->gso_segs = skb_shinfo(skb)->gso_segs;
6842 first->bytecount += (first->gso_segs - 1) * *hdr_len;
6843
Alexander Duyckc44f5f52012-10-30 06:01:45 +00006844 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00006845 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6846 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00006847
6848 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6849 vlan_macip_lens = skb_network_header_len(skb);
6850 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006851 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006852
6853 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006854 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00006855
6856 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006857}
6858
Alexander Duyck244e27a2012-02-08 07:51:11 +00006859static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6860 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07006861{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006862 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006863 u32 vlan_macip_lens = 0;
6864 u32 mss_l4len_idx = 0;
6865 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006866
Alexander Duyck897ab152011-05-27 05:31:47 +00006867 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck472148c2012-11-07 02:34:28 +00006868 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6869 !(first->tx_flags & IXGBE_TX_FLAGS_CC))
6870 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00006871 } else {
6872 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006873 switch (first->protocol) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00006874 case htons(ETH_P_IP):
Alexander Duyck897ab152011-05-27 05:31:47 +00006875 vlan_macip_lens |= skb_network_header_len(skb);
6876 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6877 l4_hdr = ip_hdr(skb)->protocol;
6878 break;
Joe Perchesa1108ff2014-03-13 05:19:25 +00006879 case htons(ETH_P_IPV6):
Alexander Duyck897ab152011-05-27 05:31:47 +00006880 vlan_macip_lens |= skb_network_header_len(skb);
6881 l4_hdr = ipv6_hdr(skb)->nexthdr;
6882 break;
6883 default:
6884 if (unlikely(net_ratelimit())) {
6885 dev_warn(tx_ring->dev,
6886 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006887 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00006888 }
6889 break;
6890 }
Auke Kok9a799d72007-09-15 14:07:45 -07006891
Alexander Duyck897ab152011-05-27 05:31:47 +00006892 switch (l4_hdr) {
6893 case IPPROTO_TCP:
6894 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6895 mss_l4len_idx = tcp_hdrlen(skb) <<
6896 IXGBE_ADVTXD_L4LEN_SHIFT;
6897 break;
6898 case IPPROTO_SCTP:
6899 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6900 mss_l4len_idx = sizeof(struct sctphdr) <<
6901 IXGBE_ADVTXD_L4LEN_SHIFT;
6902 break;
6903 case IPPROTO_UDP:
6904 mss_l4len_idx = sizeof(struct udphdr) <<
6905 IXGBE_ADVTXD_L4LEN_SHIFT;
6906 break;
6907 default:
6908 if (unlikely(net_ratelimit())) {
6909 dev_warn(tx_ring->dev,
6910 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006911 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006912 }
6913 break;
6914 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006915
6916 /* update TX checksum flag */
6917 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006918 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006919
Alexander Duyck244e27a2012-02-08 07:51:11 +00006920 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006921 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006922 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006923
6924 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6925 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006926}
6927
Alexander Duyck472148c2012-11-07 02:34:28 +00006928#define IXGBE_SET_FLAG(_input, _flag, _result) \
6929 ((_flag <= _result) ? \
6930 ((u32)(_input & _flag) * (_result / _flag)) : \
6931 ((u32)(_input & _flag) / (_flag / _result)))
6932
6933static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006934{
6935 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00006936 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
6937 IXGBE_ADVTXD_DCMD_DEXT |
6938 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006939
6940 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00006941 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
6942 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006943
Alexander Duyckd3d00232011-07-15 02:31:25 +00006944 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006945 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
6946 IXGBE_ADVTXD_DCMD_TSE);
6947
6948 /* set timestamp bit if present */
6949 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
6950 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006951
Alexander Duyck62748b72012-07-20 08:09:01 +00006952 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00006953 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00006954
Alexander Duyckd3d00232011-07-15 02:31:25 +00006955 return cmd_type;
6956}
6957
Alexander Duyck729739b2012-02-08 07:51:06 +00006958static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6959 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006960{
Alexander Duyck472148c2012-11-07 02:34:28 +00006961 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006962
6963 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00006964 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6965 IXGBE_TX_FLAGS_CSUM,
6966 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006967
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006968 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006969 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6970 IXGBE_TX_FLAGS_IPV4,
6971 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006972
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006973 /*
6974 * Check Context must be set if Tx switch is enabled, which it
6975 * always is for case where virtual functions are running
6976 */
Alexander Duyck472148c2012-11-07 02:34:28 +00006977 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6978 IXGBE_TX_FLAGS_CC,
6979 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006980
Alexander Duyck472148c2012-11-07 02:34:28 +00006981 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006982}
6983
Daniel Borkmann2367a172014-08-26 19:34:18 +02006984static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6985{
6986 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
6987
6988 /* Herbert's original patch had:
6989 * smp_mb__after_netif_stop_queue();
6990 * but since that doesn't exist yet, just open code it.
6991 */
6992 smp_mb();
6993
6994 /* We need to check again in a case another CPU has just
6995 * made room available.
6996 */
6997 if (likely(ixgbe_desc_unused(tx_ring) < size))
6998 return -EBUSY;
6999
7000 /* A reprieve! - use start_queue because it doesn't call schedule */
7001 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7002 ++tx_ring->tx_stats.restart_queue;
7003 return 0;
7004}
7005
7006static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7007{
7008 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7009 return 0;
7010
7011 return __ixgbe_maybe_stop_tx(tx_ring, size);
7012}
7013
Alexander Duyckd3d00232011-07-15 02:31:25 +00007014#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7015 IXGBE_TXD_CMD_RS)
7016
7017static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007018 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007019 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007020{
Alexander Duyck729739b2012-02-08 07:51:06 +00007021 struct sk_buff *skb = first->skb;
7022 struct ixgbe_tx_buffer *tx_buffer;
7023 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007024 struct skb_frag_struct *frag;
7025 dma_addr_t dma;
7026 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007027 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007028 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007029 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007030
Alexander Duyck729739b2012-02-08 07:51:06 +00007031 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7032
Alexander Duyckec718252012-10-30 06:01:55 +00007033 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7034
7035 size = skb_headlen(skb);
7036 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007037
Alexander Duyckd3d00232011-07-15 02:31:25 +00007038#ifdef IXGBE_FCOE
7039 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007040 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007041 size -= sizeof(struct fcoe_crc_eof) - data_len;
7042 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007043 } else {
7044 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007045 }
Auke Kok9a799d72007-09-15 14:07:45 -07007046 }
7047
Alexander Duyckd3d00232011-07-15 02:31:25 +00007048#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007049 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007050
Alexander Duyckec718252012-10-30 06:01:55 +00007051 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007052
Alexander Duyckec718252012-10-30 06:01:55 +00007053 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7054 if (dma_mapping_error(tx_ring->dev, dma))
7055 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007056
Alexander Duyckec718252012-10-30 06:01:55 +00007057 /* record length, and DMA address */
7058 dma_unmap_len_set(tx_buffer, len, size);
7059 dma_unmap_addr_set(tx_buffer, dma, dma);
7060
7061 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7062
Alexander Duyck729739b2012-02-08 07:51:06 +00007063 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007064 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007065 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007066
Alexander Duyckd3d00232011-07-15 02:31:25 +00007067 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007068 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007069 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007070 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007071 i = 0;
7072 }
Alexander Duyckec718252012-10-30 06:01:55 +00007073 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007074
7075 dma += IXGBE_MAX_DATA_PER_TXD;
7076 size -= IXGBE_MAX_DATA_PER_TXD;
7077
7078 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007079 }
7080
Alexander Duyck729739b2012-02-08 07:51:06 +00007081 if (likely(!data_len))
7082 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007083
Alexander Duyck472148c2012-11-07 02:34:28 +00007084 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007085
Alexander Duyck729739b2012-02-08 07:51:06 +00007086 i++;
7087 tx_desc++;
7088 if (i == tx_ring->count) {
7089 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7090 i = 0;
7091 }
Alexander Duyckec718252012-10-30 06:01:55 +00007092 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007093
Alexander Duyckd3d00232011-07-15 02:31:25 +00007094#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007095 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007096#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007097 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007098#endif
7099 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007100
Alexander Duyck729739b2012-02-08 07:51:06 +00007101 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7102 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007103
Alexander Duyck729739b2012-02-08 07:51:06 +00007104 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007105 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007106
Alexander Duyck729739b2012-02-08 07:51:06 +00007107 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007108 cmd_type |= size | IXGBE_TXD_CMD;
7109 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007110
Alexander Duyck091a6242012-02-08 07:51:01 +00007111 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007112
Alexander Duyckd3d00232011-07-15 02:31:25 +00007113 /* set the timestamp */
7114 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007115
7116 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007117 * Force memory writes to complete before letting h/w know there
7118 * are new descriptors to fetch. (Only applicable for weak-ordered
7119 * memory model archs, such as IA-64).
7120 *
7121 * We also need this memory barrier to make certain all of the
7122 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007123 */
7124 wmb();
7125
Alexander Duyckd3d00232011-07-15 02:31:25 +00007126 /* set next_to_watch value indicating a packet is present */
7127 first->next_to_watch = tx_desc;
7128
Alexander Duyck729739b2012-02-08 07:51:06 +00007129 i++;
7130 if (i == tx_ring->count)
7131 i = 0;
7132
7133 tx_ring->next_to_use = i;
7134
Daniel Borkmann2367a172014-08-26 19:34:18 +02007135 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7136
7137 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00007138 writel(i, tx_ring->tail);
7139
7140 /* we need this if more than one processor can write to our tail
7141 * at a time, it synchronizes IO on IA64/Altix systems
7142 */
7143 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02007144 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02007145
Alexander Duyckd3d00232011-07-15 02:31:25 +00007146 return;
7147dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00007148 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00007149
7150 /* clear dma mappings for failed tx_buffer_info map */
7151 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007152 tx_buffer = &tx_ring->tx_buffer_info[i];
7153 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
7154 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007155 break;
7156 if (i == 0)
7157 i = tx_ring->count;
7158 i--;
7159 }
7160
Alexander Duyckd3d00232011-07-15 02:31:25 +00007161 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07007162}
7163
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007164static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007165 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007166{
Alexander Duyck69830522011-01-06 14:29:58 +00007167 struct ixgbe_q_vector *q_vector = ring->q_vector;
7168 union ixgbe_atr_hash_dword input = { .dword = 0 };
7169 union ixgbe_atr_hash_dword common = { .dword = 0 };
7170 union {
7171 unsigned char *network;
7172 struct iphdr *ipv4;
7173 struct ipv6hdr *ipv6;
7174 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007175 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00007176 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007177
Alexander Duyck69830522011-01-06 14:29:58 +00007178 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7179 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00007180 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007181
Alexander Duyck69830522011-01-06 14:29:58 +00007182 /* do nothing if sampling is disabled */
7183 if (!ring->atr_sample_rate)
7184 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007185
Alexander Duyck69830522011-01-06 14:29:58 +00007186 ring->atr_count++;
7187
7188 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007189 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00007190
7191 /* Currently only IPv4/IPv6 with TCP is supported */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007192 if ((first->protocol != htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00007193 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Joe Perchesa1108ff2014-03-13 05:19:25 +00007194 (first->protocol != htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00007195 hdr.ipv4->protocol != IPPROTO_TCP))
7196 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08007197
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007198 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007199
Alexander Duyck66f32a82011-06-29 05:43:22 +00007200 /* skip this packet since it is invalid or the socket is closing */
7201 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00007202 return;
7203
7204 /* sample on all syn packets or once every atr sample count */
7205 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
7206 return;
7207
7208 /* reset sample count */
7209 ring->atr_count = 0;
7210
Alexander Duyck244e27a2012-02-08 07:51:11 +00007211 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00007212
7213 /*
7214 * src and dst are inverted, think how the receiver sees them
7215 *
7216 * The input is broken into two sections, a non-compressed section
7217 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7218 * is XORed together and stored in the compressed dword.
7219 */
7220 input.formatted.vlan_id = vlan_id;
7221
7222 /*
7223 * since src port and flex bytes occupy the same word XOR them together
7224 * and write the value to source port portion of compressed dword
7225 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007226 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00007227 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00007228 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00007229 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00007230 common.port.dst ^= th->source;
7231
Joe Perchesa1108ff2014-03-13 05:19:25 +00007232 if (first->protocol == htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00007233 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7234 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
7235 } else {
7236 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7237 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7238 hdr.ipv6->saddr.s6_addr32[1] ^
7239 hdr.ipv6->saddr.s6_addr32[2] ^
7240 hdr.ipv6->saddr.s6_addr32[3] ^
7241 hdr.ipv6->daddr.s6_addr32[0] ^
7242 hdr.ipv6->daddr.s6_addr32[1] ^
7243 hdr.ipv6->daddr.s6_addr32[2] ^
7244 hdr.ipv6->daddr.s6_addr32[3];
7245 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007246
7247 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007248 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7249 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007250}
7251
Jason Wangf663dd92014-01-10 16:18:26 +08007252static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01007253 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007254{
Jason Wangf663dd92014-01-10 16:18:26 +08007255 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7256#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00007257 struct ixgbe_adapter *adapter;
7258 struct ixgbe_ring_feature *f;
7259 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08007260#endif
7261
7262 if (fwd_adapter)
7263 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7264
7265#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00007266
Alexander Duyck97488bd2013-01-12 06:33:37 +00007267 /*
7268 * only execute the code below if protocol is FCoE
7269 * or FIP and we have FCoE enabled on the adapter
7270 */
7271 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00007272 case htons(ETH_P_FCOE):
7273 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00007274 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00007275
Alexander Duyck97488bd2013-01-12 06:33:37 +00007276 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7277 break;
7278 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01007279 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007280 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007281
Alexander Duyck97488bd2013-01-12 06:33:37 +00007282 f = &adapter->ring_feature[RING_F_FCOE];
7283
7284 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7285 smp_processor_id();
7286
7287 while (txq >= f->indices)
7288 txq -= f->indices;
7289
7290 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08007291#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01007292 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08007293#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007294}
7295
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007296netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007297 struct ixgbe_adapter *adapter,
7298 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007299{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007300 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007301 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007302 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007303 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00007304 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007305 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007306 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007307
Alexander Duycka535c302011-05-27 05:31:52 +00007308 /*
7309 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007310 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007311 * + 2 desc gap to keep tail from touching head,
7312 * + 1 desc for context descriptor,
7313 * otherwise try next time
7314 */
Alexander Duycka535c302011-05-27 05:31:52 +00007315 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7316 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00007317
Alexander Duycka535c302011-05-27 05:31:52 +00007318 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7319 tx_ring->tx_stats.tx_busy++;
7320 return NETDEV_TX_BUSY;
7321 }
7322
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007323 /* record the location of the first descriptor for this packet */
7324 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7325 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00007326 first->bytecount = skb->len;
7327 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007328
Alexander Duyck66f32a82011-06-29 05:43:22 +00007329 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01007330 if (skb_vlan_tag_present(skb)) {
7331 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007332 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7333 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007334 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007335 struct vlan_hdr *vhdr, _vhdr;
7336 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7337 if (!vhdr)
7338 goto out_drop;
7339
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007340 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7341 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007342 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007343 }
Toshiaki Makita02136682015-01-29 20:37:09 +09007344 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00007345
Mark Rustadd5234932014-08-09 07:02:09 +00007346 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
7347 adapter->ptp_clock &&
7348 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
7349 &adapter->state)) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007350 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
7351 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00007352
7353 /* schedule check for Tx timestamp */
7354 adapter->ptp_tx_skb = skb_get(skb);
7355 adapter->ptp_tx_start = jiffies;
7356 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007357 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007358
Jakub Kicinskiff29a862014-03-15 14:55:16 +00007359 skb_tx_timestamp(skb);
7360
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007361#ifdef CONFIG_PCI_IOV
7362 /*
7363 * Use the l2switch_enable flag - would be false if the DMA
7364 * Tx switch had been disabled.
7365 */
7366 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00007367 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007368
7369#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007370 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007371 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007372 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7373 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007374 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007375 tx_flags |= (skb->priority & 0x7) <<
7376 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007377 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7378 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007379
7380 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00007381 goto out_drop;
7382 vhdr = (struct vlan_ethhdr *)skb->data;
7383 vhdr->h_vlan_TCI = htons(tx_flags >>
7384 IXGBE_TX_FLAGS_VLAN_SHIFT);
7385 } else {
7386 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7387 }
7388 }
Alexander Duycka535c302011-05-27 05:31:52 +00007389
Alexander Duyck244e27a2012-02-08 07:51:11 +00007390 /* record initial flags and protocol */
7391 first->tx_flags = tx_flags;
7392 first->protocol = protocol;
7393
Yi Zoueacd73f2009-05-13 13:11:06 +00007394#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007395 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00007396 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00007397 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00007398 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00007399 if (tso < 0)
7400 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07007401
Alexander Duyck66f32a82011-06-29 05:43:22 +00007402 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007403 }
Auke Kok9a799d72007-09-15 14:07:45 -07007404
Auke Kok9a799d72007-09-15 14:07:45 -07007405#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007406 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007407 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007408 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007409 else if (!tso)
7410 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007411
7412 /* add the ATR filter if ATR is on */
7413 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00007414 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007415
7416#ifdef IXGBE_FCOE
7417xmit_fcoe:
7418#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007419 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007420
Auke Kok9a799d72007-09-15 14:07:45 -07007421 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007422
7423out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007424 dev_kfree_skb_any(first->skb);
7425 first->skb = NULL;
7426
Alexander Duyck897ab152011-05-27 05:31:47 +00007427 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007428}
7429
John Fastabend2a47fa42013-11-06 09:54:52 -08007430static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
7431 struct net_device *netdev,
7432 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007433{
7434 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007435 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07007436
Alexander Duycka50c29d2012-02-08 07:50:40 +00007437 /*
7438 * The minimum packet size for olinfo paylen is 17 so pad the skb
7439 * in order to meet this minimum size requirement.
7440 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08007441 if (skb_put_padto(skb, 17))
7442 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00007443
John Fastabend2a47fa42013-11-06 09:54:52 -08007444 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
7445
Auke Kok9a799d72007-09-15 14:07:45 -07007446 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7447}
7448
John Fastabend2a47fa42013-11-06 09:54:52 -08007449static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7450 struct net_device *netdev)
7451{
7452 return __ixgbe_xmit_frame(skb, netdev, NULL);
7453}
7454
Auke Kok9a799d72007-09-15 14:07:45 -07007455/**
7456 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7457 * @netdev: network interface device structure
7458 * @p: pointer to an address structure
7459 *
7460 * Returns 0 on success, negative on failure
7461 **/
7462static int ixgbe_set_mac(struct net_device *netdev, void *p)
7463{
7464 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7465 struct ixgbe_hw *hw = &adapter->hw;
7466 struct sockaddr *addr = p;
Jacob Keller5d7daa32014-03-29 06:51:25 +00007467 int ret;
Auke Kok9a799d72007-09-15 14:07:45 -07007468
7469 if (!is_valid_ether_addr(addr->sa_data))
7470 return -EADDRNOTAVAIL;
7471
Jacob Keller5d7daa32014-03-29 06:51:25 +00007472 ixgbe_del_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
Auke Kok9a799d72007-09-15 14:07:45 -07007473 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007474 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007475
Jacob Keller5d7daa32014-03-29 06:51:25 +00007476 ret = ixgbe_add_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
7477 return ret > 0 ? 0 : ret;
Auke Kok9a799d72007-09-15 14:07:45 -07007478}
7479
Ben Hutchings6b73e102009-04-29 08:08:58 +00007480static int
7481ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7482{
7483 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7484 struct ixgbe_hw *hw = &adapter->hw;
7485 u16 value;
7486 int rc;
7487
7488 if (prtad != hw->phy.mdio.prtad)
7489 return -EINVAL;
7490 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7491 if (!rc)
7492 rc = value;
7493 return rc;
7494}
7495
7496static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7497 u16 addr, u16 value)
7498{
7499 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7500 struct ixgbe_hw *hw = &adapter->hw;
7501
7502 if (prtad != hw->phy.mdio.prtad)
7503 return -EINVAL;
7504 return hw->phy.ops.write_reg(hw, addr, devad, value);
7505}
7506
7507static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7508{
7509 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7510
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007511 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007512 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08007513 return ixgbe_ptp_set_ts_config(adapter, req);
7514 case SIOCGHWTSTAMP:
7515 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007516 default:
7517 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7518 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00007519}
7520
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007521/**
7522 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007523 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007524 * @netdev: network interface device structure
7525 *
7526 * Returns non-zero on failure
7527 **/
7528static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7529{
7530 int err = 0;
7531 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007532 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007533
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007534 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007535 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007536 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007537 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00007538
7539 /* update SAN MAC vmdq pool selection */
7540 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007541 }
7542 return err;
7543}
7544
7545/**
7546 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007547 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007548 * @netdev: network interface device structure
7549 *
7550 * Returns non-zero on failure
7551 **/
7552static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7553{
7554 int err = 0;
7555 struct ixgbe_adapter *adapter = netdev_priv(dev);
7556 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7557
7558 if (is_valid_ether_addr(mac->san_addr)) {
7559 rtnl_lock();
7560 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7561 rtnl_unlock();
7562 }
7563 return err;
7564}
7565
Auke Kok9a799d72007-09-15 14:07:45 -07007566#ifdef CONFIG_NET_POLL_CONTROLLER
7567/*
7568 * Polling 'interrupt' - used by things like netconsole to send skbs
7569 * without having to re-enable interrupts. It's not called while
7570 * the interrupt routine is executing.
7571 */
7572static void ixgbe_netpoll(struct net_device *netdev)
7573{
7574 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007575 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007576
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007577 /* if interface is down do nothing */
7578 if (test_bit(__IXGBE_DOWN, &adapter->state))
7579 return;
7580
Alexander Duyck856f6062015-02-25 17:45:54 +00007581 /* loop through and schedule all active queues */
7582 for (i = 0; i < adapter->num_q_vectors; i++)
7583 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07007584}
Auke Kok9a799d72007-09-15 14:07:45 -07007585
Alexander Duyck581330b2012-02-08 07:51:47 +00007586#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00007587static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7588 struct rtnl_link_stats64 *stats)
7589{
7590 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7591 int i;
7592
Eric Dumazet1a515022010-11-16 19:26:42 -08007593 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007594 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007595 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007596 u64 bytes, packets;
7597 unsigned int start;
7598
Eric Dumazet1a515022010-11-16 19:26:42 -08007599 if (ring) {
7600 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07007601 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08007602 packets = ring->stats.packets;
7603 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07007604 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08007605 stats->rx_packets += packets;
7606 stats->rx_bytes += bytes;
7607 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007608 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007609
7610 for (i = 0; i < adapter->num_tx_queues; i++) {
7611 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7612 u64 bytes, packets;
7613 unsigned int start;
7614
7615 if (ring) {
7616 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07007617 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007618 packets = ring->stats.packets;
7619 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07007620 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007621 stats->tx_packets += packets;
7622 stats->tx_bytes += bytes;
7623 }
7624 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007625 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007626 /* following stats updated by ixgbe_watchdog_task() */
7627 stats->multicast = netdev->stats.multicast;
7628 stats->rx_errors = netdev->stats.rx_errors;
7629 stats->rx_length_errors = netdev->stats.rx_length_errors;
7630 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7631 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7632 return stats;
7633}
7634
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007635#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007636/**
7637 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7638 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00007639 * @tc: number of traffic classes currently enabled
7640 *
7641 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7642 * 802.1Q priority maps to a packet buffer that exists.
7643 */
7644static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7645{
7646 struct ixgbe_hw *hw = &adapter->hw;
7647 u32 reg, rsave;
7648 int i;
7649
7650 /* 82598 have a static priority to TC mapping that can not
7651 * be changed so no validation is needed.
7652 */
7653 if (hw->mac.type == ixgbe_mac_82598EB)
7654 return;
7655
7656 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7657 rsave = reg;
7658
7659 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7660 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7661
7662 /* If up2tc is out of bounds default to zero */
7663 if (up2tc > tc)
7664 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7665 }
7666
7667 if (reg != rsave)
7668 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7669
7670 return;
7671}
7672
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007673/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00007674 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
7675 * @adapter: Pointer to adapter struct
7676 *
7677 * Populate the netdev user priority to tc map
7678 */
7679static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
7680{
7681 struct net_device *dev = adapter->netdev;
7682 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
7683 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
7684 u8 prio;
7685
7686 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
7687 u8 tc = 0;
7688
7689 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
7690 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
7691 else if (ets)
7692 tc = ets->prio_tc[prio];
7693
7694 netdev_set_prio_tc_map(dev, prio, tc);
7695 }
7696}
7697
Alexander Duyckcca73c52013-01-12 06:33:44 +00007698#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00007699/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007700 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00007701 *
7702 * @netdev: net device to configure
7703 * @tc: number of traffic classes to enable
7704 */
7705int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7706{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007707 struct ixgbe_adapter *adapter = netdev_priv(dev);
7708 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08007709 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007710
John Fastabend8b1c0b22011-05-03 02:26:48 +00007711 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007712 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00007713 (hw->mac.type == ixgbe_mac_82598EB &&
7714 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00007715 return -EINVAL;
7716
John Fastabend2a47fa42013-11-06 09:54:52 -08007717 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
7718 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
7719 return -EBUSY;
7720
John Fastabend8b1c0b22011-05-03 02:26:48 +00007721 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007722 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007723 * hardware is not flexible enough to do this dynamically.
7724 */
7725 if (netif_running(dev))
7726 ixgbe_close(dev);
7727 ixgbe_clear_interrupt_scheme(adapter);
7728
Alexander Duyckcca73c52013-01-12 06:33:44 +00007729#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00007730 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007731 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007732 ixgbe_set_prio_tc_map(adapter);
7733
John Fastabende7589ea2011-07-18 22:38:36 +00007734 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007735
Alexander Duyck943561d2012-05-09 22:14:44 -07007736 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
7737 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007738 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07007739 }
John Fastabende7589ea2011-07-18 22:38:36 +00007740 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007741 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007742
Alexander Duyck943561d2012-05-09 22:14:44 -07007743 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7744 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007745
7746 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007747
7748 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7749 adapter->dcb_cfg.pfc_mode_enable = false;
7750 }
7751
John Fastabend8b1c0b22011-05-03 02:26:48 +00007752 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00007753
7754#endif /* CONFIG_IXGBE_DCB */
7755 ixgbe_init_interrupt_scheme(adapter);
7756
John Fastabend8b1c0b22011-05-03 02:26:48 +00007757 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00007758 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00007759
7760 return 0;
7761}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007762
Greg Roseda36b642012-12-11 08:26:43 +00007763#ifdef CONFIG_PCI_IOV
7764void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
7765{
7766 struct net_device *netdev = adapter->netdev;
7767
7768 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00007769 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00007770 rtnl_unlock();
7771}
7772
7773#endif
Don Skidmore082757a2011-07-21 05:55:00 +00007774void ixgbe_do_reset(struct net_device *netdev)
7775{
7776 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7777
7778 if (netif_running(netdev))
7779 ixgbe_reinit_locked(adapter);
7780 else
7781 ixgbe_reset(adapter);
7782}
7783
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007784static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007785 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007786{
7787 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7788
Don Skidmore082757a2011-07-21 05:55:00 +00007789 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007790 if (!(features & NETIF_F_RXCSUM))
7791 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00007792
Alexander Duyck567d2de2012-02-11 07:18:57 +00007793 /* Turn off LRO if not RSC capable */
7794 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
7795 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007796
Alexander Duyck567d2de2012-02-11 07:18:57 +00007797 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00007798}
7799
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007800static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007801 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007802{
7803 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00007804 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00007805 bool need_reset = false;
7806
Don Skidmore082757a2011-07-21 05:55:00 +00007807 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007808 if (!(features & NETIF_F_LRO)) {
7809 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00007810 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00007811 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
7812 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
7813 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7814 if (adapter->rx_itr_setting == 1 ||
7815 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
7816 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
7817 need_reset = true;
7818 } else if ((changed ^ features) & NETIF_F_LRO) {
7819 e_info(probe, "rx-usecs set too low, "
7820 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00007821 }
7822 }
7823
7824 /*
7825 * Check if Flow Director n-tuple support was enabled or disabled. If
7826 * the state changed, we need to reset.
7827 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007828 switch (features & NETIF_F_NTUPLE) {
7829 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00007830 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007831 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
7832 need_reset = true;
7833
Alexander Duyck567d2de2012-02-11 07:18:57 +00007834 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7835 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00007836 break;
7837 default:
7838 /* turn off perfect filters, enable ATR and reset */
7839 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7840 need_reset = true;
7841
7842 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7843
7844 /* We cannot enable ATR if SR-IOV is enabled */
7845 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7846 break;
7847
7848 /* We cannot enable ATR if we have 2 or more traffic classes */
7849 if (netdev_get_num_tc(netdev) > 1)
7850 break;
7851
7852 /* We cannot enable ATR if RSS is disabled */
7853 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
7854 break;
7855
7856 /* A sample rate of 0 indicates ATR disabled */
7857 if (!adapter->atr_sample_rate)
7858 break;
7859
7860 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7861 break;
Don Skidmore082757a2011-07-21 05:55:00 +00007862 }
7863
Patrick McHardyf6469682013-04-19 02:04:27 +00007864 if (features & NETIF_F_HW_VLAN_CTAG_RX)
John Fastabend146d4cc2012-05-15 05:59:26 +00007865 ixgbe_vlan_strip_enable(adapter);
7866 else
7867 ixgbe_vlan_strip_disable(adapter);
7868
Ben Greear3f2d1c02012-03-08 08:28:41 +00007869 if (changed & NETIF_F_RXALL)
7870 need_reset = true;
7871
Alexander Duyck567d2de2012-02-11 07:18:57 +00007872 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00007873 if (need_reset)
7874 ixgbe_do_reset(netdev);
7875
7876 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00007877}
7878
Don Skidmore3f207802014-12-23 07:40:34 +00007879/**
7880 * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up
7881 * @dev: The port's netdev
7882 * @sa_family: Socket Family that VXLAN is notifiying us about
7883 * @port: New UDP port number that VXLAN started listening to
7884 **/
7885static void ixgbe_add_vxlan_port(struct net_device *dev, sa_family_t sa_family,
7886 __be16 port)
7887{
7888 struct ixgbe_adapter *adapter = netdev_priv(dev);
7889 struct ixgbe_hw *hw = &adapter->hw;
7890 u16 new_port = ntohs(port);
7891
7892 if (sa_family == AF_INET6)
7893 return;
7894
7895 if (adapter->vxlan_port == new_port) {
7896 netdev_info(dev, "Port %d already offloaded\n", new_port);
7897 return;
7898 }
7899
7900 if (adapter->vxlan_port) {
7901 netdev_info(dev,
7902 "Hit Max num of UDP ports, not adding port %d\n",
7903 new_port);
7904 return;
7905 }
7906
7907 adapter->vxlan_port = new_port;
7908 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, new_port);
7909}
7910
7911/**
7912 * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away
7913 * @dev: The port's netdev
7914 * @sa_family: Socket Family that VXLAN is notifying us about
7915 * @port: UDP port number that VXLAN stopped listening to
7916 **/
7917static void ixgbe_del_vxlan_port(struct net_device *dev, sa_family_t sa_family,
7918 __be16 port)
7919{
7920 struct ixgbe_adapter *adapter = netdev_priv(dev);
7921 struct ixgbe_hw *hw = &adapter->hw;
7922 u16 new_port = ntohs(port);
7923
7924 if (sa_family == AF_INET6)
7925 return;
7926
7927 if (adapter->vxlan_port != new_port) {
7928 netdev_info(dev, "Port %d was not found, not deleting\n",
7929 new_port);
7930 return;
7931 }
7932
7933 adapter->vxlan_port = 0;
7934 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, 0);
7935}
7936
stephen hemmingeredc7d572012-10-01 12:32:33 +00007937static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007938 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01007939 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007940 u16 flags)
7941{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00007942 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00007943 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyckbcfd3432014-07-17 02:11:22 +00007944 if (IXGBE_MAX_PF_MACVLANS <= netdev_uc_count(dev))
7945 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007946 }
7947
Jiri Pirkof6f64242014-11-28 14:34:15 +01007948 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007949}
7950
Don Skidmore219efe92015-04-09 22:03:22 -07007951/**
7952 * ixgbe_configure_bridge_mode - set various bridge modes
7953 * @adapter - the private structure
7954 * @mode - requested bridge mode
7955 *
7956 * Configure some settings require for various bridge modes.
7957 **/
7958static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
7959 __u16 mode)
7960{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07007961 struct ixgbe_hw *hw = &adapter->hw;
7962 unsigned int p, num_pools;
7963 u32 vmdctl;
7964
Don Skidmore219efe92015-04-09 22:03:22 -07007965 switch (mode) {
7966 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07007967 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07007968 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07007969
7970 /* must enable Rx switching replication to allow multicast
7971 * packet reception on all VFs, and to enable source address
7972 * pruning.
7973 */
7974 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
7975 vmdctl |= IXGBE_VT_CTL_REPLEN;
7976 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
7977
7978 /* enable Rx source address pruning. Note, this requires
7979 * replication to be enabled or else it does nothing.
7980 */
7981 num_pools = adapter->num_vfs + adapter->num_rx_pools;
7982 for (p = 0; p < num_pools; p++) {
7983 if (hw->mac.ops.set_source_address_pruning)
7984 hw->mac.ops.set_source_address_pruning(hw,
7985 true,
7986 p);
7987 }
Don Skidmore219efe92015-04-09 22:03:22 -07007988 break;
7989 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07007990 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07007991 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
7992 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07007993
7994 /* disable Rx switching replication unless we have SR-IOV
7995 * virtual functions
7996 */
7997 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
7998 if (!adapter->num_vfs)
7999 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
8000 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
8001
8002 /* disable Rx source address pruning, since we don't expect to
8003 * be receiving external loopback of our transmitted frames.
8004 */
8005 num_pools = adapter->num_vfs + adapter->num_rx_pools;
8006 for (p = 0; p < num_pools; p++) {
8007 if (hw->mac.ops.set_source_address_pruning)
8008 hw->mac.ops.set_source_address_pruning(hw,
8009 false,
8010 p);
8011 }
Don Skidmore219efe92015-04-09 22:03:22 -07008012 break;
8013 default:
8014 return -EINVAL;
8015 }
8016
8017 adapter->bridge_mode = mode;
8018
8019 e_info(drv, "enabling bridge mode: %s\n",
8020 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
8021
8022 return 0;
8023}
8024
John Fastabend815cccb2012-10-24 08:13:09 +00008025static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08008026 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00008027{
8028 struct ixgbe_adapter *adapter = netdev_priv(dev);
8029 struct nlattr *attr, *br_spec;
8030 int rem;
8031
8032 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8033 return -EOPNOTSUPP;
8034
8035 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01008036 if (!br_spec)
8037 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00008038
8039 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07008040 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00008041 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00008042
8043 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8044 continue;
8045
Thomas Grafb7c1a312014-11-26 13:42:17 +01008046 if (nla_len(attr) < sizeof(mode))
8047 return -EINVAL;
8048
John Fastabend815cccb2012-10-24 08:13:09 +00008049 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07008050 status = ixgbe_configure_bridge_mode(adapter, mode);
8051 if (status)
8052 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07008053
8054 break;
John Fastabend815cccb2012-10-24 08:13:09 +00008055 }
8056
8057 return 0;
8058}
8059
8060static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00008061 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02008062 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00008063{
8064 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00008065
8066 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8067 return 0;
8068
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07008069 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02008070 adapter->bridge_mode, 0, 0, nlflags);
John Fastabend815cccb2012-10-24 08:13:09 +00008071}
8072
John Fastabend2a47fa42013-11-06 09:54:52 -08008073static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
8074{
8075 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
8076 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00008077 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08008078 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08008079 int pool, err;
8080
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00008081 /* Hardware has a limited number of available pools. Each VF, and the
8082 * PF require a pool. Check to ensure we don't attempt to use more
8083 * then the available number of pools.
8084 */
8085 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
8086 return ERR_PTR(-EINVAL);
8087
John Fastabend219354d2013-11-08 00:50:32 -08008088#ifdef CONFIG_RPS
8089 if (vdev->num_rx_queues != vdev->num_tx_queues) {
8090 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
8091 vdev->name);
8092 return ERR_PTR(-EINVAL);
8093 }
8094#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08008095 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08008096 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08008097 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
8098 netdev_info(pdev,
8099 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
8100 pdev->name);
8101 return ERR_PTR(-EINVAL);
8102 }
8103
8104 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
8105 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
8106 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
8107 return ERR_PTR(-EBUSY);
8108
8109 fwd_adapter = kcalloc(1, sizeof(struct ixgbe_fwd_adapter), GFP_KERNEL);
8110 if (!fwd_adapter)
8111 return ERR_PTR(-ENOMEM);
8112
8113 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
8114 adapter->num_rx_pools++;
8115 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08008116 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08008117
8118 /* Enable VMDq flag so device will be set in VM mode */
8119 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08008120 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08008121 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08008122
8123 /* Force reinit of ring allocation with VMDQ enabled */
8124 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8125 if (err)
8126 goto fwd_add_err;
8127 fwd_adapter->pool = pool;
8128 fwd_adapter->real_adapter = adapter;
8129 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
8130 if (err)
8131 goto fwd_add_err;
8132 netif_tx_start_all_queues(vdev);
8133 return fwd_adapter;
8134fwd_add_err:
8135 /* unwind counter and free adapter struct */
8136 netdev_info(pdev,
8137 "%s: dfwd hardware acceleration failed\n", vdev->name);
8138 clear_bit(pool, &adapter->fwd_bitmask);
8139 adapter->num_rx_pools--;
8140 kfree(fwd_adapter);
8141 return ERR_PTR(err);
8142}
8143
8144static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
8145{
8146 struct ixgbe_fwd_adapter *fwd_adapter = priv;
8147 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08008148 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08008149
8150 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
8151 adapter->num_rx_pools--;
8152
John Fastabend51f37732013-11-08 00:51:10 -08008153 limit = find_last_bit(&adapter->fwd_bitmask, 32);
8154 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08008155 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
8156 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8157 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
8158 fwd_adapter->pool, adapter->num_rx_pools,
8159 fwd_adapter->rx_base_queue,
8160 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
8161 adapter->fwd_bitmask);
8162 kfree(fwd_adapter);
8163}
8164
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008165static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00008166 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008167 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08008168 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008169 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00008170 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008171 .ndo_validate_addr = eth_validate_addr,
8172 .ndo_set_mac_address = ixgbe_set_mac,
8173 .ndo_change_mtu = ixgbe_change_mtu,
8174 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008175 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
8176 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00008177 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00008178 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
8179 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04008180 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00008181 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03008182 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Greg Rose7f016482010-05-04 22:12:06 +00008183 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00008184 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008185#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00008186 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008187#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008188#ifdef CONFIG_NET_POLL_CONTROLLER
8189 .ndo_poll_controller = ixgbe_netpoll,
8190#endif
Cong Wange0d10952013-08-01 11:10:25 +08008191#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03008192 .ndo_busy_poll = ixgbe_low_latency_recv,
Eliezer Tamir5a85e732013-06-10 11:40:20 +03008193#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008194#ifdef IXGBE_FCOE
8195 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00008196 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00008197 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00008198 .ndo_fcoe_enable = ixgbe_fcoe_enable,
8199 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00008200 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00008201 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00008202#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00008203 .ndo_set_features = ixgbe_set_features,
8204 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00008205 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00008206 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
8207 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08008208 .ndo_dfwd_add_station = ixgbe_fwd_add,
8209 .ndo_dfwd_del_station = ixgbe_fwd_del,
Don Skidmore3f207802014-12-23 07:40:34 +00008210 .ndo_add_vxlan_port = ixgbe_add_vxlan_port,
8211 .ndo_del_vxlan_port = ixgbe_del_vxlan_port,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008212};
8213
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008214/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00008215 * ixgbe_enumerate_functions - Get the number of ports this device has
8216 * @adapter: adapter structure
8217 *
8218 * This function enumerates the phsyical functions co-located on a single slot,
8219 * in order to determine how many ports a device has. This is most useful in
8220 * determining the required GT/s of PCIe bandwidth necessary for optimal
8221 * performance.
8222 **/
8223static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
8224{
Jacob Kellercaafb952014-07-19 07:17:17 +00008225 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00008226 int physfns = 0;
8227
Jacob Kellerf1f96572013-08-31 02:45:38 +00008228 /* Some cards can not use the generic count PCIe functions method,
8229 * because they are behind a parent switch, so we hardcode these with
8230 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00008231 */
Jacob Keller88189702014-07-19 07:17:16 +00008232 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00008233 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00008234
8235 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
8236 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00008237 if (entry->is_virtfn)
8238 continue;
8239
8240 /* When the devices on the bus don't all match our device ID,
8241 * we can't reliably determine the correct number of
8242 * functions. This can occur if a function has been direct
8243 * attached to a virtual machine using VT-d, for example. In
8244 * this case, simply return -1 to indicate this.
8245 */
8246 if ((entry->vendor != pdev->vendor) ||
8247 (entry->device != pdev->device))
8248 return -1;
8249
8250 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00008251 }
8252
8253 return physfns;
8254}
8255
8256/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00008257 * ixgbe_wol_supported - Check whether device supports WoL
8258 * @hw: hw specific details
8259 * @device_id: the device ID
8260 * @subdev_id: the subsystem device ID
8261 *
8262 * This function is used by probe and ethtool to determine
8263 * which devices have WoL support
8264 *
8265 **/
8266int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
8267 u16 subdevice_id)
8268{
8269 struct ixgbe_hw *hw = &adapter->hw;
8270 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
8271 int is_wol_supported = 0;
8272
8273 switch (device_id) {
8274 case IXGBE_DEV_ID_82599_SFP:
8275 /* Only these subdevices could supports WOL */
8276 switch (subdevice_id) {
Mark Rustad87557442014-02-25 17:58:55 -08008277 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008278 case IXGBE_SUBDEV_ID_82599_560FLR:
8279 /* only support first port */
8280 if (hw->bus.func != 0)
8281 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00008282 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008283 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00008284 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00008285 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller979fe5f2013-04-03 04:41:37 +00008286 case IXGBE_SUBDEV_ID_82599_LOM_SFP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008287 is_wol_supported = 1;
8288 break;
8289 }
8290 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00008291 case IXGBE_DEV_ID_82599EN_SFP:
8292 /* Only this subdevice supports WOL */
8293 switch (subdevice_id) {
8294 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
8295 is_wol_supported = 1;
8296 break;
8297 }
8298 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008299 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
8300 /* All except this subdevice support WOL */
8301 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
8302 is_wol_supported = 1;
8303 break;
8304 case IXGBE_DEV_ID_82599_KX4:
8305 is_wol_supported = 1;
8306 break;
8307 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00008308 case IXGBE_DEV_ID_X540T1:
Don Skidmoredf8c26f2015-06-09 16:00:17 -07008309 case IXGBE_DEV_ID_X550T:
8310 case IXGBE_DEV_ID_X550EM_X_KX4:
8311 case IXGBE_DEV_ID_X550EM_X_KR:
8312 case IXGBE_DEV_ID_X550EM_X_10G_T:
Jacob Keller8e2813f2012-04-21 06:05:40 +00008313 /* check eeprom to see if enabled wol */
8314 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
8315 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
8316 (hw->bus.func == 0))) {
8317 is_wol_supported = 1;
8318 }
8319 break;
8320 }
8321
8322 return is_wol_supported;
8323}
8324
8325/**
Martin K Petersenc762dff2014-11-15 14:24:51 +00008326 * ixgbe_get_platform_mac_addr - Look up MAC address in Open Firmware / IDPROM
8327 * @adapter: Pointer to adapter struct
8328 */
8329static void ixgbe_get_platform_mac_addr(struct ixgbe_adapter *adapter)
8330{
8331#ifdef CONFIG_OF
8332 struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
8333 struct ixgbe_hw *hw = &adapter->hw;
8334 const unsigned char *addr;
8335
8336 addr = of_get_mac_address(dp);
8337 if (addr) {
8338 ether_addr_copy(hw->mac.perm_addr, addr);
8339 return;
8340 }
8341#endif /* CONFIG_OF */
8342
8343#ifdef CONFIG_SPARC
8344 ether_addr_copy(hw->mac.perm_addr, idprom->id_ethaddr);
8345#endif /* CONFIG_SPARC */
8346}
8347
8348/**
Auke Kok9a799d72007-09-15 14:07:45 -07008349 * ixgbe_probe - Device Initialization Routine
8350 * @pdev: PCI device information struct
8351 * @ent: entry in ixgbe_pci_tbl
8352 *
8353 * Returns 0 on success, negative on failure
8354 *
8355 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
8356 * The OS initialization, configuring of the adapter private structure,
8357 * and a hardware reset occur.
8358 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00008359static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07008360{
8361 struct net_device *netdev;
8362 struct ixgbe_adapter *adapter = NULL;
8363 struct ixgbe_hw *hw;
8364 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +00008365 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008366 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00008367 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008368 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +00008369#ifdef IXGBE_FCOE
8370 u16 device_caps;
8371#endif
Don Skidmore289700db2010-12-03 03:32:58 +00008372 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07008373
Andy Gospodarekbded64a2010-07-21 06:40:31 +00008374 /* Catch broken hardware that put the wrong VF device ID in
8375 * the PCIe SR-IOV capability.
8376 */
8377 if (pdev->is_virtfn) {
8378 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
8379 pci_name(pdev), pdev->vendor, pdev->device);
8380 return -EINVAL;
8381 }
8382
gouji-new9ce77662009-05-06 10:44:45 +00008383 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008384 if (err)
8385 return err;
8386
Russell Kingf5f2eda2013-06-10 12:47:42 +01008387 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07008388 pci_using_dac = 1;
8389 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +01008390 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07008391 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +01008392 dev_err(&pdev->dev,
8393 "No usable DMA configuration, aborting\n");
8394 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -07008395 }
8396 pci_using_dac = 0;
8397 }
8398
gouji-new9ce77662009-05-06 10:44:45 +00008399 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008400 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07008401 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00008402 dev_err(&pdev->dev,
8403 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07008404 goto err_pci_reg;
8405 }
8406
Frans Pop19d5afd2009-10-02 10:04:12 -07008407 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008408
Auke Kok9a799d72007-09-15 14:07:45 -07008409 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07008410 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008411
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008412 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00008413#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008414 /* 8 TC w/ 4 queues per TC */
8415 indices = 4 * MAX_TRAFFIC_CLASS;
8416#else
8417 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00008418#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008419 }
John Fastabende901acd2011-04-26 07:26:08 +00008420
John Fastabendc85a2612010-02-25 23:15:21 +00008421 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07008422 if (!netdev) {
8423 err = -ENOMEM;
8424 goto err_alloc_etherdev;
8425 }
8426
Auke Kok9a799d72007-09-15 14:07:45 -07008427 SET_NETDEV_DEV(netdev, &pdev->dev);
8428
Auke Kok9a799d72007-09-15 14:07:45 -07008429 adapter = netdev_priv(netdev);
8430
8431 adapter->netdev = netdev;
8432 adapter->pdev = pdev;
8433 hw = &adapter->hw;
8434 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00008435 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07008436
Jeff Kirsher05857982008-09-11 19:57:00 -07008437 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00008438 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -08008439 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -07008440 if (!hw->hw_addr) {
8441 err = -EIO;
8442 goto err_ioremap;
8443 }
8444
Stephen Hemminger0edc3522008-11-19 22:24:29 -08008445 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07008446 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008447 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +00008448 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -07008449
Auke Kok9a799d72007-09-15 14:07:45 -07008450 /* Setup hw api */
8451 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008452 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -07008453 hw->mvals = ii->mvals;
Auke Kok9a799d72007-09-15 14:07:45 -07008454
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008455 /* EEPROM */
8456 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
Don Skidmore9a900ec2015-06-09 17:15:01 -07008457 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +00008458 if (ixgbe_removed(hw->hw_addr)) {
8459 err = -EIO;
8460 goto err_ioremap;
8461 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008462 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
8463 if (!(eec & (1 << 8)))
8464 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
8465
8466 /* PHY */
8467 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08008468 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00008469 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
8470 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
8471 hw->phy.mdio.mmds = 0;
8472 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
8473 hw->phy.mdio.dev = netdev;
8474 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
8475 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08008476
Don Skidmore8ca783a2009-05-26 20:40:47 -07008477 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07008478
8479 /* setup the private structure */
8480 err = ixgbe_sw_init(adapter);
8481 if (err)
8482 goto err_sw_init;
8483
Don Skidmoree86bff02010-02-11 04:14:08 +00008484 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08008485 switch (adapter->hw.mac.type) {
8486 case ixgbe_mac_82599EB:
8487 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00008488 case ixgbe_mac_X550:
8489 case ixgbe_mac_X550EM_x:
Don Skidmoree86bff02010-02-11 04:14:08 +00008490 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08008491 break;
8492 default:
8493 break;
8494 }
Don Skidmoree86bff02010-02-11 04:14:08 +00008495
Don Skidmorebf069c92009-05-07 10:39:54 +00008496 /*
8497 * If there is a fan on this device and it has failed log the
8498 * failure.
8499 */
8500 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
8501 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
8502 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00008503 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00008504 }
8505
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00008506 if (allow_unsupported_sfp)
8507 hw->allow_unsupported_sfp = allow_unsupported_sfp;
8508
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008509 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07008510 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008511 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07008512 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07008513 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
8514 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07008515 err = 0;
8516 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00008517 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
8518 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008519 goto err_sw_init;
8520 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008521 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008522 goto err_sw_init;
8523 }
8524
Alexander Duyck99d74482012-05-09 08:09:25 +00008525#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00008526 /* SR-IOV not supported on the 82598 */
8527 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8528 goto skip_sriov;
8529 /* Mailbox */
8530 ixgbe_init_mbx_params_pf(hw);
8531 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
ethan.zhaodcc23e32014-01-16 19:41:04 -08008532 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ethan.zhao31ac9102014-01-16 19:41:05 -08008533 ixgbe_enable_sriov(adapter);
Greg Rose60a1a682012-12-11 08:26:33 +00008534skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008535
Alexander Duyck99d74482012-05-09 08:09:25 +00008536#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00008537 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00008538 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00008539 NETIF_F_IPV6_CSUM |
Patrick McHardyf6469682013-04-19 02:04:27 +00008540 NETIF_F_HW_VLAN_CTAG_TX |
8541 NETIF_F_HW_VLAN_CTAG_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00008542 NETIF_F_TSO |
8543 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00008544 NETIF_F_RXHASH |
John Fastabend8bf12642013-11-12 12:13:29 +00008545 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07008546
John Fastabend8bf12642013-11-12 12:13:29 +00008547 netdev->hw_features = netdev->features | NETIF_F_HW_L2FW_DOFFLOAD;
Jeff Kirsherad31c402008-06-05 04:05:30 -07008548
Don Skidmore58be7662011-04-12 09:42:11 +00008549 switch (adapter->hw.mac.type) {
8550 case ixgbe_mac_82599EB:
8551 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00008552 case ixgbe_mac_X550:
8553 case ixgbe_mac_X550EM_x:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00008554 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00008555 netdev->hw_features |= NETIF_F_SCTP_CSUM |
8556 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00008557 break;
8558 default:
8559 break;
8560 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00008561
Ben Greear3f2d1c02012-03-08 08:28:41 +00008562 netdev->hw_features |= NETIF_F_RXALL;
Alexander Duyck87031c02015-04-09 22:03:24 -07008563 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Ben Greear3f2d1c02012-03-08 08:28:41 +00008564
Jeff Kirsherad31c402008-06-05 04:05:30 -07008565 netdev->vlan_features |= NETIF_F_TSO;
8566 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07008567 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00008568 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07008569 netdev->vlan_features |= NETIF_F_SG;
8570
Jiri Pirko01789342011-08-16 06:29:00 +00008571 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00008572 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00008573
Don Skidmore3f207802014-12-23 07:40:34 +00008574 switch (adapter->hw.mac.type) {
8575 case ixgbe_mac_X550:
8576 case ixgbe_mac_X550EM_x:
8577 netdev->hw_enc_features |= NETIF_F_RXCSUM;
8578 break;
8579 default:
8580 break;
8581 }
8582
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08008583#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08008584 netdev->dcbnl_ops = &dcbnl_ops;
8585#endif
8586
Yi Zoueacd73f2009-05-13 13:11:06 +00008587#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00008588 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008589 unsigned int fcoe_l;
8590
Yi Zoueacd73f2009-05-13 13:11:06 +00008591 if (hw->mac.ops.get_device_caps) {
8592 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00008593 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
8594 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00008595 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008596
Alexander Duyckd3cb9862013-01-16 01:35:35 +00008597
8598 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
8599 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008600
Alexander Duycka58915c2012-05-25 06:38:18 +00008601 netdev->features |= NETIF_F_FSO |
8602 NETIF_F_FCOE_CRC;
8603
Alexander Duyck7c8ae652012-05-05 05:32:47 +00008604 netdev->vlan_features |= NETIF_F_FSO |
8605 NETIF_F_FCOE_CRC |
8606 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00008607 }
Yi Zoueacd73f2009-05-13 13:11:06 +00008608#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00008609 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07008610 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00008611 netdev->vlan_features |= NETIF_F_HIGHDMA;
8612 }
Auke Kok9a799d72007-09-15 14:07:45 -07008613
Don Skidmore082757a2011-07-21 05:55:00 +00008614 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
8615 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00008616 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00008617 netdev->features |= NETIF_F_LRO;
8618
Auke Kok9a799d72007-09-15 14:07:45 -07008619 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07008620 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008621 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07008622 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00008623 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008624 }
8625
Martin K Petersenc762dff2014-11-15 14:24:51 +00008626 ixgbe_get_platform_mac_addr(adapter);
8627
Auke Kok9a799d72007-09-15 14:07:45 -07008628 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008629
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00008630 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008631 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07008632 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00008633 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008634 }
8635
Jacob Keller5d7daa32014-03-29 06:51:25 +00008636 ixgbe_mac_set_default_filter(adapter, hw->mac.perm_addr);
8637
Alexander Duyck70864002011-04-27 09:13:56 +00008638 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00008639 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008640
Mark Rustad58cf6632014-03-12 00:38:40 +00008641 if (ixgbe_removed(hw->hw_addr)) {
8642 err = -EIO;
8643 goto err_sw_init;
8644 }
Alexander Duyck70864002011-04-27 09:13:56 +00008645 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +00008646 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008647 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07008648
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008649 err = ixgbe_init_interrupt_scheme(adapter);
8650 if (err)
8651 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07008652
Jacob Keller8e2813f2012-04-21 06:05:40 +00008653 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00008654 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00008655 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00008656 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00008657 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00008658 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00008659 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00008660
PJ Waskiewicze8e26352009-02-27 15:45:05 +00008661 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
8662
Emil Tantilov15e52092011-09-29 05:01:29 +00008663 /* save off EEPROM version number */
8664 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
8665 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
8666
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008667 /* pick up the PCI bus settings for reporting later */
8668 hw->mac.ops.get_bus_info(hw);
Jacob Kellere027d1a2013-07-31 06:53:31 +00008669 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00008670 ixgbe_get_parent_bus_info(adapter);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00008671
Jacob Kellere027d1a2013-07-31 06:53:31 +00008672 /* calculate the expected PCIe bandwidth required for optimal
8673 * performance. Note that some older parts will never have enough
8674 * bandwidth due to being older generation PCIe parts. We clamp these
8675 * parts to ensure no warning is displayed if it can't be fixed.
8676 */
8677 switch (hw->mac.type) {
8678 case ixgbe_mac_82598EB:
8679 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
8680 break;
8681 default:
8682 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
8683 break;
Auke Kok0c254d82008-02-11 09:25:56 -08008684 }
Jacob Kellercaafb952014-07-19 07:17:17 +00008685
8686 /* don't check link if we failed to enumerate functions */
8687 if (expected_gts > 0)
8688 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08008689
Mark Rustad339de302014-06-06 01:57:06 +00008690 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00008691 if (err)
Mark Rustad339de302014-06-06 01:57:06 +00008692 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +00008693 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
8694 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
8695 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +00008696 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +00008697 else
8698 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
8699 hw->mac.type, hw->phy.type, part_str);
8700
8701 e_dev_info("%pM\n", netdev->dev_addr);
8702
Auke Kok9a799d72007-09-15 14:07:45 -07008703 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008704 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008705 if (err == IXGBE_ERR_EEPROM_VERSION) {
8706 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00008707 e_dev_warn("This device is a pre-production adapter/LOM. "
8708 "Please be aware there may be issues associated "
8709 "with your hardware. If you are experiencing "
8710 "problems please contact your Intel or hardware "
8711 "representative who provided you with this "
8712 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008713 }
Auke Kok9a799d72007-09-15 14:07:45 -07008714 strcpy(netdev->name, "eth%d");
8715 err = register_netdev(netdev);
8716 if (err)
8717 goto err_register;
8718
Emil Tantilov0fb6a552014-12-04 03:03:38 +00008719 pci_set_drvdata(pdev, adapter);
8720
Emil Tantilovec74a472012-09-20 03:33:56 +00008721 /* power down the optics for 82599 SFP+ fiber */
8722 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00008723 hw->mac.ops.disable_tx_laser(hw);
8724
Jesse Brandeburg54386462009-04-17 20:44:27 +00008725 /* carrier off reporting is important to ethtool even BEFORE open */
8726 netif_carrier_off(netdev);
8727
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008728#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03008729 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008730 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008731 ixgbe_setup_dca(adapter);
8732 }
8733#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008734 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008735 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008736 for (i = 0; i < adapter->num_vfs; i++)
8737 ixgbe_vf_configuration(pdev, (i | 0x10000000));
8738 }
8739
Jacob Keller2466dd92011-09-08 03:50:54 +00008740 /* firmware requires driver version to be 0xFFFFFFFF
8741 * since os does not support feature
8742 */
Emil Tantilov9612de92011-05-07 07:40:20 +00008743 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00008744 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
8745 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00008746
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008747 /* add san mac addr to netdev */
8748 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008749
Neerav Parikhea818752012-01-04 20:23:40 +00008750 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008751
Don Skidmore12109822012-05-04 06:07:08 +00008752#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008753 if (ixgbe_sysfs_init(adapter))
8754 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00008755#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008756
Catherine Sullivan00949162012-08-10 01:59:10 +00008757 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00008758
Emil Tantilovd1a35ee2014-05-13 08:24:00 +00008759 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
8760 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +00008761 hw->mac.ops.setup_link(hw,
8762 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
8763 true);
8764
Auke Kok9a799d72007-09-15 14:07:45 -07008765 return 0;
8766
8767err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008768 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00008769 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008770err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00008771 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00008772 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -08008773 iounmap(adapter->io_addr);
Jacob Keller5d7daa32014-03-29 06:51:25 +00008774 kfree(adapter->mac_table);
Auke Kok9a799d72007-09-15 14:07:45 -07008775err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008776 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07008777 free_netdev(netdev);
8778err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00008779 pci_release_selected_regions(pdev,
8780 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008781err_pci_reg:
8782err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008783 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00008784 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008785 return err;
8786}
8787
8788/**
8789 * ixgbe_remove - Device Removal Routine
8790 * @pdev: PCI device information struct
8791 *
8792 * ixgbe_remove is called by the PCI subsystem to alert the driver
8793 * that it should release a PCI device. The could be caused by a
8794 * Hot-Plug event, or because the driver is going to be removed from
8795 * memory.
8796 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05008797static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07008798{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008799 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +00008800 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008801 bool disable_dev;
Auke Kok9a799d72007-09-15 14:07:45 -07008802
Emil Tantilov0fb6a552014-12-04 03:03:38 +00008803 /* if !adapter then we already cleaned up in probe */
8804 if (!adapter)
8805 return;
8806
8807 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +00008808 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00008809
Mark Rustad09f40ae2014-01-14 18:53:11 -08008810 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008811 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008812
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008813
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008814#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008815 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8816 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8817 dca_remove_requester(&pdev->dev);
8818 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8819 }
8820
8821#endif
Don Skidmore12109822012-05-04 06:07:08 +00008822#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008823 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00008824#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00008825
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008826 /* remove the added san mac */
8827 ixgbe_del_sanmac_netdev(netdev);
8828
Donald Skidmorec4900be2008-11-20 21:11:42 -08008829 if (netdev->reg_state == NETREG_REGISTERED)
8830 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008831
Greg Roseda36b642012-12-11 08:26:43 +00008832#ifdef CONFIG_PCI_IOV
8833 /*
8834 * Only disable SR-IOV on unload if the user specified the now
8835 * deprecated max_vfs module parameter.
8836 */
8837 if (max_vfs)
8838 ixgbe_disable_sriov(adapter);
8839#endif
Alexander Duyck7a921c92009-05-06 10:43:28 +00008840 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008841
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008842 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008843
Alexander Duyck2b1588c2012-03-17 02:39:16 +00008844#ifdef CONFIG_DCB
8845 kfree(adapter->ixgbe_ieee_pfc);
8846 kfree(adapter->ixgbe_ieee_ets);
8847
8848#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -08008849 iounmap(adapter->io_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008850 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008851 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008852
Emil Tantilov849c4542010-06-03 16:53:41 +00008853 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008854
Jacob Keller5d7daa32014-03-29 06:51:25 +00008855 kfree(adapter->mac_table);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008856 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07008857 free_netdev(netdev);
8858
Frans Pop19d5afd2009-10-02 10:04:12 -07008859 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008860
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08008861 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +00008862 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008863}
8864
8865/**
8866 * ixgbe_io_error_detected - called when PCI error is detected
8867 * @pdev: Pointer to PCI device
8868 * @state: The current pci connection state
8869 *
8870 * This function is called after a PCI bus error affecting
8871 * this device has been detected.
8872 */
8873static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008874 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008875{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008876 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8877 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008878
Greg Rose83c61fa2011-09-07 05:59:35 +00008879#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -08008880 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +00008881 struct pci_dev *bdev, *vfdev;
8882 u32 dw0, dw1, dw2, dw3;
8883 int vf, pos;
8884 u16 req_id, pf_func;
8885
8886 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8887 adapter->num_vfs == 0)
8888 goto skip_bad_vf_detection;
8889
8890 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08008891 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00008892 bdev = bdev->bus->self;
8893
8894 if (!bdev)
8895 goto skip_bad_vf_detection;
8896
8897 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8898 if (!pos)
8899 goto skip_bad_vf_detection;
8900
Mark Rustad14438462014-02-28 15:48:57 -08008901 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
8902 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
8903 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
8904 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
8905 if (ixgbe_removed(hw->hw_addr))
8906 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +00008907
8908 req_id = dw1 >> 16;
8909 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8910 if (!(req_id & 0x0080))
8911 goto skip_bad_vf_detection;
8912
8913 pf_func = req_id & 0x01;
8914 if ((pf_func & 1) == (pdev->devfn & 1)) {
8915 unsigned int device_id;
8916
8917 vf = (req_id & 0x7F) >> 1;
8918 e_dev_err("VF %d has caused a PCIe error\n", vf);
8919 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8920 "%8.8x\tdw3: %8.8x\n",
8921 dw0, dw1, dw2, dw3);
8922 switch (adapter->hw.mac.type) {
8923 case ixgbe_mac_82599EB:
8924 device_id = IXGBE_82599_VF_DEVICE_ID;
8925 break;
8926 case ixgbe_mac_X540:
8927 device_id = IXGBE_X540_VF_DEVICE_ID;
8928 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00008929 case ixgbe_mac_X550:
8930 device_id = IXGBE_DEV_ID_X550_VF;
8931 break;
8932 case ixgbe_mac_X550EM_x:
8933 device_id = IXGBE_DEV_ID_X550EM_X_VF;
8934 break;
Greg Rose83c61fa2011-09-07 05:59:35 +00008935 default:
8936 device_id = 0;
8937 break;
8938 }
8939
8940 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00008941 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00008942 while (vfdev) {
8943 if (vfdev->devfn == (req_id & 0xFF))
8944 break;
Jon Mason36e90312012-07-19 21:02:09 +00008945 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00008946 device_id, vfdev);
8947 }
8948 /*
8949 * There's a slim chance the VF could have been hot plugged,
8950 * so if it is no longer present we don't need to issue the
8951 * VFLR. Just clean up the AER in that case.
8952 */
8953 if (vfdev) {
Emil Tantilov9079e412014-11-19 03:18:19 +00008954 ixgbe_issue_vf_flr(adapter, vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +00008955 /* Free device reference count */
8956 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +00008957 }
8958
8959 pci_cleanup_aer_uncorrect_error_status(pdev);
8960 }
8961
8962 /*
8963 * Even though the error may have occurred on the other port
8964 * we still need to increment the vf error reference count for
8965 * both ports because the I/O resume function will be called
8966 * for both of them.
8967 */
8968 adapter->vferr_refcount++;
8969
8970 return PCI_ERS_RESULT_RECOVERED;
8971
8972skip_bad_vf_detection:
8973#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +00008974 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
8975 return PCI_ERS_RESULT_DISCONNECT;
8976
Mark Rustad41c62842014-03-12 00:38:35 +00008977 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07008978 netif_device_detach(netdev);
8979
Mark Rustad41c62842014-03-12 00:38:35 +00008980 if (state == pci_channel_io_perm_failure) {
8981 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +00008982 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +00008983 }
Breno Leitao3044b8d2009-05-06 10:44:26 +00008984
Auke Kok9a799d72007-09-15 14:07:45 -07008985 if (netif_running(netdev))
8986 ixgbe_down(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +00008987
8988 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
8989 pci_disable_device(pdev);
8990 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -07008991
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008992 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008993 return PCI_ERS_RESULT_NEED_RESET;
8994}
8995
8996/**
8997 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8998 * @pdev: Pointer to PCI device
8999 *
9000 * Restart the card from scratch, as if from a cold-boot.
9001 */
9002static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
9003{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009004 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009005 pci_ers_result_t result;
9006 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07009007
gouji-new9ce77662009-05-06 10:44:45 +00009008 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00009009 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009010 result = PCI_ERS_RESULT_DISCONNECT;
9011 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +01009012 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00009013 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -08009014 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009015 pci_set_master(pdev);
9016 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00009017 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009018
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07009019 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009020
9021 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00009022 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009023 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07009024 }
Auke Kok9a799d72007-09-15 14:07:45 -07009025
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009026 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9027 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00009028 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
9029 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009030 /* non-fatal, continue */
9031 }
Auke Kok9a799d72007-09-15 14:07:45 -07009032
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08009033 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07009034}
9035
9036/**
9037 * ixgbe_io_resume - called when traffic can start flowing again.
9038 * @pdev: Pointer to PCI device
9039 *
9040 * This callback is called when the error recovery driver tells us that
9041 * its OK to resume normal operation.
9042 */
9043static void ixgbe_io_resume(struct pci_dev *pdev)
9044{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08009045 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
9046 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07009047
Greg Rose83c61fa2011-09-07 05:59:35 +00009048#ifdef CONFIG_PCI_IOV
9049 if (adapter->vferr_refcount) {
9050 e_info(drv, "Resuming after VF err\n");
9051 adapter->vferr_refcount--;
9052 return;
9053 }
9054
9055#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00009056 if (netif_running(netdev))
9057 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07009058
9059 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07009060}
9061
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07009062static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07009063 .error_detected = ixgbe_io_error_detected,
9064 .slot_reset = ixgbe_io_slot_reset,
9065 .resume = ixgbe_io_resume,
9066};
9067
9068static struct pci_driver ixgbe_driver = {
9069 .name = ixgbe_driver_name,
9070 .id_table = ixgbe_pci_tbl,
9071 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05009072 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07009073#ifdef CONFIG_PM
9074 .suspend = ixgbe_suspend,
9075 .resume = ixgbe_resume,
9076#endif
9077 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +00009078 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -07009079 .err_handler = &ixgbe_err_handler
9080};
9081
9082/**
9083 * ixgbe_init_module - Driver Registration Routine
9084 *
9085 * ixgbe_init_module is the first routine called when the driver is
9086 * loaded. All it does is register with the PCI subsystem.
9087 **/
9088static int __init ixgbe_init_module(void)
9089{
9090 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00009091 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00009092 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07009093
Catherine Sullivan00949162012-08-10 01:59:10 +00009094 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +00009095
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009096 ret = pci_register_driver(&ixgbe_driver);
9097 if (ret) {
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009098 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009099 return ret;
9100 }
9101
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009102#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009103 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009104#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009105
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00009106 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07009107}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07009108
Auke Kok9a799d72007-09-15 14:07:45 -07009109module_init(ixgbe_init_module);
9110
9111/**
9112 * ixgbe_exit_module - Driver Exit Cleanup Routine
9113 *
9114 * ixgbe_exit_module is called just before the driver is removed
9115 * from memory.
9116 **/
9117static void __exit ixgbe_exit_module(void)
9118{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009119#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009120 dca_unregister_notify(&dca_notifier);
9121#endif
Auke Kok9a799d72007-09-15 14:07:45 -07009122 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00009123
Catherine Sullivan00949162012-08-10 01:59:10 +00009124 ixgbe_dbg_exit();
Auke Kok9a799d72007-09-15 14:07:45 -07009125}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009126
Jeff Garzik5dd2d332008-10-16 05:09:31 -04009127#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009128static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00009129 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009130{
9131 int ret_val;
9132
9133 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00009134 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009135
9136 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
9137}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08009138
Alexander Duyckb4533682009-03-31 21:32:42 +00009139#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00009140
Auke Kok9a799d72007-09-15 14:07:45 -07009141module_exit(ixgbe_exit_module);
9142
9143/* ixgbe_main.c */