blob: 69c6a495aaee15c3bee28b65c8130fe96c813920 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore434c5e32013-01-08 05:02:28 +00004 Copyright(c) 1999 - 2013 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:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000047#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040048#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000049#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070050
51#include "ixgbe.h"
52#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000053#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000054#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070055
56char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070057static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000058 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000059#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000060char ixgbe_default_device_descr[] =
61 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000062#else
63static char ixgbe_default_device_descr[] =
64 "Intel(R) 10 Gigabit Network Connection";
65#endif
Don Skidmore93ac03b2013-05-15 07:34:50 +000066#define DRV_VERSION "3.15.1-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070067const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000068static const char ixgbe_copyright[] =
Don Skidmore434c5e32013-01-08 05:02:28 +000069 "Copyright (c) 1999-2013 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070070
71static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070072 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000073 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080074 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070075};
76
77/* ixgbe_pci_tbl - PCI Device ID Table
78 *
79 * Wildcard entries (PCI_ANY_ID) should come last
80 * Last entry must be all 0s
81 *
82 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
83 * Class, Class Mask, private data (not used) }
84 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000085static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000086 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Auke Kok9a799d72007-09-15 14:07:45 -0700115 /* required last entry */
116 {0, }
117};
118MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
119
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400120#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800121static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000122 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800123static struct notifier_block dca_notifier = {
124 .notifier_call = ixgbe_notify_dca,
125 .next = NULL,
126 .priority = 0
127};
128#endif
129
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000130#ifdef CONFIG_PCI_IOV
131static unsigned int max_vfs;
132module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000133MODULE_PARM_DESC(max_vfs,
Greg Rose6b42a9c2012-04-17 04:29:29 +0000134 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000135#endif /* CONFIG_PCI_IOV */
136
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000137static unsigned int allow_unsupported_sfp;
138module_param(allow_unsupported_sfp, uint, 0);
139MODULE_PARM_DESC(allow_unsupported_sfp,
140 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
141
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000142#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
143static int debug = -1;
144module_param(debug, int, 0);
145MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
146
Auke Kok9a799d72007-09-15 14:07:45 -0700147MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
148MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
149MODULE_LICENSE("GPL");
150MODULE_VERSION(DRV_VERSION);
151
Jacob Kellerb8e82002013-04-09 07:20:09 +0000152static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
153 u32 reg, u16 *value)
154{
155 int pos = 0;
156 struct pci_dev *parent_dev;
157 struct pci_bus *parent_bus;
158
159 parent_bus = adapter->pdev->bus->parent;
160 if (!parent_bus)
161 return -1;
162
163 parent_dev = parent_bus->self;
164 if (!parent_dev)
165 return -1;
166
167 pos = pci_find_capability(parent_dev, PCI_CAP_ID_EXP);
168 if (!pos)
169 return -1;
170
171 pci_read_config_word(parent_dev, pos + reg, value);
172 return 0;
173}
174
175static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
176{
177 struct ixgbe_hw *hw = &adapter->hw;
178 u16 link_status = 0;
179 int err;
180
181 hw->bus.type = ixgbe_bus_type_pci_express;
182
183 /* Get the negotiated link width and speed from PCI config space of the
184 * parent, as this device is behind a switch
185 */
186 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
187
188 /* assume caller will handle error case */
189 if (err)
190 return err;
191
192 hw->bus.width = ixgbe_convert_bus_width(link_status);
193 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
194
195 return 0;
196}
197
Jacob Kellere027d1a2013-07-31 06:53:31 +0000198/**
199 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
200 * @hw: hw specific details
201 *
202 * This function is used by probe to determine whether a device's PCI-Express
203 * bandwidth details should be gathered from the parent bus instead of from the
204 * device. Used to ensure that various locations all have the correct device ID
205 * checks.
206 */
207static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
208{
209 switch (hw->device_id) {
210 case IXGBE_DEV_ID_82599_SFP_SF_QP:
211 return true;
212 default:
213 return false;
214 }
215}
216
217static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
218 int expected_gts)
219{
220 int max_gts = 0;
221 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
222 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
223 struct pci_dev *pdev;
224
225 /* determine whether to use the the parent device
226 */
227 if (ixgbe_pcie_from_parent(&adapter->hw))
228 pdev = adapter->pdev->bus->parent->self;
229 else
230 pdev = adapter->pdev;
231
232 if (pcie_get_minimum_link(pdev, &speed, &width) ||
233 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
234 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
235 return;
236 }
237
238 switch (speed) {
239 case PCIE_SPEED_2_5GT:
240 /* 8b/10b encoding reduces max throughput by 20% */
241 max_gts = 2 * width;
242 break;
243 case PCIE_SPEED_5_0GT:
244 /* 8b/10b encoding reduces max throughput by 20% */
245 max_gts = 4 * width;
246 break;
247 case PCIE_SPEED_8_0GT:
248 /* 128b/130b encoding only reduces throughput by 1% */
249 max_gts = 8 * width;
250 break;
251 default:
252 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
253 return;
254 }
255
256 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
257 max_gts);
258 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
259 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
260 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
261 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
262 "Unknown"),
263 width,
264 (speed == PCIE_SPEED_2_5GT ? "20%" :
265 speed == PCIE_SPEED_5_0GT ? "20%" :
266 speed == PCIE_SPEED_8_0GT ? "N/a" :
267 "Unknown"));
268
269 if (max_gts < expected_gts) {
270 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
271 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
272 expected_gts);
273 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
274 }
275}
276
Alexander Duyck70864002011-04-27 09:13:56 +0000277static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
278{
279 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
280 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
281 schedule_work(&adapter->service_task);
282}
283
284static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
285{
286 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
287
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000288 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000289 smp_mb__before_clear_bit();
290 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
291}
292
Taku Izumidcd79ae2010-04-27 14:39:53 +0000293struct ixgbe_reg_info {
294 u32 ofs;
295 char *name;
296};
297
298static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
299
300 /* General Registers */
301 {IXGBE_CTRL, "CTRL"},
302 {IXGBE_STATUS, "STATUS"},
303 {IXGBE_CTRL_EXT, "CTRL_EXT"},
304
305 /* Interrupt Registers */
306 {IXGBE_EICR, "EICR"},
307
308 /* RX Registers */
309 {IXGBE_SRRCTL(0), "SRRCTL"},
310 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
311 {IXGBE_RDLEN(0), "RDLEN"},
312 {IXGBE_RDH(0), "RDH"},
313 {IXGBE_RDT(0), "RDT"},
314 {IXGBE_RXDCTL(0), "RXDCTL"},
315 {IXGBE_RDBAL(0), "RDBAL"},
316 {IXGBE_RDBAH(0), "RDBAH"},
317
318 /* TX Registers */
319 {IXGBE_TDBAL(0), "TDBAL"},
320 {IXGBE_TDBAH(0), "TDBAH"},
321 {IXGBE_TDLEN(0), "TDLEN"},
322 {IXGBE_TDH(0), "TDH"},
323 {IXGBE_TDT(0), "TDT"},
324 {IXGBE_TXDCTL(0), "TXDCTL"},
325
326 /* List Terminator */
327 {}
328};
329
330
331/*
332 * ixgbe_regdump - register printout routine
333 */
334static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
335{
336 int i = 0, j = 0;
337 char rname[16];
338 u32 regs[64];
339
340 switch (reginfo->ofs) {
341 case IXGBE_SRRCTL(0):
342 for (i = 0; i < 64; i++)
343 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
344 break;
345 case IXGBE_DCA_RXCTRL(0):
346 for (i = 0; i < 64; i++)
347 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
348 break;
349 case IXGBE_RDLEN(0):
350 for (i = 0; i < 64; i++)
351 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
352 break;
353 case IXGBE_RDH(0):
354 for (i = 0; i < 64; i++)
355 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
356 break;
357 case IXGBE_RDT(0):
358 for (i = 0; i < 64; i++)
359 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
360 break;
361 case IXGBE_RXDCTL(0):
362 for (i = 0; i < 64; i++)
363 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
364 break;
365 case IXGBE_RDBAL(0):
366 for (i = 0; i < 64; i++)
367 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
368 break;
369 case IXGBE_RDBAH(0):
370 for (i = 0; i < 64; i++)
371 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
372 break;
373 case IXGBE_TDBAL(0):
374 for (i = 0; i < 64; i++)
375 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
376 break;
377 case IXGBE_TDBAH(0):
378 for (i = 0; i < 64; i++)
379 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
380 break;
381 case IXGBE_TDLEN(0):
382 for (i = 0; i < 64; i++)
383 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
384 break;
385 case IXGBE_TDH(0):
386 for (i = 0; i < 64; i++)
387 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
388 break;
389 case IXGBE_TDT(0):
390 for (i = 0; i < 64; i++)
391 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
392 break;
393 case IXGBE_TXDCTL(0):
394 for (i = 0; i < 64; i++)
395 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
396 break;
397 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000398 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000399 IXGBE_READ_REG(hw, reginfo->ofs));
400 return;
401 }
402
403 for (i = 0; i < 8; i++) {
404 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000405 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000406 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000407 pr_cont(" %08x", regs[i*8+j]);
408 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000409 }
410
411}
412
413/*
414 * ixgbe_dump - Print registers, tx-rings and rx-rings
415 */
416static void ixgbe_dump(struct ixgbe_adapter *adapter)
417{
418 struct net_device *netdev = adapter->netdev;
419 struct ixgbe_hw *hw = &adapter->hw;
420 struct ixgbe_reg_info *reginfo;
421 int n = 0;
422 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000423 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000424 union ixgbe_adv_tx_desc *tx_desc;
425 struct my_u0 { u64 a; u64 b; } *u0;
426 struct ixgbe_ring *rx_ring;
427 union ixgbe_adv_rx_desc *rx_desc;
428 struct ixgbe_rx_buffer *rx_buffer_info;
429 u32 staterr;
430 int i = 0;
431
432 if (!netif_msg_hw(adapter))
433 return;
434
435 /* Print netdevice Info */
436 if (netdev) {
437 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000439 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000440 pr_info("%-15s %016lX %016lX %016lX\n",
441 netdev->name,
442 netdev->state,
443 netdev->trans_start,
444 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000445 }
446
447 /* Print Registers */
448 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000449 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000450 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
451 reginfo->name; reginfo++) {
452 ixgbe_regdump(hw, reginfo);
453 }
454
455 /* Print TX Ring Summary */
456 if (!netdev || !netif_running(netdev))
457 goto exit;
458
459 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000460 pr_info(" %s %s %s %s\n",
461 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
462 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000463 for (n = 0; n < adapter->num_tx_queues; n++) {
464 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000465 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000466 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000467 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000468 (u64)dma_unmap_addr(tx_buffer, dma),
469 dma_unmap_len(tx_buffer, len),
470 tx_buffer->next_to_watch,
471 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000472 }
473
474 /* Print TX Rings */
475 if (!netif_msg_tx_done(adapter))
476 goto rx_ring_summary;
477
478 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
479
480 /* Transmit Descriptor Formats
481 *
Josh Hay39ac8682012-09-26 05:59:36 +0000482 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000483 * +--------------------------------------------------------------+
484 * 0 | Buffer Address [63:0] |
485 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000486 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000487 * +--------------------------------------------------------------+
488 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000489 *
490 * 82598 Advanced Transmit Descriptor (Write-Back Format)
491 * +--------------------------------------------------------------+
492 * 0 | RSV [63:0] |
493 * +--------------------------------------------------------------+
494 * 8 | RSV | STA | NXTSEQ |
495 * +--------------------------------------------------------------+
496 * 63 36 35 32 31 0
497 *
498 * 82599+ Advanced Transmit Descriptor
499 * +--------------------------------------------------------------+
500 * 0 | Buffer Address [63:0] |
501 * +--------------------------------------------------------------+
502 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
503 * +--------------------------------------------------------------+
504 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
505 *
506 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
507 * +--------------------------------------------------------------+
508 * 0 | RSV [63:0] |
509 * +--------------------------------------------------------------+
510 * 8 | RSV | STA | RSV |
511 * +--------------------------------------------------------------+
512 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000513 */
514
515 for (n = 0; n < adapter->num_tx_queues; n++) {
516 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000517 pr_info("------------------------------------\n");
518 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
519 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000520 pr_info("%s%s %s %s %s %s\n",
521 "T [desc] [address 63:0 ] ",
522 "[PlPOIdStDDt Ln] [bi->dma ] ",
523 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000524
525 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000526 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000527 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000528 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000529 if (dma_unmap_len(tx_buffer, len) > 0) {
530 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
531 i,
532 le64_to_cpu(u0->a),
533 le64_to_cpu(u0->b),
534 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000535 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000536 tx_buffer->next_to_watch,
537 (u64)tx_buffer->time_stamp,
538 tx_buffer->skb);
539 if (i == tx_ring->next_to_use &&
540 i == tx_ring->next_to_clean)
541 pr_cont(" NTC/U\n");
542 else if (i == tx_ring->next_to_use)
543 pr_cont(" NTU\n");
544 else if (i == tx_ring->next_to_clean)
545 pr_cont(" NTC\n");
546 else
547 pr_cont("\n");
548
549 if (netif_msg_pktdata(adapter) &&
550 tx_buffer->skb)
551 print_hex_dump(KERN_INFO, "",
552 DUMP_PREFIX_ADDRESS, 16, 1,
553 tx_buffer->skb->data,
554 dma_unmap_len(tx_buffer, len),
555 true);
556 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000557 }
558 }
559
560 /* Print RX Rings Summary */
561rx_ring_summary:
562 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000563 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000564 for (n = 0; n < adapter->num_rx_queues; n++) {
565 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000566 pr_info("%5d %5X %5X\n",
567 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000568 }
569
570 /* Print RX Rings */
571 if (!netif_msg_rx_status(adapter))
572 goto exit;
573
574 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
575
Josh Hay39ac8682012-09-26 05:59:36 +0000576 /* Receive Descriptor Formats
577 *
578 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000579 * 63 1 0
580 * +-----------------------------------------------------+
581 * 0 | Packet Buffer Address [63:1] |A0/NSE|
582 * +----------------------------------------------+------+
583 * 8 | Header Buffer Address [63:1] | DD |
584 * +-----------------------------------------------------+
585 *
586 *
Josh Hay39ac8682012-09-26 05:59:36 +0000587 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000588 *
589 * 63 48 47 32 31 30 21 20 16 15 4 3 0
590 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000591 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
592 * | Packet | IP | | | | Type | Type |
593 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000594 * +------------------------------------------------------+
595 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
596 * +------------------------------------------------------+
597 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000598 *
599 * 82599+ Advanced Receive Descriptor (Read) Format
600 * 63 1 0
601 * +-----------------------------------------------------+
602 * 0 | Packet Buffer Address [63:1] |A0/NSE|
603 * +----------------------------------------------+------+
604 * 8 | Header Buffer Address [63:1] | DD |
605 * +-----------------------------------------------------+
606 *
607 *
608 * 82599+ Advanced Receive Descriptor (Write-Back) Format
609 *
610 * 63 48 47 32 31 30 21 20 17 16 4 3 0
611 * +------------------------------------------------------+
612 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
613 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
614 * |/ Flow Dir Flt ID | | | | | |
615 * +------------------------------------------------------+
616 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
617 * +------------------------------------------------------+
618 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000619 */
Josh Hay39ac8682012-09-26 05:59:36 +0000620
Taku Izumidcd79ae2010-04-27 14:39:53 +0000621 for (n = 0; n < adapter->num_rx_queues; n++) {
622 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000623 pr_info("------------------------------------\n");
624 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
625 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000626 pr_info("%s%s%s",
627 "R [desc] [ PktBuf A0] ",
628 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000629 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000630 pr_info("%s%s%s",
631 "RWB[desc] [PcsmIpSHl PtRs] ",
632 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000633 "<-- Adv Rx Write-Back format\n");
634
635 for (i = 0; i < rx_ring->count; i++) {
636 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000637 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000638 u0 = (struct my_u0 *)rx_desc;
639 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
640 if (staterr & IXGBE_RXD_STAT_DD) {
641 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000642 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000643 "%016llX ---------------- %p", i,
644 le64_to_cpu(u0->a),
645 le64_to_cpu(u0->b),
646 rx_buffer_info->skb);
647 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000648 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000649 "%016llX %016llX %p", i,
650 le64_to_cpu(u0->a),
651 le64_to_cpu(u0->b),
652 (u64)rx_buffer_info->dma,
653 rx_buffer_info->skb);
654
Emil Tantilov9c50c032012-07-26 01:21:24 +0000655 if (netif_msg_pktdata(adapter) &&
656 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000657 print_hex_dump(KERN_INFO, "",
658 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000659 page_address(rx_buffer_info->page) +
660 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000661 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000662 }
663 }
664
665 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000666 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000667 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000668 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000669 else
Joe Perchesc7689572010-09-07 21:35:17 +0000670 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000671
672 }
673 }
674
675exit:
676 return;
677}
678
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800679static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
680{
681 u32 ctrl_ext;
682
683 /* Let firmware take over control of h/w */
684 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
685 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000686 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800687}
688
689static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
690{
691 u32 ctrl_ext;
692
693 /* Let firmware know the driver has taken over */
694 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
695 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000696 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800697}
Auke Kok9a799d72007-09-15 14:07:45 -0700698
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000699/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000700 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
701 * @adapter: pointer to adapter struct
702 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
703 * @queue: queue to map the corresponding interrupt to
704 * @msix_vector: the vector to map to the corresponding queue
705 *
706 */
707static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000708 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700709{
710 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000711 struct ixgbe_hw *hw = &adapter->hw;
712 switch (hw->mac.type) {
713 case ixgbe_mac_82598EB:
714 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
715 if (direction == -1)
716 direction = 0;
717 index = (((direction * 64) + queue) >> 2) & 0x1F;
718 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
719 ivar &= ~(0xFF << (8 * (queue & 0x3)));
720 ivar |= (msix_vector << (8 * (queue & 0x3)));
721 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
722 break;
723 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800724 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000725 if (direction == -1) {
726 /* other causes */
727 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
728 index = ((queue & 1) * 8);
729 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
730 ivar &= ~(0xFF << index);
731 ivar |= (msix_vector << index);
732 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
733 break;
734 } else {
735 /* tx or rx causes */
736 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
737 index = ((16 * (queue & 1)) + (8 * direction));
738 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
739 ivar &= ~(0xFF << index);
740 ivar |= (msix_vector << index);
741 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
742 break;
743 }
744 default:
745 break;
746 }
Auke Kok9a799d72007-09-15 14:07:45 -0700747}
748
Alexander Duyckfe49f042009-06-04 16:00:09 +0000749static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000750 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000751{
752 u32 mask;
753
Alexander Duyckbd508172010-11-16 19:27:03 -0800754 switch (adapter->hw.mac.type) {
755 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000756 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
757 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800758 break;
759 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800760 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000761 mask = (qmask & 0xFFFFFFFF);
762 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
763 mask = (qmask >> 32);
764 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800765 break;
766 default:
767 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000768 }
769}
770
Alexander Duyck729739b2012-02-08 07:51:06 +0000771void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
772 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000773{
Alexander Duyck729739b2012-02-08 07:51:06 +0000774 if (tx_buffer->skb) {
775 dev_kfree_skb_any(tx_buffer->skb);
776 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000777 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000778 dma_unmap_addr(tx_buffer, dma),
779 dma_unmap_len(tx_buffer, len),
780 DMA_TO_DEVICE);
781 } else if (dma_unmap_len(tx_buffer, len)) {
782 dma_unmap_page(ring->dev,
783 dma_unmap_addr(tx_buffer, dma),
784 dma_unmap_len(tx_buffer, len),
785 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000786 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000787 tx_buffer->next_to_watch = NULL;
788 tx_buffer->skb = NULL;
789 dma_unmap_len_set(tx_buffer, len, 0);
790 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700791}
792
Alexander Duyck943561d2012-05-09 22:14:44 -0700793static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
794{
795 struct ixgbe_hw *hw = &adapter->hw;
796 struct ixgbe_hw_stats *hwstats = &adapter->stats;
797 int i;
798 u32 data;
799
800 if ((hw->fc.current_mode != ixgbe_fc_full) &&
801 (hw->fc.current_mode != ixgbe_fc_rx_pause))
802 return;
803
804 switch (hw->mac.type) {
805 case ixgbe_mac_82598EB:
806 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
807 break;
808 default:
809 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
810 }
811 hwstats->lxoffrxc += data;
812
813 /* refill credits (no tx hang) if we received xoff */
814 if (!data)
815 return;
816
817 for (i = 0; i < adapter->num_tx_queues; i++)
818 clear_bit(__IXGBE_HANG_CHECK_ARMED,
819 &adapter->tx_ring[i]->state);
820}
821
John Fastabendc84d3242010-11-16 19:27:12 -0800822static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700823{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700824 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800825 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800826 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000827 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800828 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700829 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700830
Alexander Duyck943561d2012-05-09 22:14:44 -0700831 if (adapter->ixgbe_ieee_pfc)
832 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800833
Alexander Duyck943561d2012-05-09 22:14:44 -0700834 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
835 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800836 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700837 }
John Fastabendc84d3242010-11-16 19:27:12 -0800838
839 /* update stats for each tc, only valid with PFC enabled */
840 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000841 u32 pxoffrxc;
842
John Fastabendc84d3242010-11-16 19:27:12 -0800843 switch (hw->mac.type) {
844 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000845 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800846 break;
847 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000848 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800849 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000850 hwstats->pxoffrxc[i] += pxoffrxc;
851 /* Get the TC for given UP */
852 tc = netdev_get_prio_tc_map(adapter->netdev, i);
853 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -0700854 }
855
John Fastabendc84d3242010-11-16 19:27:12 -0800856 /* disarm tx queues that have received xoff frames */
857 for (i = 0; i < adapter->num_tx_queues; i++) {
858 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -0800859
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000860 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800861 if (xoff[tc])
862 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
863 }
864}
865
866static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
867{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000868 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800869}
870
871static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
872{
873 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
874 struct ixgbe_hw *hw = &adapter->hw;
875
876 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
877 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
878
879 if (head != tail)
880 return (head < tail) ?
881 tail - head : (tail + ring->count - head);
882
883 return 0;
884}
885
886static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
887{
888 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
889 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
890 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
891 bool ret = false;
892
893 clear_check_for_tx_hang(tx_ring);
894
895 /*
896 * Check for a hung queue, but be thorough. This verifies
897 * that a transmit has been completed since the previous
898 * check AND there is at least one packet pending. The
899 * ARMED bit is set to indicate a potential hang. The
900 * bit is cleared if a pause frame is received to remove
901 * false hang detection due to PFC or 802.3x frames. By
902 * requiring this to fail twice we avoid races with
903 * pfc clearing the ARMED bit and conditions where we
904 * run the check_tx_hang logic with a transmit completion
905 * pending but without time to complete it yet.
906 */
907 if ((tx_done_old == tx_done) && tx_pending) {
908 /* make sure it is true for two checks in a row */
909 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
910 &tx_ring->state);
911 } else {
912 /* update completed stats and continue */
913 tx_ring->tx_stats.tx_done_old = tx_done;
914 /* reset the countdown */
915 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
916 }
917
918 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700919}
920
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000921/**
922 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
923 * @adapter: driver private struct
924 **/
925static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
926{
927
928 /* Do the reset outside of interrupt context */
929 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
930 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Jacob Keller12ff3f32012-12-01 07:57:17 +0000931 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000932 ixgbe_service_event_schedule(adapter);
933 }
934}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700935
Auke Kok9a799d72007-09-15 14:07:45 -0700936/**
937 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000938 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700939 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700940 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000941static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000942 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700943{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000944 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000945 struct ixgbe_tx_buffer *tx_buffer;
946 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700947 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000948 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000949 unsigned int i = tx_ring->next_to_clean;
950
951 if (test_bit(__IXGBE_DOWN, &adapter->state))
952 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700953
Alexander Duyckd3d00232011-07-15 02:31:25 +0000954 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000955 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000956 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800957
Alexander Duyck729739b2012-02-08 07:51:06 +0000958 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000959 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700960
Alexander Duyckd3d00232011-07-15 02:31:25 +0000961 /* if next_to_watch is not set then there is no work pending */
962 if (!eop_desc)
963 break;
964
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000965 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +0000966 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000967
Alexander Duyckd3d00232011-07-15 02:31:25 +0000968 /* if DD is not set pending work has not been completed */
969 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
970 break;
971
Alexander Duyckd3d00232011-07-15 02:31:25 +0000972 /* clear next_to_watch to prevent false hangs */
973 tx_buffer->next_to_watch = NULL;
974
Alexander Duyck091a6242012-02-08 07:51:01 +0000975 /* update the statistics for this packet */
976 total_bytes += tx_buffer->bytecount;
977 total_packets += tx_buffer->gso_segs;
978
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000979 /* free the skb */
980 dev_kfree_skb_any(tx_buffer->skb);
981
Alexander Duyck729739b2012-02-08 07:51:06 +0000982 /* unmap skb header data */
983 dma_unmap_single(tx_ring->dev,
984 dma_unmap_addr(tx_buffer, dma),
985 dma_unmap_len(tx_buffer, len),
986 DMA_TO_DEVICE);
987
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000988 /* clear tx_buffer data */
989 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000990 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000991
Alexander Duyck729739b2012-02-08 07:51:06 +0000992 /* unmap remaining buffers */
993 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000994 tx_buffer++;
995 tx_desc++;
996 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000997 if (unlikely(!i)) {
998 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000999 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001000 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001001 }
1002
Alexander Duyck729739b2012-02-08 07:51:06 +00001003 /* unmap any remaining paged data */
1004 if (dma_unmap_len(tx_buffer, len)) {
1005 dma_unmap_page(tx_ring->dev,
1006 dma_unmap_addr(tx_buffer, dma),
1007 dma_unmap_len(tx_buffer, len),
1008 DMA_TO_DEVICE);
1009 dma_unmap_len_set(tx_buffer, len, 0);
1010 }
1011 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001012
Alexander Duyck729739b2012-02-08 07:51:06 +00001013 /* move us one more past the eop_desc for start of next pkt */
1014 tx_buffer++;
1015 tx_desc++;
1016 i++;
1017 if (unlikely(!i)) {
1018 i -= tx_ring->count;
1019 tx_buffer = tx_ring->tx_buffer_info;
1020 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1021 }
1022
1023 /* issue prefetch for next Tx descriptor */
1024 prefetch(tx_desc);
1025
1026 /* update budget accounting */
1027 budget--;
1028 } while (likely(budget));
1029
1030 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001031 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001032 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001033 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001034 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001035 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001036 q_vector->tx.total_bytes += total_bytes;
1037 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001038
John Fastabendc84d3242010-11-16 19:27:12 -08001039 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001040 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001041 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001042 e_err(drv, "Detected Tx Unit Hang\n"
1043 " Tx Queue <%d>\n"
1044 " TDH, TDT <%x>, <%x>\n"
1045 " next_to_use <%x>\n"
1046 " next_to_clean <%x>\n"
1047 "tx_buffer_info[next_to_clean]\n"
1048 " time_stamp <%lx>\n"
1049 " jiffies <%lx>\n",
1050 tx_ring->queue_index,
1051 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1052 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001053 tx_ring->next_to_use, i,
1054 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001055
1056 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1057
1058 e_info(probe,
1059 "tx hang %d detected on queue %d, resetting adapter\n",
1060 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1061
1062 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001063 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001064
1065 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001066 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001067 }
Auke Kok9a799d72007-09-15 14:07:45 -07001068
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001069 netdev_tx_completed_queue(txring_txq(tx_ring),
1070 total_packets, total_bytes);
1071
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001072#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001073 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001074 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001075 /* Make sure that anybody stopping the queue after this
1076 * sees the new next_to_clean.
1077 */
1078 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001079 if (__netif_subqueue_stopped(tx_ring->netdev,
1080 tx_ring->queue_index)
1081 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1082 netif_wake_subqueue(tx_ring->netdev,
1083 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001084 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001085 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001086 }
Auke Kok9a799d72007-09-15 14:07:45 -07001087
Alexander Duyck59224552011-08-31 00:01:06 +00001088 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001089}
1090
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001091#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001092static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001093 struct ixgbe_ring *tx_ring,
1094 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001095{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001096 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001097 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1098 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001099
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001100 switch (hw->mac.type) {
1101 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001102 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001103 break;
1104 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001105 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001106 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1107 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1108 break;
1109 default:
1110 /* for unknown hardware do not write register */
1111 return;
1112 }
1113
1114 /*
1115 * We can enable relaxed ordering for reads, but not writes when
1116 * DCA is enabled. This is due to a known issue in some chipsets
1117 * which will cause the DCA tag to be cleared.
1118 */
1119 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1120 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1121 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1122
1123 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1124}
1125
1126static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1127 struct ixgbe_ring *rx_ring,
1128 int cpu)
1129{
1130 struct ixgbe_hw *hw = &adapter->hw;
1131 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1132 u8 reg_idx = rx_ring->reg_idx;
1133
1134
1135 switch (hw->mac.type) {
1136 case ixgbe_mac_82599EB:
1137 case ixgbe_mac_X540:
1138 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001139 break;
1140 default:
1141 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001142 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001143
1144 /*
1145 * We can enable relaxed ordering for reads, but not writes when
1146 * DCA is enabled. This is due to a known issue in some chipsets
1147 * which will cause the DCA tag to be cleared.
1148 */
1149 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001150 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1151
1152 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001153}
1154
1155static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1156{
1157 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001158 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001159 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001160
1161 if (q_vector->cpu == cpu)
1162 goto out_no_update;
1163
Alexander Duycka5579282012-02-08 07:50:04 +00001164 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001165 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001166
Alexander Duycka5579282012-02-08 07:50:04 +00001167 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001168 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001169
1170 q_vector->cpu = cpu;
1171out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001172 put_cpu();
1173}
1174
1175static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1176{
1177 int i;
1178
1179 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1180 return;
1181
Alexander Duycke35ec122009-05-21 13:07:12 +00001182 /* always use CB2 mode, difference is masked in the CB driver */
1183 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1184
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001185 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001186 adapter->q_vector[i]->cpu = -1;
1187 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001188 }
1189}
1190
1191static int __ixgbe_notify_dca(struct device *dev, void *data)
1192{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001193 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001194 unsigned long event = *(unsigned long *)data;
1195
Don Skidmore2a72c312011-07-20 02:27:05 +00001196 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001197 return 0;
1198
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001199 switch (event) {
1200 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001201 /* if we're already enabled, don't do it again */
1202 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1203 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001204 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001205 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001206 ixgbe_setup_dca(adapter);
1207 break;
1208 }
1209 /* Fall Through since DCA is disabled. */
1210 case DCA_PROVIDER_REMOVE:
1211 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1212 dca_remove_requester(dev);
1213 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1214 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1215 }
1216 break;
1217 }
1218
Denis V. Lunev652f0932008-03-27 14:39:17 +03001219 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001220}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001221
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001222#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001223static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1224 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001225 struct sk_buff *skb)
1226{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001227 if (ring->netdev->features & NETIF_F_RXHASH)
1228 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001229}
1230
Alexander Duyckf8003262012-03-03 02:35:52 +00001231#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001232/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001233 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001234 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001235 * @rx_desc: advanced rx descriptor
1236 *
1237 * Returns : true if it is FCoE pkt
1238 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001239static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001240 union ixgbe_adv_rx_desc *rx_desc)
1241{
1242 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1243
Alexander Duyck57efd442012-06-25 21:54:46 +00001244 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001245 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1246 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1247 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1248}
1249
Alexander Duyckf8003262012-03-03 02:35:52 +00001250#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001251/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001252 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001253 * @ring: structure containing ring specific data
1254 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001255 * @skb: skb currently being received and modified
1256 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001257static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001258 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001259 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001260{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001261 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001262
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001263 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001264 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001265 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001266
1267 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001268 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1269 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001270 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001271 return;
1272 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001273
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001274 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001275 return;
1276
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001277 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001278 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001279
1280 /*
1281 * 82599 errata, UDP frames with a 0 checksum can be marked as
1282 * checksum errors.
1283 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001284 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1285 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001286 return;
1287
Alexander Duyck8a0da212012-01-31 02:59:49 +00001288 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001289 return;
1290 }
1291
Auke Kok9a799d72007-09-15 14:07:45 -07001292 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001293 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001294}
1295
Alexander Duyck84ea2592010-11-16 19:26:49 -08001296static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001297{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001298 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001299
1300 /* update next to alloc since we have filled the ring */
1301 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001302 /*
1303 * Force memory writes to complete before letting h/w
1304 * know there are new descriptors to fetch. (Only
1305 * applicable for weak-ordered memory model archs,
1306 * such as IA-64).
1307 */
1308 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001309 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001310}
1311
Alexander Duyckf990b792012-01-31 02:59:34 +00001312static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1313 struct ixgbe_rx_buffer *bi)
1314{
1315 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001316 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001317
Alexander Duyckf8003262012-03-03 02:35:52 +00001318 /* since we are recycling buffers we should seldom need to alloc */
1319 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001320 return true;
1321
Alexander Duyckf8003262012-03-03 02:35:52 +00001322 /* alloc new page for storage */
1323 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001324 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1325 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001326 if (unlikely(!page)) {
1327 rx_ring->rx_stats.alloc_rx_page_failed++;
1328 return false;
1329 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001330 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001331 }
1332
Alexander Duyckf8003262012-03-03 02:35:52 +00001333 /* map page for use */
1334 dma = dma_map_page(rx_ring->dev, page, 0,
1335 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001336
Alexander Duyckf8003262012-03-03 02:35:52 +00001337 /*
1338 * if mapping failed free memory back to system since
1339 * there isn't much point in holding memory we can't use
1340 */
1341 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001342 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001343 bi->page = NULL;
1344
Alexander Duyckf990b792012-01-31 02:59:34 +00001345 rx_ring->rx_stats.alloc_rx_page_failed++;
1346 return false;
1347 }
1348
Alexander Duyckf8003262012-03-03 02:35:52 +00001349 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001350 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001351
Alexander Duyckf990b792012-01-31 02:59:34 +00001352 return true;
1353}
1354
Auke Kok9a799d72007-09-15 14:07:45 -07001355/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001356 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001357 * @rx_ring: ring to place buffers on
1358 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001359 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001360void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001361{
Auke Kok9a799d72007-09-15 14:07:45 -07001362 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001363 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001364 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001365
Alexander Duyckf8003262012-03-03 02:35:52 +00001366 /* nothing to do */
1367 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001368 return;
1369
Alexander Duycke4f74022012-01-31 02:59:44 +00001370 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001371 bi = &rx_ring->rx_buffer_info[i];
1372 i -= rx_ring->count;
1373
Alexander Duyckf8003262012-03-03 02:35:52 +00001374 do {
1375 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001376 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001377
Alexander Duyckf8003262012-03-03 02:35:52 +00001378 /*
1379 * Refresh the desc even if buffer_addrs didn't change
1380 * because each write-back erases this info.
1381 */
1382 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001383
Alexander Duyckf990b792012-01-31 02:59:34 +00001384 rx_desc++;
1385 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001386 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001387 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001388 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001389 bi = rx_ring->rx_buffer_info;
1390 i -= rx_ring->count;
1391 }
1392
1393 /* clear the hdr_addr for the next_to_use descriptor */
1394 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001395
1396 cleaned_count--;
1397 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001398
Alexander Duyckf990b792012-01-31 02:59:34 +00001399 i += rx_ring->count;
1400
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001401 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001402 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001403}
1404
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001405/**
1406 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1407 * @data: pointer to the start of the headers
1408 * @max_len: total length of section to find headers in
1409 *
1410 * This function is meant to determine the length of headers that will
1411 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1412 * motivation of doing this is to only perform one pull for IPv4 TCP
1413 * packets so that we can do basic things like calculating the gso_size
1414 * based on the average data per packet.
1415 **/
1416static unsigned int ixgbe_get_headlen(unsigned char *data,
1417 unsigned int max_len)
1418{
1419 union {
1420 unsigned char *network;
1421 /* l2 headers */
1422 struct ethhdr *eth;
1423 struct vlan_hdr *vlan;
1424 /* l3 headers */
1425 struct iphdr *ipv4;
Alexander Duycka048b402012-05-24 08:26:29 +00001426 struct ipv6hdr *ipv6;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001427 } hdr;
1428 __be16 protocol;
1429 u8 nexthdr = 0; /* default to not TCP */
1430 u8 hlen;
1431
1432 /* this should never happen, but better safe than sorry */
1433 if (max_len < ETH_HLEN)
1434 return max_len;
1435
1436 /* initialize network frame pointer */
1437 hdr.network = data;
1438
1439 /* set first protocol and move network header forward */
1440 protocol = hdr.eth->h_proto;
1441 hdr.network += ETH_HLEN;
1442
1443 /* handle any vlan tag if present */
1444 if (protocol == __constant_htons(ETH_P_8021Q)) {
1445 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1446 return max_len;
1447
1448 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1449 hdr.network += VLAN_HLEN;
1450 }
1451
1452 /* handle L3 protocols */
1453 if (protocol == __constant_htons(ETH_P_IP)) {
1454 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1455 return max_len;
1456
1457 /* access ihl as a u8 to avoid unaligned access on ia64 */
1458 hlen = (hdr.network[0] & 0x0F) << 2;
1459
1460 /* verify hlen meets minimum size requirements */
1461 if (hlen < sizeof(struct iphdr))
1462 return hdr.network - data;
1463
Alexander Duycked83da12012-11-13 01:13:33 +00001464 /* record next protocol if header is present */
Alexander Duyck20967f42013-02-01 08:56:41 +00001465 if (!(hdr.ipv4->frag_off & htons(IP_OFFSET)))
Alexander Duycked83da12012-11-13 01:13:33 +00001466 nexthdr = hdr.ipv4->protocol;
Alexander Duycka048b402012-05-24 08:26:29 +00001467 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1468 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1469 return max_len;
1470
1471 /* record next protocol */
1472 nexthdr = hdr.ipv6->nexthdr;
Alexander Duycked83da12012-11-13 01:13:33 +00001473 hlen = sizeof(struct ipv6hdr);
Alexander Duyckf8003262012-03-03 02:35:52 +00001474#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001475 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1476 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1477 return max_len;
Alexander Duycked83da12012-11-13 01:13:33 +00001478 hlen = FCOE_HEADER_LEN;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001479#endif
1480 } else {
1481 return hdr.network - data;
1482 }
1483
Alexander Duycked83da12012-11-13 01:13:33 +00001484 /* relocate pointer to start of L4 header */
1485 hdr.network += hlen;
1486
Alexander Duycka048b402012-05-24 08:26:29 +00001487 /* finally sort out TCP/UDP */
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001488 if (nexthdr == IPPROTO_TCP) {
1489 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1490 return max_len;
1491
1492 /* access doff as a u8 to avoid unaligned access on ia64 */
1493 hlen = (hdr.network[12] & 0xF0) >> 2;
1494
1495 /* verify hlen meets minimum size requirements */
1496 if (hlen < sizeof(struct tcphdr))
1497 return hdr.network - data;
1498
1499 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001500 } else if (nexthdr == IPPROTO_UDP) {
1501 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1502 return max_len;
1503
1504 hdr.network += sizeof(struct udphdr);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001505 }
1506
1507 /*
1508 * If everything has gone correctly hdr.network should be the
1509 * data section of the packet and will be the end of the header.
1510 * If not then it probably represents the end of the last recognized
1511 * header.
1512 */
1513 if ((hdr.network - data) < max_len)
1514 return hdr.network - data;
1515 else
1516 return max_len;
1517}
1518
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001519static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1520 struct sk_buff *skb)
1521{
Alexander Duyckf8003262012-03-03 02:35:52 +00001522 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001523
1524 /* set gso_size to avoid messing up TCP MSS */
1525 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1526 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001527 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001528}
1529
1530static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1531 struct sk_buff *skb)
1532{
1533 /* if append_cnt is 0 then frame is not RSC */
1534 if (!IXGBE_CB(skb)->append_cnt)
1535 return;
1536
1537 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1538 rx_ring->rx_stats.rsc_flush++;
1539
1540 ixgbe_set_rsc_gso_size(rx_ring, skb);
1541
1542 /* gso_size is computed using append_cnt so always clear it last */
1543 IXGBE_CB(skb)->append_cnt = 0;
1544}
1545
Alexander Duyck8a0da212012-01-31 02:59:49 +00001546/**
1547 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1548 * @rx_ring: rx descriptor ring packet is being transacted on
1549 * @rx_desc: pointer to the EOP Rx descriptor
1550 * @skb: pointer to current skb being populated
1551 *
1552 * This function checks the ring, descriptor, and packet information in
1553 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1554 * other fields within the skb.
1555 **/
1556static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1557 union ixgbe_adv_rx_desc *rx_desc,
1558 struct sk_buff *skb)
1559{
John Fastabend43e95f12012-05-15 06:12:17 +00001560 struct net_device *dev = rx_ring->netdev;
1561
Alexander Duyck8a0da212012-01-31 02:59:49 +00001562 ixgbe_update_rsc_stats(rx_ring, skb);
1563
1564 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1565
1566 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1567
Jacob Keller6cb562d2012-12-05 07:24:41 +00001568 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001569
Patrick McHardyf6469682013-04-19 02:04:27 +00001570 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001571 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001572 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001573 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001574 }
1575
1576 skb_record_rx_queue(skb, rx_ring->queue_index);
1577
John Fastabend43e95f12012-05-15 06:12:17 +00001578 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001579}
1580
1581static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1582 struct sk_buff *skb)
1583{
1584 struct ixgbe_adapter *adapter = q_vector->adapter;
1585
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001586 if (ixgbe_qv_ll_polling(q_vector))
1587 netif_receive_skb(skb);
1588 else if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
Alexander Duyck8a0da212012-01-31 02:59:49 +00001589 napi_gro_receive(&q_vector->napi, skb);
1590 else
1591 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001592}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001593
Alexander Duyckf8003262012-03-03 02:35:52 +00001594/**
1595 * ixgbe_is_non_eop - process handling of non-EOP buffers
1596 * @rx_ring: Rx ring being processed
1597 * @rx_desc: Rx descriptor for current buffer
1598 * @skb: Current socket buffer containing buffer in progress
1599 *
1600 * This function updates next to clean. If the buffer is an EOP buffer
1601 * this function exits returning false, otherwise it will place the
1602 * sk_buff in the next buffer to be chained and return true indicating
1603 * that this is in fact a non-EOP buffer.
1604 **/
1605static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1606 union ixgbe_adv_rx_desc *rx_desc,
1607 struct sk_buff *skb)
1608{
1609 u32 ntc = rx_ring->next_to_clean + 1;
1610
1611 /* fetch, update, and store next to clean */
1612 ntc = (ntc < rx_ring->count) ? ntc : 0;
1613 rx_ring->next_to_clean = ntc;
1614
1615 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1616
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001617 /* update RSC append count if present */
1618 if (ring_is_rsc_enabled(rx_ring)) {
1619 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1620 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1621
1622 if (unlikely(rsc_enabled)) {
1623 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1624
1625 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1626 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1627
1628 /* update ntc based on RSC value */
1629 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1630 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1631 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1632 }
1633 }
1634
1635 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001636 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1637 return false;
1638
Alexander Duyckf8003262012-03-03 02:35:52 +00001639 /* place skb in next buffer to be received */
1640 rx_ring->rx_buffer_info[ntc].skb = skb;
1641 rx_ring->rx_stats.non_eop_descs++;
1642
1643 return true;
1644}
1645
1646/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001647 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1648 * @rx_ring: rx descriptor ring packet is being transacted on
1649 * @skb: pointer to current skb being adjusted
1650 *
1651 * This function is an ixgbe specific version of __pskb_pull_tail. The
1652 * main difference between this version and the original function is that
1653 * this function can make several assumptions about the state of things
1654 * that allow for significant optimizations versus the standard function.
1655 * As a result we can do things like drop a frag and maintain an accurate
1656 * truesize for the skb.
1657 */
1658static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1659 struct sk_buff *skb)
1660{
1661 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1662 unsigned char *va;
1663 unsigned int pull_len;
1664
1665 /*
1666 * it is valid to use page_address instead of kmap since we are
1667 * working with pages allocated out of the lomem pool per
1668 * alloc_page(GFP_ATOMIC)
1669 */
1670 va = skb_frag_address(frag);
1671
1672 /*
1673 * we need the header to contain the greater of either ETH_HLEN or
1674 * 60 bytes if the skb->len is less than 60 for skb_pad.
1675 */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001676 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001677
1678 /* align pull length to size of long to optimize memcpy performance */
1679 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1680
1681 /* update all of the pointers */
1682 skb_frag_size_sub(frag, pull_len);
1683 frag->page_offset += pull_len;
1684 skb->data_len -= pull_len;
1685 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001686}
1687
1688/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001689 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1690 * @rx_ring: rx descriptor ring packet is being transacted on
1691 * @skb: pointer to current skb being updated
1692 *
1693 * This function provides a basic DMA sync up for the first fragment of an
1694 * skb. The reason for doing this is that the first fragment cannot be
1695 * unmapped until we have reached the end of packet descriptor for a buffer
1696 * chain.
1697 */
1698static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1699 struct sk_buff *skb)
1700{
1701 /* if the page was released unmap it, else just sync our portion */
1702 if (unlikely(IXGBE_CB(skb)->page_released)) {
1703 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1704 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1705 IXGBE_CB(skb)->page_released = false;
1706 } else {
1707 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1708
1709 dma_sync_single_range_for_cpu(rx_ring->dev,
1710 IXGBE_CB(skb)->dma,
1711 frag->page_offset,
1712 ixgbe_rx_bufsz(rx_ring),
1713 DMA_FROM_DEVICE);
1714 }
1715 IXGBE_CB(skb)->dma = 0;
1716}
1717
1718/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001719 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1720 * @rx_ring: rx descriptor ring packet is being transacted on
1721 * @rx_desc: pointer to the EOP Rx descriptor
1722 * @skb: pointer to current skb being fixed
1723 *
1724 * Check for corrupted packet headers caused by senders on the local L2
1725 * embedded NIC switch not setting up their Tx Descriptors right. These
1726 * should be very rare.
1727 *
1728 * Also address the case where we are pulling data in on pages only
1729 * and as such no data is present in the skb header.
1730 *
1731 * In addition if skb is not at least 60 bytes we need to pad it so that
1732 * it is large enough to qualify as a valid Ethernet frame.
1733 *
1734 * Returns true if an error was encountered and skb was freed.
1735 **/
1736static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1737 union ixgbe_adv_rx_desc *rx_desc,
1738 struct sk_buff *skb)
1739{
Alexander Duyckf8003262012-03-03 02:35:52 +00001740 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001741
1742 /* verify that the packet does not have any known errors */
1743 if (unlikely(ixgbe_test_staterr(rx_desc,
1744 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1745 !(netdev->features & NETIF_F_RXALL))) {
1746 dev_kfree_skb_any(skb);
1747 return true;
1748 }
1749
Alexander Duyck19861ce2012-07-20 08:08:33 +00001750 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001751 if (skb_is_nonlinear(skb))
1752 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001753
Alexander Duyck57efd442012-06-25 21:54:46 +00001754#ifdef IXGBE_FCOE
1755 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1756 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1757 return false;
1758
1759#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001760 /* if skb_pad returns an error the skb was freed */
1761 if (unlikely(skb->len < 60)) {
1762 int pad_len = 60 - skb->len;
1763
1764 if (skb_pad(skb, pad_len))
1765 return true;
1766 __skb_put(skb, pad_len);
1767 }
1768
1769 return false;
1770}
1771
1772/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001773 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1774 * @rx_ring: rx descriptor ring to store buffers on
1775 * @old_buff: donor buffer to have page reused
1776 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001777 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001778 **/
1779static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1780 struct ixgbe_rx_buffer *old_buff)
1781{
1782 struct ixgbe_rx_buffer *new_buff;
1783 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001784
1785 new_buff = &rx_ring->rx_buffer_info[nta];
1786
1787 /* update, and store next to alloc */
1788 nta++;
1789 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1790
1791 /* transfer page from old buffer to new buffer */
1792 new_buff->page = old_buff->page;
1793 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001794 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001795
1796 /* sync the buffer for use by the device */
1797 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001798 new_buff->page_offset,
1799 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001800 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001801}
1802
1803/**
1804 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1805 * @rx_ring: rx descriptor ring to transact packets on
1806 * @rx_buffer: buffer containing page to add
1807 * @rx_desc: descriptor containing length of buffer written by hardware
1808 * @skb: sk_buff to place the data into
1809 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001810 * This function will add the data contained in rx_buffer->page to the skb.
1811 * This is done either through a direct copy if the data in the buffer is
1812 * less than the skb header size, otherwise it will just attach the page as
1813 * a frag to the skb.
1814 *
1815 * The function will then update the page offset if necessary and return
1816 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001817 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001818static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001819 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001820 union ixgbe_adv_rx_desc *rx_desc,
1821 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001822{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001823 struct page *page = rx_buffer->page;
1824 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001825#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001826 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001827#else
1828 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1829 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1830 ixgbe_rx_bufsz(rx_ring);
1831#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001832
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001833 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1834 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1835
1836 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1837
1838 /* we can reuse buffer as-is, just make sure it is local */
1839 if (likely(page_to_nid(page) == numa_node_id()))
1840 return true;
1841
1842 /* this page cannot be reused so discard it */
1843 put_page(page);
1844 return false;
1845 }
1846
Alexander Duyck0549ae22012-07-20 08:08:18 +00001847 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1848 rx_buffer->page_offset, size, truesize);
1849
Alexander Duyck09816fb2012-07-20 08:08:23 +00001850 /* avoid re-using remote pages */
1851 if (unlikely(page_to_nid(page) != numa_node_id()))
1852 return false;
1853
1854#if (PAGE_SIZE < 8192)
1855 /* if we are only owner of page we can reuse it */
1856 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001857 return false;
1858
1859 /* flip page offset to other buffer */
1860 rx_buffer->page_offset ^= truesize;
1861
Alexander Duyck09816fb2012-07-20 08:08:23 +00001862 /*
1863 * since we are the only owner of the page and we need to
1864 * increment it, just set the value to 2 in order to avoid
1865 * an unecessary locked operation
1866 */
1867 atomic_set(&page->_count, 2);
1868#else
1869 /* move offset up to the next cache line */
1870 rx_buffer->page_offset += truesize;
1871
1872 if (rx_buffer->page_offset > last_offset)
1873 return false;
1874
Alexander Duyck0549ae22012-07-20 08:08:18 +00001875 /* bump ref count on page before it is given to the stack */
1876 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001877#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001878
1879 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001880}
1881
Alexander Duyck18806c92012-07-20 08:08:44 +00001882static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1883 union ixgbe_adv_rx_desc *rx_desc)
1884{
1885 struct ixgbe_rx_buffer *rx_buffer;
1886 struct sk_buff *skb;
1887 struct page *page;
1888
1889 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1890 page = rx_buffer->page;
1891 prefetchw(page);
1892
1893 skb = rx_buffer->skb;
1894
1895 if (likely(!skb)) {
1896 void *page_addr = page_address(page) +
1897 rx_buffer->page_offset;
1898
1899 /* prefetch first cache line of first page */
1900 prefetch(page_addr);
1901#if L1_CACHE_BYTES < 128
1902 prefetch(page_addr + L1_CACHE_BYTES);
1903#endif
1904
1905 /* allocate a skb to store the frags */
1906 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1907 IXGBE_RX_HDR_SIZE);
1908 if (unlikely(!skb)) {
1909 rx_ring->rx_stats.alloc_rx_buff_failed++;
1910 return NULL;
1911 }
1912
1913 /*
1914 * we will be copying header into skb->data in
1915 * pskb_may_pull so it is in our interest to prefetch
1916 * it now to avoid a possible cache miss
1917 */
1918 prefetchw(skb->data);
1919
1920 /*
1921 * Delay unmapping of the first packet. It carries the
1922 * header information, HW may still access the header
1923 * after the writeback. Only unmap it when EOP is
1924 * reached
1925 */
1926 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1927 goto dma_sync;
1928
1929 IXGBE_CB(skb)->dma = rx_buffer->dma;
1930 } else {
1931 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1932 ixgbe_dma_sync_frag(rx_ring, skb);
1933
1934dma_sync:
1935 /* we are reusing so sync this buffer for CPU use */
1936 dma_sync_single_range_for_cpu(rx_ring->dev,
1937 rx_buffer->dma,
1938 rx_buffer->page_offset,
1939 ixgbe_rx_bufsz(rx_ring),
1940 DMA_FROM_DEVICE);
1941 }
1942
1943 /* pull page into skb */
1944 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1945 /* hand second half of page back to the ring */
1946 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1947 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1948 /* the page has been released from the ring */
1949 IXGBE_CB(skb)->page_released = true;
1950 } else {
1951 /* we are not reusing the buffer so unmap it */
1952 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1953 ixgbe_rx_pg_size(rx_ring),
1954 DMA_FROM_DEVICE);
1955 }
1956
1957 /* clear contents of buffer_info */
1958 rx_buffer->skb = NULL;
1959 rx_buffer->dma = 0;
1960 rx_buffer->page = NULL;
1961
1962 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001963}
1964
1965/**
1966 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1967 * @q_vector: structure containing interrupt and ring information
1968 * @rx_ring: rx descriptor ring to transact packets on
1969 * @budget: Total limit on number of packets to process
1970 *
1971 * This function provides a "bounce buffer" approach to Rx interrupt
1972 * processing. The advantage to this is that on systems that have
1973 * expensive overhead for IOMMU access this provides a means of avoiding
1974 * it by maintaining the mapping of the page to the syste.
1975 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001976 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00001977 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001978static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001979 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001980 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001981{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001982 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001983#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001984 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00001985 int ddp_bytes;
1986 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00001987#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001988 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001989
Alexander Duyckf8003262012-03-03 02:35:52 +00001990 do {
Alexander Duyckf8003262012-03-03 02:35:52 +00001991 union ixgbe_adv_rx_desc *rx_desc;
1992 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001993
Alexander Duyckf8003262012-03-03 02:35:52 +00001994 /* return some buffers to hardware, one at a time is too slow */
1995 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1996 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1997 cleaned_count = 0;
1998 }
Auke Kok9a799d72007-09-15 14:07:45 -07001999
Alexander Duyck18806c92012-07-20 08:08:44 +00002000 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07002001
Alexander Duyckf8003262012-03-03 02:35:52 +00002002 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
2003 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002004
Alexander Duyckf8003262012-03-03 02:35:52 +00002005 /*
2006 * This memory barrier is needed to keep us from reading
2007 * any other fields out of the rx_desc until we know the
2008 * RXD_STAT_DD bit is set
2009 */
2010 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002011
Alexander Duyck18806c92012-07-20 08:08:44 +00002012 /* retrieve a buffer from the ring */
2013 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00002014
Alexander Duyck18806c92012-07-20 08:08:44 +00002015 /* exit if we failed to retrieve a buffer */
2016 if (!skb)
2017 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002018
Auke Kok9a799d72007-09-15 14:07:45 -07002019 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002020
Alexander Duyckf8003262012-03-03 02:35:52 +00002021 /* place incomplete frames back on ring for completion */
2022 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2023 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002024
Alexander Duyckf8003262012-03-03 02:35:52 +00002025 /* verify the packet layout is correct */
2026 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2027 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002028
2029 /* probably a little skewed due to removing CRC */
2030 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002031
Alexander Duyck8a0da212012-01-31 02:59:49 +00002032 /* populate checksum, timestamp, VLAN, and protocol */
2033 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2034
Yi Zou332d4a72009-05-13 13:11:53 +00002035#ifdef IXGBE_FCOE
2036 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002037 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002038 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002039 /* include DDPed FCoE data */
2040 if (ddp_bytes > 0) {
2041 if (!mss) {
2042 mss = rx_ring->netdev->mtu -
2043 sizeof(struct fcoe_hdr) -
2044 sizeof(struct fc_frame_header) -
2045 sizeof(struct fcoe_crc_eof);
2046 if (mss > 512)
2047 mss &= ~511;
2048 }
2049 total_rx_bytes += ddp_bytes;
2050 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2051 mss);
2052 }
David S. Miller823dcd22011-08-20 10:39:12 -07002053 if (!ddp_bytes) {
2054 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002055 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002056 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002057 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002058
Yi Zou332d4a72009-05-13 13:11:53 +00002059#endif /* IXGBE_FCOE */
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03002060 skb_mark_napi_id(skb, &q_vector->napi);
Alexander Duyck8a0da212012-01-31 02:59:49 +00002061 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002062
Alexander Duyckf8003262012-03-03 02:35:52 +00002063 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002064 total_rx_packets++;
2065 } while (likely(total_rx_packets < budget));
Auke Kok9a799d72007-09-15 14:07:45 -07002066
Alexander Duyckc267fc12010-11-16 19:27:00 -08002067 u64_stats_update_begin(&rx_ring->syncp);
2068 rx_ring->stats.packets += total_rx_packets;
2069 rx_ring->stats.bytes += total_rx_bytes;
2070 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002071 q_vector->rx.total_packets += total_rx_packets;
2072 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002073
Alexander Duyckf8003262012-03-03 02:35:52 +00002074 if (cleaned_count)
2075 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2076
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002077 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002078}
2079
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002080#ifdef CONFIG_NET_LL_RX_POLL
2081/* must be called with local_bh_disable()d */
2082static int ixgbe_low_latency_recv(struct napi_struct *napi)
2083{
2084 struct ixgbe_q_vector *q_vector =
2085 container_of(napi, struct ixgbe_q_vector, napi);
2086 struct ixgbe_adapter *adapter = q_vector->adapter;
2087 struct ixgbe_ring *ring;
2088 int found = 0;
2089
2090 if (test_bit(__IXGBE_DOWN, &adapter->state))
2091 return LL_FLUSH_FAILED;
2092
2093 if (!ixgbe_qv_lock_poll(q_vector))
2094 return LL_FLUSH_BUSY;
2095
2096 ixgbe_for_each_ring(ring, q_vector->rx) {
2097 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
Eliezer Tamir7e15b902013-06-10 11:40:31 +03002098#ifdef LL_EXTENDED_STATS
2099 if (found)
2100 ring->stats.cleaned += found;
2101 else
2102 ring->stats.misses++;
2103#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002104 if (found)
2105 break;
2106 }
2107
2108 ixgbe_qv_unlock_poll(q_vector);
2109
2110 return found;
2111}
2112#endif /* CONFIG_NET_LL_RX_POLL */
2113
Auke Kok9a799d72007-09-15 14:07:45 -07002114/**
2115 * ixgbe_configure_msix - Configure MSI-X hardware
2116 * @adapter: board private structure
2117 *
2118 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2119 * interrupts.
2120 **/
2121static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2122{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002123 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002124 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002125 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002126
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002127 /* Populate MSIX to EITR Select */
2128 if (adapter->num_vfs > 32) {
2129 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2130 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2131 }
2132
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002133 /*
2134 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002135 * corresponding register.
2136 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002137 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002138 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002139 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002140
Alexander Duycka5579282012-02-08 07:50:04 +00002141 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002142 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002143
Alexander Duycka5579282012-02-08 07:50:04 +00002144 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002145 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002146
Alexander Duyckfe49f042009-06-04 16:00:09 +00002147 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002148 }
2149
Alexander Duyckbd508172010-11-16 19:27:03 -08002150 switch (adapter->hw.mac.type) {
2151 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002152 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002153 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002154 break;
2155 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002156 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002157 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002158 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002159 default:
2160 break;
2161 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002162 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002163
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002164 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002165 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002166 mask &= ~(IXGBE_EIMS_OTHER |
2167 IXGBE_EIMS_MAILBOX |
2168 IXGBE_EIMS_LSC);
2169
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002170 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002171}
2172
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002173enum latency_range {
2174 lowest_latency = 0,
2175 low_latency = 1,
2176 bulk_latency = 2,
2177 latency_invalid = 255
2178};
2179
2180/**
2181 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002182 * @q_vector: structure containing interrupt and ring information
2183 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002184 *
2185 * Stores a new ITR value based on packets and byte
2186 * counts during the last interrupt. The advantage of per interrupt
2187 * computation is faster updates and more accurate ITR for the current
2188 * traffic pattern. Constants in this function were computed
2189 * based on theoretical maximum wire speed and thresholds were set based
2190 * on testing data as well as attempting to minimize response time
2191 * while increasing bulk throughput.
2192 * this functionality is controlled by the InterruptThrottleRate module
2193 * parameter (see ixgbe_param.c)
2194 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002195static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2196 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002197{
Alexander Duyckbd198052011-06-11 01:45:08 +00002198 int bytes = ring_container->total_bytes;
2199 int packets = ring_container->total_packets;
2200 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002201 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002202 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002203
2204 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002205 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002206
2207 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002208 * 0-10MB/s lowest (100000 ints/s)
2209 * 10-20MB/s low (20000 ints/s)
2210 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002211 */
2212 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002213 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002214 if (timepassed_us == 0)
2215 return;
2216
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002217 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2218
2219 switch (itr_setting) {
2220 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002221 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002222 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002223 break;
2224 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002225 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002226 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002227 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002228 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002229 break;
2230 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002231 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002232 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002233 break;
2234 }
2235
Alexander Duyckbd198052011-06-11 01:45:08 +00002236 /* clear work counters since we have the values we need */
2237 ring_container->total_bytes = 0;
2238 ring_container->total_packets = 0;
2239
2240 /* write updated itr to ring container */
2241 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002242}
2243
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002244/**
2245 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002246 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002247 *
2248 * This function is made to be called by ethtool and by the driver
2249 * when it needs to update EITR registers at runtime. Hardware
2250 * specific quirks/differences are taken care of here.
2251 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002252void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002253{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002254 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002255 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002256 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002257 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002258
Alexander Duyckbd508172010-11-16 19:27:03 -08002259 switch (adapter->hw.mac.type) {
2260 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002261 /* must write high and low 16 bits to reset counter */
2262 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002263 break;
2264 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002265 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002266 /*
2267 * set the WDIS bit to not clear the timer bits and cause an
2268 * immediate assertion of the interrupt
2269 */
2270 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002271 break;
2272 default:
2273 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002274 }
2275 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2276}
2277
Alexander Duyckbd198052011-06-11 01:45:08 +00002278static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002279{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002280 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002281 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002282
Alexander Duyckbd198052011-06-11 01:45:08 +00002283 ixgbe_update_itr(q_vector, &q_vector->tx);
2284 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002285
Alexander Duyck08c88332011-06-11 01:45:03 +00002286 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002287
2288 switch (current_itr) {
2289 /* counts and packets in update_itr are dependent on these numbers */
2290 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002291 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002292 break;
2293 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002294 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002295 break;
2296 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002297 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002298 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002299 default:
2300 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002301 }
2302
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002303 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002304 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002305 new_itr = (10 * new_itr * q_vector->itr) /
2306 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002307
Alexander Duyckbd198052011-06-11 01:45:08 +00002308 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002309 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002310
2311 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002312 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002313}
2314
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002315/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002316 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002317 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002318 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002319static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002320{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002321 struct ixgbe_hw *hw = &adapter->hw;
2322 u32 eicr = adapter->interrupt_event;
2323
Alexander Duyckf0f97782011-04-22 04:08:09 +00002324 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002325 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002326
Alexander Duyckf0f97782011-04-22 04:08:09 +00002327 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2328 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2329 return;
2330
2331 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2332
Joe Perches7ca647b2010-09-07 21:35:40 +00002333 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002334 case IXGBE_DEV_ID_82599_T3_LOM:
2335 /*
2336 * Since the warning interrupt is for both ports
2337 * we don't have to check if:
2338 * - This interrupt wasn't for our port.
2339 * - We may have missed the interrupt so always have to
2340 * check if we got a LSC
2341 */
2342 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2343 !(eicr & IXGBE_EICR_LSC))
2344 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002345
Alexander Duyckf0f97782011-04-22 04:08:09 +00002346 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002347 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002348 bool link_up = false;
2349
Josh Hay3d292262012-12-15 03:28:19 +00002350 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002351
Alexander Duyckf0f97782011-04-22 04:08:09 +00002352 if (link_up)
2353 return;
2354 }
2355
2356 /* Check if this is not due to overtemp */
2357 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2358 return;
2359
2360 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002361 default:
2362 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2363 return;
2364 break;
2365 }
2366 e_crit(drv,
2367 "Network adapter has been stopped because it has over heated. "
2368 "Restart the computer. If the problem persists, "
2369 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002370
2371 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002372}
2373
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002374static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2375{
2376 struct ixgbe_hw *hw = &adapter->hw;
2377
2378 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2379 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002380 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002381 /* write to clear the interrupt */
2382 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2383 }
2384}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002385
Jacob Keller4f51bf72011-08-20 04:49:45 +00002386static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2387{
2388 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2389 return;
2390
2391 switch (adapter->hw.mac.type) {
2392 case ixgbe_mac_82599EB:
2393 /*
2394 * Need to check link state so complete overtemp check
2395 * on service task
2396 */
2397 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2398 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2399 adapter->interrupt_event = eicr;
2400 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2401 ixgbe_service_event_schedule(adapter);
2402 return;
2403 }
2404 return;
2405 case ixgbe_mac_X540:
2406 if (!(eicr & IXGBE_EICR_TS))
2407 return;
2408 break;
2409 default:
2410 return;
2411 }
2412
2413 e_crit(drv,
2414 "Network adapter has been stopped because it has over heated. "
2415 "Restart the computer. If the problem persists, "
2416 "power off the system and replace the adapter\n");
2417}
2418
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002419static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2420{
2421 struct ixgbe_hw *hw = &adapter->hw;
2422
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002423 if (eicr & IXGBE_EICR_GPI_SDP2) {
2424 /* Clear the interrupt */
2425 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002426 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2427 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2428 ixgbe_service_event_schedule(adapter);
2429 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002430 }
2431
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002432 if (eicr & IXGBE_EICR_GPI_SDP1) {
2433 /* Clear the interrupt */
2434 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002435 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2436 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2437 ixgbe_service_event_schedule(adapter);
2438 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002439 }
2440}
2441
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002442static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2443{
2444 struct ixgbe_hw *hw = &adapter->hw;
2445
2446 adapter->lsc_int++;
2447 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2448 adapter->link_check_timeout = jiffies;
2449 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2450 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002451 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002452 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002453 }
2454}
2455
Alexander Duyckfe49f042009-06-04 16:00:09 +00002456static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2457 u64 qmask)
2458{
2459 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002460 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002461
Alexander Duyckbd508172010-11-16 19:27:03 -08002462 switch (hw->mac.type) {
2463 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002464 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002465 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2466 break;
2467 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002468 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002469 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002470 if (mask)
2471 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002472 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002473 if (mask)
2474 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2475 break;
2476 default:
2477 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002478 }
2479 /* skip the flush */
2480}
2481
2482static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002483 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002484{
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_EIMC, mask);
2492 break;
2493 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002494 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002495 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002496 if (mask)
2497 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002498 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002499 if (mask)
2500 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2501 break;
2502 default:
2503 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002504 }
2505 /* skip the flush */
2506}
2507
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002508/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002509 * ixgbe_irq_enable - Enable default interrupt generation settings
2510 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002511 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002512static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2513 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002514{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002515 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002516
Alexander Duyck2c4af692011-07-15 07:29:55 +00002517 /* don't reenable LSC while waiting for link */
2518 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2519 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002520
Alexander Duyck2c4af692011-07-15 07:29:55 +00002521 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002522 switch (adapter->hw.mac.type) {
2523 case ixgbe_mac_82599EB:
2524 mask |= IXGBE_EIMS_GPI_SDP0;
2525 break;
2526 case ixgbe_mac_X540:
2527 mask |= IXGBE_EIMS_TS;
2528 break;
2529 default:
2530 break;
2531 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002532 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2533 mask |= IXGBE_EIMS_GPI_SDP1;
2534 switch (adapter->hw.mac.type) {
2535 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002536 mask |= IXGBE_EIMS_GPI_SDP1;
2537 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002538 case ixgbe_mac_X540:
2539 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002540 mask |= IXGBE_EIMS_MAILBOX;
2541 break;
2542 default:
2543 break;
2544 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002545
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002546 if (adapter->hw.mac.type == ixgbe_mac_X540)
2547 mask |= IXGBE_EIMS_TIMESYNC;
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002548
Alexander Duyck2c4af692011-07-15 07:29:55 +00002549 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2550 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2551 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002552
Alexander Duyck2c4af692011-07-15 07:29:55 +00002553 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2554 if (queues)
2555 ixgbe_irq_enable_queues(adapter, ~0);
2556 if (flush)
2557 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002558}
2559
Alexander Duyck2c4af692011-07-15 07:29:55 +00002560static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002561{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002562 struct ixgbe_adapter *adapter = data;
2563 struct ixgbe_hw *hw = &adapter->hw;
2564 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002565
Alexander Duyck2c4af692011-07-15 07:29:55 +00002566 /*
2567 * Workaround for Silicon errata. Use clear-by-write instead
2568 * of clear-by-read. Reading with EICS will return the
2569 * interrupt causes without clearing, which later be done
2570 * with the write to EICR.
2571 */
2572 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002573
2574 /* The lower 16bits of the EICR register are for the queue interrupts
2575 * which should be masked here in order to not accidently clear them if
2576 * the bits are high when ixgbe_msix_other is called. There is a race
2577 * condition otherwise which results in possible performance loss
2578 * especially if the ixgbe_msix_other interrupt is triggering
2579 * consistently (as it would when PPS is turned on for the X540 device)
2580 */
2581 eicr &= 0xFFFF0000;
2582
Alexander Duyck2c4af692011-07-15 07:29:55 +00002583 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002584
Alexander Duyck2c4af692011-07-15 07:29:55 +00002585 if (eicr & IXGBE_EICR_LSC)
2586 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002587
Alexander Duyck2c4af692011-07-15 07:29:55 +00002588 if (eicr & IXGBE_EICR_MAILBOX)
2589 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002590
Alexander Duyck2c4af692011-07-15 07:29:55 +00002591 switch (hw->mac.type) {
2592 case ixgbe_mac_82599EB:
2593 case ixgbe_mac_X540:
2594 if (eicr & IXGBE_EICR_ECC)
2595 e_info(link, "Received unrecoverable ECC Err, please "
2596 "reboot\n");
2597 /* Handle Flow Director Full threshold interrupt */
2598 if (eicr & IXGBE_EICR_FLOW_DIR) {
2599 int reinit_count = 0;
2600 int i;
2601 for (i = 0; i < adapter->num_tx_queues; i++) {
2602 struct ixgbe_ring *ring = adapter->tx_ring[i];
2603 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2604 &ring->state))
2605 reinit_count++;
2606 }
2607 if (reinit_count) {
2608 /* no more flow director interrupts until after init */
2609 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2610 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2611 ixgbe_service_event_schedule(adapter);
2612 }
2613 }
2614 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002615 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002616 break;
2617 default:
2618 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002619 }
2620
Alexander Duyck2c4af692011-07-15 07:29:55 +00002621 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002622
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002623 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2624 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002625
Alexander Duyck2c4af692011-07-15 07:29:55 +00002626 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002627 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002628 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002629
Alexander Duyck2c4af692011-07-15 07:29:55 +00002630 return IRQ_HANDLED;
2631}
2632
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002633static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002634{
2635 struct ixgbe_q_vector *q_vector = data;
2636
Auke Kok9a799d72007-09-15 14:07:45 -07002637 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002638
2639 if (q_vector->rx.ring || q_vector->tx.ring)
2640 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002641
2642 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002643}
2644
Auke Kok9a799d72007-09-15 14:07:45 -07002645/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002646 * ixgbe_poll - NAPI Rx polling callback
2647 * @napi: structure for representing this polling device
2648 * @budget: how many packets driver is allowed to clean
2649 *
2650 * This function is used for legacy and MSI, NAPI mode
2651 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002652int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002653{
2654 struct ixgbe_q_vector *q_vector =
2655 container_of(napi, struct ixgbe_q_vector, napi);
2656 struct ixgbe_adapter *adapter = q_vector->adapter;
2657 struct ixgbe_ring *ring;
2658 int per_ring_budget;
2659 bool clean_complete = true;
2660
2661#ifdef CONFIG_IXGBE_DCA
2662 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2663 ixgbe_update_dca(q_vector);
2664#endif
2665
2666 ixgbe_for_each_ring(ring, q_vector->tx)
2667 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2668
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002669 if (!ixgbe_qv_lock_napi(q_vector))
2670 return budget;
2671
Alexander Duyckeb01b972012-02-08 07:51:27 +00002672 /* attempt to distribute budget to each queue fairly, but don't allow
2673 * the budget to go below 1 because we'll exit polling */
2674 if (q_vector->rx.count > 1)
2675 per_ring_budget = max(budget/q_vector->rx.count, 1);
2676 else
2677 per_ring_budget = budget;
2678
2679 ixgbe_for_each_ring(ring, q_vector->rx)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002680 clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring,
2681 per_ring_budget) < per_ring_budget);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002682
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002683 ixgbe_qv_unlock_napi(q_vector);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002684 /* If all work not completed, return budget and keep polling */
2685 if (!clean_complete)
2686 return budget;
2687
2688 /* all work done, exit the polling mode */
2689 napi_complete(napi);
2690 if (adapter->rx_itr_setting & 1)
2691 ixgbe_set_itr(q_vector);
2692 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2693 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2694
2695 return 0;
2696}
2697
2698/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002699 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2700 * @adapter: board private structure
2701 *
2702 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2703 * interrupts from the kernel.
2704 **/
2705static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2706{
2707 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002708 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002709 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002710
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002711 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002712 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002713 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002714
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002715 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002716 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002717 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002718 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002719 } else if (q_vector->rx.ring) {
2720 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2721 "%s-%s-%d", netdev->name, "rx", ri++);
2722 } else if (q_vector->tx.ring) {
2723 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2724 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002725 } else {
2726 /* skip this unused q_vector */
2727 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002728 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002729 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2730 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002731 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002732 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002733 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002734 goto free_queue_irqs;
2735 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002736 /* If Flow Director is enabled, set interrupt affinity */
2737 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2738 /* assign the mask for this irq */
2739 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002740 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002741 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002742 }
2743
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002744 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002745 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002746 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002747 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002748 goto free_queue_irqs;
2749 }
2750
2751 return 0;
2752
2753free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002754 while (vector) {
2755 vector--;
2756 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2757 NULL);
2758 free_irq(adapter->msix_entries[vector].vector,
2759 adapter->q_vector[vector]);
2760 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002761 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2762 pci_disable_msix(adapter->pdev);
2763 kfree(adapter->msix_entries);
2764 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002765 return err;
2766}
2767
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002768/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002769 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002770 * @irq: interrupt number
2771 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002772 **/
2773static irqreturn_t ixgbe_intr(int irq, void *data)
2774{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002775 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002776 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002777 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002778 u32 eicr;
2779
Don Skidmore54037502009-02-21 15:42:56 -08002780 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002781 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002782 * before the read of EICR.
2783 */
2784 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2785
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002786 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002787 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002788 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002789 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002790 /*
2791 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002792 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002793 * have disabled interrupts due to EIAM
2794 * finish the workaround of silicon errata on 82598. Unmask
2795 * the interrupt that we masked before the EICR read.
2796 */
2797 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2798 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002799 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002800 }
Auke Kok9a799d72007-09-15 14:07:45 -07002801
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002802 if (eicr & IXGBE_EICR_LSC)
2803 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002804
Alexander Duyckbd508172010-11-16 19:27:03 -08002805 switch (hw->mac.type) {
2806 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002807 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002808 /* Fall through */
2809 case ixgbe_mac_X540:
2810 if (eicr & IXGBE_EICR_ECC)
2811 e_info(link, "Received unrecoverable ECC err, please "
2812 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002813 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002814 break;
2815 default:
2816 break;
2817 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002818
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002819 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002820 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2821 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002822
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002823 /* would disable interrupts here but EIAM disabled it */
2824 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002825
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002826 /*
2827 * re-enable link(maybe) and non-queue interrupts, no flush.
2828 * ixgbe_poll will re-enable the queue interrupts
2829 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002830 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2831 ixgbe_irq_enable(adapter, false, false);
2832
Auke Kok9a799d72007-09-15 14:07:45 -07002833 return IRQ_HANDLED;
2834}
2835
2836/**
2837 * ixgbe_request_irq - initialize interrupts
2838 * @adapter: board private structure
2839 *
2840 * Attempts to configure interrupts using the best available
2841 * capabilities of the hardware and kernel.
2842 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002843static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002844{
2845 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002846 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002847
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002848 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002849 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002850 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002851 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002852 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002853 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002854 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002855 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002856
Alexander Duyckde88eee2012-02-08 07:49:59 +00002857 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002858 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002859
Auke Kok9a799d72007-09-15 14:07:45 -07002860 return err;
2861}
2862
2863static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2864{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002865 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002866
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002867 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002868 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002869 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002870 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002871
2872 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2873 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2874 struct msix_entry *entry = &adapter->msix_entries[vector];
2875
2876 /* free only the irqs that were actually requested */
2877 if (!q_vector->rx.ring && !q_vector->tx.ring)
2878 continue;
2879
2880 /* clear the affinity_mask in the IRQ descriptor */
2881 irq_set_affinity_hint(entry->vector, NULL);
2882
2883 free_irq(entry->vector, q_vector);
2884 }
2885
2886 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002887}
2888
2889/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002890 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2891 * @adapter: board private structure
2892 **/
2893static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2894{
Alexander Duyckbd508172010-11-16 19:27:03 -08002895 switch (adapter->hw.mac.type) {
2896 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002897 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002898 break;
2899 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002900 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002901 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2902 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002903 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002904 break;
2905 default:
2906 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002907 }
2908 IXGBE_WRITE_FLUSH(&adapter->hw);
2909 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002910 int vector;
2911
2912 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2913 synchronize_irq(adapter->msix_entries[vector].vector);
2914
2915 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002916 } else {
2917 synchronize_irq(adapter->pdev->irq);
2918 }
2919}
2920
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002921/**
Auke Kok9a799d72007-09-15 14:07:45 -07002922 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2923 *
2924 **/
2925static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2926{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002927 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002928
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002929 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002930
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002931 ixgbe_set_ivar(adapter, 0, 0, 0);
2932 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002933
Emil Tantilov396e7992010-07-01 20:05:12 +00002934 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002935}
2936
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002937/**
2938 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2939 * @adapter: board private structure
2940 * @ring: structure containing ring specific data
2941 *
2942 * Configure the Tx descriptor ring after a reset.
2943 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002944void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2945 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002946{
2947 struct ixgbe_hw *hw = &adapter->hw;
2948 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002949 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002950 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002951 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002952
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002953 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002954 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002955 IXGBE_WRITE_FLUSH(hw);
2956
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002957 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002958 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002959 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2960 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2961 ring->count * sizeof(union ixgbe_adv_tx_desc));
2962 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2963 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002964 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002965
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002966 /*
2967 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00002968 * higher than 1 when:
2969 * - ITR is 0 as it could cause false TX hangs
2970 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002971 *
2972 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2973 * to or less than the number of on chip descriptors, which is
2974 * currently 40.
2975 */
Emil Tantilov67da0972013-01-25 06:19:20 +00002976#if IS_ENABLED(CONFIG_BQL)
2977 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
2978#else
Alexander Duycke954b372012-02-08 07:49:38 +00002979 if (!ring->q_vector || (ring->q_vector->itr < 8))
Emil Tantilov67da0972013-01-25 06:19:20 +00002980#endif
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002981 txdctl |= (1 << 16); /* WTHRESH = 1 */
2982 else
2983 txdctl |= (8 << 16); /* WTHRESH = 8 */
2984
Alexander Duycke954b372012-02-08 07:49:38 +00002985 /*
2986 * Setting PTHRESH to 32 both improves performance
2987 * and avoids a TX hang with DFP enabled
2988 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002989 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2990 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002991
2992 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00002993 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002994 ring->atr_sample_rate = adapter->atr_sample_rate;
2995 ring->atr_count = 0;
2996 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2997 } else {
2998 ring->atr_sample_rate = 0;
2999 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003000
Alexander Duyckfd786b72013-01-12 06:33:31 +00003001 /* initialize XPS */
3002 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3003 struct ixgbe_q_vector *q_vector = ring->q_vector;
3004
3005 if (q_vector)
3006 netif_set_xps_queue(adapter->netdev,
3007 &q_vector->affinity_mask,
3008 ring->queue_index);
3009 }
3010
John Fastabendc84d3242010-11-16 19:27:12 -08003011 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3012
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003013 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003014 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3015
3016 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3017 if (hw->mac.type == ixgbe_mac_82598EB &&
3018 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3019 return;
3020
3021 /* poll to verify queue is enabled */
3022 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003023 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003024 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3025 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3026 if (!wait_loop)
3027 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003028}
3029
Alexander Duyck120ff942010-08-19 13:34:50 +00003030static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3031{
3032 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003033 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003034 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003035
3036 if (hw->mac.type == ixgbe_mac_82598EB)
3037 return;
3038
3039 /* disable the arbiter while setting MTQC */
3040 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3041 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3042 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3043
3044 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003045 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3046 mtqc = IXGBE_MTQC_VT_ENA;
3047 if (tcs > 4)
3048 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3049 else if (tcs > 1)
3050 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3051 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3052 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003053 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003054 mtqc |= IXGBE_MTQC_64VF;
3055 } else {
3056 if (tcs > 4)
3057 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3058 else if (tcs > 1)
3059 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3060 else
3061 mtqc = IXGBE_MTQC_64Q_1PB;
3062 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003063
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003064 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003065
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003066 /* Enable Security TX Buffer IFG for multiple pb */
3067 if (tcs) {
3068 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3069 sectx |= IXGBE_SECTX_DCB;
3070 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003071 }
3072
3073 /* re-enable the arbiter */
3074 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3075 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3076}
3077
Auke Kok9a799d72007-09-15 14:07:45 -07003078/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003079 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003080 * @adapter: board private structure
3081 *
3082 * Configure the Tx unit of the MAC after a reset.
3083 **/
3084static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3085{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003086 struct ixgbe_hw *hw = &adapter->hw;
3087 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003088 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003089
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003090 ixgbe_setup_mtqc(adapter);
3091
3092 if (hw->mac.type != ixgbe_mac_82598EB) {
3093 /* DMATXCTL.EN must be before Tx queues are enabled */
3094 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3095 dmatxctl |= IXGBE_DMATXCTL_TE;
3096 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3097 }
3098
Auke Kok9a799d72007-09-15 14:07:45 -07003099 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003100 for (i = 0; i < adapter->num_tx_queues; i++)
3101 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003102}
3103
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003104static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3105 struct ixgbe_ring *ring)
3106{
3107 struct ixgbe_hw *hw = &adapter->hw;
3108 u8 reg_idx = ring->reg_idx;
3109 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3110
3111 srrctl |= IXGBE_SRRCTL_DROP_EN;
3112
3113 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3114}
3115
3116static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3117 struct ixgbe_ring *ring)
3118{
3119 struct ixgbe_hw *hw = &adapter->hw;
3120 u8 reg_idx = ring->reg_idx;
3121 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3122
3123 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3124
3125 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3126}
3127
3128#ifdef CONFIG_IXGBE_DCB
3129void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3130#else
3131static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3132#endif
3133{
3134 int i;
3135 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3136
3137 if (adapter->ixgbe_ieee_pfc)
3138 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3139
3140 /*
3141 * We should set the drop enable bit if:
3142 * SR-IOV is enabled
3143 * or
3144 * Number of Rx queues > 1 and flow control is disabled
3145 *
3146 * This allows us to avoid head of line blocking for security
3147 * and performance reasons.
3148 */
3149 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3150 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3151 for (i = 0; i < adapter->num_rx_queues; i++)
3152 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3153 } else {
3154 for (i = 0; i < adapter->num_rx_queues; i++)
3155 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3156 }
3157}
3158
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003159#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003160
Yi Zoua6616b42009-08-06 13:05:23 +00003161static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003162 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003163{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003164 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003165 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003166 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003167
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003168 if (hw->mac.type == ixgbe_mac_82598EB) {
3169 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3170
3171 /*
3172 * if VMDq is not active we must program one srrctl register
3173 * per RSS queue since we have enabled RDRXCTL.MVMEN
3174 */
3175 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003176 }
3177
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003178 /* configure header buffer length, needed for RSC */
3179 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003180
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003181 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00003182 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003183
3184 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003185 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003186
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003187 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003188}
3189
Alexander Duyck05abb122010-08-19 13:35:41 +00003190static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003191{
Alexander Duyck05abb122010-08-19 13:35:41 +00003192 struct ixgbe_hw *hw = &adapter->hw;
3193 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00003194 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
3195 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00003196 u32 mrqc = 0, reta = 0;
3197 u32 rxcsum;
3198 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003199 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00003200
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003201 /*
3202 * Program table for at least 2 queues w/ SR-IOV so that VFs can
3203 * make full use of any rings they may have. We will use the
3204 * PSRTYPE register to control how many rings we use within the PF.
3205 */
3206 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3207 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003208
Alexander Duyck05abb122010-08-19 13:35:41 +00003209 /* Fill out hash function seeds */
3210 for (i = 0; i < 10; i++)
3211 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003212
Alexander Duyck05abb122010-08-19 13:35:41 +00003213 /* Fill out redirection table */
3214 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003215 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003216 j = 0;
3217 /* reta = 4-byte sliding window of
3218 * 0x00..(indices-1)(indices-1)00..etc. */
3219 reta = (reta << 8) | (j * 0x11);
3220 if ((i & 3) == 3)
3221 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3222 }
3223
3224 /* Disable indicating checksum in descriptor, enables RSS hash */
3225 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3226 rxcsum |= IXGBE_RXCSUM_PCSD;
3227 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3228
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003229 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003230 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003231 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003232 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003233 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003234
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003235 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3236 if (tcs > 4)
3237 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3238 else if (tcs > 1)
3239 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3240 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3241 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3242 else
3243 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3244 } else {
3245 if (tcs > 4)
3246 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3247 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003248 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3249 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003250 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003251 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003252 }
3253
Alexander Duyck05abb122010-08-19 13:35:41 +00003254 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003255 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3256 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3257 IXGBE_MRQC_RSS_FIELD_IPV6 |
3258 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003259
Alexander Duyckef6afc02012-02-08 07:51:53 +00003260 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3261 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3262 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3263 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3264
Alexander Duyck05abb122010-08-19 13:35:41 +00003265 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003266}
3267
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003268/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003269 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3270 * @adapter: address of board private structure
3271 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003272 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003273static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003274 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003275{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003276 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003277 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003278 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003279
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003280 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003281 return;
3282
Alexander Duyck73670962010-08-19 13:38:34 +00003283 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003284 rscctrl |= IXGBE_RSCCTL_RSCEN;
3285 /*
3286 * we must limit the number of descriptors so that the
3287 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003288 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003289 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003290 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003291 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003292}
3293
Alexander Duyck9e10e042010-08-19 13:40:06 +00003294#define IXGBE_MAX_RX_DESC_POLL 10
3295static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3296 struct ixgbe_ring *ring)
3297{
3298 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003299 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3300 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003301 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003302
3303 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3304 if (hw->mac.type == ixgbe_mac_82598EB &&
3305 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3306 return;
3307
3308 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003309 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003310 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3311 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3312
3313 if (!wait_loop) {
3314 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3315 "the polling period\n", reg_idx);
3316 }
3317}
3318
Yi Zou2d39d572011-01-06 14:29:56 +00003319void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3320 struct ixgbe_ring *ring)
3321{
3322 struct ixgbe_hw *hw = &adapter->hw;
3323 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3324 u32 rxdctl;
3325 u8 reg_idx = ring->reg_idx;
3326
3327 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3328 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3329
3330 /* write value back with RXDCTL.ENABLE bit cleared */
3331 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3332
3333 if (hw->mac.type == ixgbe_mac_82598EB &&
3334 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3335 return;
3336
3337 /* the hardware may take up to 100us to really disable the rx queue */
3338 do {
3339 udelay(10);
3340 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3341 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3342
3343 if (!wait_loop) {
3344 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3345 "the polling period\n", reg_idx);
3346 }
3347}
3348
Alexander Duyck84418e32010-08-19 13:40:54 +00003349void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3350 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003351{
3352 struct ixgbe_hw *hw = &adapter->hw;
3353 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003354 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003355 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003356
Alexander Duyck9e10e042010-08-19 13:40:06 +00003357 /* disable queue to avoid issues while updating state */
3358 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003359 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003360
Alexander Duyckacd37172010-08-19 13:36:05 +00003361 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3362 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3363 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3364 ring->count * sizeof(union ixgbe_adv_rx_desc));
3365 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3366 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003367 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003368
3369 ixgbe_configure_srrctl(adapter, ring);
3370 ixgbe_configure_rscctl(adapter, ring);
3371
3372 if (hw->mac.type == ixgbe_mac_82598EB) {
3373 /*
3374 * enable cache line friendly hardware writes:
3375 * PTHRESH=32 descriptors (half the internal cache),
3376 * this also removes ugly rx_no_buffer_count increment
3377 * HTHRESH=4 descriptors (to minimize latency on fetch)
3378 * WTHRESH=8 burst writeback up to two cache lines
3379 */
3380 rxdctl &= ~0x3FFFFF;
3381 rxdctl |= 0x080420;
3382 }
3383
3384 /* enable receive descriptor ring */
3385 rxdctl |= IXGBE_RXDCTL_ENABLE;
3386 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3387
3388 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003389 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003390}
3391
Alexander Duyck48654522010-08-19 13:36:27 +00003392static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3393{
3394 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003395 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck48654522010-08-19 13:36:27 +00003396 int p;
3397
3398 /* PSRTYPE must be initialized in non 82598 adapters */
3399 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003400 IXGBE_PSRTYPE_UDPHDR |
3401 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003402 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003403 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003404
3405 if (hw->mac.type == ixgbe_mac_82598EB)
3406 return;
3407
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003408 if (rss_i > 3)
3409 psrtype |= 2 << 29;
3410 else if (rss_i > 1)
3411 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003412
3413 for (p = 0; p < adapter->num_rx_pools; p++)
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003414 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
Alexander Duyck48654522010-08-19 13:36:27 +00003415 psrtype);
3416}
3417
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003418static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3419{
3420 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003421 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003422 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003423 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003424
3425 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3426 return;
3427
3428 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003429 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3430 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003431 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003432 vmdctl |= IXGBE_VT_CTL_REPLEN;
3433 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003434
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003435 vf_shift = VMDQ_P(0) % 32;
3436 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003437
3438 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003439 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3440 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3441 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3442 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Greg Rose9b735982012-11-08 02:41:35 +00003443 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
3444 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003445
3446 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003447 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003448
3449 /*
3450 * Set up VF register offsets for selected VT Mode,
3451 * i.e. 32 or 64 VFs for SR-IOV
3452 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003453 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3454 case IXGBE_82599_VMDQ_8Q_MASK:
3455 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3456 break;
3457 case IXGBE_82599_VMDQ_4Q_MASK:
3458 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3459 break;
3460 default:
3461 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3462 break;
3463 }
3464
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003465 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3466
Alexander Duyck435b19f2012-05-18 06:34:08 +00003467
Greg Rosea985b6c32010-11-18 03:02:52 +00003468 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003469 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003470 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003471 /* For VFs that have spoof checking turned off */
3472 for (i = 0; i < adapter->num_vfs; i++) {
3473 if (!adapter->vfinfo[i].spoofchk_enabled)
3474 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3475 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003476}
3477
Alexander Duyck477de6e2010-08-19 13:38:11 +00003478static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003479{
Auke Kok9a799d72007-09-15 14:07:45 -07003480 struct ixgbe_hw *hw = &adapter->hw;
3481 struct net_device *netdev = adapter->netdev;
3482 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003483 struct ixgbe_ring *rx_ring;
3484 int i;
3485 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003486
Alexander Duyck477de6e2010-08-19 13:38:11 +00003487#ifdef IXGBE_FCOE
3488 /* adjust max frame to be able to do baby jumbo for FCoE */
3489 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3490 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3491 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3492
3493#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003494
3495 /* adjust max frame to be at least the size of a standard frame */
3496 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3497 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3498
Alexander Duyck477de6e2010-08-19 13:38:11 +00003499 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3500 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3501 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3502 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3503
3504 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003505 }
3506
Auke Kok9a799d72007-09-15 14:07:45 -07003507 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003508 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3509 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003510 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3511
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003512 /*
3513 * Setup the HW Rx Head and Tail Descriptor Pointers and
3514 * the Base and Length of the Rx Descriptor Ring
3515 */
Auke Kok9a799d72007-09-15 14:07:45 -07003516 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003517 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003518 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3519 set_ring_rsc_enabled(rx_ring);
3520 else
3521 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003522 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003523}
3524
Alexander Duyck73670962010-08-19 13:38:34 +00003525static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3526{
3527 struct ixgbe_hw *hw = &adapter->hw;
3528 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3529
3530 switch (hw->mac.type) {
3531 case ixgbe_mac_82598EB:
3532 /*
3533 * For VMDq support of different descriptor types or
3534 * buffer sizes through the use of multiple SRRCTL
3535 * registers, RDRXCTL.MVMEN must be set to 1
3536 *
3537 * also, the manual doesn't mention it clearly but DCA hints
3538 * will only use queue 0's tags unless this bit is set. Side
3539 * effects of setting this bit are only that SRRCTL must be
3540 * fully programmed [0..15]
3541 */
3542 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3543 break;
3544 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003545 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003546 /* Disable RSC for ACK packets */
3547 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3548 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3549 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3550 /* hardware requires some bits to be set by default */
3551 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3552 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3553 break;
3554 default:
3555 /* We should do nothing since we don't know this hardware */
3556 return;
3557 }
3558
3559 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3560}
3561
Alexander Duyck477de6e2010-08-19 13:38:11 +00003562/**
3563 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3564 * @adapter: board private structure
3565 *
3566 * Configure the Rx unit of the MAC after a reset.
3567 **/
3568static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3569{
3570 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003571 int i;
3572 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003573
3574 /* disable receives while setting up the descriptors */
3575 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3576 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3577
3578 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003579 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003580
Alexander Duyck9e10e042010-08-19 13:40:06 +00003581 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003582 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003583
Alexander Duyck477de6e2010-08-19 13:38:11 +00003584 /* set_rx_buffer_len must be called before ring initialization */
3585 ixgbe_set_rx_buffer_len(adapter);
3586
3587 /*
3588 * Setup the HW Rx Head and Tail Descriptor Pointers and
3589 * the Base and Length of the Rx Descriptor Ring
3590 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003591 for (i = 0; i < adapter->num_rx_queues; i++)
3592 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003593
Alexander Duyck9e10e042010-08-19 13:40:06 +00003594 /* disable drop enable for 82598 parts */
3595 if (hw->mac.type == ixgbe_mac_82598EB)
3596 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3597
3598 /* enable all receives */
3599 rxctrl |= IXGBE_RXCTRL_RXEN;
3600 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003601}
3602
Patrick McHardy80d5c362013-04-19 02:04:28 +00003603static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3604 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003605{
3606 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003607 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003608
3609 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003610 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003611 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003612
3613 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003614}
3615
Patrick McHardy80d5c362013-04-19 02:04:28 +00003616static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
3617 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003618{
3619 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003620 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003621
Auke Kok9a799d72007-09-15 14:07:45 -07003622 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003623 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003624 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003625
3626 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003627}
3628
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003629/**
3630 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3631 * @adapter: driver data
3632 */
3633static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3634{
3635 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003636 u32 vlnctrl;
3637
3638 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3639 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3640 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3641}
3642
3643/**
3644 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3645 * @adapter: driver data
3646 */
3647static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3648{
3649 struct ixgbe_hw *hw = &adapter->hw;
3650 u32 vlnctrl;
3651
3652 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3653 vlnctrl |= IXGBE_VLNCTRL_VFE;
3654 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3655 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3656}
3657
3658/**
3659 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3660 * @adapter: driver data
3661 */
3662static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3663{
3664 struct ixgbe_hw *hw = &adapter->hw;
3665 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003666 int i, j;
3667
3668 switch (hw->mac.type) {
3669 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003670 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3671 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003672 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3673 break;
3674 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003675 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003676 for (i = 0; i < adapter->num_rx_queues; i++) {
3677 j = adapter->rx_ring[i]->reg_idx;
3678 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3679 vlnctrl &= ~IXGBE_RXDCTL_VME;
3680 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3681 }
3682 break;
3683 default:
3684 break;
3685 }
3686}
3687
3688/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003689 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003690 * @adapter: driver data
3691 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003692static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003693{
3694 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003695 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003696 int i, j;
3697
3698 switch (hw->mac.type) {
3699 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003700 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3701 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003702 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3703 break;
3704 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003705 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003706 for (i = 0; i < adapter->num_rx_queues; i++) {
3707 j = adapter->rx_ring[i]->reg_idx;
3708 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3709 vlnctrl |= IXGBE_RXDCTL_VME;
3710 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3711 }
3712 break;
3713 default:
3714 break;
3715 }
3716}
3717
Auke Kok9a799d72007-09-15 14:07:45 -07003718static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3719{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003720 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003721
Patrick McHardy80d5c362013-04-19 02:04:28 +00003722 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003723
3724 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00003725 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003726}
3727
3728/**
Alexander Duyck28500622010-06-15 09:25:48 +00003729 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3730 * @netdev: network interface device structure
3731 *
3732 * Writes unicast address list to the RAR table.
3733 * Returns: -ENOMEM on failure/insufficient address space
3734 * 0 on no addresses written
3735 * X on writing X addresses to the RAR table
3736 **/
3737static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3738{
3739 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3740 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend95447462012-05-31 12:42:26 +00003741 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
Alexander Duyck28500622010-06-15 09:25:48 +00003742 int count = 0;
3743
John Fastabend95447462012-05-31 12:42:26 +00003744 /* In SR-IOV mode significantly less RAR entries are available */
3745 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3746 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3747
Alexander Duyck28500622010-06-15 09:25:48 +00003748 /* return ENOMEM indicating insufficient memory for addresses */
3749 if (netdev_uc_count(netdev) > rar_entries)
3750 return -ENOMEM;
3751
John Fastabend95447462012-05-31 12:42:26 +00003752 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003753 struct netdev_hw_addr *ha;
3754 /* return error if we do not support writing to RAR table */
3755 if (!hw->mac.ops.set_rar)
3756 return -ENOMEM;
3757
3758 netdev_for_each_uc_addr(ha, netdev) {
3759 if (!rar_entries)
3760 break;
3761 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003762 VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck28500622010-06-15 09:25:48 +00003763 count++;
3764 }
3765 }
3766 /* write the addresses in reverse order to avoid write combining */
3767 for (; rar_entries > 0 ; rar_entries--)
3768 hw->mac.ops.clear_rar(hw, rar_entries);
3769
3770 return count;
3771}
3772
3773/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003774 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003775 * @netdev: network interface device structure
3776 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003777 * The set_rx_method entry point is called whenever the unicast/multicast
3778 * address list or the network interface flags are updated. This routine is
3779 * responsible for configuring the hardware for proper unicast, multicast and
3780 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003781 **/
Greg Rose7f870472010-01-09 02:25:29 +00003782void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003783{
3784 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3785 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003786 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3787 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003788
3789 /* Check for Promiscuous and All Multicast modes */
3790
3791 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3792
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003793 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003794 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003795 fctrl |= IXGBE_FCTRL_BAM;
3796 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3797 fctrl |= IXGBE_FCTRL_PMCF;
3798
Alexander Duyck28500622010-06-15 09:25:48 +00003799 /* clear the bits we are changing the status of */
3800 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3801
Auke Kok9a799d72007-09-15 14:07:45 -07003802 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003803 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003804 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003805 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Greg Rose670224f2013-02-22 02:14:39 +00003806 /* Only disable hardware filter vlans in promiscuous mode
3807 * if SR-IOV and VMDQ are disabled - otherwise ensure
3808 * that hardware VLAN filters remain enabled.
3809 */
3810 if (!(adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED |
3811 IXGBE_FLAG_SRIOV_ENABLED)))
3812 ixgbe_vlan_filter_disable(adapter);
3813 else
3814 ixgbe_vlan_filter_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003815 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003816 if (netdev->flags & IFF_ALLMULTI) {
3817 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003818 vmolr |= IXGBE_VMOLR_MPE;
3819 } else {
3820 /*
3821 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003822 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003823 * that we can at least receive multicast traffic
3824 */
3825 hw->mac.ops.update_mc_addr_list(hw, netdev);
3826 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003827 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003828 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003829 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003830 }
3831
3832 /*
3833 * Write addresses to available RAR registers, if there is not
3834 * sufficient space to store all the addresses then enable
3835 * unicast promiscuous mode
3836 */
3837 count = ixgbe_write_uc_addr_list(netdev);
3838 if (count < 0) {
3839 fctrl |= IXGBE_FCTRL_UPE;
3840 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003841 }
3842
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003843 if (adapter->num_vfs)
Alexander Duyck28500622010-06-15 09:25:48 +00003844 ixgbe_restore_vf_multicasts(adapter);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003845
3846 if (hw->mac.type != ixgbe_mac_82598EB) {
3847 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003848 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3849 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003850 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003851 }
3852
Ben Greear3f2d1c02012-03-08 08:28:41 +00003853 /* This is useful for sniffing bad packets. */
3854 if (adapter->netdev->features & NETIF_F_RXALL) {
3855 /* UPE and MPE will be handled by normal PROMISC logic
3856 * in e1000e_set_rx_mode */
3857 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3858 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3859 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3860
3861 fctrl &= ~(IXGBE_FCTRL_DPF);
3862 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3863 }
3864
Auke Kok9a799d72007-09-15 14:07:45 -07003865 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003866
Patrick McHardyf6469682013-04-19 02:04:27 +00003867 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00003868 ixgbe_vlan_strip_enable(adapter);
3869 else
3870 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003871}
3872
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003873static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3874{
3875 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003876
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003877 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
3878 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003879 napi_enable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003880 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003881}
3882
3883static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3884{
3885 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003886
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003887 local_bh_disable(); /* for ixgbe_qv_lock_napi() */
3888 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003889 napi_disable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003890 while (!ixgbe_qv_lock_napi(adapter->q_vector[q_idx])) {
3891 pr_info("QV %d locked\n", q_idx);
3892 mdelay(1);
3893 }
3894 }
3895 local_bh_enable();
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003896}
3897
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003898#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003899/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08003900 * ixgbe_configure_dcb - Configure DCB hardware
3901 * @adapter: ixgbe adapter struct
3902 *
3903 * This is called by the driver on open to configure the DCB hardware.
3904 * This is also called by the gennetlink interface when reconfiguring
3905 * the DCB state.
3906 */
3907static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3908{
3909 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003910 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003911
Alexander Duyck67ebd792010-08-19 13:34:04 +00003912 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3913 if (hw->mac.type == ixgbe_mac_82598EB)
3914 netif_set_gso_max_size(adapter->netdev, 65536);
3915 return;
3916 }
3917
3918 if (hw->mac.type == ixgbe_mac_82598EB)
3919 netif_set_gso_max_size(adapter->netdev, 32768);
3920
John Fastabendb1208182011-10-15 05:00:10 +00003921#ifdef IXGBE_FCOE
3922 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3923 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3924#endif
3925
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003926 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003927 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003928 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3929 DCB_TX_CONFIG);
3930 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3931 DCB_RX_CONFIG);
3932 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003933 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3934 ixgbe_dcb_hw_ets(&adapter->hw,
3935 adapter->ixgbe_ieee_ets,
3936 max_frame);
3937 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3938 adapter->ixgbe_ieee_pfc->pfc_en,
3939 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003940 }
John Fastabend8187cd42011-02-23 05:58:08 +00003941
3942 /* Enable RSS Hash per TC */
3943 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00003944 u32 msb = 0;
3945 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003946
Alexander Duyckd411a932012-06-30 00:14:01 +00003947 while (rss_i) {
3948 msb++;
3949 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003950 }
Alexander Duyckd411a932012-06-30 00:14:01 +00003951
Alexander Duyck4ae63732012-06-22 06:46:33 +00003952 /* write msb to all 8 TCs in one write */
3953 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00003954 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003955}
John Fastabend9da712d2011-08-23 03:14:22 +00003956#endif
3957
3958/* Additional bittime to account for IXGBE framing */
3959#define IXGBE_ETH_FRAMING 20
3960
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003961/**
John Fastabend9da712d2011-08-23 03:14:22 +00003962 * ixgbe_hpbthresh - calculate high water mark for flow control
3963 *
3964 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003965 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003966 */
3967static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3968{
3969 struct ixgbe_hw *hw = &adapter->hw;
3970 struct net_device *dev = adapter->netdev;
3971 int link, tc, kb, marker;
3972 u32 dv_id, rx_pba;
3973
3974 /* Calculate max LAN frame size */
3975 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3976
3977#ifdef IXGBE_FCOE
3978 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00003979 if ((dev->features & NETIF_F_FCOE_MTU) &&
3980 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3981 (pb == ixgbe_fcoe_get_tc(adapter)))
3982 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003983
3984#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003985 /* Calculate delay value for device */
3986 switch (hw->mac.type) {
3987 case ixgbe_mac_X540:
3988 dv_id = IXGBE_DV_X540(link, tc);
3989 break;
3990 default:
3991 dv_id = IXGBE_DV(link, tc);
3992 break;
3993 }
3994
3995 /* Loopback switch introduces additional latency */
3996 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3997 dv_id += IXGBE_B2BT(tc);
3998
3999 /* Delay value is calculated in bit times convert to KB */
4000 kb = IXGBE_BT2KB(dv_id);
4001 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4002
4003 marker = rx_pba - kb;
4004
4005 /* It is possible that the packet buffer is not large enough
4006 * to provide required headroom. In this case throw an error
4007 * to user and a do the best we can.
4008 */
4009 if (marker < 0) {
4010 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4011 "headroom to support flow control."
4012 "Decrease MTU or number of traffic classes\n", pb);
4013 marker = tc + 1;
4014 }
4015
4016 return marker;
4017}
4018
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004019/**
John Fastabend9da712d2011-08-23 03:14:22 +00004020 * ixgbe_lpbthresh - calculate low water mark for for flow control
4021 *
4022 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004023 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004024 */
4025static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
4026{
4027 struct ixgbe_hw *hw = &adapter->hw;
4028 struct net_device *dev = adapter->netdev;
4029 int tc;
4030 u32 dv_id;
4031
4032 /* Calculate max LAN frame size */
4033 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4034
4035 /* Calculate delay value for device */
4036 switch (hw->mac.type) {
4037 case ixgbe_mac_X540:
4038 dv_id = IXGBE_LOW_DV_X540(tc);
4039 break;
4040 default:
4041 dv_id = IXGBE_LOW_DV(tc);
4042 break;
4043 }
4044
4045 /* Delay value is calculated in bit times convert to KB */
4046 return IXGBE_BT2KB(dv_id);
4047}
4048
4049/*
4050 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4051 */
4052static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4053{
4054 struct ixgbe_hw *hw = &adapter->hw;
4055 int num_tc = netdev_get_num_tc(adapter->netdev);
4056 int i;
4057
4058 if (!num_tc)
4059 num_tc = 1;
4060
4061 hw->fc.low_water = ixgbe_lpbthresh(adapter);
4062
4063 for (i = 0; i < num_tc; i++) {
4064 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
4065
4066 /* Low water marks must not be larger than high water marks */
4067 if (hw->fc.low_water > hw->fc.high_water[i])
4068 hw->fc.low_water = 0;
4069 }
4070}
John Fastabend80605c652011-05-02 12:34:10 +00004071
4072static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4073{
John Fastabend80605c652011-05-02 12:34:10 +00004074 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00004075 int hdrm;
4076 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00004077
4078 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4079 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00004080 hdrm = 32 << adapter->fdir_pballoc;
4081 else
4082 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00004083
Alexander Duyckf7e10272011-07-21 00:40:35 +00004084 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00004085 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00004086}
4087
Alexander Duycke4911d52011-05-11 07:18:52 +00004088static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4089{
4090 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08004091 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004092 struct ixgbe_fdir_filter *filter;
4093
4094 spin_lock(&adapter->fdir_perfect_lock);
4095
4096 if (!hlist_empty(&adapter->fdir_filter_list))
4097 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4098
Sasha Levinb67bfe02013-02-27 17:06:00 -08004099 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004100 &adapter->fdir_filter_list, fdir_node) {
4101 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004102 &filter->filter,
4103 filter->sw_idx,
4104 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4105 IXGBE_FDIR_DROP_QUEUE :
4106 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004107 }
4108
4109 spin_unlock(&adapter->fdir_perfect_lock);
4110}
4111
Auke Kok9a799d72007-09-15 14:07:45 -07004112static void ixgbe_configure(struct ixgbe_adapter *adapter)
4113{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004114 struct ixgbe_hw *hw = &adapter->hw;
4115
John Fastabend80605c652011-05-02 12:34:10 +00004116 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004117#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00004118 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004119#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00004120 /*
4121 * We must restore virtualization before VLANs or else
4122 * the VLVF registers will not be populated
4123 */
4124 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004125
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004126 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004127 ixgbe_restore_vlan(adapter);
4128
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004129 switch (hw->mac.type) {
4130 case ixgbe_mac_82599EB:
4131 case ixgbe_mac_X540:
4132 hw->mac.ops.disable_rx_buff(hw);
4133 break;
4134 default:
4135 break;
4136 }
4137
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004138 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004139 ixgbe_init_fdir_signature_82599(&adapter->hw,
4140 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00004141 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
4142 ixgbe_init_fdir_perfect_82599(&adapter->hw,
4143 adapter->fdir_pballoc);
4144 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004145 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004146
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004147 switch (hw->mac.type) {
4148 case ixgbe_mac_82599EB:
4149 case ixgbe_mac_X540:
4150 hw->mac.ops.enable_rx_buff(hw);
4151 break;
4152 default:
4153 break;
4154 }
4155
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004156#ifdef IXGBE_FCOE
4157 /* configure FCoE L2 filters, redirection table, and Rx control */
4158 ixgbe_configure_fcoe(adapter);
4159
4160#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07004161 ixgbe_configure_tx(adapter);
4162 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004163}
4164
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004165static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
4166{
4167 switch (hw->phy.type) {
4168 case ixgbe_phy_sfp_avago:
4169 case ixgbe_phy_sfp_ftl:
4170 case ixgbe_phy_sfp_intel:
4171 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00004172 case ixgbe_phy_sfp_passive_tyco:
4173 case ixgbe_phy_sfp_passive_unknown:
4174 case ixgbe_phy_sfp_active_unknown:
4175 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004176 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00004177 case ixgbe_phy_nl:
4178 if (hw->mac.type == ixgbe_mac_82598EB)
4179 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004180 default:
4181 return false;
4182 }
4183}
4184
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004185/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004186 * ixgbe_sfp_link_config - set up SFP+ link
4187 * @adapter: pointer to private adapter struct
4188 **/
4189static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
4190{
Alexander Duyck70864002011-04-27 09:13:56 +00004191 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004192 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00004193 * is that an SFP was inserted/removed after the reset
4194 * but before SFP detection was enabled. As such the best
4195 * solution is to just start searching as soon as we start
4196 */
4197 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
4198 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004199
Alexander Duyck70864002011-04-27 09:13:56 +00004200 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004201}
4202
4203/**
4204 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004205 * @hw: pointer to private hardware struct
4206 *
4207 * Returns 0 on success, negative on failure
4208 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004209static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004210{
Josh Hay3d292262012-12-15 03:28:19 +00004211 u32 speed;
4212 bool autoneg, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004213 u32 ret = IXGBE_ERR_LINK_SETUP;
4214
4215 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00004216 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004217
4218 if (ret)
4219 goto link_cfg_out;
4220
Josh Hay3d292262012-12-15 03:28:19 +00004221 speed = hw->phy.autoneg_advertised;
4222 if ((!speed) && (hw->mac.ops.get_link_capabilities))
4223 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
4224 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004225 if (ret)
4226 goto link_cfg_out;
4227
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004228 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00004229 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004230link_cfg_out:
4231 return ret;
4232}
4233
Alexander Duycka34bcff2010-08-19 13:39:20 +00004234static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004235{
Auke Kok9a799d72007-09-15 14:07:45 -07004236 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004237 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004238
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004239 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004240 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4241 IXGBE_GPIE_OCD;
4242 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004243 /*
4244 * use EIAM to auto-mask when MSI-X interrupt is asserted
4245 * this saves a register write for every interrupt
4246 */
4247 switch (hw->mac.type) {
4248 case ixgbe_mac_82598EB:
4249 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4250 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004251 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004252 case ixgbe_mac_X540:
4253 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004254 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4255 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4256 break;
4257 }
4258 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004259 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4260 * specifically only auto mask tx and rx interrupts */
4261 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004262 }
4263
Alexander Duycka34bcff2010-08-19 13:39:20 +00004264 /* XXX: to interrupt immediately for EICS writes, enable this */
4265 /* gpie |= IXGBE_GPIE_EIMEN; */
4266
4267 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4268 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004269
4270 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4271 case IXGBE_82599_VMDQ_8Q_MASK:
4272 gpie |= IXGBE_GPIE_VTMODE_16;
4273 break;
4274 case IXGBE_82599_VMDQ_4Q_MASK:
4275 gpie |= IXGBE_GPIE_VTMODE_32;
4276 break;
4277 default:
4278 gpie |= IXGBE_GPIE_VTMODE_64;
4279 break;
4280 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004281 }
4282
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004283 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004284 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4285 switch (adapter->hw.mac.type) {
4286 case ixgbe_mac_82599EB:
4287 gpie |= IXGBE_SDP0_GPIEN;
4288 break;
4289 case ixgbe_mac_X540:
4290 gpie |= IXGBE_EIMS_TS;
4291 break;
4292 default:
4293 break;
4294 }
4295 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004296
Alexander Duycka34bcff2010-08-19 13:39:20 +00004297 /* Enable fan failure interrupt */
4298 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004299 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004300
Don Skidmore2698b202011-04-13 07:01:52 +00004301 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004302 gpie |= IXGBE_SDP1_GPIEN;
4303 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004304 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004305
4306 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4307}
4308
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004309static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004310{
4311 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004312 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004313 u32 ctrl_ext;
4314
4315 ixgbe_get_hw_control(adapter);
4316 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004317
Auke Kok9a799d72007-09-15 14:07:45 -07004318 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4319 ixgbe_configure_msix(adapter);
4320 else
4321 ixgbe_configure_msi_and_legacy(adapter);
4322
Emil Tantilovec74a472012-09-20 03:33:56 +00004323 /* enable the optics for 82599 SFP+ fiber */
4324 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004325 hw->mac.ops.enable_tx_laser(hw);
4326
Auke Kok9a799d72007-09-15 14:07:45 -07004327 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004328 ixgbe_napi_enable_all(adapter);
4329
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004330 if (ixgbe_is_sfp(hw)) {
4331 ixgbe_sfp_link_config(adapter);
4332 } else {
4333 err = ixgbe_non_sfp_link_config(hw);
4334 if (err)
4335 e_err(probe, "link_config FAILED %d\n", err);
4336 }
4337
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004338 /* clear any pending interrupts, may auto mask */
4339 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004340 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004341
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004342 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004343 * If this adapter has a fan, check to see if we had a failure
4344 * before we enabled the interrupt.
4345 */
4346 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4347 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4348 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004349 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004350 }
4351
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004352 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004353 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004354
Auke Kok9a799d72007-09-15 14:07:45 -07004355 /* bring the link up in the watchdog, this could race with our first
4356 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004357 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4358 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004359 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004360
4361 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4362 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4363 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4364 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004365}
4366
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004367void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4368{
4369 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004370 /* put off any impending NetWatchDogTimeout */
4371 adapter->netdev->trans_start = jiffies;
4372
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004373 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004374 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004375 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004376 /*
4377 * If SR-IOV enabled then wait a bit before bringing the adapter
4378 * back up to give the VFs time to respond to the reset. The
4379 * two second wait is based upon the watchdog timer cycle in
4380 * the VF driver.
4381 */
4382 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4383 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004384 ixgbe_up(adapter);
4385 clear_bit(__IXGBE_RESETTING, &adapter->state);
4386}
4387
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004388void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004389{
4390 /* hardware has been reset, we need to reload some things */
4391 ixgbe_configure(adapter);
4392
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004393 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004394}
4395
4396void ixgbe_reset(struct ixgbe_adapter *adapter)
4397{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004398 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004399 int err;
4400
Alexander Duyck70864002011-04-27 09:13:56 +00004401 /* lock SFP init bit to prevent race conditions with the watchdog */
4402 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4403 usleep_range(1000, 2000);
4404
4405 /* clear all SFP and link config related flags while holding SFP_INIT */
4406 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4407 IXGBE_FLAG2_SFP_NEEDS_RESET);
4408 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4409
Don Skidmore8ca783a2009-05-26 20:40:47 -07004410 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004411 switch (err) {
4412 case 0:
4413 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004414 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004415 break;
4416 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004417 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004418 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004419 case IXGBE_ERR_EEPROM_VERSION:
4420 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004421 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004422 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004423 "your hardware. If you are experiencing problems "
4424 "please contact your Intel or hardware "
4425 "representative who provided you with this "
4426 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004427 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004428 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004429 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004430 }
Auke Kok9a799d72007-09-15 14:07:45 -07004431
Alexander Duyck70864002011-04-27 09:13:56 +00004432 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4433
Auke Kok9a799d72007-09-15 14:07:45 -07004434 /* reprogram the RAR[0] in case user changed it. */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004435 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004436
4437 /* update SAN MAC vmdq pool selection */
4438 if (hw->mac.san_mac_rar_index)
4439 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004440
Jacob Keller1a71ab22012-08-25 03:54:19 +00004441 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4442 ixgbe_ptp_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004443}
4444
Auke Kok9a799d72007-09-15 14:07:45 -07004445/**
4446 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004447 * @rx_ring: ring to free buffers from
4448 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004449static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004450{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004451 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004452 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004453 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004454
Alexander Duyck84418e32010-08-19 13:40:54 +00004455 /* ring already cleared, nothing to do */
4456 if (!rx_ring->rx_buffer_info)
4457 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004458
Alexander Duyck84418e32010-08-19 13:40:54 +00004459 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004460 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004461 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004462
Alexander Duyckf8003262012-03-03 02:35:52 +00004463 rx_buffer = &rx_ring->rx_buffer_info[i];
4464 if (rx_buffer->skb) {
4465 struct sk_buff *skb = rx_buffer->skb;
4466 if (IXGBE_CB(skb)->page_released) {
4467 dma_unmap_page(dev,
4468 IXGBE_CB(skb)->dma,
4469 ixgbe_rx_bufsz(rx_ring),
4470 DMA_FROM_DEVICE);
4471 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004472 }
4473 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004474 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004475 rx_buffer->skb = NULL;
4476 if (rx_buffer->dma)
4477 dma_unmap_page(dev, rx_buffer->dma,
4478 ixgbe_rx_pg_size(rx_ring),
4479 DMA_FROM_DEVICE);
4480 rx_buffer->dma = 0;
4481 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004482 __free_pages(rx_buffer->page,
4483 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004484 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004485 }
4486
4487 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4488 memset(rx_ring->rx_buffer_info, 0, size);
4489
4490 /* Zero out the descriptor ring */
4491 memset(rx_ring->desc, 0, rx_ring->size);
4492
Alexander Duyckf8003262012-03-03 02:35:52 +00004493 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004494 rx_ring->next_to_clean = 0;
4495 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004496}
4497
4498/**
4499 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004500 * @tx_ring: ring to be cleaned
4501 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004502static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004503{
4504 struct ixgbe_tx_buffer *tx_buffer_info;
4505 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004506 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004507
Alexander Duyck84418e32010-08-19 13:40:54 +00004508 /* ring already cleared, nothing to do */
4509 if (!tx_ring->tx_buffer_info)
4510 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004511
Alexander Duyck84418e32010-08-19 13:40:54 +00004512 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004513 for (i = 0; i < tx_ring->count; i++) {
4514 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004515 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004516 }
4517
John Fastabenddad8a3b2012-04-23 12:22:39 +00004518 netdev_tx_reset_queue(txring_txq(tx_ring));
4519
Auke Kok9a799d72007-09-15 14:07:45 -07004520 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4521 memset(tx_ring->tx_buffer_info, 0, size);
4522
4523 /* Zero out the descriptor ring */
4524 memset(tx_ring->desc, 0, tx_ring->size);
4525
4526 tx_ring->next_to_use = 0;
4527 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004528}
4529
4530/**
Auke Kok9a799d72007-09-15 14:07:45 -07004531 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4532 * @adapter: board private structure
4533 **/
4534static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4535{
4536 int i;
4537
4538 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004539 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004540}
4541
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004542/**
4543 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4544 * @adapter: board private structure
4545 **/
4546static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4547{
4548 int i;
4549
4550 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004551 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004552}
4553
Alexander Duycke4911d52011-05-11 07:18:52 +00004554static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4555{
Sasha Levinb67bfe02013-02-27 17:06:00 -08004556 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004557 struct ixgbe_fdir_filter *filter;
4558
4559 spin_lock(&adapter->fdir_perfect_lock);
4560
Sasha Levinb67bfe02013-02-27 17:06:00 -08004561 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004562 &adapter->fdir_filter_list, fdir_node) {
4563 hlist_del(&filter->fdir_node);
4564 kfree(filter);
4565 }
4566 adapter->fdir_filter_count = 0;
4567
4568 spin_unlock(&adapter->fdir_perfect_lock);
4569}
4570
Auke Kok9a799d72007-09-15 14:07:45 -07004571void ixgbe_down(struct ixgbe_adapter *adapter)
4572{
4573 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004574 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004575 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004576 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004577
4578 /* signal that we are down to the interrupt handler */
4579 set_bit(__IXGBE_DOWN, &adapter->state);
4580
4581 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004582 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4583 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004584
Yi Zou2d39d572011-01-06 14:29:56 +00004585 /* disable all enabled rx queues */
4586 for (i = 0; i < adapter->num_rx_queues; i++)
4587 /* this call also flushes the previous write */
4588 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4589
Don Skidmore032b4322011-03-18 09:32:53 +00004590 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004591
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004592 netif_tx_stop_all_queues(netdev);
4593
Alexander Duyck70864002011-04-27 09:13:56 +00004594 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004595 netif_carrier_off(netdev);
4596 netif_tx_disable(netdev);
4597
4598 ixgbe_irq_disable(adapter);
4599
4600 ixgbe_napi_disable_all(adapter);
4601
Alexander Duyckd034acf2011-04-27 09:25:34 +00004602 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4603 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004604 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4605
4606 del_timer_sync(&adapter->service_timer);
4607
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004608 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004609 /* Clear EITR Select mapping */
4610 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4611
4612 /* Mark all the VFs as inactive */
4613 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004614 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004615
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004616 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004617 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004618
Auke Kok9a799d72007-09-15 14:07:45 -07004619 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004620 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004621 }
4622
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004623 /* disable transmits in the hardware now that interrupts are off */
4624 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004625 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004626 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004627 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004628
4629 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004630 switch (hw->mac.type) {
4631 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004632 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004633 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004634 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4635 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004636 break;
4637 default:
4638 break;
4639 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004640
Paul Larson6f4a0e42008-06-24 17:00:56 -07004641 if (!pci_channel_offline(adapter->pdev))
4642 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004643
Emil Tantilovec74a472012-09-20 03:33:56 +00004644 /* power down the optics for 82599 SFP+ fiber */
4645 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00004646 hw->mac.ops.disable_tx_laser(hw);
4647
Auke Kok9a799d72007-09-15 14:07:45 -07004648 ixgbe_clean_all_tx_rings(adapter);
4649 ixgbe_clean_all_rx_rings(adapter);
4650
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004651#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004652 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004653 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004654#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004655}
4656
Auke Kok9a799d72007-09-15 14:07:45 -07004657/**
Auke Kok9a799d72007-09-15 14:07:45 -07004658 * ixgbe_tx_timeout - Respond to a Tx Hang
4659 * @netdev: network interface device structure
4660 **/
4661static void ixgbe_tx_timeout(struct net_device *netdev)
4662{
4663 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4664
4665 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004666 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004667}
4668
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004669/**
Auke Kok9a799d72007-09-15 14:07:45 -07004670 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4671 * @adapter: board private structure to initialize
4672 *
4673 * ixgbe_sw_init initializes the Adapter private data structure.
4674 * Fields are initialized based on PCI device information and
4675 * OS network device settings (MTU size).
4676 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004677static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004678{
4679 struct ixgbe_hw *hw = &adapter->hw;
4680 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00004681 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004682 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004683#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004684 int j;
4685 struct tc_configuration *tc;
4686#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004687
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004688 /* PCI config space info */
4689
4690 hw->vendor_id = pdev->vendor;
4691 hw->device_id = pdev->device;
4692 hw->revision_id = pdev->revision;
4693 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4694 hw->subsystem_device_id = pdev->subsystem_device;
4695
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004696 /* Set common capability flags and settings */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004697 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00004698 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004699 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4700 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004701 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
4702 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00004703 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
4704 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004705 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
4706#ifdef CONFIG_IXGBE_DCA
4707 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
4708#endif
4709#ifdef IXGBE_FCOE
4710 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4711 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4712#ifdef CONFIG_IXGBE_DCB
4713 /* Default traffic class to use for FCoE */
4714 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
4715#endif /* CONFIG_IXGBE_DCB */
4716#endif /* IXGBE_FCOE */
4717
4718 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08004719 switch (hw->mac.type) {
4720 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004721 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
4722 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
4723
Don Skidmorebf069c92009-05-07 10:39:54 +00004724 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4725 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004726
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004727 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004728 adapter->ring_feature[RING_F_FDIR].limit = 0;
4729 adapter->atr_sample_rate = 0;
4730 adapter->fdir_pballoc = 0;
4731#ifdef IXGBE_FCOE
4732 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
4733 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4734#ifdef CONFIG_IXGBE_DCB
4735 adapter->fcoe.up = 0;
4736#endif /* IXGBE_DCB */
4737#endif /* IXGBE_FCOE */
4738 break;
4739 case ixgbe_mac_82599EB:
4740 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4741 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08004742 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004743 case ixgbe_mac_X540:
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004744 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
4745 if (fwsm & IXGBE_FWSM_TS_ENABLED)
4746 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08004747 break;
4748 default:
4749 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004750 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004751
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004752#ifdef IXGBE_FCOE
4753 /* FCoE support exists, always init the FCoE lock */
4754 spin_lock_init(&adapter->fcoe.lock);
4755
4756#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004757 /* n-tuple support exists, always init our spinlock */
4758 spin_lock_init(&adapter->fdir_perfect_lock);
4759
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004760#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004761 switch (hw->mac.type) {
4762 case ixgbe_mac_X540:
4763 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4764 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4765 break;
4766 default:
4767 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4768 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4769 break;
4770 }
4771
Alexander Duyck2f90b862008-11-20 20:52:10 -08004772 /* Configure DCB traffic classes */
4773 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4774 tc = &adapter->dcb_cfg.tc_config[j];
4775 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4776 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4777 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4778 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4779 tc->dcb_pfc = pfc_disabled;
4780 }
John Fastabend4de2a022011-09-27 03:52:01 +00004781
4782 /* Initialize default user to priority mapping, UPx->TC0 */
4783 tc = &adapter->dcb_cfg.tc_config[0];
4784 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4785 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4786
Alexander Duyck2f90b862008-11-20 20:52:10 -08004787 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4788 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004789 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004790 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004791 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004792 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4793 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004794
4795#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004796
4797 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004798 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004799 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00004800 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004801 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4802 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00004803 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07004804
Alexander Duyck99d74482012-05-09 08:09:25 +00004805#ifdef CONFIG_PCI_IOV
4806 /* assign number of SR-IOV VFs */
4807 if (hw->mac.type != ixgbe_mac_82598EB)
4808 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4809
4810#endif
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004811 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004812 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004813 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004814
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004815 /* set default ring sizes */
4816 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4817 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4818
Alexander Duyckbd198052011-06-11 01:45:08 +00004819 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004820 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004821
Auke Kok9a799d72007-09-15 14:07:45 -07004822 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004823 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004824 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004825 return -EIO;
4826 }
4827
Auke Kok9a799d72007-09-15 14:07:45 -07004828 set_bit(__IXGBE_DOWN, &adapter->state);
4829
4830 return 0;
4831}
4832
4833/**
4834 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004835 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004836 *
4837 * Return 0 on success, negative on failure
4838 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004839int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004840{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004841 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004842 int orig_node = dev_to_node(dev);
4843 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004844 int size;
4845
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004846 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004847
4848 if (tx_ring->q_vector)
4849 numa_node = tx_ring->q_vector->numa_node;
4850
4851 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004852 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004853 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004854 if (!tx_ring->tx_buffer_info)
4855 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004856
4857 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004858 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004859 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004860
Alexander Duyckde88eee2012-02-08 07:49:59 +00004861 set_dev_node(dev, numa_node);
4862 tx_ring->desc = dma_alloc_coherent(dev,
4863 tx_ring->size,
4864 &tx_ring->dma,
4865 GFP_KERNEL);
4866 set_dev_node(dev, orig_node);
4867 if (!tx_ring->desc)
4868 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4869 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004870 if (!tx_ring->desc)
4871 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004872
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004873 tx_ring->next_to_use = 0;
4874 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004875 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004876
4877err:
4878 vfree(tx_ring->tx_buffer_info);
4879 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004880 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004881 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004882}
4883
4884/**
Alexander Duyck69888672008-09-11 20:05:39 -07004885 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4886 * @adapter: board private structure
4887 *
4888 * If this function returns with an error, then it's possible one or
4889 * more of the rings is populated (while the rest are not). It is the
4890 * callers duty to clean those orphaned rings.
4891 *
4892 * Return 0 on success, negative on failure
4893 **/
4894static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4895{
4896 int i, err = 0;
4897
4898 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004899 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004900 if (!err)
4901 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004902
Emil Tantilov396e7992010-07-01 20:05:12 +00004903 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004904 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07004905 }
4906
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004907 return 0;
4908err_setup_tx:
4909 /* rewind the index freeing the rings as we go */
4910 while (i--)
4911 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004912 return err;
4913}
4914
4915/**
Auke Kok9a799d72007-09-15 14:07:45 -07004916 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004917 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004918 *
4919 * Returns 0 on success, negative on failure
4920 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004921int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004922{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004923 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004924 int orig_node = dev_to_node(dev);
4925 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004926 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004927
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004928 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004929
4930 if (rx_ring->q_vector)
4931 numa_node = rx_ring->q_vector->numa_node;
4932
4933 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004934 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004935 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004936 if (!rx_ring->rx_buffer_info)
4937 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004938
Auke Kok9a799d72007-09-15 14:07:45 -07004939 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004940 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4941 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004942
Alexander Duyckde88eee2012-02-08 07:49:59 +00004943 set_dev_node(dev, numa_node);
4944 rx_ring->desc = dma_alloc_coherent(dev,
4945 rx_ring->size,
4946 &rx_ring->dma,
4947 GFP_KERNEL);
4948 set_dev_node(dev, orig_node);
4949 if (!rx_ring->desc)
4950 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4951 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004952 if (!rx_ring->desc)
4953 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004954
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004955 rx_ring->next_to_clean = 0;
4956 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004957
4958 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004959err:
4960 vfree(rx_ring->rx_buffer_info);
4961 rx_ring->rx_buffer_info = NULL;
4962 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004963 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004964}
4965
4966/**
Alexander Duyck69888672008-09-11 20:05:39 -07004967 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4968 * @adapter: board private structure
4969 *
4970 * If this function returns with an error, then it's possible one or
4971 * more of the rings is populated (while the rest are not). It is the
4972 * callers duty to clean those orphaned rings.
4973 *
4974 * Return 0 on success, negative on failure
4975 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004976static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4977{
4978 int i, err = 0;
4979
4980 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004981 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004982 if (!err)
4983 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004984
Emil Tantilov396e7992010-07-01 20:05:12 +00004985 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004986 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07004987 }
4988
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004989#ifdef IXGBE_FCOE
4990 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4991 if (!err)
4992#endif
4993 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004994err_setup_rx:
4995 /* rewind the index freeing the rings as we go */
4996 while (i--)
4997 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004998 return err;
4999}
5000
5001/**
Auke Kok9a799d72007-09-15 14:07:45 -07005002 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005003 * @tx_ring: Tx descriptor ring for a specific queue
5004 *
5005 * Free all transmit software resources
5006 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005007void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005008{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005009 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005010
5011 vfree(tx_ring->tx_buffer_info);
5012 tx_ring->tx_buffer_info = NULL;
5013
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005014 /* if not set, then don't free */
5015 if (!tx_ring->desc)
5016 return;
5017
5018 dma_free_coherent(tx_ring->dev, tx_ring->size,
5019 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005020
5021 tx_ring->desc = NULL;
5022}
5023
5024/**
5025 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5026 * @adapter: board private structure
5027 *
5028 * Free all transmit software resources
5029 **/
5030static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5031{
5032 int i;
5033
5034 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005035 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005036 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005037}
5038
5039/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005040 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005041 * @rx_ring: ring to clean the resources from
5042 *
5043 * Free all receive software resources
5044 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005045void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005046{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005047 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005048
5049 vfree(rx_ring->rx_buffer_info);
5050 rx_ring->rx_buffer_info = NULL;
5051
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005052 /* if not set, then don't free */
5053 if (!rx_ring->desc)
5054 return;
5055
5056 dma_free_coherent(rx_ring->dev, rx_ring->size,
5057 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005058
5059 rx_ring->desc = NULL;
5060}
5061
5062/**
5063 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5064 * @adapter: board private structure
5065 *
5066 * Free all receive software resources
5067 **/
5068static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5069{
5070 int i;
5071
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005072#ifdef IXGBE_FCOE
5073 ixgbe_free_fcoe_ddp_resources(adapter);
5074
5075#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005076 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005077 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005078 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005079}
5080
5081/**
Auke Kok9a799d72007-09-15 14:07:45 -07005082 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5083 * @netdev: network interface device structure
5084 * @new_mtu: new value for maximum frame size
5085 *
5086 * Returns 0 on success, negative on failure
5087 **/
5088static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5089{
5090 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5091 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5092
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005093 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005094 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5095 return -EINVAL;
5096
5097 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00005098 * For 82599EB we cannot allow legacy VFs to enable their receive
5099 * paths when MTU greater than 1500 is configured. So display a
5100 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00005101 */
5102 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5103 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Alexander Duyckc5604512013-01-09 08:50:42 +00005104 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck872844d2012-08-15 02:10:43 +00005105 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005106
Emil Tantilov396e7992010-07-01 20:05:12 +00005107 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005108
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005109 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005110 netdev->mtu = new_mtu;
5111
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005112 if (netif_running(netdev))
5113 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005114
5115 return 0;
5116}
5117
5118/**
5119 * ixgbe_open - Called when a network interface is made active
5120 * @netdev: network interface device structure
5121 *
5122 * Returns 0 on success, negative value on failure
5123 *
5124 * The open entry point is called when a network interface is made
5125 * active by the system (IFF_UP). At this point all resources needed
5126 * for transmit and receive operations are allocated, the interrupt
5127 * handler is registered with the OS, the watchdog timer is started,
5128 * and the stack is notified that the interface is ready.
5129 **/
5130static int ixgbe_open(struct net_device *netdev)
5131{
5132 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5133 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005134
Auke Kok4bebfaa2008-02-11 09:26:01 -08005135 /* disallow open during test */
5136 if (test_bit(__IXGBE_TESTING, &adapter->state))
5137 return -EBUSY;
5138
Jesse Brandeburg54386462009-04-17 20:44:27 +00005139 netif_carrier_off(netdev);
5140
Auke Kok9a799d72007-09-15 14:07:45 -07005141 /* allocate transmit descriptors */
5142 err = ixgbe_setup_all_tx_resources(adapter);
5143 if (err)
5144 goto err_setup_tx;
5145
Auke Kok9a799d72007-09-15 14:07:45 -07005146 /* allocate receive descriptors */
5147 err = ixgbe_setup_all_rx_resources(adapter);
5148 if (err)
5149 goto err_setup_rx;
5150
5151 ixgbe_configure(adapter);
5152
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005153 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005154 if (err)
5155 goto err_req_irq;
5156
Alexander Duyckac802f52012-07-12 05:52:53 +00005157 /* Notify the stack of the actual queue counts. */
5158 err = netif_set_real_num_tx_queues(netdev,
5159 adapter->num_rx_pools > 1 ? 1 :
5160 adapter->num_tx_queues);
5161 if (err)
5162 goto err_set_queues;
5163
5164
5165 err = netif_set_real_num_rx_queues(netdev,
5166 adapter->num_rx_pools > 1 ? 1 :
5167 adapter->num_rx_queues);
5168 if (err)
5169 goto err_set_queues;
5170
Jacob Keller1a71ab22012-08-25 03:54:19 +00005171 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005172
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005173 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005174
5175 return 0;
5176
Alexander Duyckac802f52012-07-12 05:52:53 +00005177err_set_queues:
5178 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005179err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005180 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005181err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005182 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005183err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07005184 ixgbe_reset(adapter);
5185
5186 return err;
5187}
5188
5189/**
5190 * ixgbe_close - Disables a network interface
5191 * @netdev: network interface device structure
5192 *
5193 * Returns 0, this is not allowed to fail
5194 *
5195 * The close entry point is called when an interface is de-activated
5196 * by the OS. The hardware is still under the drivers control, but
5197 * needs to be disabled. A global MAC reset is issued to stop the
5198 * hardware, and all transmit and receive resources are freed.
5199 **/
5200static int ixgbe_close(struct net_device *netdev)
5201{
5202 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005203
Jacob Keller1a71ab22012-08-25 03:54:19 +00005204 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005205
Auke Kok9a799d72007-09-15 14:07:45 -07005206 ixgbe_down(adapter);
5207 ixgbe_free_irq(adapter);
5208
Alexander Duycke4911d52011-05-11 07:18:52 +00005209 ixgbe_fdir_filter_exit(adapter);
5210
Auke Kok9a799d72007-09-15 14:07:45 -07005211 ixgbe_free_all_tx_resources(adapter);
5212 ixgbe_free_all_rx_resources(adapter);
5213
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005214 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005215
5216 return 0;
5217}
5218
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005219#ifdef CONFIG_PM
5220static int ixgbe_resume(struct pci_dev *pdev)
5221{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005222 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5223 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005224 u32 err;
5225
5226 pci_set_power_state(pdev, PCI_D0);
5227 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005228 /*
5229 * pci_restore_state clears dev->state_saved so call
5230 * pci_save_state to restore it.
5231 */
5232 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005233
5234 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005235 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005236 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005237 return err;
5238 }
5239 pci_set_master(pdev);
5240
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005241 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005242
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005243 ixgbe_reset(adapter);
5244
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005245 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5246
Alexander Duyckac802f52012-07-12 05:52:53 +00005247 rtnl_lock();
5248 err = ixgbe_init_interrupt_scheme(adapter);
5249 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005250 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005251
5252 rtnl_unlock();
5253
5254 if (err)
5255 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005256
5257 netif_device_attach(netdev);
5258
5259 return 0;
5260}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005261#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005262
5263static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005264{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005265 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5266 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005267 struct ixgbe_hw *hw = &adapter->hw;
5268 u32 ctrl, fctrl;
5269 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005270#ifdef CONFIG_PM
5271 int retval = 0;
5272#endif
5273
5274 netif_device_detach(netdev);
5275
akepner499ab5c2013-03-13 14:54:58 +00005276 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005277 if (netif_running(netdev)) {
5278 ixgbe_down(adapter);
5279 ixgbe_free_irq(adapter);
5280 ixgbe_free_all_tx_resources(adapter);
5281 ixgbe_free_all_rx_resources(adapter);
5282 }
akepner499ab5c2013-03-13 14:54:58 +00005283 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005284
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005285 ixgbe_clear_interrupt_scheme(adapter);
5286
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005287#ifdef CONFIG_PM
5288 retval = pci_save_state(pdev);
5289 if (retval)
5290 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005291
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005292#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005293 if (wufc) {
5294 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005295
Emil Tantilovec74a472012-09-20 03:33:56 +00005296 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5297 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005298 hw->mac.ops.enable_tx_laser(hw);
5299
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005300 /* turn on all-multi mode if wake on multicast is enabled */
5301 if (wufc & IXGBE_WUFC_MC) {
5302 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5303 fctrl |= IXGBE_FCTRL_MPE;
5304 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5305 }
5306
5307 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5308 ctrl |= IXGBE_CTRL_GIO_DIS;
5309 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5310
5311 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5312 } else {
5313 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5314 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5315 }
5316
Alexander Duyckbd508172010-11-16 19:27:03 -08005317 switch (hw->mac.type) {
5318 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005319 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005320 break;
5321 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005322 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005323 pci_wake_from_d3(pdev, !!wufc);
5324 break;
5325 default:
5326 break;
5327 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005328
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005329 *enable_wake = !!wufc;
5330
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005331 ixgbe_release_hw_control(adapter);
5332
5333 pci_disable_device(pdev);
5334
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005335 return 0;
5336}
5337
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005338#ifdef CONFIG_PM
5339static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5340{
5341 int retval;
5342 bool wake;
5343
5344 retval = __ixgbe_shutdown(pdev, &wake);
5345 if (retval)
5346 return retval;
5347
5348 if (wake) {
5349 pci_prepare_to_sleep(pdev);
5350 } else {
5351 pci_wake_from_d3(pdev, false);
5352 pci_set_power_state(pdev, PCI_D3hot);
5353 }
5354
5355 return 0;
5356}
5357#endif /* CONFIG_PM */
5358
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005359static void ixgbe_shutdown(struct pci_dev *pdev)
5360{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005361 bool wake;
5362
5363 __ixgbe_shutdown(pdev, &wake);
5364
5365 if (system_state == SYSTEM_POWER_OFF) {
5366 pci_wake_from_d3(pdev, wake);
5367 pci_set_power_state(pdev, PCI_D3hot);
5368 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005369}
5370
5371/**
Auke Kok9a799d72007-09-15 14:07:45 -07005372 * ixgbe_update_stats - Update the board statistics counters.
5373 * @adapter: board private structure
5374 **/
5375void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5376{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005377 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005378 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005379 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005380 u64 total_mpc = 0;
5381 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005382 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5383 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005384 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005385
Don Skidmored08935c2010-06-11 13:20:29 +00005386 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5387 test_bit(__IXGBE_RESETTING, &adapter->state))
5388 return;
5389
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005390 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005391 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005392 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005393 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005394 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5395 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005396 }
5397 adapter->rsc_total_count = rsc_count;
5398 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005399 }
5400
Alexander Duyck5b7da512010-11-16 19:26:50 -08005401 for (i = 0; i < adapter->num_rx_queues; i++) {
5402 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5403 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5404 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5405 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005406 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005407 bytes += rx_ring->stats.bytes;
5408 packets += rx_ring->stats.packets;
5409 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005410 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005411 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5412 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005413 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005414 netdev->stats.rx_bytes = bytes;
5415 netdev->stats.rx_packets = packets;
5416
5417 bytes = 0;
5418 packets = 0;
5419 /* gather some stats to the adapter struct that are per queue */
5420 for (i = 0; i < adapter->num_tx_queues; i++) {
5421 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5422 restart_queue += tx_ring->tx_stats.restart_queue;
5423 tx_busy += tx_ring->tx_stats.tx_busy;
5424 bytes += tx_ring->stats.bytes;
5425 packets += tx_ring->stats.packets;
5426 }
5427 adapter->restart_queue = restart_queue;
5428 adapter->tx_busy = tx_busy;
5429 netdev->stats.tx_bytes = bytes;
5430 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005431
Joe Perches7ca647b2010-09-07 21:35:40 +00005432 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005433
5434 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005435 for (i = 0; i < 8; i++) {
5436 /* for packet buffers not used, the register should read 0 */
5437 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5438 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005439 hwstats->mpc[i] += mpc;
5440 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005441 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5442 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005443 switch (hw->mac.type) {
5444 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005445 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5446 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5447 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005448 hwstats->pxonrxc[i] +=
5449 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005450 break;
5451 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005452 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005453 hwstats->pxonrxc[i] +=
5454 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005455 break;
5456 default:
5457 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005458 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005459 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005460
5461 /*16 register reads */
5462 for (i = 0; i < 16; i++) {
5463 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5464 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5465 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5466 (hw->mac.type == ixgbe_mac_X540)) {
5467 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5468 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5469 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5470 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5471 }
5472 }
5473
Joe Perches7ca647b2010-09-07 21:35:40 +00005474 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005475 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005476 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005477
John Fastabendc84d3242010-11-16 19:27:12 -08005478 ixgbe_update_xoff_received(adapter);
5479
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005480 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005481 switch (hw->mac.type) {
5482 case ixgbe_mac_82598EB:
5483 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005484 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5485 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5486 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5487 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005488 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005489 /* OS2BMC stats are X540 only*/
5490 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5491 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5492 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5493 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5494 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005495 for (i = 0; i < 16; i++)
5496 adapter->hw_rx_no_dma_resources +=
5497 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005498 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005499 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005500 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005501 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005502 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005503 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005504 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005505 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5506 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005507#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005508 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5509 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5510 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5511 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5512 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5513 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005514 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005515 if (adapter->fcoe.ddp_pool) {
5516 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5517 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5518 unsigned int cpu;
5519 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005520 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005521 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5522 noddp += ddp_pool->noddp;
5523 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005524 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005525 hwstats->fcoe_noddp = noddp;
5526 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005527 }
Yi Zou6d455222009-05-13 13:12:16 +00005528#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005529 break;
5530 default:
5531 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005532 }
Auke Kok9a799d72007-09-15 14:07:45 -07005533 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005534 hwstats->bprc += bprc;
5535 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005536 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005537 hwstats->mprc -= bprc;
5538 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5539 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5540 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5541 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5542 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5543 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5544 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5545 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005546 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005547 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005548 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005549 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005550 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5551 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005552 /*
5553 * 82598 errata - tx of flow control packets is included in tx counters
5554 */
5555 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005556 hwstats->gptc -= xon_off_tot;
5557 hwstats->mptc -= xon_off_tot;
5558 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5559 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5560 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5561 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5562 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5563 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5564 hwstats->ptc64 -= xon_off_tot;
5565 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5566 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5567 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5568 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5569 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5570 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005571
5572 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005573 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005574
5575 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005576 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005577 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005578 netdev->stats.rx_length_errors = hwstats->rlec;
5579 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005580 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005581}
5582
5583/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005584 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005585 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005586 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005587static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005588{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005589 struct ixgbe_hw *hw = &adapter->hw;
5590 int i;
5591
Alexander Duyckd034acf2011-04-27 09:25:34 +00005592 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5593 return;
5594
5595 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5596
5597 /* if interface is down do nothing */
5598 if (test_bit(__IXGBE_DOWN, &adapter->state))
5599 return;
5600
5601 /* do nothing if we are not using signature filters */
5602 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5603 return;
5604
5605 adapter->fdir_overflow++;
5606
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005607 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5608 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005609 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005610 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005611 /* re-enable flow director interrupts */
5612 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005613 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005614 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005615 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005616 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005617}
5618
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005619/**
5620 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005621 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005622 *
5623 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005624 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005625 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005626 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005627 */
5628static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5629{
Auke Kok9a799d72007-09-15 14:07:45 -07005630 struct ixgbe_hw *hw = &adapter->hw;
5631 u64 eics = 0;
5632 int i;
5633
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005634 /* If we're down or resetting, just bail */
5635 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5636 test_bit(__IXGBE_RESETTING, &adapter->state))
5637 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005638
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005639 /* Force detection of hung controller */
5640 if (netif_carrier_ok(adapter->netdev)) {
5641 for (i = 0; i < adapter->num_tx_queues; i++)
5642 set_check_for_tx_hang(adapter->tx_ring[i]);
5643 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005644
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005645 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005646 /*
5647 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005648 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005649 * would set *both* EIMS and EICS for any bit in EIAM
5650 */
5651 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5652 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005653 } else {
5654 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005655 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005656 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005657 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005658 eics |= ((u64)1 << i);
5659 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005660 }
5661
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005662 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005663 ixgbe_irq_rearm_queues(adapter, eics);
5664
Alexander Duyckfe49f042009-06-04 16:00:09 +00005665}
5666
5667/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005668 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005669 * @adapter: pointer to the device adapter structure
5670 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005671 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005672static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005673{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005674 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005675 u32 link_speed = adapter->link_speed;
5676 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005677 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005678
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005679 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5680 return;
5681
5682 if (hw->mac.ops.check_link) {
5683 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005684 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005685 /* always assume link is up, if no check link function */
5686 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5687 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005688 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005689
5690 if (adapter->ixgbe_ieee_pfc)
5691 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5692
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005693 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00005694 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005695 ixgbe_set_rx_drop_en(adapter);
5696 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005697
5698 if (link_up ||
5699 time_after(jiffies, (adapter->link_check_timeout +
5700 IXGBE_TRY_LINK_TIMEOUT))) {
5701 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5702 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5703 IXGBE_WRITE_FLUSH(hw);
5704 }
5705
5706 adapter->link_up = link_up;
5707 adapter->link_speed = link_speed;
5708}
5709
Alexander Duyck107d3012012-10-02 00:17:03 +00005710static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
5711{
5712#ifdef CONFIG_IXGBE_DCB
5713 struct net_device *netdev = adapter->netdev;
5714 struct dcb_app app = {
5715 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
5716 .protocol = 0,
5717 };
5718 u8 up = 0;
5719
5720 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
5721 up = dcb_ieee_getapp_mask(netdev, &app);
5722
5723 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
5724#endif
5725}
5726
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005727/**
5728 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5729 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005730 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005731 **/
5732static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5733{
5734 struct net_device *netdev = adapter->netdev;
5735 struct ixgbe_hw *hw = &adapter->hw;
5736 u32 link_speed = adapter->link_speed;
5737 bool flow_rx, flow_tx;
5738
5739 /* only continue if link was previously down */
5740 if (netif_carrier_ok(netdev))
5741 return;
5742
5743 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5744
5745 switch (hw->mac.type) {
5746 case ixgbe_mac_82598EB: {
5747 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5748 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5749 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5750 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5751 }
5752 break;
5753 case ixgbe_mac_X540:
5754 case ixgbe_mac_82599EB: {
5755 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5756 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5757 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5758 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5759 }
5760 break;
5761 default:
5762 flow_tx = false;
5763 flow_rx = false;
5764 break;
5765 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005766
Jacob Keller6cb562d2012-12-05 07:24:41 +00005767 adapter->last_rx_ptp_check = jiffies;
5768
Jacob Keller1a71ab22012-08-25 03:54:19 +00005769 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5770 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005771
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005772 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5773 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5774 "10 Gbps" :
5775 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5776 "1 Gbps" :
5777 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5778 "100 Mbps" :
5779 "unknown speed"))),
5780 ((flow_rx && flow_tx) ? "RX/TX" :
5781 (flow_rx ? "RX" :
5782 (flow_tx ? "TX" : "None"))));
5783
5784 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005785 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005786
Alexander Duyck107d3012012-10-02 00:17:03 +00005787 /* update the default user priority for VFs */
5788 ixgbe_update_default_up(adapter);
5789
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005790 /* ping all the active vfs to let them know link has changed */
5791 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005792}
5793
5794/**
5795 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5796 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005797 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005798 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005799static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005800{
5801 struct net_device *netdev = adapter->netdev;
5802 struct ixgbe_hw *hw = &adapter->hw;
5803
5804 adapter->link_up = false;
5805 adapter->link_speed = 0;
5806
5807 /* only continue if link was up previously */
5808 if (!netif_carrier_ok(netdev))
5809 return;
5810
5811 /* poll for SFP+ cable when link is down */
5812 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5813 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5814
Jacob Keller1a71ab22012-08-25 03:54:19 +00005815 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5816 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005817
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005818 e_info(drv, "NIC Link is Down\n");
5819 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005820
5821 /* ping all the active vfs to let them know link has changed */
5822 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005823}
5824
5825/**
5826 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005827 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005828 **/
5829static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5830{
5831 int i;
5832 int some_tx_pending = 0;
5833
5834 if (!netif_carrier_ok(adapter->netdev)) {
5835 for (i = 0; i < adapter->num_tx_queues; i++) {
5836 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5837 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5838 some_tx_pending = 1;
5839 break;
5840 }
5841 }
5842
5843 if (some_tx_pending) {
5844 /* We've lost link, so the controller stops DMA,
5845 * but we've got queued Tx work that's never going
5846 * to get done, so reset controller to flush Tx.
5847 * (Do the reset outside of interrupt context).
5848 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00005849 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005850 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005851 }
5852 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005853}
5854
Greg Rosea985b6c32010-11-18 03:02:52 +00005855static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5856{
5857 u32 ssvpc;
5858
Greg Rose0584d992012-08-08 00:00:58 +00005859 /* Do not perform spoof check for 82598 or if not in IOV mode */
5860 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5861 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00005862 return;
5863
5864 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5865
5866 /*
5867 * ssvpc register is cleared on read, if zero then no
5868 * spoofed packets in the last interval.
5869 */
5870 if (!ssvpc)
5871 return;
5872
Emil Tantilovd6ea0752012-08-08 06:28:37 +00005873 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00005874}
5875
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005876/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005877 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005878 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005879 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005880static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005881{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005882 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005883 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5884 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005885 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005886
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005887 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005888
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005889 if (adapter->link_up)
5890 ixgbe_watchdog_link_is_up(adapter);
5891 else
5892 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005893
Greg Rosea985b6c32010-11-18 03:02:52 +00005894 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005895 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005896
5897 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005898}
5899
Alexander Duyck70864002011-04-27 09:13:56 +00005900/**
5901 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005902 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005903 **/
5904static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5905{
5906 struct ixgbe_hw *hw = &adapter->hw;
5907 s32 err;
5908
5909 /* not searching for SFP so there is nothing to do here */
5910 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5911 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5912 return;
5913
5914 /* someone else is in init, wait until next service event */
5915 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5916 return;
5917
5918 err = hw->phy.ops.identify_sfp(hw);
5919 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5920 goto sfp_out;
5921
5922 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5923 /* If no cable is present, then we need to reset
5924 * the next time we find a good cable. */
5925 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5926 }
5927
5928 /* exit on error */
5929 if (err)
5930 goto sfp_out;
5931
5932 /* exit if reset not needed */
5933 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5934 goto sfp_out;
5935
5936 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5937
5938 /*
5939 * A module may be identified correctly, but the EEPROM may not have
5940 * support for that module. setup_sfp() will fail in that case, so
5941 * we should not allow that module to load.
5942 */
5943 if (hw->mac.type == ixgbe_mac_82598EB)
5944 err = hw->phy.ops.reset(hw);
5945 else
5946 err = hw->mac.ops.setup_sfp(hw);
5947
5948 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5949 goto sfp_out;
5950
5951 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5952 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5953
5954sfp_out:
5955 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5956
5957 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5958 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5959 e_dev_err("failed to initialize because an unsupported "
5960 "SFP+ module type was detected.\n");
5961 e_dev_err("Reload the driver after installing a "
5962 "supported module.\n");
5963 unregister_netdev(adapter->netdev);
5964 }
5965}
5966
5967/**
5968 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005969 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005970 **/
5971static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5972{
5973 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00005974 u32 speed;
5975 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00005976
5977 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5978 return;
5979
5980 /* someone else is in init, wait until next service event */
5981 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5982 return;
5983
5984 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5985
Josh Hay3d292262012-12-15 03:28:19 +00005986 speed = hw->phy.autoneg_advertised;
5987 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5988 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Alexander Duyck70864002011-04-27 09:13:56 +00005989 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005990 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00005991
5992 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5993 adapter->link_check_timeout = jiffies;
5994 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5995}
5996
Greg Rose83c61fa2011-09-07 05:59:35 +00005997#ifdef CONFIG_PCI_IOV
5998static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5999{
6000 int vf;
6001 struct ixgbe_hw *hw = &adapter->hw;
6002 struct net_device *netdev = adapter->netdev;
6003 u32 gpc;
6004 u32 ciaa, ciad;
6005
6006 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6007 if (gpc) /* If incrementing then no need for the check below */
6008 return;
6009 /*
6010 * Check to see if a bad DMA write target from an errant or
6011 * malicious VF has caused a PCIe error. If so then we can
6012 * issue a VFLR to the offending VF(s) and then resume without
6013 * requesting a full slot reset.
6014 */
6015
6016 for (vf = 0; vf < adapter->num_vfs; vf++) {
6017 ciaa = (vf << 16) | 0x80000000;
6018 /* 32 bit read so align, we really want status at offset 6 */
6019 ciaa |= PCI_COMMAND;
6020 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6021 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6022 ciaa &= 0x7FFFFFFF;
6023 /* disable debug mode asap after reading data */
6024 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6025 /* Get the upper 16 bits which will be the PCI status reg */
6026 ciad >>= 16;
6027 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6028 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6029 /* Issue VFLR */
6030 ciaa = (vf << 16) | 0x80000000;
6031 ciaa |= 0xA8;
6032 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6033 ciad = 0x00008000; /* VFLR */
6034 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6035 ciaa &= 0x7FFFFFFF;
6036 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6037 }
6038 }
6039}
6040
6041#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006042/**
6043 * ixgbe_service_timer - Timer Call-back
6044 * @data: pointer to adapter cast into an unsigned long
6045 **/
6046static void ixgbe_service_timer(unsigned long data)
6047{
6048 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6049 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006050 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006051
6052 /* poll faster when waiting for link */
6053 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6054 next_event_offset = HZ / 10;
6055 else
6056 next_event_offset = HZ * 2;
6057
Greg Rose83c61fa2011-09-07 05:59:35 +00006058#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00006059 /*
6060 * don't bother with SR-IOV VF DMA hang check if there are
6061 * no VFs or the link is down
6062 */
6063 if (!adapter->num_vfs ||
6064 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6065 goto normal_timer_service;
6066
6067 /* If we have VFs allocated then we must check for DMA hangs */
6068 ixgbe_check_for_bad_vf(adapter);
6069 next_event_offset = HZ / 50;
6070 adapter->timer_event_accumulator++;
6071
6072 if (adapter->timer_event_accumulator >= 100)
6073 adapter->timer_event_accumulator = 0;
6074 else
6075 ready = false;
6076
6077normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00006078#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006079 /* Reset the timer */
6080 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6081
Greg Rose83c61fa2011-09-07 05:59:35 +00006082 if (ready)
6083 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006084}
6085
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006086static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6087{
6088 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6089 return;
6090
6091 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6092
6093 /* If we're already down or resetting, just bail */
6094 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6095 test_bit(__IXGBE_RESETTING, &adapter->state))
6096 return;
6097
6098 ixgbe_dump(adapter);
6099 netdev_err(adapter->netdev, "Reset adapter\n");
6100 adapter->tx_timeout_count++;
6101
6102 ixgbe_reinit_locked(adapter);
6103}
6104
Alexander Duyck70864002011-04-27 09:13:56 +00006105/**
6106 * ixgbe_service_task - manages and runs subtasks
6107 * @work: pointer to work_struct containing our data
6108 **/
6109static void ixgbe_service_task(struct work_struct *work)
6110{
6111 struct ixgbe_adapter *adapter = container_of(work,
6112 struct ixgbe_adapter,
6113 service_task);
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006114 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006115 ixgbe_sfp_detection_subtask(adapter);
6116 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006117 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006118 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006119 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006120 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00006121
6122 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) {
6123 ixgbe_ptp_overflow_check(adapter);
6124 ixgbe_ptp_rx_hang(adapter);
6125 }
Alexander Duyck70864002011-04-27 09:13:56 +00006126
6127 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006128}
6129
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006130static int ixgbe_tso(struct ixgbe_ring *tx_ring,
6131 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006132 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00006133{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006134 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006135 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006136 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006137
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00006138 if (skb->ip_summed != CHECKSUM_PARTIAL)
6139 return 0;
6140
Alexander Duyck897ab152011-05-27 05:31:47 +00006141 if (!skb_is_gso(skb))
6142 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006143
Alexander Duyck897ab152011-05-27 05:31:47 +00006144 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006145 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00006146 if (err)
6147 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006148 }
6149
Alexander Duyck897ab152011-05-27 05:31:47 +00006150 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6151 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6152
Alexander Duyck244e27a2012-02-08 07:51:11 +00006153 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006154 struct iphdr *iph = ip_hdr(skb);
6155 iph->tot_len = 0;
6156 iph->check = 0;
6157 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6158 iph->daddr, 0,
6159 IPPROTO_TCP,
6160 0);
6161 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006162 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6163 IXGBE_TX_FLAGS_CSUM |
6164 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006165 } else if (skb_is_gso_v6(skb)) {
6166 ipv6_hdr(skb)->payload_len = 0;
6167 tcp_hdr(skb)->check =
6168 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6169 &ipv6_hdr(skb)->daddr,
6170 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00006171 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6172 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00006173 }
6174
Alexander Duyck091a6242012-02-08 07:51:01 +00006175 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00006176 l4len = tcp_hdrlen(skb);
6177 *hdr_len = skb_transport_offset(skb) + l4len;
6178
Alexander Duyck091a6242012-02-08 07:51:01 +00006179 /* update gso size and bytecount with header size */
6180 first->gso_segs = skb_shinfo(skb)->gso_segs;
6181 first->bytecount += (first->gso_segs - 1) * *hdr_len;
6182
Alexander Duyckc44f5f52012-10-30 06:01:45 +00006183 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00006184 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6185 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00006186
6187 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6188 vlan_macip_lens = skb_network_header_len(skb);
6189 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006190 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006191
6192 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006193 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00006194
6195 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006196}
6197
Alexander Duyck244e27a2012-02-08 07:51:11 +00006198static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6199 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07006200{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006201 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006202 u32 vlan_macip_lens = 0;
6203 u32 mss_l4len_idx = 0;
6204 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006205
Alexander Duyck897ab152011-05-27 05:31:47 +00006206 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck472148c2012-11-07 02:34:28 +00006207 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6208 !(first->tx_flags & IXGBE_TX_FLAGS_CC))
6209 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00006210 } else {
6211 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006212 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006213 case __constant_htons(ETH_P_IP):
6214 vlan_macip_lens |= skb_network_header_len(skb);
6215 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6216 l4_hdr = ip_hdr(skb)->protocol;
6217 break;
6218 case __constant_htons(ETH_P_IPV6):
6219 vlan_macip_lens |= skb_network_header_len(skb);
6220 l4_hdr = ipv6_hdr(skb)->nexthdr;
6221 break;
6222 default:
6223 if (unlikely(net_ratelimit())) {
6224 dev_warn(tx_ring->dev,
6225 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006226 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00006227 }
6228 break;
6229 }
Auke Kok9a799d72007-09-15 14:07:45 -07006230
Alexander Duyck897ab152011-05-27 05:31:47 +00006231 switch (l4_hdr) {
6232 case IPPROTO_TCP:
6233 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6234 mss_l4len_idx = tcp_hdrlen(skb) <<
6235 IXGBE_ADVTXD_L4LEN_SHIFT;
6236 break;
6237 case IPPROTO_SCTP:
6238 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6239 mss_l4len_idx = sizeof(struct sctphdr) <<
6240 IXGBE_ADVTXD_L4LEN_SHIFT;
6241 break;
6242 case IPPROTO_UDP:
6243 mss_l4len_idx = sizeof(struct udphdr) <<
6244 IXGBE_ADVTXD_L4LEN_SHIFT;
6245 break;
6246 default:
6247 if (unlikely(net_ratelimit())) {
6248 dev_warn(tx_ring->dev,
6249 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006250 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006251 }
6252 break;
6253 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006254
6255 /* update TX checksum flag */
6256 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006257 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006258
Alexander Duyck244e27a2012-02-08 07:51:11 +00006259 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006260 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006261 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006262
6263 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6264 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006265}
6266
Alexander Duyck472148c2012-11-07 02:34:28 +00006267#define IXGBE_SET_FLAG(_input, _flag, _result) \
6268 ((_flag <= _result) ? \
6269 ((u32)(_input & _flag) * (_result / _flag)) : \
6270 ((u32)(_input & _flag) / (_flag / _result)))
6271
6272static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006273{
6274 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00006275 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
6276 IXGBE_ADVTXD_DCMD_DEXT |
6277 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006278
6279 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00006280 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
6281 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006282
Alexander Duyckd3d00232011-07-15 02:31:25 +00006283 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006284 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
6285 IXGBE_ADVTXD_DCMD_TSE);
6286
6287 /* set timestamp bit if present */
6288 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
6289 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006290
Alexander Duyck62748b72012-07-20 08:09:01 +00006291 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00006292 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00006293
Alexander Duyckd3d00232011-07-15 02:31:25 +00006294 return cmd_type;
6295}
6296
Alexander Duyck729739b2012-02-08 07:51:06 +00006297static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6298 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006299{
Alexander Duyck472148c2012-11-07 02:34:28 +00006300 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006301
6302 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00006303 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6304 IXGBE_TX_FLAGS_CSUM,
6305 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006306
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006307 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006308 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6309 IXGBE_TX_FLAGS_IPV4,
6310 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006311
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006312 /*
6313 * Check Context must be set if Tx switch is enabled, which it
6314 * always is for case where virtual functions are running
6315 */
Alexander Duyck472148c2012-11-07 02:34:28 +00006316 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6317 IXGBE_TX_FLAGS_CC,
6318 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006319
Alexander Duyck472148c2012-11-07 02:34:28 +00006320 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006321}
6322
6323#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6324 IXGBE_TXD_CMD_RS)
6325
6326static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006327 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006328 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006329{
Alexander Duyck729739b2012-02-08 07:51:06 +00006330 struct sk_buff *skb = first->skb;
6331 struct ixgbe_tx_buffer *tx_buffer;
6332 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00006333 struct skb_frag_struct *frag;
6334 dma_addr_t dma;
6335 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006336 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00006337 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006338 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006339
Alexander Duyck729739b2012-02-08 07:51:06 +00006340 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6341
Alexander Duyckec718252012-10-30 06:01:55 +00006342 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
6343
6344 size = skb_headlen(skb);
6345 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00006346
Alexander Duyckd3d00232011-07-15 02:31:25 +00006347#ifdef IXGBE_FCOE
6348 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006349 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006350 size -= sizeof(struct fcoe_crc_eof) - data_len;
6351 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006352 } else {
6353 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006354 }
Auke Kok9a799d72007-09-15 14:07:45 -07006355 }
6356
Alexander Duyckd3d00232011-07-15 02:31:25 +00006357#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006358 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006359
Alexander Duyckec718252012-10-30 06:01:55 +00006360 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006361
Alexander Duyckec718252012-10-30 06:01:55 +00006362 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
6363 if (dma_mapping_error(tx_ring->dev, dma))
6364 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006365
Alexander Duyckec718252012-10-30 06:01:55 +00006366 /* record length, and DMA address */
6367 dma_unmap_len_set(tx_buffer, len, size);
6368 dma_unmap_addr_set(tx_buffer, dma, dma);
6369
6370 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6371
Alexander Duyck729739b2012-02-08 07:51:06 +00006372 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006373 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00006374 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006375
Alexander Duyckd3d00232011-07-15 02:31:25 +00006376 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006377 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006378 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006379 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006380 i = 0;
6381 }
Alexander Duyckec718252012-10-30 06:01:55 +00006382 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006383
6384 dma += IXGBE_MAX_DATA_PER_TXD;
6385 size -= IXGBE_MAX_DATA_PER_TXD;
6386
6387 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006388 }
6389
Alexander Duyck729739b2012-02-08 07:51:06 +00006390 if (likely(!data_len))
6391 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006392
Alexander Duyck472148c2012-11-07 02:34:28 +00006393 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006394
Alexander Duyck729739b2012-02-08 07:51:06 +00006395 i++;
6396 tx_desc++;
6397 if (i == tx_ring->count) {
6398 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6399 i = 0;
6400 }
Alexander Duyckec718252012-10-30 06:01:55 +00006401 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006402
Alexander Duyckd3d00232011-07-15 02:31:25 +00006403#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006404 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006405#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006406 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006407#endif
6408 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006409
Alexander Duyck729739b2012-02-08 07:51:06 +00006410 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6411 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07006412
Alexander Duyck729739b2012-02-08 07:51:06 +00006413 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07006414 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006415
Alexander Duyck729739b2012-02-08 07:51:06 +00006416 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00006417 cmd_type |= size | IXGBE_TXD_CMD;
6418 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006419
Alexander Duyck091a6242012-02-08 07:51:01 +00006420 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006421
Alexander Duyckd3d00232011-07-15 02:31:25 +00006422 /* set the timestamp */
6423 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006424
6425 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006426 * Force memory writes to complete before letting h/w know there
6427 * are new descriptors to fetch. (Only applicable for weak-ordered
6428 * memory model archs, such as IA-64).
6429 *
6430 * We also need this memory barrier to make certain all of the
6431 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006432 */
6433 wmb();
6434
Alexander Duyckd3d00232011-07-15 02:31:25 +00006435 /* set next_to_watch value indicating a packet is present */
6436 first->next_to_watch = tx_desc;
6437
Alexander Duyck729739b2012-02-08 07:51:06 +00006438 i++;
6439 if (i == tx_ring->count)
6440 i = 0;
6441
6442 tx_ring->next_to_use = i;
6443
Alexander Duyckd3d00232011-07-15 02:31:25 +00006444 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006445 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006446
6447 return;
6448dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006449 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006450
6451 /* clear dma mappings for failed tx_buffer_info map */
6452 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006453 tx_buffer = &tx_ring->tx_buffer_info[i];
6454 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6455 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006456 break;
6457 if (i == 0)
6458 i = tx_ring->count;
6459 i--;
6460 }
6461
Alexander Duyckd3d00232011-07-15 02:31:25 +00006462 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006463}
6464
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006465static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006466 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006467{
Alexander Duyck69830522011-01-06 14:29:58 +00006468 struct ixgbe_q_vector *q_vector = ring->q_vector;
6469 union ixgbe_atr_hash_dword input = { .dword = 0 };
6470 union ixgbe_atr_hash_dword common = { .dword = 0 };
6471 union {
6472 unsigned char *network;
6473 struct iphdr *ipv4;
6474 struct ipv6hdr *ipv6;
6475 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006476 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006477 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006478
Alexander Duyck69830522011-01-06 14:29:58 +00006479 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6480 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006481 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006482
Alexander Duyck69830522011-01-06 14:29:58 +00006483 /* do nothing if sampling is disabled */
6484 if (!ring->atr_sample_rate)
6485 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006486
Alexander Duyck69830522011-01-06 14:29:58 +00006487 ring->atr_count++;
6488
6489 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006490 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006491
6492 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006493 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006494 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006495 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006496 hdr.ipv4->protocol != IPPROTO_TCP))
6497 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006498
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006499 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006500
Alexander Duyck66f32a82011-06-29 05:43:22 +00006501 /* skip this packet since it is invalid or the socket is closing */
6502 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006503 return;
6504
6505 /* sample on all syn packets or once every atr sample count */
6506 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6507 return;
6508
6509 /* reset sample count */
6510 ring->atr_count = 0;
6511
Alexander Duyck244e27a2012-02-08 07:51:11 +00006512 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006513
6514 /*
6515 * src and dst are inverted, think how the receiver sees them
6516 *
6517 * The input is broken into two sections, a non-compressed section
6518 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6519 * is XORed together and stored in the compressed dword.
6520 */
6521 input.formatted.vlan_id = vlan_id;
6522
6523 /*
6524 * since src port and flex bytes occupy the same word XOR them together
6525 * and write the value to source port portion of compressed dword
6526 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006527 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006528 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6529 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006530 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006531 common.port.dst ^= th->source;
6532
Alexander Duyck244e27a2012-02-08 07:51:11 +00006533 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006534 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6535 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6536 } else {
6537 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6538 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6539 hdr.ipv6->saddr.s6_addr32[1] ^
6540 hdr.ipv6->saddr.s6_addr32[2] ^
6541 hdr.ipv6->saddr.s6_addr32[3] ^
6542 hdr.ipv6->daddr.s6_addr32[0] ^
6543 hdr.ipv6->daddr.s6_addr32[1] ^
6544 hdr.ipv6->daddr.s6_addr32[2] ^
6545 hdr.ipv6->daddr.s6_addr32[3];
6546 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006547
6548 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006549 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6550 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006551}
6552
Alexander Duyck63544e92011-05-27 05:31:42 +00006553static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006554{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006555 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006556 /* Herbert's original patch had:
6557 * smp_mb__after_netif_stop_queue();
6558 * but since that doesn't exist yet, just open code it. */
6559 smp_mb();
6560
6561 /* We need to check again in a case another CPU has just
6562 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006563 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006564 return -EBUSY;
6565
6566 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006567 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006568 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006569 return 0;
6570}
6571
Alexander Duyck82d4e462011-06-11 01:44:58 +00006572static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006573{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006574 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006575 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006576 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006577}
6578
Alexander Duyck97488bd2013-01-12 06:33:37 +00006579#ifdef IXGBE_FCOE
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006580static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6581{
Alexander Duyck97488bd2013-01-12 06:33:37 +00006582 struct ixgbe_adapter *adapter;
6583 struct ixgbe_ring_feature *f;
6584 int txq;
Hao Zheng5e09a102010-11-11 13:47:59 +00006585
Alexander Duyck97488bd2013-01-12 06:33:37 +00006586 /*
6587 * only execute the code below if protocol is FCoE
6588 * or FIP and we have FCoE enabled on the adapter
6589 */
6590 switch (vlan_get_protocol(skb)) {
6591 case __constant_htons(ETH_P_FCOE):
6592 case __constant_htons(ETH_P_FIP):
6593 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00006594
Alexander Duyck97488bd2013-01-12 06:33:37 +00006595 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
6596 break;
6597 default:
6598 return __netdev_pick_tx(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006599 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006600
Alexander Duyck97488bd2013-01-12 06:33:37 +00006601 f = &adapter->ring_feature[RING_F_FCOE];
6602
6603 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6604 smp_processor_id();
6605
6606 while (txq >= f->indices)
6607 txq -= f->indices;
6608
6609 return txq + f->offset;
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006610}
6611
Alexander Duyck97488bd2013-01-12 06:33:37 +00006612#endif
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006613netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006614 struct ixgbe_adapter *adapter,
6615 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006616{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006617 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006618 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006619 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006620 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00006621 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006622 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006623 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006624
Alexander Duycka535c302011-05-27 05:31:52 +00006625 /*
6626 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006627 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006628 * + 2 desc gap to keep tail from touching head,
6629 * + 1 desc for context descriptor,
6630 * otherwise try next time
6631 */
Alexander Duycka535c302011-05-27 05:31:52 +00006632 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6633 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00006634
Alexander Duycka535c302011-05-27 05:31:52 +00006635 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6636 tx_ring->tx_stats.tx_busy++;
6637 return NETDEV_TX_BUSY;
6638 }
6639
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006640 /* record the location of the first descriptor for this packet */
6641 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6642 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006643 first->bytecount = skb->len;
6644 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006645
Alexander Duyck66f32a82011-06-29 05:43:22 +00006646 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006647 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006648 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6649 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6650 /* else if it is a SW VLAN check the next protocol and store the tag */
6651 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6652 struct vlan_hdr *vhdr, _vhdr;
6653 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6654 if (!vhdr)
6655 goto out_drop;
6656
6657 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006658 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6659 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006660 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006661 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006662
Jacob Kelleraa7bd462012-05-04 01:55:23 +00006663 skb_tx_timestamp(skb);
6664
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006665 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6666 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6667 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00006668
6669 /* schedule check for Tx timestamp */
6670 adapter->ptp_tx_skb = skb_get(skb);
6671 adapter->ptp_tx_start = jiffies;
6672 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006673 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006674
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006675#ifdef CONFIG_PCI_IOV
6676 /*
6677 * Use the l2switch_enable flag - would be false if the DMA
6678 * Tx switch had been disabled.
6679 */
6680 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00006681 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006682
6683#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006684 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006685 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006686 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6687 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006688 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006689 tx_flags |= (skb->priority & 0x7) <<
6690 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006691 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6692 struct vlan_ethhdr *vhdr;
6693 if (skb_header_cloned(skb) &&
6694 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6695 goto out_drop;
6696 vhdr = (struct vlan_ethhdr *)skb->data;
6697 vhdr->h_vlan_TCI = htons(tx_flags >>
6698 IXGBE_TX_FLAGS_VLAN_SHIFT);
6699 } else {
6700 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6701 }
6702 }
Alexander Duycka535c302011-05-27 05:31:52 +00006703
Alexander Duyck244e27a2012-02-08 07:51:11 +00006704 /* record initial flags and protocol */
6705 first->tx_flags = tx_flags;
6706 first->protocol = protocol;
6707
Yi Zoueacd73f2009-05-13 13:11:06 +00006708#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006709 /* setup tx offload for FCoE */
6710 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00006711 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006712 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006713 if (tso < 0)
6714 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006715
Alexander Duyck66f32a82011-06-29 05:43:22 +00006716 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006717 }
Auke Kok9a799d72007-09-15 14:07:45 -07006718
Auke Kok9a799d72007-09-15 14:07:45 -07006719#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006720 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006721 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006722 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006723 else if (!tso)
6724 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006725
6726 /* add the ATR filter if ATR is on */
6727 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006728 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006729
6730#ifdef IXGBE_FCOE
6731xmit_fcoe:
6732#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006733 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006734
6735 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006736
6737 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006738
6739out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006740 dev_kfree_skb_any(first->skb);
6741 first->skb = NULL;
6742
Alexander Duyck897ab152011-05-27 05:31:47 +00006743 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006744}
6745
Alexander Duycka50c29d2012-02-08 07:50:40 +00006746static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6747 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006748{
6749 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006750 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006751
Alexander Duycka50c29d2012-02-08 07:50:40 +00006752 /*
6753 * The minimum packet size for olinfo paylen is 17 so pad the skb
6754 * in order to meet this minimum size requirement.
6755 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00006756 if (unlikely(skb->len < 17)) {
6757 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00006758 return NETDEV_TX_OK;
6759 skb->len = 17;
Tushar Dave71a49f72012-09-14 04:24:49 +00006760 skb_set_tail_pointer(skb, 17);
Alexander Duycka50c29d2012-02-08 07:50:40 +00006761 }
6762
Auke Kok9a799d72007-09-15 14:07:45 -07006763 tx_ring = adapter->tx_ring[skb->queue_mapping];
6764 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6765}
6766
6767/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006768 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006769 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006770 * @p: pointer to an address structure
6771 *
Auke Kok9a799d72007-09-15 14:07:45 -07006772 * Returns 0 on success, negative on failure
6773 **/
6774static int ixgbe_set_mac(struct net_device *netdev, void *p)
6775{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006776 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6777 struct ixgbe_hw *hw = &adapter->hw;
6778 struct sockaddr *addr = p;
6779
6780 if (!is_valid_ether_addr(addr->sa_data))
6781 return -EADDRNOTAVAIL;
6782
6783 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6784 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6785
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00006786 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006787
6788 return 0;
6789}
6790
Ben Hutchings6b73e102009-04-29 08:08:58 +00006791static int
6792ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6793{
6794 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6795 struct ixgbe_hw *hw = &adapter->hw;
6796 u16 value;
6797 int rc;
6798
6799 if (prtad != hw->phy.mdio.prtad)
6800 return -EINVAL;
6801 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6802 if (!rc)
6803 rc = value;
6804 return rc;
6805}
6806
6807static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6808 u16 addr, u16 value)
6809{
6810 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6811 struct ixgbe_hw *hw = &adapter->hw;
6812
6813 if (prtad != hw->phy.mdio.prtad)
6814 return -EINVAL;
6815 return hw->phy.ops.write_reg(hw, addr, devad, value);
6816}
6817
6818static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6819{
6820 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6821
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006822 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006823 case SIOCSHWTSTAMP:
6824 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006825 default:
6826 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6827 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00006828}
6829
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006830/**
6831 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006832 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006833 * @netdev: network interface device structure
6834 *
6835 * Returns non-zero on failure
6836 **/
6837static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6838{
6839 int err = 0;
6840 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006841 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006842
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006843 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006844 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006845 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006846 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006847
6848 /* update SAN MAC vmdq pool selection */
6849 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006850 }
6851 return err;
6852}
6853
6854/**
6855 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006856 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006857 * @netdev: network interface device structure
6858 *
6859 * Returns non-zero on failure
6860 **/
6861static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6862{
6863 int err = 0;
6864 struct ixgbe_adapter *adapter = netdev_priv(dev);
6865 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6866
6867 if (is_valid_ether_addr(mac->san_addr)) {
6868 rtnl_lock();
6869 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6870 rtnl_unlock();
6871 }
6872 return err;
6873}
6874
Auke Kok9a799d72007-09-15 14:07:45 -07006875#ifdef CONFIG_NET_POLL_CONTROLLER
6876/*
6877 * Polling 'interrupt' - used by things like netconsole to send skbs
6878 * without having to re-enable interrupts. It's not called while
6879 * the interrupt routine is executing.
6880 */
6881static void ixgbe_netpoll(struct net_device *netdev)
6882{
6883 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006884 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006885
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006886 /* if interface is down do nothing */
6887 if (test_bit(__IXGBE_DOWN, &adapter->state))
6888 return;
6889
Auke Kok9a799d72007-09-15 14:07:45 -07006890 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006891 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006892 for (i = 0; i < adapter->num_q_vectors; i++)
6893 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006894 } else {
6895 ixgbe_intr(adapter->pdev->irq, netdev);
6896 }
Auke Kok9a799d72007-09-15 14:07:45 -07006897 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006898}
Auke Kok9a799d72007-09-15 14:07:45 -07006899
Alexander Duyck581330b2012-02-08 07:51:47 +00006900#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006901static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6902 struct rtnl_link_stats64 *stats)
6903{
6904 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6905 int i;
6906
Eric Dumazet1a515022010-11-16 19:26:42 -08006907 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006908 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006909 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006910 u64 bytes, packets;
6911 unsigned int start;
6912
Eric Dumazet1a515022010-11-16 19:26:42 -08006913 if (ring) {
6914 do {
6915 start = u64_stats_fetch_begin_bh(&ring->syncp);
6916 packets = ring->stats.packets;
6917 bytes = ring->stats.bytes;
6918 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6919 stats->rx_packets += packets;
6920 stats->rx_bytes += bytes;
6921 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006922 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006923
6924 for (i = 0; i < adapter->num_tx_queues; i++) {
6925 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6926 u64 bytes, packets;
6927 unsigned int start;
6928
6929 if (ring) {
6930 do {
6931 start = u64_stats_fetch_begin_bh(&ring->syncp);
6932 packets = ring->stats.packets;
6933 bytes = ring->stats.bytes;
6934 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6935 stats->tx_packets += packets;
6936 stats->tx_bytes += bytes;
6937 }
6938 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006939 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006940 /* following stats updated by ixgbe_watchdog_task() */
6941 stats->multicast = netdev->stats.multicast;
6942 stats->rx_errors = netdev->stats.rx_errors;
6943 stats->rx_length_errors = netdev->stats.rx_length_errors;
6944 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6945 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6946 return stats;
6947}
6948
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006949#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006950/**
6951 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6952 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00006953 * @tc: number of traffic classes currently enabled
6954 *
6955 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6956 * 802.1Q priority maps to a packet buffer that exists.
6957 */
6958static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6959{
6960 struct ixgbe_hw *hw = &adapter->hw;
6961 u32 reg, rsave;
6962 int i;
6963
6964 /* 82598 have a static priority to TC mapping that can not
6965 * be changed so no validation is needed.
6966 */
6967 if (hw->mac.type == ixgbe_mac_82598EB)
6968 return;
6969
6970 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6971 rsave = reg;
6972
6973 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6974 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6975
6976 /* If up2tc is out of bounds default to zero */
6977 if (up2tc > tc)
6978 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6979 }
6980
6981 if (reg != rsave)
6982 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6983
6984 return;
6985}
6986
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006987/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00006988 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6989 * @adapter: Pointer to adapter struct
6990 *
6991 * Populate the netdev user priority to tc map
6992 */
6993static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6994{
6995 struct net_device *dev = adapter->netdev;
6996 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6997 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6998 u8 prio;
6999
7000 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
7001 u8 tc = 0;
7002
7003 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
7004 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
7005 else if (ets)
7006 tc = ets->prio_tc[prio];
7007
7008 netdev_set_prio_tc_map(dev, prio, tc);
7009 }
7010}
7011
Alexander Duyckcca73c52013-01-12 06:33:44 +00007012#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00007013/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007014 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00007015 *
7016 * @netdev: net device to configure
7017 * @tc: number of traffic classes to enable
7018 */
7019int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7020{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007021 struct ixgbe_adapter *adapter = netdev_priv(dev);
7022 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007023
John Fastabend8b1c0b22011-05-03 02:26:48 +00007024 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007025 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00007026 (hw->mac.type == ixgbe_mac_82598EB &&
7027 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00007028 return -EINVAL;
7029
7030 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007031 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007032 * hardware is not flexible enough to do this dynamically.
7033 */
7034 if (netif_running(dev))
7035 ixgbe_close(dev);
7036 ixgbe_clear_interrupt_scheme(adapter);
7037
Alexander Duyckcca73c52013-01-12 06:33:44 +00007038#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00007039 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007040 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007041 ixgbe_set_prio_tc_map(adapter);
7042
John Fastabende7589ea2011-07-18 22:38:36 +00007043 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007044
Alexander Duyck943561d2012-05-09 22:14:44 -07007045 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
7046 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007047 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07007048 }
John Fastabende7589ea2011-07-18 22:38:36 +00007049 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007050 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00007051
Alexander Duyck943561d2012-05-09 22:14:44 -07007052 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7053 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007054
7055 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00007056
7057 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7058 adapter->dcb_cfg.pfc_mode_enable = false;
7059 }
7060
John Fastabend8b1c0b22011-05-03 02:26:48 +00007061 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00007062
7063#endif /* CONFIG_IXGBE_DCB */
7064 ixgbe_init_interrupt_scheme(adapter);
7065
John Fastabend8b1c0b22011-05-03 02:26:48 +00007066 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00007067 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00007068
7069 return 0;
7070}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007071
Greg Roseda36b642012-12-11 08:26:43 +00007072#ifdef CONFIG_PCI_IOV
7073void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
7074{
7075 struct net_device *netdev = adapter->netdev;
7076
7077 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00007078 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00007079 rtnl_unlock();
7080}
7081
7082#endif
Don Skidmore082757a2011-07-21 05:55:00 +00007083void ixgbe_do_reset(struct net_device *netdev)
7084{
7085 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7086
7087 if (netif_running(netdev))
7088 ixgbe_reinit_locked(adapter);
7089 else
7090 ixgbe_reset(adapter);
7091}
7092
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007093static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007094 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007095{
7096 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7097
Don Skidmore082757a2011-07-21 05:55:00 +00007098 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007099 if (!(features & NETIF_F_RXCSUM))
7100 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00007101
Alexander Duyck567d2de2012-02-11 07:18:57 +00007102 /* Turn off LRO if not RSC capable */
7103 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
7104 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007105
Alexander Duyck567d2de2012-02-11 07:18:57 +00007106 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00007107}
7108
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007109static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007110 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007111{
7112 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00007113 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00007114 bool need_reset = false;
7115
Don Skidmore082757a2011-07-21 05:55:00 +00007116 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007117 if (!(features & NETIF_F_LRO)) {
7118 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00007119 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00007120 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
7121 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
7122 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7123 if (adapter->rx_itr_setting == 1 ||
7124 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
7125 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
7126 need_reset = true;
7127 } else if ((changed ^ features) & NETIF_F_LRO) {
7128 e_info(probe, "rx-usecs set too low, "
7129 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00007130 }
7131 }
7132
7133 /*
7134 * Check if Flow Director n-tuple support was enabled or disabled. If
7135 * the state changed, we need to reset.
7136 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007137 switch (features & NETIF_F_NTUPLE) {
7138 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00007139 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007140 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
7141 need_reset = true;
7142
Alexander Duyck567d2de2012-02-11 07:18:57 +00007143 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7144 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00007145 break;
7146 default:
7147 /* turn off perfect filters, enable ATR and reset */
7148 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7149 need_reset = true;
7150
7151 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7152
7153 /* We cannot enable ATR if SR-IOV is enabled */
7154 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7155 break;
7156
7157 /* We cannot enable ATR if we have 2 or more traffic classes */
7158 if (netdev_get_num_tc(netdev) > 1)
7159 break;
7160
7161 /* We cannot enable ATR if RSS is disabled */
7162 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
7163 break;
7164
7165 /* A sample rate of 0 indicates ATR disabled */
7166 if (!adapter->atr_sample_rate)
7167 break;
7168
7169 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7170 break;
Don Skidmore082757a2011-07-21 05:55:00 +00007171 }
7172
Patrick McHardyf6469682013-04-19 02:04:27 +00007173 if (features & NETIF_F_HW_VLAN_CTAG_RX)
John Fastabend146d4cc2012-05-15 05:59:26 +00007174 ixgbe_vlan_strip_enable(adapter);
7175 else
7176 ixgbe_vlan_strip_disable(adapter);
7177
Ben Greear3f2d1c02012-03-08 08:28:41 +00007178 if (changed & NETIF_F_RXALL)
7179 need_reset = true;
7180
Alexander Duyck567d2de2012-02-11 07:18:57 +00007181 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00007182 if (need_reset)
7183 ixgbe_do_reset(netdev);
7184
7185 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00007186}
7187
stephen hemmingeredc7d572012-10-01 12:32:33 +00007188static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007189 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00007190 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007191 u16 flags)
7192{
7193 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend95447462012-05-31 12:42:26 +00007194 int err;
7195
7196 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
Vlad Yasevichfaaf02d2013-03-06 15:39:43 +00007197 return ndo_dflt_fdb_add(ndm, tb, dev, addr, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007198
John Fastabendb1ac1ef2012-11-01 05:00:44 +00007199 /* Hardware does not support aging addresses so if a
7200 * ndm_state is given only allow permanent addresses
7201 */
7202 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007203 pr_info("%s: FDB only supports static addresses\n",
7204 ixgbe_driver_name);
7205 return -EINVAL;
7206 }
7207
Ben Hutchings46acc462012-11-01 09:11:11 +00007208 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
John Fastabend95447462012-05-31 12:42:26 +00007209 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
7210
7211 if (netdev_uc_count(dev) < rar_uc_entries)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007212 err = dev_uc_add_excl(dev, addr);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007213 else
John Fastabend95447462012-05-31 12:42:26 +00007214 err = -ENOMEM;
7215 } else if (is_multicast_ether_addr(addr)) {
7216 err = dev_mc_add_excl(dev, addr);
7217 } else {
7218 err = -EINVAL;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007219 }
7220
7221 /* Only return duplicate errors if NLM_F_EXCL is set */
7222 if (err == -EEXIST && !(flags & NLM_F_EXCL))
7223 err = 0;
7224
7225 return err;
7226}
7227
John Fastabend815cccb2012-10-24 08:13:09 +00007228static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7229 struct nlmsghdr *nlh)
7230{
7231 struct ixgbe_adapter *adapter = netdev_priv(dev);
7232 struct nlattr *attr, *br_spec;
7233 int rem;
7234
7235 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7236 return -EOPNOTSUPP;
7237
7238 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7239
7240 nla_for_each_nested(attr, br_spec, rem) {
7241 __u16 mode;
7242 u32 reg = 0;
7243
7244 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7245 continue;
7246
7247 mode = nla_get_u16(attr);
Greg Rose9b735982012-11-08 02:41:35 +00007248 if (mode == BRIDGE_MODE_VEPA) {
John Fastabend815cccb2012-10-24 08:13:09 +00007249 reg = 0;
Greg Rose9b735982012-11-08 02:41:35 +00007250 adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB;
7251 } else if (mode == BRIDGE_MODE_VEB) {
John Fastabend815cccb2012-10-24 08:13:09 +00007252 reg = IXGBE_PFDTXGSWC_VT_LBEN;
Greg Rose9b735982012-11-08 02:41:35 +00007253 adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB;
7254 } else
John Fastabend815cccb2012-10-24 08:13:09 +00007255 return -EINVAL;
7256
7257 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7258
7259 e_info(drv, "enabling bridge mode: %s\n",
7260 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7261 }
7262
7263 return 0;
7264}
7265
7266static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00007267 struct net_device *dev,
7268 u32 filter_mask)
John Fastabend815cccb2012-10-24 08:13:09 +00007269{
7270 struct ixgbe_adapter *adapter = netdev_priv(dev);
7271 u16 mode;
7272
7273 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7274 return 0;
7275
Greg Rose9b735982012-11-08 02:41:35 +00007276 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
John Fastabend815cccb2012-10-24 08:13:09 +00007277 mode = BRIDGE_MODE_VEB;
7278 else
7279 mode = BRIDGE_MODE_VEPA;
7280
7281 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7282}
7283
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007284static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007285 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007286 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007287 .ndo_start_xmit = ixgbe_xmit_frame,
Alexander Duyck97488bd2013-01-12 06:33:37 +00007288#ifdef IXGBE_FCOE
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007289 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck97488bd2013-01-12 06:33:37 +00007290#endif
Alexander Duyck581330b2012-02-08 07:51:47 +00007291 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007292 .ndo_validate_addr = eth_validate_addr,
7293 .ndo_set_mac_address = ixgbe_set_mac,
7294 .ndo_change_mtu = ixgbe_change_mtu,
7295 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007296 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7297 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007298 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007299 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7300 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7301 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007302 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007303 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007304 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007305#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007306 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007307#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007308#ifdef CONFIG_NET_POLL_CONTROLLER
7309 .ndo_poll_controller = ixgbe_netpoll,
7310#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03007311#ifdef CONFIG_NET_LL_RX_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +03007312 .ndo_busy_poll = ixgbe_low_latency_recv,
Eliezer Tamir5a85e732013-06-10 11:40:20 +03007313#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007314#ifdef IXGBE_FCOE
7315 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007316 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007317 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007318 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7319 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007320 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007321 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007322#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007323 .ndo_set_features = ixgbe_set_features,
7324 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007325 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00007326 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7327 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007328};
7329
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007330/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00007331 * ixgbe_enumerate_functions - Get the number of ports this device has
7332 * @adapter: adapter structure
7333 *
7334 * This function enumerates the phsyical functions co-located on a single slot,
7335 * in order to determine how many ports a device has. This is most useful in
7336 * determining the required GT/s of PCIe bandwidth necessary for optimal
7337 * performance.
7338 **/
7339static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
7340{
7341 struct ixgbe_hw *hw = &adapter->hw;
7342 struct list_head *entry;
7343 int physfns = 0;
7344
7345 /* Some cards can not use the generic count PCIe functions method, and
7346 * so must be hardcoded to the correct value.
7347 */
7348 switch (hw->device_id) {
7349 case IXGBE_DEV_ID_82599_SFP_SF_QP:
7350 physfns = 4;
7351 break;
7352 default:
7353 list_for_each(entry, &adapter->pdev->bus_list) {
7354 struct pci_dev *pdev =
7355 list_entry(entry, struct pci_dev, bus_list);
7356 /* don't count virtual functions */
7357 if (!pdev->is_virtfn)
7358 physfns++;
7359 }
7360 }
7361
7362 return physfns;
7363}
7364
7365/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007366 * ixgbe_wol_supported - Check whether device supports WoL
7367 * @hw: hw specific details
7368 * @device_id: the device ID
7369 * @subdev_id: the subsystem device ID
7370 *
7371 * This function is used by probe and ethtool to determine
7372 * which devices have WoL support
7373 *
7374 **/
7375int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7376 u16 subdevice_id)
7377{
7378 struct ixgbe_hw *hw = &adapter->hw;
7379 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7380 int is_wol_supported = 0;
7381
7382 switch (device_id) {
7383 case IXGBE_DEV_ID_82599_SFP:
7384 /* Only these subdevices could supports WOL */
7385 switch (subdevice_id) {
7386 case IXGBE_SUBDEV_ID_82599_560FLR:
7387 /* only support first port */
7388 if (hw->bus.func != 0)
7389 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00007390 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007391 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007392 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00007393 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller979fe5f2013-04-03 04:41:37 +00007394 case IXGBE_SUBDEV_ID_82599_LOM_SFP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007395 is_wol_supported = 1;
7396 break;
7397 }
7398 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00007399 case IXGBE_DEV_ID_82599EN_SFP:
7400 /* Only this subdevice supports WOL */
7401 switch (subdevice_id) {
7402 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
7403 is_wol_supported = 1;
7404 break;
7405 }
7406 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007407 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7408 /* All except this subdevice support WOL */
7409 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7410 is_wol_supported = 1;
7411 break;
7412 case IXGBE_DEV_ID_82599_KX4:
7413 is_wol_supported = 1;
7414 break;
7415 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007416 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007417 /* check eeprom to see if enabled wol */
7418 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7419 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7420 (hw->bus.func == 0))) {
7421 is_wol_supported = 1;
7422 }
7423 break;
7424 }
7425
7426 return is_wol_supported;
7427}
7428
7429/**
Auke Kok9a799d72007-09-15 14:07:45 -07007430 * ixgbe_probe - Device Initialization Routine
7431 * @pdev: PCI device information struct
7432 * @ent: entry in ixgbe_pci_tbl
7433 *
7434 * Returns 0 on success, negative on failure
7435 *
7436 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7437 * The OS initialization, configuring of the adapter private structure,
7438 * and a hardware reset occur.
7439 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00007440static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007441{
7442 struct net_device *netdev;
7443 struct ixgbe_adapter *adapter = NULL;
7444 struct ixgbe_hw *hw;
7445 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007446 static int cards_found;
Jacob Kellere027d1a2013-07-31 06:53:31 +00007447 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007448 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00007449 u8 part_str[IXGBE_PBANUM_LENGTH];
Yi Zoueacd73f2009-05-13 13:11:06 +00007450#ifdef IXGBE_FCOE
7451 u16 device_caps;
7452#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007453 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007454
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007455 /* Catch broken hardware that put the wrong VF device ID in
7456 * the PCIe SR-IOV capability.
7457 */
7458 if (pdev->is_virtfn) {
7459 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7460 pci_name(pdev), pdev->vendor, pdev->device);
7461 return -EINVAL;
7462 }
7463
gouji-new9ce77662009-05-06 10:44:45 +00007464 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007465 if (err)
7466 return err;
7467
Nick Nunley1b507732010-04-27 13:10:27 +00007468 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7469 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007470 pci_using_dac = 1;
7471 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007472 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007473 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007474 err = dma_set_coherent_mask(&pdev->dev,
7475 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007476 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007477 dev_err(&pdev->dev,
7478 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007479 goto err_dma;
7480 }
7481 }
7482 pci_using_dac = 0;
7483 }
7484
gouji-new9ce77662009-05-06 10:44:45 +00007485 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007486 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007487 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007488 dev_err(&pdev->dev,
7489 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007490 goto err_pci_reg;
7491 }
7492
Frans Pop19d5afd2009-10-02 10:04:12 -07007493 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007494
Auke Kok9a799d72007-09-15 14:07:45 -07007495 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007496 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007497
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007498 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00007499#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007500 /* 8 TC w/ 4 queues per TC */
7501 indices = 4 * MAX_TRAFFIC_CLASS;
7502#else
7503 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00007504#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007505 }
John Fastabende901acd2011-04-26 07:26:08 +00007506
John Fastabendc85a2612010-02-25 23:15:21 +00007507 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007508 if (!netdev) {
7509 err = -ENOMEM;
7510 goto err_alloc_etherdev;
7511 }
7512
Auke Kok9a799d72007-09-15 14:07:45 -07007513 SET_NETDEV_DEV(netdev, &pdev->dev);
7514
Auke Kok9a799d72007-09-15 14:07:45 -07007515 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007516 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007517
7518 adapter->netdev = netdev;
7519 adapter->pdev = pdev;
7520 hw = &adapter->hw;
7521 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007522 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007523
Jeff Kirsher05857982008-09-11 19:57:00 -07007524 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007525 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007526 if (!hw->hw_addr) {
7527 err = -EIO;
7528 goto err_ioremap;
7529 }
7530
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007531 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007532 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007533 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007534 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007535
Auke Kok9a799d72007-09-15 14:07:45 -07007536 adapter->bd_number = cards_found;
7537
Auke Kok9a799d72007-09-15 14:07:45 -07007538 /* Setup hw api */
7539 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007540 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007541
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007542 /* EEPROM */
7543 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7544 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7545 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7546 if (!(eec & (1 << 8)))
7547 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7548
7549 /* PHY */
7550 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007551 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007552 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7553 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7554 hw->phy.mdio.mmds = 0;
7555 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7556 hw->phy.mdio.dev = netdev;
7557 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7558 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007559
Don Skidmore8ca783a2009-05-26 20:40:47 -07007560 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007561
7562 /* setup the private structure */
7563 err = ixgbe_sw_init(adapter);
7564 if (err)
7565 goto err_sw_init;
7566
Don Skidmore0b2679d2013-02-21 03:00:04 +00007567 /* Cache if MNG FW is up so we don't have to read the REG later */
7568 if (hw->mac.ops.mng_fw_enabled)
7569 hw->mng_fw_enabled = hw->mac.ops.mng_fw_enabled(hw);
7570
Don Skidmoree86bff02010-02-11 04:14:08 +00007571 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007572 switch (adapter->hw.mac.type) {
7573 case ixgbe_mac_82599EB:
7574 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007575 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007576 break;
7577 default:
7578 break;
7579 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007580
Don Skidmorebf069c92009-05-07 10:39:54 +00007581 /*
7582 * If there is a fan on this device and it has failed log the
7583 * failure.
7584 */
7585 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7586 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7587 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007588 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007589 }
7590
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007591 if (allow_unsupported_sfp)
7592 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7593
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007594 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007595 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007596 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007597 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007598 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7599 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007600 err = 0;
7601 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007602 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007603 "module type was detected.\n");
7604 e_dev_err("Reload the driver after installing a supported "
7605 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007606 goto err_sw_init;
7607 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007608 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007609 goto err_sw_init;
7610 }
7611
Alexander Duyck99d74482012-05-09 08:09:25 +00007612#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00007613 /* SR-IOV not supported on the 82598 */
7614 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7615 goto skip_sriov;
7616 /* Mailbox */
7617 ixgbe_init_mbx_params_pf(hw);
7618 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
7619 ixgbe_enable_sriov(adapter);
Donald Dutile43dc4e02012-12-11 08:26:48 +00007620 pci_sriov_set_totalvfs(pdev, 63);
Greg Rose60a1a682012-12-11 08:26:33 +00007621skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007622
Alexander Duyck99d74482012-05-09 08:09:25 +00007623#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00007624 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007625 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007626 NETIF_F_IPV6_CSUM |
Patrick McHardyf6469682013-04-19 02:04:27 +00007627 NETIF_F_HW_VLAN_CTAG_TX |
7628 NETIF_F_HW_VLAN_CTAG_RX |
7629 NETIF_F_HW_VLAN_CTAG_FILTER |
Don Skidmore082757a2011-07-21 05:55:00 +00007630 NETIF_F_TSO |
7631 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007632 NETIF_F_RXHASH |
7633 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007634
Don Skidmore082757a2011-07-21 05:55:00 +00007635 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007636
Don Skidmore58be7662011-04-12 09:42:11 +00007637 switch (adapter->hw.mac.type) {
7638 case ixgbe_mac_82599EB:
7639 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007640 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007641 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7642 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007643 break;
7644 default:
7645 break;
7646 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007647
Ben Greear3f2d1c02012-03-08 08:28:41 +00007648 netdev->hw_features |= NETIF_F_RXALL;
7649
Jeff Kirsherad31c402008-06-05 04:05:30 -07007650 netdev->vlan_features |= NETIF_F_TSO;
7651 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007652 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007653 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007654 netdev->vlan_features |= NETIF_F_SG;
7655
Jiri Pirko01789342011-08-16 06:29:00 +00007656 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007657 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007658
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007659#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007660 netdev->dcbnl_ops = &dcbnl_ops;
7661#endif
7662
Yi Zoueacd73f2009-05-13 13:11:06 +00007663#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007664 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007665 unsigned int fcoe_l;
7666
Yi Zoueacd73f2009-05-13 13:11:06 +00007667 if (hw->mac.ops.get_device_caps) {
7668 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007669 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7670 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007671 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007672
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007673
7674 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
7675 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007676
Alexander Duycka58915c2012-05-25 06:38:18 +00007677 netdev->features |= NETIF_F_FSO |
7678 NETIF_F_FCOE_CRC;
7679
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007680 netdev->vlan_features |= NETIF_F_FSO |
7681 NETIF_F_FCOE_CRC |
7682 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00007683 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007684#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007685 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007686 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007687 netdev->vlan_features |= NETIF_F_HIGHDMA;
7688 }
Auke Kok9a799d72007-09-15 14:07:45 -07007689
Don Skidmore082757a2011-07-21 05:55:00 +00007690 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7691 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007692 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007693 netdev->features |= NETIF_F_LRO;
7694
Auke Kok9a799d72007-09-15 14:07:45 -07007695 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007696 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007697 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007698 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007699 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007700 }
7701
7702 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007703
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00007704 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007705 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007706 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007707 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007708 }
7709
Alexander Duyck70864002011-04-27 09:13:56 +00007710 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007711 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007712
Alexander Duyck70864002011-04-27 09:13:56 +00007713 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7714 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007715
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007716 err = ixgbe_init_interrupt_scheme(adapter);
7717 if (err)
7718 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007719
Jacob Keller8e2813f2012-04-21 06:05:40 +00007720 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007721 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007722 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00007723 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00007724 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00007725 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007726 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007727
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007728 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7729
Emil Tantilov15e52092011-09-29 05:01:29 +00007730 /* save off EEPROM version number */
7731 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7732 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7733
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007734 /* pick up the PCI bus settings for reporting later */
7735 hw->mac.ops.get_bus_info(hw);
Jacob Kellere027d1a2013-07-31 06:53:31 +00007736 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +00007737 ixgbe_get_parent_bus_info(adapter);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007738
Auke Kok9a799d72007-09-15 14:07:45 -07007739 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007740 e_dev_info("(PCI Express:%s:%s) %pM\n",
Jacob Kellere8710a52013-02-15 09:18:10 +00007741 (hw->bus.speed == ixgbe_bus_speed_8000 ? "8.0GT/s" :
7742 hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
Don Skidmore67163442011-04-26 08:00:00 +00007743 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007744 "Unknown"),
7745 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7746 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7747 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7748 "Unknown"),
7749 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007750
7751 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7752 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007753 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007754 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007755 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007756 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007757 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007758 else
Don Skidmore289700db2010-12-03 03:32:58 +00007759 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7760 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007761
Jacob Kellere027d1a2013-07-31 06:53:31 +00007762 /* calculate the expected PCIe bandwidth required for optimal
7763 * performance. Note that some older parts will never have enough
7764 * bandwidth due to being older generation PCIe parts. We clamp these
7765 * parts to ensure no warning is displayed if it can't be fixed.
7766 */
7767 switch (hw->mac.type) {
7768 case ixgbe_mac_82598EB:
7769 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
7770 break;
7771 default:
7772 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
7773 break;
Auke Kok0c254d82008-02-11 09:25:56 -08007774 }
Jacob Kellere027d1a2013-07-31 06:53:31 +00007775 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -08007776
Auke Kok9a799d72007-09-15 14:07:45 -07007777 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007778 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007779 if (err == IXGBE_ERR_EEPROM_VERSION) {
7780 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007781 e_dev_warn("This device is a pre-production adapter/LOM. "
7782 "Please be aware there may be issues associated "
7783 "with your hardware. If you are experiencing "
7784 "problems please contact your Intel or hardware "
7785 "representative who provided you with this "
7786 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007787 }
Auke Kok9a799d72007-09-15 14:07:45 -07007788 strcpy(netdev->name, "eth%d");
7789 err = register_netdev(netdev);
7790 if (err)
7791 goto err_register;
7792
Emil Tantilovec74a472012-09-20 03:33:56 +00007793 /* power down the optics for 82599 SFP+ fiber */
7794 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007795 hw->mac.ops.disable_tx_laser(hw);
7796
Jesse Brandeburg54386462009-04-17 20:44:27 +00007797 /* carrier off reporting is important to ethtool even BEFORE open */
7798 netif_carrier_off(netdev);
7799
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007800#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007801 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007802 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007803 ixgbe_setup_dca(adapter);
7804 }
7805#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007806 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007807 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007808 for (i = 0; i < adapter->num_vfs; i++)
7809 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7810 }
7811
Jacob Keller2466dd92011-09-08 03:50:54 +00007812 /* firmware requires driver version to be 0xFFFFFFFF
7813 * since os does not support feature
7814 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007815 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007816 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7817 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007818
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007819 /* add san mac addr to netdev */
7820 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007821
Neerav Parikhea818752012-01-04 20:23:40 +00007822 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007823 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007824
Don Skidmore12109822012-05-04 06:07:08 +00007825#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007826 if (ixgbe_sysfs_init(adapter))
7827 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00007828#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007829
Catherine Sullivan00949162012-08-10 01:59:10 +00007830 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00007831
Don Skidmore0b2679d2013-02-21 03:00:04 +00007832 /* Need link setup for MNG FW, else wait for IXGBE_UP */
7833 if (hw->mng_fw_enabled && hw->mac.ops.setup_link)
7834 hw->mac.ops.setup_link(hw,
7835 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
7836 true);
7837
Auke Kok9a799d72007-09-15 14:07:45 -07007838 return 0;
7839
7840err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007841 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007842 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007843err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00007844 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007845 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007846 iounmap(hw->hw_addr);
7847err_ioremap:
7848 free_netdev(netdev);
7849err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007850 pci_release_selected_regions(pdev,
7851 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007852err_pci_reg:
7853err_dma:
7854 pci_disable_device(pdev);
7855 return err;
7856}
7857
7858/**
7859 * ixgbe_remove - Device Removal Routine
7860 * @pdev: PCI device information struct
7861 *
7862 * ixgbe_remove is called by the PCI subsystem to alert the driver
7863 * that it should release a PCI device. The could be caused by a
7864 * Hot-Plug event, or because the driver is going to be removed from
7865 * memory.
7866 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007867static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07007868{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007869 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7870 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007871
Catherine Sullivan00949162012-08-10 01:59:10 +00007872 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00007873
Auke Kok9a799d72007-09-15 14:07:45 -07007874 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007875 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007876
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007877
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007878#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007879 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7880 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7881 dca_remove_requester(&pdev->dev);
7882 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7883 }
7884
7885#endif
Don Skidmore12109822012-05-04 06:07:08 +00007886#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007887 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00007888#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007889
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007890 /* remove the added san mac */
7891 ixgbe_del_sanmac_netdev(netdev);
7892
Donald Skidmorec4900be2008-11-20 21:11:42 -08007893 if (netdev->reg_state == NETREG_REGISTERED)
7894 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007895
Greg Roseda36b642012-12-11 08:26:43 +00007896#ifdef CONFIG_PCI_IOV
7897 /*
7898 * Only disable SR-IOV on unload if the user specified the now
7899 * deprecated max_vfs module parameter.
7900 */
7901 if (max_vfs)
7902 ixgbe_disable_sriov(adapter);
7903#endif
Alexander Duyck7a921c92009-05-06 10:43:28 +00007904 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007905
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007906 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007907
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007908#ifdef CONFIG_DCB
7909 kfree(adapter->ixgbe_ieee_pfc);
7910 kfree(adapter->ixgbe_ieee_ets);
7911
7912#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007913 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007914 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007915 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007916
Emil Tantilov849c4542010-06-03 16:53:41 +00007917 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007918
Auke Kok9a799d72007-09-15 14:07:45 -07007919 free_netdev(netdev);
7920
Frans Pop19d5afd2009-10-02 10:04:12 -07007921 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007922
Auke Kok9a799d72007-09-15 14:07:45 -07007923 pci_disable_device(pdev);
7924}
7925
7926/**
7927 * ixgbe_io_error_detected - called when PCI error is detected
7928 * @pdev: Pointer to PCI device
7929 * @state: The current pci connection state
7930 *
7931 * This function is called after a PCI bus error affecting
7932 * this device has been detected.
7933 */
7934static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007935 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007936{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007937 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7938 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007939
Greg Rose83c61fa2011-09-07 05:59:35 +00007940#ifdef CONFIG_PCI_IOV
7941 struct pci_dev *bdev, *vfdev;
7942 u32 dw0, dw1, dw2, dw3;
7943 int vf, pos;
7944 u16 req_id, pf_func;
7945
7946 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7947 adapter->num_vfs == 0)
7948 goto skip_bad_vf_detection;
7949
7950 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08007951 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00007952 bdev = bdev->bus->self;
7953
7954 if (!bdev)
7955 goto skip_bad_vf_detection;
7956
7957 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7958 if (!pos)
7959 goto skip_bad_vf_detection;
7960
7961 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7962 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7963 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7964 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7965
7966 req_id = dw1 >> 16;
7967 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7968 if (!(req_id & 0x0080))
7969 goto skip_bad_vf_detection;
7970
7971 pf_func = req_id & 0x01;
7972 if ((pf_func & 1) == (pdev->devfn & 1)) {
7973 unsigned int device_id;
7974
7975 vf = (req_id & 0x7F) >> 1;
7976 e_dev_err("VF %d has caused a PCIe error\n", vf);
7977 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7978 "%8.8x\tdw3: %8.8x\n",
7979 dw0, dw1, dw2, dw3);
7980 switch (adapter->hw.mac.type) {
7981 case ixgbe_mac_82599EB:
7982 device_id = IXGBE_82599_VF_DEVICE_ID;
7983 break;
7984 case ixgbe_mac_X540:
7985 device_id = IXGBE_X540_VF_DEVICE_ID;
7986 break;
7987 default:
7988 device_id = 0;
7989 break;
7990 }
7991
7992 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00007993 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00007994 while (vfdev) {
7995 if (vfdev->devfn == (req_id & 0xFF))
7996 break;
Jon Mason36e90312012-07-19 21:02:09 +00007997 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00007998 device_id, vfdev);
7999 }
8000 /*
8001 * There's a slim chance the VF could have been hot plugged,
8002 * so if it is no longer present we don't need to issue the
8003 * VFLR. Just clean up the AER in that case.
8004 */
8005 if (vfdev) {
8006 e_dev_err("Issuing VFLR to VF %d\n", vf);
8007 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
Greg Roseb4fafbe2012-12-13 01:14:06 +00008008 /* Free device reference count */
8009 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +00008010 }
8011
8012 pci_cleanup_aer_uncorrect_error_status(pdev);
8013 }
8014
8015 /*
8016 * Even though the error may have occurred on the other port
8017 * we still need to increment the vf error reference count for
8018 * both ports because the I/O resume function will be called
8019 * for both of them.
8020 */
8021 adapter->vferr_refcount++;
8022
8023 return PCI_ERS_RESULT_RECOVERED;
8024
8025skip_bad_vf_detection:
8026#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008027 netif_device_detach(netdev);
8028
Breno Leitao3044b8d2009-05-06 10:44:26 +00008029 if (state == pci_channel_io_perm_failure)
8030 return PCI_ERS_RESULT_DISCONNECT;
8031
Auke Kok9a799d72007-09-15 14:07:45 -07008032 if (netif_running(netdev))
8033 ixgbe_down(adapter);
8034 pci_disable_device(pdev);
8035
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008036 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008037 return PCI_ERS_RESULT_NEED_RESET;
8038}
8039
8040/**
8041 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8042 * @pdev: Pointer to PCI device
8043 *
8044 * Restart the card from scratch, as if from a cold-boot.
8045 */
8046static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8047{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008048 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008049 pci_ers_result_t result;
8050 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008051
gouji-new9ce77662009-05-06 10:44:45 +00008052 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008053 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008054 result = PCI_ERS_RESULT_DISCONNECT;
8055 } else {
8056 pci_set_master(pdev);
8057 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008058 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008059
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008060 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008061
8062 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008063 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008064 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008065 }
Auke Kok9a799d72007-09-15 14:07:45 -07008066
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008067 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8068 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008069 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8070 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008071 /* non-fatal, continue */
8072 }
Auke Kok9a799d72007-09-15 14:07:45 -07008073
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008074 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008075}
8076
8077/**
8078 * ixgbe_io_resume - called when traffic can start flowing again.
8079 * @pdev: Pointer to PCI device
8080 *
8081 * This callback is called when the error recovery driver tells us that
8082 * its OK to resume normal operation.
8083 */
8084static void ixgbe_io_resume(struct pci_dev *pdev)
8085{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008086 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8087 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008088
Greg Rose83c61fa2011-09-07 05:59:35 +00008089#ifdef CONFIG_PCI_IOV
8090 if (adapter->vferr_refcount) {
8091 e_info(drv, "Resuming after VF err\n");
8092 adapter->vferr_refcount--;
8093 return;
8094 }
8095
8096#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008097 if (netif_running(netdev))
8098 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008099
8100 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008101}
8102
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07008103static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07008104 .error_detected = ixgbe_io_error_detected,
8105 .slot_reset = ixgbe_io_slot_reset,
8106 .resume = ixgbe_io_resume,
8107};
8108
8109static struct pci_driver ixgbe_driver = {
8110 .name = ixgbe_driver_name,
8111 .id_table = ixgbe_pci_tbl,
8112 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05008113 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07008114#ifdef CONFIG_PM
8115 .suspend = ixgbe_suspend,
8116 .resume = ixgbe_resume,
8117#endif
8118 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +00008119 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -07008120 .err_handler = &ixgbe_err_handler
8121};
8122
8123/**
8124 * ixgbe_init_module - Driver Registration Routine
8125 *
8126 * ixgbe_init_module is the first routine called when the driver is
8127 * loaded. All it does is register with the PCI subsystem.
8128 **/
8129static int __init ixgbe_init_module(void)
8130{
8131 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008132 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008133 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008134
Catherine Sullivan00949162012-08-10 01:59:10 +00008135 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +00008136
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008137 ret = pci_register_driver(&ixgbe_driver);
8138 if (ret) {
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008139 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008140 return ret;
8141 }
8142
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008143#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008144 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008145#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008146
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008147 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008148}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008149
Auke Kok9a799d72007-09-15 14:07:45 -07008150module_init(ixgbe_init_module);
8151
8152/**
8153 * ixgbe_exit_module - Driver Exit Cleanup Routine
8154 *
8155 * ixgbe_exit_module is called just before the driver is removed
8156 * from memory.
8157 **/
8158static void __exit ixgbe_exit_module(void)
8159{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008160#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008161 dca_unregister_notify(&dca_notifier);
8162#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008163 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00008164
Catherine Sullivan00949162012-08-10 01:59:10 +00008165 ixgbe_dbg_exit();
Catherine Sullivan00949162012-08-10 01:59:10 +00008166
Eric Dumazet1a515022010-11-16 19:26:42 -08008167 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008168}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008169
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008170#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008171static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008172 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008173{
8174 int ret_val;
8175
8176 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008177 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008178
8179 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8180}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008181
Alexander Duyckb4533682009-03-31 21:32:42 +00008182#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008183
Auke Kok9a799d72007-09-15 14:07:45 -07008184module_exit(ixgbe_exit_module);
8185
8186/* ixgbe_main.c */