ixgbe: Make ixgbe_fc_autoneg return void and always set current_mode
[deliverable/linux.git] / drivers / net / ethernet / intel / ixgbe / ixgbe_main.c
CommitLineData
9a799d71
AK
1/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
94971820 4 Copyright(c) 1999 - 2012 Intel Corporation.
9a799d71
AK
5
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:
9a799d71
AK
23 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>
a6b7a407 35#include <linux/interrupt.h>
9a799d71
AK
36#include <linux/ip.h>
37#include <linux/tcp.h>
897ab156 38#include <linux/sctp.h>
60127865 39#include <linux/pkt_sched.h>
9a799d71 40#include <linux/ipv6.h>
5a0e3ad6 41#include <linux/slab.h>
9a799d71
AK
42#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
01789349 45#include <linux/if.h>
9a799d71 46#include <linux/if_vlan.h>
70c71606 47#include <linux/prefetch.h>
eacd73f7 48#include <scsi/fc/fc_fcoe.h>
9a799d71
AK
49
50#include "ixgbe.h"
51#include "ixgbe_common.h"
ee5f784a 52#include "ixgbe_dcb_82599.h"
1cdd1ec8 53#include "ixgbe_sriov.h"
9a799d71
AK
54
55char ixgbe_driver_name[] = "ixgbe";
9c8eb720 56static const char ixgbe_driver_string[] =
e8e9f696 57 "Intel(R) 10 Gigabit PCI Express Network Driver";
8af3c33f 58#ifdef IXGBE_FCOE
ea81875a
NP
59char ixgbe_default_device_descr[] =
60 "Intel(R) 10 Gigabit Network Connection";
8af3c33f
JK
61#else
62static char ixgbe_default_device_descr[] =
63 "Intel(R) 10 Gigabit Network Connection";
64#endif
75e3d3c6 65#define MAJ 3
8e4f3250
DS
66#define MIN 8
67#define BUILD 21
75e3d3c6 68#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
a38a104d 69 __stringify(BUILD) "-k"
9c8eb720 70const char ixgbe_driver_version[] = DRV_VERSION;
a52055e0 71static const char ixgbe_copyright[] =
94971820 72 "Copyright (c) 1999-2012 Intel Corporation.";
9a799d71
AK
73
74static const struct ixgbe_info *ixgbe_info_tbl[] = {
b4617240 75 [board_82598] = &ixgbe_82598_info,
e8e26350 76 [board_82599] = &ixgbe_82599_info,
fe15e8e1 77 [board_X540] = &ixgbe_X540_info,
9a799d71
AK
78};
79
80/* ixgbe_pci_tbl - PCI Device ID Table
81 *
82 * Wildcard entries (PCI_ANY_ID) should come last
83 * Last entry must be all 0s
84 *
85 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
86 * Class, Class Mask, private data (not used) }
87 */
a3aa1884 88static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
54239c67
AD
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
7d145282 115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
9e791e4a 116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
9a799d71
AK
117 /* required last entry */
118 {0, }
119};
120MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
121
5dd2d332 122#ifdef CONFIG_IXGBE_DCA
bd0362dd 123static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
e8e9f696 124 void *p);
bd0362dd
JC
125static struct notifier_block dca_notifier = {
126 .notifier_call = ixgbe_notify_dca,
127 .next = NULL,
128 .priority = 0
129};
130#endif
131
1cdd1ec8
GR
132#ifdef CONFIG_PCI_IOV
133static unsigned int max_vfs;
134module_param(max_vfs, uint, 0);
e8e9f696 135MODULE_PARM_DESC(max_vfs,
6b42a9c5 136 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
1cdd1ec8
GR
137#endif /* CONFIG_PCI_IOV */
138
8ef78adc
PWJ
139static unsigned int allow_unsupported_sfp;
140module_param(allow_unsupported_sfp, uint, 0);
141MODULE_PARM_DESC(allow_unsupported_sfp,
142 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
143
b3f4d599 144#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
145static int debug = -1;
146module_param(debug, int, 0);
147MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
148
9a799d71
AK
149MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
150MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
151MODULE_LICENSE("GPL");
152MODULE_VERSION(DRV_VERSION);
153
7086400d
AD
154static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
155{
156 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
157 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
158 schedule_work(&adapter->service_task);
159}
160
161static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
162{
163 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
164
52f33af8 165 /* flush memory to make sure state is correct before next watchdog */
7086400d
AD
166 smp_mb__before_clear_bit();
167 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
168}
169
dcd79aeb
TI
170struct ixgbe_reg_info {
171 u32 ofs;
172 char *name;
173};
174
175static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
176
177 /* General Registers */
178 {IXGBE_CTRL, "CTRL"},
179 {IXGBE_STATUS, "STATUS"},
180 {IXGBE_CTRL_EXT, "CTRL_EXT"},
181
182 /* Interrupt Registers */
183 {IXGBE_EICR, "EICR"},
184
185 /* RX Registers */
186 {IXGBE_SRRCTL(0), "SRRCTL"},
187 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
188 {IXGBE_RDLEN(0), "RDLEN"},
189 {IXGBE_RDH(0), "RDH"},
190 {IXGBE_RDT(0), "RDT"},
191 {IXGBE_RXDCTL(0), "RXDCTL"},
192 {IXGBE_RDBAL(0), "RDBAL"},
193 {IXGBE_RDBAH(0), "RDBAH"},
194
195 /* TX Registers */
196 {IXGBE_TDBAL(0), "TDBAL"},
197 {IXGBE_TDBAH(0), "TDBAH"},
198 {IXGBE_TDLEN(0), "TDLEN"},
199 {IXGBE_TDH(0), "TDH"},
200 {IXGBE_TDT(0), "TDT"},
201 {IXGBE_TXDCTL(0), "TXDCTL"},
202
203 /* List Terminator */
204 {}
205};
206
207
208/*
209 * ixgbe_regdump - register printout routine
210 */
211static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
212{
213 int i = 0, j = 0;
214 char rname[16];
215 u32 regs[64];
216
217 switch (reginfo->ofs) {
218 case IXGBE_SRRCTL(0):
219 for (i = 0; i < 64; i++)
220 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
221 break;
222 case IXGBE_DCA_RXCTRL(0):
223 for (i = 0; i < 64; i++)
224 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
225 break;
226 case IXGBE_RDLEN(0):
227 for (i = 0; i < 64; i++)
228 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
229 break;
230 case IXGBE_RDH(0):
231 for (i = 0; i < 64; i++)
232 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
233 break;
234 case IXGBE_RDT(0):
235 for (i = 0; i < 64; i++)
236 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
237 break;
238 case IXGBE_RXDCTL(0):
239 for (i = 0; i < 64; i++)
240 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
241 break;
242 case IXGBE_RDBAL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
245 break;
246 case IXGBE_RDBAH(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
249 break;
250 case IXGBE_TDBAL(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
253 break;
254 case IXGBE_TDBAH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
257 break;
258 case IXGBE_TDLEN(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
261 break;
262 case IXGBE_TDH(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
265 break;
266 case IXGBE_TDT(0):
267 for (i = 0; i < 64; i++)
268 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
269 break;
270 case IXGBE_TXDCTL(0):
271 for (i = 0; i < 64; i++)
272 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
273 break;
274 default:
c7689578 275 pr_info("%-15s %08x\n", reginfo->name,
dcd79aeb
TI
276 IXGBE_READ_REG(hw, reginfo->ofs));
277 return;
278 }
279
280 for (i = 0; i < 8; i++) {
281 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
c7689578 282 pr_err("%-15s", rname);
dcd79aeb 283 for (j = 0; j < 8; j++)
c7689578
JP
284 pr_cont(" %08x", regs[i*8+j]);
285 pr_cont("\n");
dcd79aeb
TI
286 }
287
288}
289
290/*
291 * ixgbe_dump - Print registers, tx-rings and rx-rings
292 */
293static void ixgbe_dump(struct ixgbe_adapter *adapter)
294{
295 struct net_device *netdev = adapter->netdev;
296 struct ixgbe_hw *hw = &adapter->hw;
297 struct ixgbe_reg_info *reginfo;
298 int n = 0;
299 struct ixgbe_ring *tx_ring;
729739b7 300 struct ixgbe_tx_buffer *tx_buffer;
dcd79aeb
TI
301 union ixgbe_adv_tx_desc *tx_desc;
302 struct my_u0 { u64 a; u64 b; } *u0;
303 struct ixgbe_ring *rx_ring;
304 union ixgbe_adv_rx_desc *rx_desc;
305 struct ixgbe_rx_buffer *rx_buffer_info;
306 u32 staterr;
307 int i = 0;
308
309 if (!netif_msg_hw(adapter))
310 return;
311
312 /* Print netdevice Info */
313 if (netdev) {
314 dev_info(&adapter->pdev->dev, "Net device Info\n");
c7689578 315 pr_info("Device Name state "
dcd79aeb 316 "trans_start last_rx\n");
c7689578
JP
317 pr_info("%-15s %016lX %016lX %016lX\n",
318 netdev->name,
319 netdev->state,
320 netdev->trans_start,
321 netdev->last_rx);
dcd79aeb
TI
322 }
323
324 /* Print Registers */
325 dev_info(&adapter->pdev->dev, "Register Dump\n");
c7689578 326 pr_info(" Register Name Value\n");
dcd79aeb
TI
327 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
328 reginfo->name; reginfo++) {
329 ixgbe_regdump(hw, reginfo);
330 }
331
332 /* Print TX Ring Summary */
333 if (!netdev || !netif_running(netdev))
334 goto exit;
335
336 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
c7689578 337 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
dcd79aeb
TI
338 for (n = 0; n < adapter->num_tx_queues; n++) {
339 tx_ring = adapter->tx_ring[n];
729739b7 340 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
d3d00239 341 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
dcd79aeb 342 n, tx_ring->next_to_use, tx_ring->next_to_clean,
729739b7
AD
343 (u64)dma_unmap_addr(tx_buffer, dma),
344 dma_unmap_len(tx_buffer, len),
345 tx_buffer->next_to_watch,
346 (u64)tx_buffer->time_stamp);
dcd79aeb
TI
347 }
348
349 /* Print TX Rings */
350 if (!netif_msg_tx_done(adapter))
351 goto rx_ring_summary;
352
353 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
354
355 /* Transmit Descriptor Formats
356 *
357 * Advanced Transmit Descriptor
358 * +--------------------------------------------------------------+
359 * 0 | Buffer Address [63:0] |
360 * +--------------------------------------------------------------+
361 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
362 * +--------------------------------------------------------------+
363 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
364 */
365
366 for (n = 0; n < adapter->num_tx_queues; n++) {
367 tx_ring = adapter->tx_ring[n];
c7689578
JP
368 pr_info("------------------------------------\n");
369 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
370 pr_info("------------------------------------\n");
371 pr_info("T [desc] [address 63:0 ] "
dcd79aeb
TI
372 "[PlPOIdStDDt Ln] [bi->dma ] "
373 "leng ntw timestamp bi->skb\n");
374
375 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
e4f74028 376 tx_desc = IXGBE_TX_DESC(tx_ring, i);
729739b7 377 tx_buffer = &tx_ring->tx_buffer_info[i];
dcd79aeb 378 u0 = (struct my_u0 *)tx_desc;
c7689578 379 pr_info("T [0x%03X] %016llX %016llX %016llX"
d3d00239 380 " %04X %p %016llX %p", i,
dcd79aeb
TI
381 le64_to_cpu(u0->a),
382 le64_to_cpu(u0->b),
729739b7
AD
383 (u64)dma_unmap_addr(tx_buffer, dma),
384 dma_unmap_len(tx_buffer, len),
385 tx_buffer->next_to_watch,
386 (u64)tx_buffer->time_stamp,
387 tx_buffer->skb);
dcd79aeb
TI
388 if (i == tx_ring->next_to_use &&
389 i == tx_ring->next_to_clean)
c7689578 390 pr_cont(" NTC/U\n");
dcd79aeb 391 else if (i == tx_ring->next_to_use)
c7689578 392 pr_cont(" NTU\n");
dcd79aeb 393 else if (i == tx_ring->next_to_clean)
c7689578 394 pr_cont(" NTC\n");
dcd79aeb 395 else
c7689578 396 pr_cont("\n");
dcd79aeb
TI
397
398 if (netif_msg_pktdata(adapter) &&
729739b7 399 dma_unmap_len(tx_buffer, len) != 0)
dcd79aeb
TI
400 print_hex_dump(KERN_INFO, "",
401 DUMP_PREFIX_ADDRESS, 16, 1,
729739b7
AD
402 phys_to_virt(dma_unmap_addr(tx_buffer,
403 dma)),
404 dma_unmap_len(tx_buffer, len),
405 true);
dcd79aeb
TI
406 }
407 }
408
409 /* Print RX Rings Summary */
410rx_ring_summary:
411 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
c7689578 412 pr_info("Queue [NTU] [NTC]\n");
dcd79aeb
TI
413 for (n = 0; n < adapter->num_rx_queues; n++) {
414 rx_ring = adapter->rx_ring[n];
c7689578
JP
415 pr_info("%5d %5X %5X\n",
416 n, rx_ring->next_to_use, rx_ring->next_to_clean);
dcd79aeb
TI
417 }
418
419 /* Print RX Rings */
420 if (!netif_msg_rx_status(adapter))
421 goto exit;
422
423 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
424
425 /* Advanced Receive Descriptor (Read) Format
426 * 63 1 0
427 * +-----------------------------------------------------+
428 * 0 | Packet Buffer Address [63:1] |A0/NSE|
429 * +----------------------------------------------+------+
430 * 8 | Header Buffer Address [63:1] | DD |
431 * +-----------------------------------------------------+
432 *
433 *
434 * Advanced Receive Descriptor (Write-Back) Format
435 *
436 * 63 48 47 32 31 30 21 20 16 15 4 3 0
437 * +------------------------------------------------------+
438 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
439 * | Checksum Ident | | | | Type | Type |
440 * +------------------------------------------------------+
441 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
442 * +------------------------------------------------------+
443 * 63 48 47 32 31 20 19 0
444 */
445 for (n = 0; n < adapter->num_rx_queues; n++) {
446 rx_ring = adapter->rx_ring[n];
c7689578
JP
447 pr_info("------------------------------------\n");
448 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
449 pr_info("------------------------------------\n");
450 pr_info("R [desc] [ PktBuf A0] "
dcd79aeb
TI
451 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
452 "<-- Adv Rx Read format\n");
c7689578 453 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
dcd79aeb
TI
454 "[vl er S cks ln] ---------------- [bi->skb] "
455 "<-- Adv Rx Write-Back format\n");
456
457 for (i = 0; i < rx_ring->count; i++) {
458 rx_buffer_info = &rx_ring->rx_buffer_info[i];
e4f74028 459 rx_desc = IXGBE_RX_DESC(rx_ring, i);
dcd79aeb
TI
460 u0 = (struct my_u0 *)rx_desc;
461 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
462 if (staterr & IXGBE_RXD_STAT_DD) {
463 /* Descriptor Done */
c7689578 464 pr_info("RWB[0x%03X] %016llX "
dcd79aeb
TI
465 "%016llX ---------------- %p", i,
466 le64_to_cpu(u0->a),
467 le64_to_cpu(u0->b),
468 rx_buffer_info->skb);
469 } else {
c7689578 470 pr_info("R [0x%03X] %016llX "
dcd79aeb
TI
471 "%016llX %016llX %p", i,
472 le64_to_cpu(u0->a),
473 le64_to_cpu(u0->b),
474 (u64)rx_buffer_info->dma,
475 rx_buffer_info->skb);
476
477 if (netif_msg_pktdata(adapter)) {
478 print_hex_dump(KERN_INFO, "",
479 DUMP_PREFIX_ADDRESS, 16, 1,
480 phys_to_virt(rx_buffer_info->dma),
f800326d 481 ixgbe_rx_bufsz(rx_ring), true);
dcd79aeb
TI
482 }
483 }
484
485 if (i == rx_ring->next_to_use)
c7689578 486 pr_cont(" NTU\n");
dcd79aeb 487 else if (i == rx_ring->next_to_clean)
c7689578 488 pr_cont(" NTC\n");
dcd79aeb 489 else
c7689578 490 pr_cont("\n");
dcd79aeb
TI
491
492 }
493 }
494
495exit:
496 return;
497}
498
5eba3699
AV
499static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
500{
501 u32 ctrl_ext;
502
503 /* Let firmware take over control of h/w */
504 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
505 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
e8e9f696 506 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
5eba3699
AV
507}
508
509static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
510{
511 u32 ctrl_ext;
512
513 /* Let firmware know the driver has taken over */
514 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
515 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
e8e9f696 516 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
5eba3699 517}
9a799d71 518
e8e26350
PW
519/*
520 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
521 * @adapter: pointer to adapter struct
522 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
523 * @queue: queue to map the corresponding interrupt to
524 * @msix_vector: the vector to map to the corresponding queue
525 *
526 */
527static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
e8e9f696 528 u8 queue, u8 msix_vector)
9a799d71
AK
529{
530 u32 ivar, index;
e8e26350
PW
531 struct ixgbe_hw *hw = &adapter->hw;
532 switch (hw->mac.type) {
533 case ixgbe_mac_82598EB:
534 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
535 if (direction == -1)
536 direction = 0;
537 index = (((direction * 64) + queue) >> 2) & 0x1F;
538 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
539 ivar &= ~(0xFF << (8 * (queue & 0x3)));
540 ivar |= (msix_vector << (8 * (queue & 0x3)));
541 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
542 break;
543 case ixgbe_mac_82599EB:
b93a2226 544 case ixgbe_mac_X540:
e8e26350
PW
545 if (direction == -1) {
546 /* other causes */
547 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
548 index = ((queue & 1) * 8);
549 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
550 ivar &= ~(0xFF << index);
551 ivar |= (msix_vector << index);
552 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
553 break;
554 } else {
555 /* tx or rx causes */
556 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
557 index = ((16 * (queue & 1)) + (8 * direction));
558 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
559 ivar &= ~(0xFF << index);
560 ivar |= (msix_vector << index);
561 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
562 break;
563 }
564 default:
565 break;
566 }
9a799d71
AK
567}
568
fe49f04a 569static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
e8e9f696 570 u64 qmask)
fe49f04a
AD
571{
572 u32 mask;
573
bd508178
AD
574 switch (adapter->hw.mac.type) {
575 case ixgbe_mac_82598EB:
fe49f04a
AD
576 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
577 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
bd508178
AD
578 break;
579 case ixgbe_mac_82599EB:
b93a2226 580 case ixgbe_mac_X540:
fe49f04a
AD
581 mask = (qmask & 0xFFFFFFFF);
582 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
583 mask = (qmask >> 32);
584 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
bd508178
AD
585 break;
586 default:
587 break;
fe49f04a
AD
588 }
589}
590
729739b7
AD
591void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
592 struct ixgbe_tx_buffer *tx_buffer)
9a799d71 593{
729739b7
AD
594 if (tx_buffer->skb) {
595 dev_kfree_skb_any(tx_buffer->skb);
596 if (dma_unmap_len(tx_buffer, len))
d3d00239 597 dma_unmap_single(ring->dev,
729739b7
AD
598 dma_unmap_addr(tx_buffer, dma),
599 dma_unmap_len(tx_buffer, len),
600 DMA_TO_DEVICE);
601 } else if (dma_unmap_len(tx_buffer, len)) {
602 dma_unmap_page(ring->dev,
603 dma_unmap_addr(tx_buffer, dma),
604 dma_unmap_len(tx_buffer, len),
605 DMA_TO_DEVICE);
e5a43549 606 }
729739b7
AD
607 tx_buffer->next_to_watch = NULL;
608 tx_buffer->skb = NULL;
609 dma_unmap_len_set(tx_buffer, len, 0);
610 /* tx_buffer must be completely set up in the transmit path */
9a799d71
AK
611}
612
c84d324c
JF
613static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
614{
615 struct ixgbe_hw *hw = &adapter->hw;
616 struct ixgbe_hw_stats *hwstats = &adapter->stats;
617 u32 data = 0;
618 u32 xoff[8] = {0};
619 int i;
620
621 if ((hw->fc.current_mode == ixgbe_fc_full) ||
622 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
623 switch (hw->mac.type) {
624 case ixgbe_mac_82598EB:
625 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
6837e895
PW
626 break;
627 default:
c84d324c
JF
628 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
629 }
630 hwstats->lxoffrxc += data;
631
632 /* refill credits (no tx hang) if we received xoff */
633 if (!data)
634 return;
635
636 for (i = 0; i < adapter->num_tx_queues; i++)
637 clear_bit(__IXGBE_HANG_CHECK_ARMED,
638 &adapter->tx_ring[i]->state);
639 return;
640 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
641 return;
642
643 /* update stats for each tc, only valid with PFC enabled */
644 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
645 switch (hw->mac.type) {
646 case ixgbe_mac_82598EB:
647 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
bd508178 648 break;
c84d324c
JF
649 default:
650 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
26f23d82 651 }
c84d324c
JF
652 hwstats->pxoffrxc[i] += xoff[i];
653 }
654
655 /* disarm tx queues that have received xoff frames */
656 for (i = 0; i < adapter->num_tx_queues; i++) {
657 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
fb5475ff 658 u8 tc = tx_ring->dcb_tc;
c84d324c
JF
659
660 if (xoff[tc])
661 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
26f23d82 662 }
26f23d82
YZ
663}
664
c84d324c 665static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
9a799d71 666{
7d7ce682 667 return ring->stats.packets;
c84d324c
JF
668}
669
670static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
671{
672 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
e01c31a5 673 struct ixgbe_hw *hw = &adapter->hw;
e01c31a5 674
c84d324c
JF
675 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
676 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
677
678 if (head != tail)
679 return (head < tail) ?
680 tail - head : (tail + ring->count - head);
681
682 return 0;
683}
684
685static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
686{
687 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
688 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
689 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
690 bool ret = false;
691
7d637bcc 692 clear_check_for_tx_hang(tx_ring);
c84d324c
JF
693
694 /*
695 * Check for a hung queue, but be thorough. This verifies
696 * that a transmit has been completed since the previous
697 * check AND there is at least one packet pending. The
698 * ARMED bit is set to indicate a potential hang. The
699 * bit is cleared if a pause frame is received to remove
700 * false hang detection due to PFC or 802.3x frames. By
701 * requiring this to fail twice we avoid races with
702 * pfc clearing the ARMED bit and conditions where we
703 * run the check_tx_hang logic with a transmit completion
704 * pending but without time to complete it yet.
705 */
706 if ((tx_done_old == tx_done) && tx_pending) {
707 /* make sure it is true for two checks in a row */
708 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
709 &tx_ring->state);
710 } else {
711 /* update completed stats and continue */
712 tx_ring->tx_stats.tx_done_old = tx_done;
713 /* reset the countdown */
714 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
9a799d71
AK
715 }
716
c84d324c 717 return ret;
9a799d71
AK
718}
719
c83c6cbd
AD
720/**
721 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
722 * @adapter: driver private struct
723 **/
724static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
725{
726
727 /* Do the reset outside of interrupt context */
728 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
729 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
730 ixgbe_service_event_schedule(adapter);
731 }
732}
e01c31a5 733
9a799d71
AK
734/**
735 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
fe49f04a 736 * @q_vector: structure containing interrupt and ring information
e01c31a5 737 * @tx_ring: tx ring to clean
9a799d71 738 **/
fe49f04a 739static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
e8e9f696 740 struct ixgbe_ring *tx_ring)
9a799d71 741{
fe49f04a 742 struct ixgbe_adapter *adapter = q_vector->adapter;
d3d00239
AD
743 struct ixgbe_tx_buffer *tx_buffer;
744 union ixgbe_adv_tx_desc *tx_desc;
e01c31a5 745 unsigned int total_bytes = 0, total_packets = 0;
59224555 746 unsigned int budget = q_vector->tx.work_limit;
729739b7
AD
747 unsigned int i = tx_ring->next_to_clean;
748
749 if (test_bit(__IXGBE_DOWN, &adapter->state))
750 return true;
9a799d71 751
d3d00239 752 tx_buffer = &tx_ring->tx_buffer_info[i];
e4f74028 753 tx_desc = IXGBE_TX_DESC(tx_ring, i);
729739b7 754 i -= tx_ring->count;
12207e49 755
729739b7 756 do {
d3d00239
AD
757 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
758
759 /* if next_to_watch is not set then there is no work pending */
760 if (!eop_desc)
761 break;
762
7f83a9e6
AD
763 /* prevent any other reads prior to eop_desc */
764 rmb();
765
d3d00239
AD
766 /* if DD is not set pending work has not been completed */
767 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
768 break;
8ad494b0 769
d3d00239
AD
770 /* clear next_to_watch to prevent false hangs */
771 tx_buffer->next_to_watch = NULL;
8ad494b0 772
091a6246
AD
773 /* update the statistics for this packet */
774 total_bytes += tx_buffer->bytecount;
775 total_packets += tx_buffer->gso_segs;
776
fd0db0ed
AD
777 /* free the skb */
778 dev_kfree_skb_any(tx_buffer->skb);
779
729739b7
AD
780 /* unmap skb header data */
781 dma_unmap_single(tx_ring->dev,
782 dma_unmap_addr(tx_buffer, dma),
783 dma_unmap_len(tx_buffer, len),
784 DMA_TO_DEVICE);
785
fd0db0ed
AD
786 /* clear tx_buffer data */
787 tx_buffer->skb = NULL;
729739b7 788 dma_unmap_len_set(tx_buffer, len, 0);
fd0db0ed 789
729739b7
AD
790 /* unmap remaining buffers */
791 while (tx_desc != eop_desc) {
d3d00239
AD
792 tx_buffer++;
793 tx_desc++;
8ad494b0 794 i++;
729739b7
AD
795 if (unlikely(!i)) {
796 i -= tx_ring->count;
d3d00239 797 tx_buffer = tx_ring->tx_buffer_info;
e4f74028 798 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
e092be60 799 }
e01c31a5 800
729739b7
AD
801 /* unmap any remaining paged data */
802 if (dma_unmap_len(tx_buffer, len)) {
803 dma_unmap_page(tx_ring->dev,
804 dma_unmap_addr(tx_buffer, dma),
805 dma_unmap_len(tx_buffer, len),
806 DMA_TO_DEVICE);
807 dma_unmap_len_set(tx_buffer, len, 0);
808 }
809 }
810
811 /* move us one more past the eop_desc for start of next pkt */
812 tx_buffer++;
813 tx_desc++;
814 i++;
815 if (unlikely(!i)) {
816 i -= tx_ring->count;
817 tx_buffer = tx_ring->tx_buffer_info;
818 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
819 }
820
821 /* issue prefetch for next Tx descriptor */
822 prefetch(tx_desc);
12207e49 823
729739b7
AD
824 /* update budget accounting */
825 budget--;
826 } while (likely(budget));
827
828 i += tx_ring->count;
9a799d71 829 tx_ring->next_to_clean = i;
d3d00239 830 u64_stats_update_begin(&tx_ring->syncp);
b953799e 831 tx_ring->stats.bytes += total_bytes;
bd198058 832 tx_ring->stats.packets += total_packets;
d3d00239 833 u64_stats_update_end(&tx_ring->syncp);
bd198058
AD
834 q_vector->tx.total_bytes += total_bytes;
835 q_vector->tx.total_packets += total_packets;
b953799e 836
c84d324c
JF
837 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
838 /* schedule immediate reset if we believe we hung */
839 struct ixgbe_hw *hw = &adapter->hw;
c84d324c
JF
840 e_err(drv, "Detected Tx Unit Hang\n"
841 " Tx Queue <%d>\n"
842 " TDH, TDT <%x>, <%x>\n"
843 " next_to_use <%x>\n"
844 " next_to_clean <%x>\n"
845 "tx_buffer_info[next_to_clean]\n"
846 " time_stamp <%lx>\n"
847 " jiffies <%lx>\n",
848 tx_ring->queue_index,
849 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
850 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
d3d00239
AD
851 tx_ring->next_to_use, i,
852 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
c84d324c
JF
853
854 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
855
856 e_info(probe,
857 "tx hang %d detected on queue %d, resetting adapter\n",
858 adapter->tx_timeout_count + 1, tx_ring->queue_index);
859
b953799e 860 /* schedule immediate reset if we believe we hung */
c83c6cbd 861 ixgbe_tx_timeout_reset(adapter);
b953799e
AD
862
863 /* the adapter is about to reset, no point in enabling stuff */
59224555 864 return true;
b953799e 865 }
9a799d71 866
b2d96e0a
AD
867 netdev_tx_completed_queue(txring_txq(tx_ring),
868 total_packets, total_bytes);
869
e092be60 870#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
30065e63 871 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
7d4987de 872 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
e092be60
AV
873 /* Make sure that anybody stopping the queue after this
874 * sees the new next_to_clean.
875 */
876 smp_mb();
729739b7
AD
877 if (__netif_subqueue_stopped(tx_ring->netdev,
878 tx_ring->queue_index)
879 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
880 netif_wake_subqueue(tx_ring->netdev,
881 tx_ring->queue_index);
5b7da515 882 ++tx_ring->tx_stats.restart_queue;
30eba97a 883 }
e092be60 884 }
9a799d71 885
59224555 886 return !!budget;
9a799d71
AK
887}
888
5dd2d332 889#ifdef CONFIG_IXGBE_DCA
bdda1a61
AD
890static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
891 struct ixgbe_ring *tx_ring,
33cf09c9 892 int cpu)
bd0362dd 893{
33cf09c9 894 struct ixgbe_hw *hw = &adapter->hw;
bdda1a61
AD
895 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
896 u16 reg_offset;
33cf09c9 897
33cf09c9
AD
898 switch (hw->mac.type) {
899 case ixgbe_mac_82598EB:
bdda1a61 900 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
33cf09c9
AD
901 break;
902 case ixgbe_mac_82599EB:
b93a2226 903 case ixgbe_mac_X540:
bdda1a61
AD
904 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
905 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
33cf09c9
AD
906 break;
907 default:
bdda1a61
AD
908 /* for unknown hardware do not write register */
909 return;
bd0362dd 910 }
bdda1a61
AD
911
912 /*
913 * We can enable relaxed ordering for reads, but not writes when
914 * DCA is enabled. This is due to a known issue in some chipsets
915 * which will cause the DCA tag to be cleared.
916 */
917 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
918 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
919 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
920
921 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
bd0362dd
JC
922}
923
bdda1a61
AD
924static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
925 struct ixgbe_ring *rx_ring,
33cf09c9 926 int cpu)
bd0362dd 927{
33cf09c9 928 struct ixgbe_hw *hw = &adapter->hw;
bdda1a61
AD
929 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
930 u8 reg_idx = rx_ring->reg_idx;
931
33cf09c9
AD
932
933 switch (hw->mac.type) {
33cf09c9 934 case ixgbe_mac_82599EB:
b93a2226 935 case ixgbe_mac_X540:
bdda1a61 936 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
33cf09c9
AD
937 break;
938 default:
939 break;
940 }
bdda1a61
AD
941
942 /*
943 * We can enable relaxed ordering for reads, but not writes when
944 * DCA is enabled. This is due to a known issue in some chipsets
945 * which will cause the DCA tag to be cleared.
946 */
947 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
948 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
949 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
950
951 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
33cf09c9
AD
952}
953
954static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
955{
956 struct ixgbe_adapter *adapter = q_vector->adapter;
efe3d3c8 957 struct ixgbe_ring *ring;
bd0362dd 958 int cpu = get_cpu();
bd0362dd 959
33cf09c9
AD
960 if (q_vector->cpu == cpu)
961 goto out_no_update;
962
a557928e 963 ixgbe_for_each_ring(ring, q_vector->tx)
efe3d3c8 964 ixgbe_update_tx_dca(adapter, ring, cpu);
33cf09c9 965
a557928e 966 ixgbe_for_each_ring(ring, q_vector->rx)
efe3d3c8 967 ixgbe_update_rx_dca(adapter, ring, cpu);
33cf09c9
AD
968
969 q_vector->cpu = cpu;
970out_no_update:
bd0362dd
JC
971 put_cpu();
972}
973
974static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
975{
33cf09c9 976 int num_q_vectors;
bd0362dd
JC
977 int i;
978
979 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
980 return;
981
e35ec126
AD
982 /* always use CB2 mode, difference is masked in the CB driver */
983 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
984
33cf09c9
AD
985 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
986 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
987 else
988 num_q_vectors = 1;
989
990 for (i = 0; i < num_q_vectors; i++) {
991 adapter->q_vector[i]->cpu = -1;
992 ixgbe_update_dca(adapter->q_vector[i]);
bd0362dd
JC
993 }
994}
995
996static int __ixgbe_notify_dca(struct device *dev, void *data)
997{
c60fbb00 998 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
bd0362dd
JC
999 unsigned long event = *(unsigned long *)data;
1000
2a72c31e 1001 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
33cf09c9
AD
1002 return 0;
1003
bd0362dd
JC
1004 switch (event) {
1005 case DCA_PROVIDER_ADD:
96b0e0f6
JB
1006 /* if we're already enabled, don't do it again */
1007 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1008 break;
652f093f 1009 if (dca_add_requester(dev) == 0) {
96b0e0f6 1010 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
bd0362dd
JC
1011 ixgbe_setup_dca(adapter);
1012 break;
1013 }
1014 /* Fall Through since DCA is disabled. */
1015 case DCA_PROVIDER_REMOVE:
1016 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1017 dca_remove_requester(dev);
1018 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1019 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1020 }
1021 break;
1022 }
1023
652f093f 1024 return 0;
bd0362dd 1025}
67a74ee2 1026
bdda1a61 1027#endif /* CONFIG_IXGBE_DCA */
8a0da21b
AD
1028static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1029 union ixgbe_adv_rx_desc *rx_desc,
67a74ee2
ET
1030 struct sk_buff *skb)
1031{
8a0da21b
AD
1032 if (ring->netdev->features & NETIF_F_RXHASH)
1033 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
67a74ee2
ET
1034}
1035
f800326d 1036#ifdef IXGBE_FCOE
ff886dfc
AD
1037/**
1038 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1039 * @adapter: address of board private structure
1040 * @rx_desc: advanced rx descriptor
1041 *
1042 * Returns : true if it is FCoE pkt
1043 */
1044static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1045 union ixgbe_adv_rx_desc *rx_desc)
1046{
1047 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1048
1049 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1050 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1051 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1052 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1053}
1054
f800326d 1055#endif /* IXGBE_FCOE */
e59bd25d
AV
1056/**
1057 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
8a0da21b
AD
1058 * @ring: structure containing ring specific data
1059 * @rx_desc: current Rx descriptor being processed
e59bd25d
AV
1060 * @skb: skb currently being received and modified
1061 **/
8a0da21b 1062static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
8bae1b2b 1063 union ixgbe_adv_rx_desc *rx_desc,
f56e0cb1 1064 struct sk_buff *skb)
9a799d71 1065{
8a0da21b 1066 skb_checksum_none_assert(skb);
9a799d71 1067
712744be 1068 /* Rx csum disabled */
8a0da21b 1069 if (!(ring->netdev->features & NETIF_F_RXCSUM))
9a799d71 1070 return;
e59bd25d
AV
1071
1072 /* if IP and error */
f56e0cb1
AD
1073 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1074 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
8a0da21b 1075 ring->rx_stats.csum_err++;
9a799d71
AK
1076 return;
1077 }
e59bd25d 1078
f56e0cb1 1079 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
e59bd25d
AV
1080 return;
1081
f56e0cb1 1082 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
f800326d 1083 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
8bae1b2b
DS
1084
1085 /*
1086 * 82599 errata, UDP frames with a 0 checksum can be marked as
1087 * checksum errors.
1088 */
8a0da21b
AD
1089 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1090 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
8bae1b2b
DS
1091 return;
1092
8a0da21b 1093 ring->rx_stats.csum_err++;
e59bd25d
AV
1094 return;
1095 }
1096
9a799d71 1097 /* It must be a TCP or UDP packet with a valid checksum */
e59bd25d 1098 skb->ip_summed = CHECKSUM_UNNECESSARY;
9a799d71
AK
1099}
1100
84ea2591 1101static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
e8e26350 1102{
f56e0cb1 1103 rx_ring->next_to_use = val;
f800326d
AD
1104
1105 /* update next to alloc since we have filled the ring */
1106 rx_ring->next_to_alloc = val;
e8e26350
PW
1107 /*
1108 * Force memory writes to complete before letting h/w
1109 * know there are new descriptors to fetch. (Only
1110 * applicable for weak-ordered memory model archs,
1111 * such as IA-64).
1112 */
1113 wmb();
84ea2591 1114 writel(val, rx_ring->tail);
e8e26350
PW
1115}
1116
f990b79b
AD
1117static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1118 struct ixgbe_rx_buffer *bi)
1119{
1120 struct page *page = bi->page;
f800326d 1121 dma_addr_t dma = bi->dma;
f990b79b 1122
f800326d
AD
1123 /* since we are recycling buffers we should seldom need to alloc */
1124 if (likely(dma))
f990b79b
AD
1125 return true;
1126
f800326d
AD
1127 /* alloc new page for storage */
1128 if (likely(!page)) {
1129 page = alloc_pages(GFP_ATOMIC | __GFP_COLD,
1130 ixgbe_rx_pg_order(rx_ring));
f990b79b
AD
1131 if (unlikely(!page)) {
1132 rx_ring->rx_stats.alloc_rx_page_failed++;
1133 return false;
1134 }
f800326d 1135 bi->page = page;
f990b79b
AD
1136 }
1137
f800326d
AD
1138 /* map page for use */
1139 dma = dma_map_page(rx_ring->dev, page, 0,
1140 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1141
1142 /*
1143 * if mapping failed free memory back to system since
1144 * there isn't much point in holding memory we can't use
1145 */
1146 if (dma_mapping_error(rx_ring->dev, dma)) {
1147 put_page(page);
1148 bi->page = NULL;
f990b79b 1149
f990b79b
AD
1150 rx_ring->rx_stats.alloc_rx_page_failed++;
1151 return false;
1152 }
1153
f800326d
AD
1154 bi->dma = dma;
1155 bi->page_offset ^= ixgbe_rx_bufsz(rx_ring);
1156
f990b79b
AD
1157 return true;
1158}
1159
9a799d71 1160/**
f990b79b 1161 * ixgbe_alloc_rx_buffers - Replace used receive buffers
fc77dc3c
AD
1162 * @rx_ring: ring to place buffers on
1163 * @cleaned_count: number of buffers to replace
9a799d71 1164 **/
fc77dc3c 1165void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
9a799d71 1166{
9a799d71 1167 union ixgbe_adv_rx_desc *rx_desc;
3a581073 1168 struct ixgbe_rx_buffer *bi;
d5f398ed 1169 u16 i = rx_ring->next_to_use;
9a799d71 1170
f800326d
AD
1171 /* nothing to do */
1172 if (!cleaned_count)
fc77dc3c
AD
1173 return;
1174
e4f74028 1175 rx_desc = IXGBE_RX_DESC(rx_ring, i);
f990b79b
AD
1176 bi = &rx_ring->rx_buffer_info[i];
1177 i -= rx_ring->count;
9a799d71 1178
f800326d
AD
1179 do {
1180 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
f990b79b 1181 break;
d5f398ed 1182
f800326d
AD
1183 /*
1184 * Refresh the desc even if buffer_addrs didn't change
1185 * because each write-back erases this info.
1186 */
1187 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
9a799d71 1188
f990b79b
AD
1189 rx_desc++;
1190 bi++;
9a799d71 1191 i++;
f990b79b 1192 if (unlikely(!i)) {
e4f74028 1193 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
f990b79b
AD
1194 bi = rx_ring->rx_buffer_info;
1195 i -= rx_ring->count;
1196 }
1197
1198 /* clear the hdr_addr for the next_to_use descriptor */
1199 rx_desc->read.hdr_addr = 0;
f800326d
AD
1200
1201 cleaned_count--;
1202 } while (cleaned_count);
7c6e0a43 1203
f990b79b
AD
1204 i += rx_ring->count;
1205
f56e0cb1 1206 if (rx_ring->next_to_use != i)
84ea2591 1207 ixgbe_release_rx_desc(rx_ring, i);
9a799d71
AK
1208}
1209
1d2024f6
AD
1210/**
1211 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1212 * @data: pointer to the start of the headers
1213 * @max_len: total length of section to find headers in
1214 *
1215 * This function is meant to determine the length of headers that will
1216 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1217 * motivation of doing this is to only perform one pull for IPv4 TCP
1218 * packets so that we can do basic things like calculating the gso_size
1219 * based on the average data per packet.
1220 **/
1221static unsigned int ixgbe_get_headlen(unsigned char *data,
1222 unsigned int max_len)
1223{
1224 union {
1225 unsigned char *network;
1226 /* l2 headers */
1227 struct ethhdr *eth;
1228 struct vlan_hdr *vlan;
1229 /* l3 headers */
1230 struct iphdr *ipv4;
1231 } hdr;
1232 __be16 protocol;
1233 u8 nexthdr = 0; /* default to not TCP */
1234 u8 hlen;
1235
1236 /* this should never happen, but better safe than sorry */
1237 if (max_len < ETH_HLEN)
1238 return max_len;
1239
1240 /* initialize network frame pointer */
1241 hdr.network = data;
1242
1243 /* set first protocol and move network header forward */
1244 protocol = hdr.eth->h_proto;
1245 hdr.network += ETH_HLEN;
1246
1247 /* handle any vlan tag if present */
1248 if (protocol == __constant_htons(ETH_P_8021Q)) {
1249 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1250 return max_len;
1251
1252 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1253 hdr.network += VLAN_HLEN;
1254 }
1255
1256 /* handle L3 protocols */
1257 if (protocol == __constant_htons(ETH_P_IP)) {
1258 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1259 return max_len;
1260
1261 /* access ihl as a u8 to avoid unaligned access on ia64 */
1262 hlen = (hdr.network[0] & 0x0F) << 2;
1263
1264 /* verify hlen meets minimum size requirements */
1265 if (hlen < sizeof(struct iphdr))
1266 return hdr.network - data;
1267
1268 /* record next protocol */
1269 nexthdr = hdr.ipv4->protocol;
1270 hdr.network += hlen;
f800326d 1271#ifdef IXGBE_FCOE
1d2024f6
AD
1272 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1273 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1274 return max_len;
1275 hdr.network += FCOE_HEADER_LEN;
1276#endif
1277 } else {
1278 return hdr.network - data;
1279 }
1280
1281 /* finally sort out TCP */
1282 if (nexthdr == IPPROTO_TCP) {
1283 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1284 return max_len;
1285
1286 /* access doff as a u8 to avoid unaligned access on ia64 */
1287 hlen = (hdr.network[12] & 0xF0) >> 2;
1288
1289 /* verify hlen meets minimum size requirements */
1290 if (hlen < sizeof(struct tcphdr))
1291 return hdr.network - data;
1292
1293 hdr.network += hlen;
1294 }
1295
1296 /*
1297 * If everything has gone correctly hdr.network should be the
1298 * data section of the packet and will be the end of the header.
1299 * If not then it probably represents the end of the last recognized
1300 * header.
1301 */
1302 if ((hdr.network - data) < max_len)
1303 return hdr.network - data;
1304 else
1305 return max_len;
1306}
1307
4c1975d7
AD
1308static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1309 union ixgbe_adv_rx_desc *rx_desc,
1310 struct sk_buff *skb)
aa80175a 1311{
4c1975d7
AD
1312 __le32 rsc_enabled;
1313 u32 rsc_cnt;
1314
1315 if (!ring_is_rsc_enabled(rx_ring))
1316 return;
1317
1318 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1319 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1320
1321 /* If this is an RSC frame rsc_cnt should be non-zero */
1322 if (!rsc_enabled)
1323 return;
1324
1325 rsc_cnt = le32_to_cpu(rsc_enabled);
1326 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1327
1328 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
aa80175a 1329}
43634e82 1330
1d2024f6
AD
1331static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1332 struct sk_buff *skb)
1333{
f800326d 1334 u16 hdr_len = skb_headlen(skb);
1d2024f6
AD
1335
1336 /* set gso_size to avoid messing up TCP MSS */
1337 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1338 IXGBE_CB(skb)->append_cnt);
1339}
1340
1341static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1342 struct sk_buff *skb)
1343{
1344 /* if append_cnt is 0 then frame is not RSC */
1345 if (!IXGBE_CB(skb)->append_cnt)
1346 return;
1347
1348 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1349 rx_ring->rx_stats.rsc_flush++;
1350
1351 ixgbe_set_rsc_gso_size(rx_ring, skb);
1352
1353 /* gso_size is computed using append_cnt so always clear it last */
1354 IXGBE_CB(skb)->append_cnt = 0;
1355}
1356
8a0da21b
AD
1357/**
1358 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1359 * @rx_ring: rx descriptor ring packet is being transacted on
1360 * @rx_desc: pointer to the EOP Rx descriptor
1361 * @skb: pointer to current skb being populated
f8212f97 1362 *
8a0da21b
AD
1363 * This function checks the ring, descriptor, and packet information in
1364 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1365 * other fields within the skb.
f8212f97 1366 **/
8a0da21b
AD
1367static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1368 union ixgbe_adv_rx_desc *rx_desc,
1369 struct sk_buff *skb)
f8212f97 1370{
8a0da21b
AD
1371 ixgbe_update_rsc_stats(rx_ring, skb);
1372
1373 ixgbe_rx_hash(rx_ring, rx_desc, skb);
f8212f97 1374
8a0da21b
AD
1375 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1376
1377 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1378 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1379 __vlan_hwaccel_put_tag(skb, vid);
f8212f97
AD
1380 }
1381
8a0da21b 1382 skb_record_rx_queue(skb, rx_ring->queue_index);
aa80175a 1383
8a0da21b 1384 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
f8212f97
AD
1385}
1386
8a0da21b
AD
1387static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1388 struct sk_buff *skb)
aa80175a 1389{
8a0da21b
AD
1390 struct ixgbe_adapter *adapter = q_vector->adapter;
1391
1392 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1393 napi_gro_receive(&q_vector->napi, skb);
1394 else
1395 netif_rx(skb);
aa80175a 1396}
43634e82 1397
f800326d
AD
1398/**
1399 * ixgbe_is_non_eop - process handling of non-EOP buffers
1400 * @rx_ring: Rx ring being processed
1401 * @rx_desc: Rx descriptor for current buffer
1402 * @skb: Current socket buffer containing buffer in progress
1403 *
1404 * This function updates next to clean. If the buffer is an EOP buffer
1405 * this function exits returning false, otherwise it will place the
1406 * sk_buff in the next buffer to be chained and return true indicating
1407 * that this is in fact a non-EOP buffer.
1408 **/
1409static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1410 union ixgbe_adv_rx_desc *rx_desc,
1411 struct sk_buff *skb)
1412{
1413 u32 ntc = rx_ring->next_to_clean + 1;
1414
1415 /* fetch, update, and store next to clean */
1416 ntc = (ntc < rx_ring->count) ? ntc : 0;
1417 rx_ring->next_to_clean = ntc;
1418
1419 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1420
1421 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1422 return false;
1423
1424 /* append_cnt indicates packet is RSC, if so fetch nextp */
1425 if (IXGBE_CB(skb)->append_cnt) {
1426 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1427 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1428 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1429 }
1430
1431 /* place skb in next buffer to be received */
1432 rx_ring->rx_buffer_info[ntc].skb = skb;
1433 rx_ring->rx_stats.non_eop_descs++;
1434
1435 return true;
1436}
1437
1438/**
1439 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1440 * @rx_ring: rx descriptor ring packet is being transacted on
1441 * @rx_desc: pointer to the EOP Rx descriptor
1442 * @skb: pointer to current skb being fixed
1443 *
1444 * Check for corrupted packet headers caused by senders on the local L2
1445 * embedded NIC switch not setting up their Tx Descriptors right. These
1446 * should be very rare.
1447 *
1448 * Also address the case where we are pulling data in on pages only
1449 * and as such no data is present in the skb header.
1450 *
1451 * In addition if skb is not at least 60 bytes we need to pad it so that
1452 * it is large enough to qualify as a valid Ethernet frame.
1453 *
1454 * Returns true if an error was encountered and skb was freed.
1455 **/
1456static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1457 union ixgbe_adv_rx_desc *rx_desc,
1458 struct sk_buff *skb)
1459{
1460 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1461 struct net_device *netdev = rx_ring->netdev;
1462 unsigned char *va;
1463 unsigned int pull_len;
1464
1465 /* if the page was released unmap it, else just sync our portion */
1466 if (unlikely(IXGBE_CB(skb)->page_released)) {
1467 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1468 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1469 IXGBE_CB(skb)->page_released = false;
1470 } else {
1471 dma_sync_single_range_for_cpu(rx_ring->dev,
1472 IXGBE_CB(skb)->dma,
1473 frag->page_offset,
1474 ixgbe_rx_bufsz(rx_ring),
1475 DMA_FROM_DEVICE);
1476 }
1477 IXGBE_CB(skb)->dma = 0;
1478
1479 /* verify that the packet does not have any known errors */
1480 if (unlikely(ixgbe_test_staterr(rx_desc,
1481 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1482 !(netdev->features & NETIF_F_RXALL))) {
1483 dev_kfree_skb_any(skb);
1484 return true;
1485 }
1486
1487 /*
1488 * it is valid to use page_address instead of kmap since we are
1489 * working with pages allocated out of the lomem pool per
1490 * alloc_page(GFP_ATOMIC)
1491 */
1492 va = skb_frag_address(frag);
1493
1494 /*
1495 * we need the header to contain the greater of either ETH_HLEN or
1496 * 60 bytes if the skb->len is less than 60 for skb_pad.
1497 */
1498 pull_len = skb_frag_size(frag);
1499 if (pull_len > 256)
1500 pull_len = ixgbe_get_headlen(va, pull_len);
1501
1502 /* align pull length to size of long to optimize memcpy performance */
1503 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1504
1505 /* update all of the pointers */
1506 skb_frag_size_sub(frag, pull_len);
1507 frag->page_offset += pull_len;
1508 skb->data_len -= pull_len;
1509 skb->tail += pull_len;
1510
1511 /*
1512 * if we sucked the frag empty then we should free it,
1513 * if there are other frags here something is screwed up in hardware
1514 */
1515 if (skb_frag_size(frag) == 0) {
1516 BUG_ON(skb_shinfo(skb)->nr_frags != 1);
1517 skb_shinfo(skb)->nr_frags = 0;
1518 __skb_frag_unref(frag);
1519 skb->truesize -= ixgbe_rx_bufsz(rx_ring);
1520 }
1521
1522 /* if skb_pad returns an error the skb was freed */
1523 if (unlikely(skb->len < 60)) {
1524 int pad_len = 60 - skb->len;
1525
1526 if (skb_pad(skb, pad_len))
1527 return true;
1528 __skb_put(skb, pad_len);
1529 }
1530
1531 return false;
1532}
1533
1534/**
1535 * ixgbe_can_reuse_page - determine if we can reuse a page
1536 * @rx_buffer: pointer to rx_buffer containing the page we want to reuse
1537 *
1538 * Returns true if page can be reused in another Rx buffer
1539 **/
1540static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer)
1541{
1542 struct page *page = rx_buffer->page;
1543
1544 /* if we are only owner of page and it is local we can reuse it */
1545 return likely(page_count(page) == 1) &&
1546 likely(page_to_nid(page) == numa_node_id());
1547}
1548
1549/**
1550 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1551 * @rx_ring: rx descriptor ring to store buffers on
1552 * @old_buff: donor buffer to have page reused
1553 *
1554 * Syncronizes page for reuse by the adapter
1555 **/
1556static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1557 struct ixgbe_rx_buffer *old_buff)
1558{
1559 struct ixgbe_rx_buffer *new_buff;
1560 u16 nta = rx_ring->next_to_alloc;
1561 u16 bufsz = ixgbe_rx_bufsz(rx_ring);
1562
1563 new_buff = &rx_ring->rx_buffer_info[nta];
1564
1565 /* update, and store next to alloc */
1566 nta++;
1567 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1568
1569 /* transfer page from old buffer to new buffer */
1570 new_buff->page = old_buff->page;
1571 new_buff->dma = old_buff->dma;
1572
1573 /* flip page offset to other buffer and store to new_buff */
1574 new_buff->page_offset = old_buff->page_offset ^ bufsz;
1575
1576 /* sync the buffer for use by the device */
1577 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1578 new_buff->page_offset, bufsz,
1579 DMA_FROM_DEVICE);
1580
1581 /* bump ref count on page before it is given to the stack */
1582 get_page(new_buff->page);
1583}
1584
1585/**
1586 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1587 * @rx_ring: rx descriptor ring to transact packets on
1588 * @rx_buffer: buffer containing page to add
1589 * @rx_desc: descriptor containing length of buffer written by hardware
1590 * @skb: sk_buff to place the data into
1591 *
1592 * This function is based on skb_add_rx_frag. I would have used that
1593 * function however it doesn't handle the truesize case correctly since we
1594 * are allocating more memory than might be used for a single receive.
1595 **/
1596static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1597 struct ixgbe_rx_buffer *rx_buffer,
1598 struct sk_buff *skb, int size)
1599{
1600 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1601 rx_buffer->page, rx_buffer->page_offset,
1602 size);
1603 skb->len += size;
1604 skb->data_len += size;
1605 skb->truesize += ixgbe_rx_bufsz(rx_ring);
1606}
1607
1608/**
1609 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1610 * @q_vector: structure containing interrupt and ring information
1611 * @rx_ring: rx descriptor ring to transact packets on
1612 * @budget: Total limit on number of packets to process
1613 *
1614 * This function provides a "bounce buffer" approach to Rx interrupt
1615 * processing. The advantage to this is that on systems that have
1616 * expensive overhead for IOMMU access this provides a means of avoiding
1617 * it by maintaining the mapping of the page to the syste.
1618 *
1619 * Returns true if all work is completed without reaching budget
1620 **/
4ff7fb12 1621static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
e8e9f696 1622 struct ixgbe_ring *rx_ring,
4ff7fb12 1623 int budget)
9a799d71 1624{
d2f4fbe2 1625 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
3f2d1c0f 1626#ifdef IXGBE_FCOE
f800326d 1627 struct ixgbe_adapter *adapter = q_vector->adapter;
3d8fd385
YZ
1628 int ddp_bytes = 0;
1629#endif /* IXGBE_FCOE */
f800326d 1630 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
9a799d71 1631
f800326d
AD
1632 do {
1633 struct ixgbe_rx_buffer *rx_buffer;
1634 union ixgbe_adv_rx_desc *rx_desc;
1635 struct sk_buff *skb;
1636 struct page *page;
1637 u16 ntc;
1638
1639 /* return some buffers to hardware, one at a time is too slow */
1640 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1641 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1642 cleaned_count = 0;
1643 }
1644
1645 ntc = rx_ring->next_to_clean;
1646 rx_desc = IXGBE_RX_DESC(rx_ring, ntc);
1647 rx_buffer = &rx_ring->rx_buffer_info[ntc];
1648
1649 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1650 break;
9a799d71 1651
f800326d
AD
1652 /*
1653 * This memory barrier is needed to keep us from reading
1654 * any other fields out of the rx_desc until we know the
1655 * RXD_STAT_DD bit is set
1656 */
1657 rmb();
9a799d71 1658
f800326d
AD
1659 page = rx_buffer->page;
1660 prefetchw(page);
9a799d71 1661
f800326d 1662 skb = rx_buffer->skb;
c267fc16 1663
f800326d
AD
1664 if (likely(!skb)) {
1665 void *page_addr = page_address(page) +
1666 rx_buffer->page_offset;
9a799d71 1667
f800326d
AD
1668 /* prefetch first cache line of first page */
1669 prefetch(page_addr);
1670#if L1_CACHE_BYTES < 128
1671 prefetch(page_addr + L1_CACHE_BYTES);
1672#endif
1673
1674 /* allocate a skb to store the frags */
1675 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1676 IXGBE_RX_HDR_SIZE);
1677 if (unlikely(!skb)) {
1678 rx_ring->rx_stats.alloc_rx_buff_failed++;
1679 break;
c267fc16
AD
1680 }
1681
f800326d
AD
1682 /*
1683 * we will be copying header into skb->data in
1684 * pskb_may_pull so it is in our interest to prefetch
1685 * it now to avoid a possible cache miss
1686 */
1687 prefetchw(skb->data);
4c1975d7
AD
1688
1689 /*
1690 * Delay unmapping of the first packet. It carries the
1691 * header information, HW may still access the header
f800326d
AD
1692 * after the writeback. Only unmap it when EOP is
1693 * reached
4c1975d7 1694 */
f800326d 1695 IXGBE_CB(skb)->dma = rx_buffer->dma;
c267fc16 1696 } else {
f800326d
AD
1697 /* we are reusing so sync this buffer for CPU use */
1698 dma_sync_single_range_for_cpu(rx_ring->dev,
1699 rx_buffer->dma,
1700 rx_buffer->page_offset,
1701 ixgbe_rx_bufsz(rx_ring),
1702 DMA_FROM_DEVICE);
9a799d71
AK
1703 }
1704
f800326d
AD
1705 /* pull page into skb */
1706 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb,
1707 le16_to_cpu(rx_desc->wb.upper.length));
9a799d71 1708
f800326d
AD
1709 if (ixgbe_can_reuse_page(rx_buffer)) {
1710 /* hand second half of page back to the ring */
1711 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1712 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1713 /* the page has been released from the ring */
1714 IXGBE_CB(skb)->page_released = true;
1715 } else {
1716 /* we are not reusing the buffer so unmap it */
1717 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1718 ixgbe_rx_pg_size(rx_ring),
1719 DMA_FROM_DEVICE);
9a799d71
AK
1720 }
1721
f800326d
AD
1722 /* clear contents of buffer_info */
1723 rx_buffer->skb = NULL;
1724 rx_buffer->dma = 0;
1725 rx_buffer->page = NULL;
4c1975d7 1726
f800326d 1727 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
9a799d71 1728
9a799d71 1729 cleaned_count++;
f8212f97 1730
f800326d
AD
1731 /* place incomplete frames back on ring for completion */
1732 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1733 continue;
c267fc16 1734
f800326d
AD
1735 /* verify the packet layout is correct */
1736 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1737 continue;
9a799d71 1738
d2f4fbe2
AV
1739 /* probably a little skewed due to removing CRC */
1740 total_rx_bytes += skb->len;
1741 total_rx_packets++;
1742
8a0da21b
AD
1743 /* populate checksum, timestamp, VLAN, and protocol */
1744 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1745
332d4a7d
YZ
1746#ifdef IXGBE_FCOE
1747 /* if ddp, not passing to ULD unless for FCP_RSP or error */
ff886dfc 1748 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
f56e0cb1 1749 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
63d635b2
AD
1750 if (!ddp_bytes) {
1751 dev_kfree_skb_any(skb);
f800326d 1752 continue;
63d635b2 1753 }
3d8fd385 1754 }
f800326d 1755
332d4a7d 1756#endif /* IXGBE_FCOE */
8a0da21b 1757 ixgbe_rx_skb(q_vector, skb);
9a799d71 1758
f800326d 1759 /* update budget accounting */
4ff7fb12 1760 budget--;
f800326d 1761 } while (likely(budget));
9a799d71 1762
3d8fd385
YZ
1763#ifdef IXGBE_FCOE
1764 /* include DDPed FCoE data */
1765 if (ddp_bytes > 0) {
1766 unsigned int mss;
1767
fc77dc3c 1768 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
3d8fd385
YZ
1769 sizeof(struct fc_frame_header) -
1770 sizeof(struct fcoe_crc_eof);
1771 if (mss > 512)
1772 mss &= ~511;
1773 total_rx_bytes += ddp_bytes;
1774 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1775 }
3d8fd385 1776
f800326d 1777#endif /* IXGBE_FCOE */
c267fc16
AD
1778 u64_stats_update_begin(&rx_ring->syncp);
1779 rx_ring->stats.packets += total_rx_packets;
1780 rx_ring->stats.bytes += total_rx_bytes;
1781 u64_stats_update_end(&rx_ring->syncp);
bd198058
AD
1782 q_vector->rx.total_packets += total_rx_packets;
1783 q_vector->rx.total_bytes += total_rx_bytes;
4ff7fb12 1784
f800326d
AD
1785 if (cleaned_count)
1786 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1787
4ff7fb12 1788 return !!budget;
9a799d71
AK
1789}
1790
9a799d71
AK
1791/**
1792 * ixgbe_configure_msix - Configure MSI-X hardware
1793 * @adapter: board private structure
1794 *
1795 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1796 * interrupts.
1797 **/
1798static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1799{
021230d4 1800 struct ixgbe_q_vector *q_vector;
efe3d3c8 1801 int q_vectors, v_idx;
021230d4 1802 u32 mask;
9a799d71 1803
021230d4 1804 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
9a799d71 1805
8e34d1aa
AD
1806 /* Populate MSIX to EITR Select */
1807 if (adapter->num_vfs > 32) {
1808 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1809 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1810 }
1811
4df10466
JB
1812 /*
1813 * Populate the IVAR table and set the ITR values to the
021230d4
AV
1814 * corresponding register.
1815 */
1816 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
efe3d3c8 1817 struct ixgbe_ring *ring;
7a921c93 1818 q_vector = adapter->q_vector[v_idx];
021230d4 1819
a557928e 1820 ixgbe_for_each_ring(ring, q_vector->rx)
efe3d3c8
AD
1821 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
1822
a557928e 1823 ixgbe_for_each_ring(ring, q_vector->tx)
efe3d3c8
AD
1824 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
1825
d5bf4f67
ET
1826 if (q_vector->tx.ring && !q_vector->rx.ring) {
1827 /* tx only vector */
1828 if (adapter->tx_itr_setting == 1)
1829 q_vector->itr = IXGBE_10K_ITR;
1830 else
1831 q_vector->itr = adapter->tx_itr_setting;
1832 } else {
1833 /* rx or rx/tx vector */
1834 if (adapter->rx_itr_setting == 1)
1835 q_vector->itr = IXGBE_20K_ITR;
1836 else
1837 q_vector->itr = adapter->rx_itr_setting;
1838 }
021230d4 1839
fe49f04a 1840 ixgbe_write_eitr(q_vector);
9a799d71
AK
1841 }
1842
bd508178
AD
1843 switch (adapter->hw.mac.type) {
1844 case ixgbe_mac_82598EB:
e8e26350 1845 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
e8e9f696 1846 v_idx);
bd508178
AD
1847 break;
1848 case ixgbe_mac_82599EB:
b93a2226 1849 case ixgbe_mac_X540:
e8e26350 1850 ixgbe_set_ivar(adapter, -1, 1, v_idx);
bd508178 1851 break;
bd508178
AD
1852 default:
1853 break;
1854 }
021230d4
AV
1855 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
1856
41fb9248 1857 /* set up to autoclear timer, and the vectors */
021230d4 1858 mask = IXGBE_EIMS_ENABLE_MASK;
d5bf4f67
ET
1859 mask &= ~(IXGBE_EIMS_OTHER |
1860 IXGBE_EIMS_MAILBOX |
1861 IXGBE_EIMS_LSC);
1862
021230d4 1863 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
9a799d71
AK
1864}
1865
f494e8fa
AV
1866enum latency_range {
1867 lowest_latency = 0,
1868 low_latency = 1,
1869 bulk_latency = 2,
1870 latency_invalid = 255
1871};
1872
1873/**
1874 * ixgbe_update_itr - update the dynamic ITR value based on statistics
bd198058
AD
1875 * @q_vector: structure containing interrupt and ring information
1876 * @ring_container: structure containing ring performance data
f494e8fa
AV
1877 *
1878 * Stores a new ITR value based on packets and byte
1879 * counts during the last interrupt. The advantage of per interrupt
1880 * computation is faster updates and more accurate ITR for the current
1881 * traffic pattern. Constants in this function were computed
1882 * based on theoretical maximum wire speed and thresholds were set based
1883 * on testing data as well as attempting to minimize response time
1884 * while increasing bulk throughput.
1885 * this functionality is controlled by the InterruptThrottleRate module
1886 * parameter (see ixgbe_param.c)
1887 **/
bd198058
AD
1888static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1889 struct ixgbe_ring_container *ring_container)
f494e8fa 1890{
bd198058
AD
1891 int bytes = ring_container->total_bytes;
1892 int packets = ring_container->total_packets;
1893 u32 timepassed_us;
621bd70e 1894 u64 bytes_perint;
bd198058 1895 u8 itr_setting = ring_container->itr;
f494e8fa
AV
1896
1897 if (packets == 0)
bd198058 1898 return;
f494e8fa
AV
1899
1900 /* simple throttlerate management
621bd70e
AD
1901 * 0-10MB/s lowest (100000 ints/s)
1902 * 10-20MB/s low (20000 ints/s)
1903 * 20-1249MB/s bulk (8000 ints/s)
f494e8fa
AV
1904 */
1905 /* what was last interrupt timeslice? */
d5bf4f67 1906 timepassed_us = q_vector->itr >> 2;
f494e8fa
AV
1907 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1908
1909 switch (itr_setting) {
1910 case lowest_latency:
621bd70e 1911 if (bytes_perint > 10)
bd198058 1912 itr_setting = low_latency;
f494e8fa
AV
1913 break;
1914 case low_latency:
621bd70e 1915 if (bytes_perint > 20)
bd198058 1916 itr_setting = bulk_latency;
621bd70e 1917 else if (bytes_perint <= 10)
bd198058 1918 itr_setting = lowest_latency;
f494e8fa
AV
1919 break;
1920 case bulk_latency:
621bd70e 1921 if (bytes_perint <= 20)
bd198058 1922 itr_setting = low_latency;
f494e8fa
AV
1923 break;
1924 }
1925
bd198058
AD
1926 /* clear work counters since we have the values we need */
1927 ring_container->total_bytes = 0;
1928 ring_container->total_packets = 0;
1929
1930 /* write updated itr to ring container */
1931 ring_container->itr = itr_setting;
f494e8fa
AV
1932}
1933
509ee935
JB
1934/**
1935 * ixgbe_write_eitr - write EITR register in hardware specific way
fe49f04a 1936 * @q_vector: structure containing interrupt and ring information
509ee935
JB
1937 *
1938 * This function is made to be called by ethtool and by the driver
1939 * when it needs to update EITR registers at runtime. Hardware
1940 * specific quirks/differences are taken care of here.
1941 */
fe49f04a 1942void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
509ee935 1943{
fe49f04a 1944 struct ixgbe_adapter *adapter = q_vector->adapter;
509ee935 1945 struct ixgbe_hw *hw = &adapter->hw;
fe49f04a 1946 int v_idx = q_vector->v_idx;
5d967eb7 1947 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
fe49f04a 1948
bd508178
AD
1949 switch (adapter->hw.mac.type) {
1950 case ixgbe_mac_82598EB:
509ee935
JB
1951 /* must write high and low 16 bits to reset counter */
1952 itr_reg |= (itr_reg << 16);
bd508178
AD
1953 break;
1954 case ixgbe_mac_82599EB:
b93a2226 1955 case ixgbe_mac_X540:
509ee935
JB
1956 /*
1957 * set the WDIS bit to not clear the timer bits and cause an
1958 * immediate assertion of the interrupt
1959 */
1960 itr_reg |= IXGBE_EITR_CNT_WDIS;
bd508178
AD
1961 break;
1962 default:
1963 break;
509ee935
JB
1964 }
1965 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1966}
1967
bd198058 1968static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
f494e8fa 1969{
d5bf4f67 1970 u32 new_itr = q_vector->itr;
bd198058 1971 u8 current_itr;
f494e8fa 1972
bd198058
AD
1973 ixgbe_update_itr(q_vector, &q_vector->tx);
1974 ixgbe_update_itr(q_vector, &q_vector->rx);
f494e8fa 1975
08c8833b 1976 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
f494e8fa
AV
1977
1978 switch (current_itr) {
1979 /* counts and packets in update_itr are dependent on these numbers */
1980 case lowest_latency:
d5bf4f67 1981 new_itr = IXGBE_100K_ITR;
f494e8fa
AV
1982 break;
1983 case low_latency:
d5bf4f67 1984 new_itr = IXGBE_20K_ITR;
f494e8fa
AV
1985 break;
1986 case bulk_latency:
d5bf4f67 1987 new_itr = IXGBE_8K_ITR;
f494e8fa 1988 break;
bd198058
AD
1989 default:
1990 break;
f494e8fa
AV
1991 }
1992
d5bf4f67 1993 if (new_itr != q_vector->itr) {
fe49f04a 1994 /* do an exponential smoothing */
d5bf4f67
ET
1995 new_itr = (10 * new_itr * q_vector->itr) /
1996 ((9 * new_itr) + q_vector->itr);
509ee935 1997
bd198058 1998 /* save the algorithm value here */
5d967eb7 1999 q_vector->itr = new_itr;
fe49f04a
AD
2000
2001 ixgbe_write_eitr(q_vector);
f494e8fa 2002 }
f494e8fa
AV
2003}
2004
119fc60a 2005/**
de88eeeb 2006 * ixgbe_check_overtemp_subtask - check for over temperature
f0f9778d 2007 * @adapter: pointer to adapter
119fc60a 2008 **/
f0f9778d 2009static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
119fc60a 2010{
119fc60a
MC
2011 struct ixgbe_hw *hw = &adapter->hw;
2012 u32 eicr = adapter->interrupt_event;
2013
f0f9778d 2014 if (test_bit(__IXGBE_DOWN, &adapter->state))
7ca647bd
JP
2015 return;
2016
f0f9778d
AD
2017 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2018 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2019 return;
2020
2021 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2022
7ca647bd 2023 switch (hw->device_id) {
f0f9778d
AD
2024 case IXGBE_DEV_ID_82599_T3_LOM:
2025 /*
2026 * Since the warning interrupt is for both ports
2027 * we don't have to check if:
2028 * - This interrupt wasn't for our port.
2029 * - We may have missed the interrupt so always have to
2030 * check if we got a LSC
2031 */
2032 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2033 !(eicr & IXGBE_EICR_LSC))
2034 return;
2035
2036 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2037 u32 autoneg;
2038 bool link_up = false;
7ca647bd 2039
7ca647bd
JP
2040 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2041
f0f9778d
AD
2042 if (link_up)
2043 return;
2044 }
2045
2046 /* Check if this is not due to overtemp */
2047 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2048 return;
2049
2050 break;
7ca647bd
JP
2051 default:
2052 if (!(eicr & IXGBE_EICR_GPI_SDP0))
119fc60a 2053 return;
7ca647bd 2054 break;
119fc60a 2055 }
7ca647bd
JP
2056 e_crit(drv,
2057 "Network adapter has been stopped because it has over heated. "
2058 "Restart the computer. If the problem persists, "
2059 "power off the system and replace the adapter\n");
f0f9778d
AD
2060
2061 adapter->interrupt_event = 0;
119fc60a
MC
2062}
2063
0befdb3e
JB
2064static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2065{
2066 struct ixgbe_hw *hw = &adapter->hw;
2067
2068 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2069 (eicr & IXGBE_EICR_GPI_SDP1)) {
396e799c 2070 e_crit(probe, "Fan has stopped, replace the adapter\n");
0befdb3e
JB
2071 /* write to clear the interrupt */
2072 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2073 }
2074}
cf8280ee 2075
4f51bf70
JK
2076static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2077{
2078 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2079 return;
2080
2081 switch (adapter->hw.mac.type) {
2082 case ixgbe_mac_82599EB:
2083 /*
2084 * Need to check link state so complete overtemp check
2085 * on service task
2086 */
2087 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2088 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2089 adapter->interrupt_event = eicr;
2090 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2091 ixgbe_service_event_schedule(adapter);
2092 return;
2093 }
2094 return;
2095 case ixgbe_mac_X540:
2096 if (!(eicr & IXGBE_EICR_TS))
2097 return;
2098 break;
2099 default:
2100 return;
2101 }
2102
2103 e_crit(drv,
2104 "Network adapter has been stopped because it has over heated. "
2105 "Restart the computer. If the problem persists, "
2106 "power off the system and replace the adapter\n");
2107}
2108
e8e26350
PW
2109static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2110{
2111 struct ixgbe_hw *hw = &adapter->hw;
2112
73c4b7cd
AD
2113 if (eicr & IXGBE_EICR_GPI_SDP2) {
2114 /* Clear the interrupt */
2115 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
7086400d
AD
2116 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2117 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2118 ixgbe_service_event_schedule(adapter);
2119 }
73c4b7cd
AD
2120 }
2121
e8e26350
PW
2122 if (eicr & IXGBE_EICR_GPI_SDP1) {
2123 /* Clear the interrupt */
2124 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
7086400d
AD
2125 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2126 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2127 ixgbe_service_event_schedule(adapter);
2128 }
e8e26350
PW
2129 }
2130}
2131
cf8280ee
JB
2132static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2133{
2134 struct ixgbe_hw *hw = &adapter->hw;
2135
2136 adapter->lsc_int++;
2137 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2138 adapter->link_check_timeout = jiffies;
2139 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2140 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
8a0717f3 2141 IXGBE_WRITE_FLUSH(hw);
93c52dd0 2142 ixgbe_service_event_schedule(adapter);
cf8280ee
JB
2143 }
2144}
2145
fe49f04a
AD
2146static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2147 u64 qmask)
2148{
2149 u32 mask;
bd508178 2150 struct ixgbe_hw *hw = &adapter->hw;
fe49f04a 2151
bd508178
AD
2152 switch (hw->mac.type) {
2153 case ixgbe_mac_82598EB:
fe49f04a 2154 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
bd508178
AD
2155 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2156 break;
2157 case ixgbe_mac_82599EB:
b93a2226 2158 case ixgbe_mac_X540:
fe49f04a 2159 mask = (qmask & 0xFFFFFFFF);
bd508178
AD
2160 if (mask)
2161 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
fe49f04a 2162 mask = (qmask >> 32);
bd508178
AD
2163 if (mask)
2164 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2165 break;
2166 default:
2167 break;
fe49f04a
AD
2168 }
2169 /* skip the flush */
2170}
2171
2172static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
e8e9f696 2173 u64 qmask)
fe49f04a
AD
2174{
2175 u32 mask;
bd508178 2176 struct ixgbe_hw *hw = &adapter->hw;
fe49f04a 2177
bd508178
AD
2178 switch (hw->mac.type) {
2179 case ixgbe_mac_82598EB:
fe49f04a 2180 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
bd508178
AD
2181 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2182 break;
2183 case ixgbe_mac_82599EB:
b93a2226 2184 case ixgbe_mac_X540:
fe49f04a 2185 mask = (qmask & 0xFFFFFFFF);
bd508178
AD
2186 if (mask)
2187 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
fe49f04a 2188 mask = (qmask >> 32);
bd508178
AD
2189 if (mask)
2190 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2191 break;
2192 default:
2193 break;
fe49f04a
AD
2194 }
2195 /* skip the flush */
2196}
2197
021230d4 2198/**
2c4af694
AD
2199 * ixgbe_irq_enable - Enable default interrupt generation settings
2200 * @adapter: board private structure
021230d4 2201 **/
2c4af694
AD
2202static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2203 bool flush)
9a799d71 2204{
2c4af694 2205 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
9a799d71 2206
2c4af694
AD
2207 /* don't reenable LSC while waiting for link */
2208 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2209 mask &= ~IXGBE_EIMS_LSC;
9a799d71 2210
2c4af694 2211 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
4f51bf70
JK
2212 switch (adapter->hw.mac.type) {
2213 case ixgbe_mac_82599EB:
2214 mask |= IXGBE_EIMS_GPI_SDP0;
2215 break;
2216 case ixgbe_mac_X540:
2217 mask |= IXGBE_EIMS_TS;
2218 break;
2219 default:
2220 break;
2221 }
2c4af694
AD
2222 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2223 mask |= IXGBE_EIMS_GPI_SDP1;
2224 switch (adapter->hw.mac.type) {
2225 case ixgbe_mac_82599EB:
2c4af694
AD
2226 mask |= IXGBE_EIMS_GPI_SDP1;
2227 mask |= IXGBE_EIMS_GPI_SDP2;
858bc081
DS
2228 case ixgbe_mac_X540:
2229 mask |= IXGBE_EIMS_ECC;
2c4af694
AD
2230 mask |= IXGBE_EIMS_MAILBOX;
2231 break;
2232 default:
2233 break;
9a799d71 2234 }
2c4af694
AD
2235 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2236 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2237 mask |= IXGBE_EIMS_FLOW_DIR;
9a799d71 2238
2c4af694
AD
2239 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2240 if (queues)
2241 ixgbe_irq_enable_queues(adapter, ~0);
2242 if (flush)
2243 IXGBE_WRITE_FLUSH(&adapter->hw);
9a799d71
AK
2244}
2245
2c4af694 2246static irqreturn_t ixgbe_msix_other(int irq, void *data)
f0848276 2247{
a65151ba 2248 struct ixgbe_adapter *adapter = data;
9a799d71 2249 struct ixgbe_hw *hw = &adapter->hw;
54037505 2250 u32 eicr;
91281fd3 2251
54037505
DS
2252 /*
2253 * Workaround for Silicon errata. Use clear-by-write instead
2254 * of clear-by-read. Reading with EICS will return the
2255 * interrupt causes without clearing, which later be done
2256 * with the write to EICR.
2257 */
2258 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2259 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
33cf09c9 2260
cf8280ee
JB
2261 if (eicr & IXGBE_EICR_LSC)
2262 ixgbe_check_lsc(adapter);
f0848276 2263
1cdd1ec8
GR
2264 if (eicr & IXGBE_EICR_MAILBOX)
2265 ixgbe_msg_task(adapter);
efe3d3c8 2266
bd508178
AD
2267 switch (hw->mac.type) {
2268 case ixgbe_mac_82599EB:
b93a2226 2269 case ixgbe_mac_X540:
2c4af694
AD
2270 if (eicr & IXGBE_EICR_ECC)
2271 e_info(link, "Received unrecoverable ECC Err, please "
2272 "reboot\n");
c4cf55e5
PWJ
2273 /* Handle Flow Director Full threshold interrupt */
2274 if (eicr & IXGBE_EICR_FLOW_DIR) {
d034acf1 2275 int reinit_count = 0;
c4cf55e5 2276 int i;
c4cf55e5 2277 for (i = 0; i < adapter->num_tx_queues; i++) {
d034acf1 2278 struct ixgbe_ring *ring = adapter->tx_ring[i];
7d637bcc 2279 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
d034acf1
AD
2280 &ring->state))
2281 reinit_count++;
2282 }
2283 if (reinit_count) {
2284 /* no more flow director interrupts until after init */
2285 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
d034acf1
AD
2286 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2287 ixgbe_service_event_schedule(adapter);
c4cf55e5
PWJ
2288 }
2289 }
f0f9778d 2290 ixgbe_check_sfp_event(adapter, eicr);
4f51bf70 2291 ixgbe_check_overtemp_event(adapter, eicr);
bd508178
AD
2292 break;
2293 default:
2294 break;
c4cf55e5 2295 }
f0848276 2296
bd508178 2297 ixgbe_check_fan_failure(adapter, eicr);
efe3d3c8 2298
7086400d 2299 /* re-enable the original interrupt state, no lsc, no queues */
d4f80882 2300 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2c4af694 2301 ixgbe_irq_enable(adapter, false, false);
f0848276 2302
9a799d71 2303 return IRQ_HANDLED;
f0848276 2304}
91281fd3 2305
4ff7fb12 2306static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
91281fd3 2307{
021230d4 2308 struct ixgbe_q_vector *q_vector = data;
91281fd3 2309
9b471446 2310 /* EIAM disabled interrupts (on this vector) for us */
91281fd3 2311
4ff7fb12
AD
2312 if (q_vector->rx.ring || q_vector->tx.ring)
2313 napi_schedule(&q_vector->napi);
91281fd3 2314
9a799d71 2315 return IRQ_HANDLED;
91281fd3
AD
2316}
2317
eb01b975
AD
2318/**
2319 * ixgbe_poll - NAPI Rx polling callback
2320 * @napi: structure for representing this polling device
2321 * @budget: how many packets driver is allowed to clean
2322 *
2323 * This function is used for legacy and MSI, NAPI mode
2324 **/
8af3c33f 2325int ixgbe_poll(struct napi_struct *napi, int budget)
eb01b975
AD
2326{
2327 struct ixgbe_q_vector *q_vector =
2328 container_of(napi, struct ixgbe_q_vector, napi);
2329 struct ixgbe_adapter *adapter = q_vector->adapter;
2330 struct ixgbe_ring *ring;
2331 int per_ring_budget;
2332 bool clean_complete = true;
2333
2334#ifdef CONFIG_IXGBE_DCA
2335 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2336 ixgbe_update_dca(q_vector);
2337#endif
2338
2339 ixgbe_for_each_ring(ring, q_vector->tx)
2340 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2341
2342 /* attempt to distribute budget to each queue fairly, but don't allow
2343 * the budget to go below 1 because we'll exit polling */
2344 if (q_vector->rx.count > 1)
2345 per_ring_budget = max(budget/q_vector->rx.count, 1);
2346 else
2347 per_ring_budget = budget;
2348
2349 ixgbe_for_each_ring(ring, q_vector->rx)
2350 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2351 per_ring_budget);
2352
2353 /* If all work not completed, return budget and keep polling */
2354 if (!clean_complete)
2355 return budget;
2356
2357 /* all work done, exit the polling mode */
2358 napi_complete(napi);
2359 if (adapter->rx_itr_setting & 1)
2360 ixgbe_set_itr(q_vector);
2361 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2362 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2363
2364 return 0;
2365}
2366
021230d4
AV
2367/**
2368 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2369 * @adapter: board private structure
2370 *
2371 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2372 * interrupts from the kernel.
2373 **/
2374static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2375{
2376 struct net_device *netdev = adapter->netdev;
207867f5
AD
2377 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2378 int vector, err;
e8e9f696 2379 int ri = 0, ti = 0;
021230d4 2380
021230d4 2381 for (vector = 0; vector < q_vectors; vector++) {
d0759ebb 2382 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
207867f5 2383 struct msix_entry *entry = &adapter->msix_entries[vector];
cb13fc20 2384
4ff7fb12 2385 if (q_vector->tx.ring && q_vector->rx.ring) {
9fe93afd 2386 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
4ff7fb12
AD
2387 "%s-%s-%d", netdev->name, "TxRx", ri++);
2388 ti++;
2389 } else if (q_vector->rx.ring) {
9fe93afd 2390 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
4ff7fb12
AD
2391 "%s-%s-%d", netdev->name, "rx", ri++);
2392 } else if (q_vector->tx.ring) {
9fe93afd 2393 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
4ff7fb12 2394 "%s-%s-%d", netdev->name, "tx", ti++);
d0759ebb
AD
2395 } else {
2396 /* skip this unused q_vector */
2397 continue;
32aa77a4 2398 }
207867f5
AD
2399 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2400 q_vector->name, q_vector);
9a799d71 2401 if (err) {
396e799c 2402 e_err(probe, "request_irq failed for MSIX interrupt "
849c4542 2403 "Error: %d\n", err);
021230d4 2404 goto free_queue_irqs;
9a799d71 2405 }
207867f5
AD
2406 /* If Flow Director is enabled, set interrupt affinity */
2407 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2408 /* assign the mask for this irq */
2409 irq_set_affinity_hint(entry->vector,
de88eeeb 2410 &q_vector->affinity_mask);
207867f5 2411 }
9a799d71
AK
2412 }
2413
021230d4 2414 err = request_irq(adapter->msix_entries[vector].vector,
2c4af694 2415 ixgbe_msix_other, 0, netdev->name, adapter);
9a799d71 2416 if (err) {
de88eeeb 2417 e_err(probe, "request_irq for msix_other failed: %d\n", err);
021230d4 2418 goto free_queue_irqs;
9a799d71
AK
2419 }
2420
9a799d71
AK
2421 return 0;
2422
021230d4 2423free_queue_irqs:
207867f5
AD
2424 while (vector) {
2425 vector--;
2426 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2427 NULL);
2428 free_irq(adapter->msix_entries[vector].vector,
2429 adapter->q_vector[vector]);
2430 }
021230d4
AV
2431 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2432 pci_disable_msix(adapter->pdev);
9a799d71
AK
2433 kfree(adapter->msix_entries);
2434 adapter->msix_entries = NULL;
9a799d71
AK
2435 return err;
2436}
2437
2438/**
021230d4 2439 * ixgbe_intr - legacy mode Interrupt Handler
9a799d71
AK
2440 * @irq: interrupt number
2441 * @data: pointer to a network interface device structure
9a799d71
AK
2442 **/
2443static irqreturn_t ixgbe_intr(int irq, void *data)
2444{
a65151ba 2445 struct ixgbe_adapter *adapter = data;
9a799d71 2446 struct ixgbe_hw *hw = &adapter->hw;
7a921c93 2447 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
9a799d71
AK
2448 u32 eicr;
2449
54037505 2450 /*
24ddd967 2451 * Workaround for silicon errata #26 on 82598. Mask the interrupt
54037505
DS
2452 * before the read of EICR.
2453 */
2454 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2455
021230d4 2456 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
52f33af8 2457 * therefore no explicit interrupt disable is necessary */
021230d4 2458 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
f47cf66e 2459 if (!eicr) {
6af3b9eb
ET
2460 /*
2461 * shared interrupt alert!
f47cf66e 2462 * make sure interrupts are enabled because the read will
6af3b9eb
ET
2463 * have disabled interrupts due to EIAM
2464 * finish the workaround of silicon errata on 82598. Unmask
2465 * the interrupt that we masked before the EICR read.
2466 */
2467 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2468 ixgbe_irq_enable(adapter, true, true);
9a799d71 2469 return IRQ_NONE; /* Not our interrupt */
f47cf66e 2470 }
9a799d71 2471
cf8280ee
JB
2472 if (eicr & IXGBE_EICR_LSC)
2473 ixgbe_check_lsc(adapter);
021230d4 2474
bd508178
AD
2475 switch (hw->mac.type) {
2476 case ixgbe_mac_82599EB:
e8e26350 2477 ixgbe_check_sfp_event(adapter, eicr);
0ccb974d
DS
2478 /* Fall through */
2479 case ixgbe_mac_X540:
2480 if (eicr & IXGBE_EICR_ECC)
2481 e_info(link, "Received unrecoverable ECC err, please "
2482 "reboot\n");
4f51bf70 2483 ixgbe_check_overtemp_event(adapter, eicr);
bd508178
AD
2484 break;
2485 default:
2486 break;
2487 }
e8e26350 2488
0befdb3e
JB
2489 ixgbe_check_fan_failure(adapter, eicr);
2490
b9f6ed2b
AD
2491 /* would disable interrupts here but EIAM disabled it */
2492 napi_schedule(&q_vector->napi);
9a799d71 2493
6af3b9eb
ET
2494 /*
2495 * re-enable link(maybe) and non-queue interrupts, no flush.
2496 * ixgbe_poll will re-enable the queue interrupts
2497 */
6af3b9eb
ET
2498 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2499 ixgbe_irq_enable(adapter, false, false);
2500
9a799d71
AK
2501 return IRQ_HANDLED;
2502}
2503
2504/**
2505 * ixgbe_request_irq - initialize interrupts
2506 * @adapter: board private structure
2507 *
2508 * Attempts to configure interrupts using the best available
2509 * capabilities of the hardware and kernel.
2510 **/
021230d4 2511static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
9a799d71
AK
2512{
2513 struct net_device *netdev = adapter->netdev;
021230d4 2514 int err;
9a799d71 2515
4cc6df29 2516 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
021230d4 2517 err = ixgbe_request_msix_irqs(adapter);
4cc6df29 2518 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
a0607fd3 2519 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
a65151ba 2520 netdev->name, adapter);
4cc6df29 2521 else
a0607fd3 2522 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
a65151ba 2523 netdev->name, adapter);
9a799d71 2524
de88eeeb 2525 if (err)
396e799c 2526 e_err(probe, "request_irq failed, Error %d\n", err);
9a799d71 2527
9a799d71
AK
2528 return err;
2529}
2530
2531static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2532{
9a799d71 2533 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
021230d4 2534 int i, q_vectors;
9a799d71 2535
021230d4 2536 q_vectors = adapter->num_msix_vectors;
021230d4 2537 i = q_vectors - 1;
a65151ba 2538 free_irq(adapter->msix_entries[i].vector, adapter);
021230d4 2539 i--;
4cc6df29 2540
021230d4 2541 for (; i >= 0; i--) {
894ff7cf 2542 /* free only the irqs that were actually requested */
4ff7fb12
AD
2543 if (!adapter->q_vector[i]->rx.ring &&
2544 !adapter->q_vector[i]->tx.ring)
894ff7cf
AD
2545 continue;
2546
207867f5
AD
2547 /* clear the affinity_mask in the IRQ descriptor */
2548 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2549 NULL);
2550
021230d4 2551 free_irq(adapter->msix_entries[i].vector,
e8e9f696 2552 adapter->q_vector[i]);
021230d4 2553 }
021230d4 2554 } else {
a65151ba 2555 free_irq(adapter->pdev->irq, adapter);
9a799d71
AK
2556 }
2557}
2558
22d5a71b
JB
2559/**
2560 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2561 * @adapter: board private structure
2562 **/
2563static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2564{
bd508178
AD
2565 switch (adapter->hw.mac.type) {
2566 case ixgbe_mac_82598EB:
835462fc 2567 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
bd508178
AD
2568 break;
2569 case ixgbe_mac_82599EB:
b93a2226 2570 case ixgbe_mac_X540:
835462fc
NS
2571 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2572 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
22d5a71b 2573 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
bd508178
AD
2574 break;
2575 default:
2576 break;
22d5a71b
JB
2577 }
2578 IXGBE_WRITE_FLUSH(&adapter->hw);
2579 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2580 int i;
2581 for (i = 0; i < adapter->num_msix_vectors; i++)
2582 synchronize_irq(adapter->msix_entries[i].vector);
2583 } else {
2584 synchronize_irq(adapter->pdev->irq);
2585 }
2586}
2587
9a799d71
AK
2588/**
2589 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2590 *
2591 **/
2592static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2593{
d5bf4f67 2594 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
9a799d71 2595
d5bf4f67
ET
2596 /* rx/tx vector */
2597 if (adapter->rx_itr_setting == 1)
2598 q_vector->itr = IXGBE_20K_ITR;
2599 else
2600 q_vector->itr = adapter->rx_itr_setting;
2601
2602 ixgbe_write_eitr(q_vector);
9a799d71 2603
e8e26350
PW
2604 ixgbe_set_ivar(adapter, 0, 0, 0);
2605 ixgbe_set_ivar(adapter, 1, 0, 0);
021230d4 2606
396e799c 2607 e_info(hw, "Legacy interrupt IVAR setup done\n");
9a799d71
AK
2608}
2609
43e69bf0
AD
2610/**
2611 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2612 * @adapter: board private structure
2613 * @ring: structure containing ring specific data
2614 *
2615 * Configure the Tx descriptor ring after a reset.
2616 **/
84418e3b
AD
2617void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2618 struct ixgbe_ring *ring)
43e69bf0
AD
2619{
2620 struct ixgbe_hw *hw = &adapter->hw;
2621 u64 tdba = ring->dma;
2f1860b8 2622 int wait_loop = 10;
b88c6de2 2623 u32 txdctl = IXGBE_TXDCTL_ENABLE;
bf29ee6c 2624 u8 reg_idx = ring->reg_idx;
43e69bf0 2625
2f1860b8 2626 /* disable queue to avoid issues while updating state */
b88c6de2 2627 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
2f1860b8
AD
2628 IXGBE_WRITE_FLUSH(hw);
2629
43e69bf0 2630 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
e8e9f696 2631 (tdba & DMA_BIT_MASK(32)));
43e69bf0
AD
2632 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2633 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2634 ring->count * sizeof(union ixgbe_adv_tx_desc));
2635 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2636 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
84ea2591 2637 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
43e69bf0 2638
b88c6de2
AD
2639 /*
2640 * set WTHRESH to encourage burst writeback, it should not be set
2641 * higher than 1 when ITR is 0 as it could cause false TX hangs
2642 *
2643 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2644 * to or less than the number of on chip descriptors, which is
2645 * currently 40.
2646 */
e954b374 2647 if (!ring->q_vector || (ring->q_vector->itr < 8))
b88c6de2
AD
2648 txdctl |= (1 << 16); /* WTHRESH = 1 */
2649 else
2650 txdctl |= (8 << 16); /* WTHRESH = 8 */
2651
e954b374
AD
2652 /*
2653 * Setting PTHRESH to 32 both improves performance
2654 * and avoids a TX hang with DFP enabled
2655 */
b88c6de2
AD
2656 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2657 32; /* PTHRESH = 32 */
2f1860b8
AD
2658
2659 /* reinitialize flowdirector state */
ee9e0f0b
AD
2660 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2661 adapter->atr_sample_rate) {
2662 ring->atr_sample_rate = adapter->atr_sample_rate;
2663 ring->atr_count = 0;
2664 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2665 } else {
2666 ring->atr_sample_rate = 0;
2667 }
2f1860b8 2668
c84d324c
JF
2669 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2670
2f1860b8 2671 /* enable queue */
2f1860b8
AD
2672 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2673
b2d96e0a
AD
2674 netdev_tx_reset_queue(txring_txq(ring));
2675
2f1860b8
AD
2676 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2677 if (hw->mac.type == ixgbe_mac_82598EB &&
2678 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2679 return;
2680
2681 /* poll to verify queue is enabled */
2682 do {
032b4325 2683 usleep_range(1000, 2000);
2f1860b8
AD
2684 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2685 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2686 if (!wait_loop)
2687 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
43e69bf0
AD
2688}
2689
120ff942
AD
2690static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2691{
2692 struct ixgbe_hw *hw = &adapter->hw;
2693 u32 rttdcs;
72a32f1f 2694 u32 reg;
8b1c0b24 2695 u8 tcs = netdev_get_num_tc(adapter->netdev);
120ff942
AD
2696
2697 if (hw->mac.type == ixgbe_mac_82598EB)
2698 return;
2699
2700 /* disable the arbiter while setting MTQC */
2701 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2702 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2703 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2704
2705 /* set transmit pool layout */
8b1c0b24 2706 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
120ff942
AD
2707 case (IXGBE_FLAG_SRIOV_ENABLED):
2708 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2709 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2710 break;
8b1c0b24
JF
2711 default:
2712 if (!tcs)
2713 reg = IXGBE_MTQC_64Q_1PB;
2714 else if (tcs <= 4)
2715 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2716 else
2717 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
120ff942 2718
8b1c0b24 2719 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
120ff942 2720
8b1c0b24
JF
2721 /* Enable Security TX Buffer IFG for multiple pb */
2722 if (tcs) {
2723 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2724 reg |= IXGBE_SECTX_DCB;
2725 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2726 }
120ff942
AD
2727 break;
2728 }
2729
2730 /* re-enable the arbiter */
2731 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2732 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2733}
2734
9a799d71 2735/**
3a581073 2736 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
9a799d71
AK
2737 * @adapter: board private structure
2738 *
2739 * Configure the Tx unit of the MAC after a reset.
2740 **/
2741static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2742{
2f1860b8
AD
2743 struct ixgbe_hw *hw = &adapter->hw;
2744 u32 dmatxctl;
43e69bf0 2745 u32 i;
9a799d71 2746
2f1860b8
AD
2747 ixgbe_setup_mtqc(adapter);
2748
2749 if (hw->mac.type != ixgbe_mac_82598EB) {
2750 /* DMATXCTL.EN must be before Tx queues are enabled */
2751 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2752 dmatxctl |= IXGBE_DMATXCTL_TE;
2753 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2754 }
2755
9a799d71 2756 /* Setup the HW Tx Head and Tail descriptor pointers */
43e69bf0
AD
2757 for (i = 0; i < adapter->num_tx_queues; i++)
2758 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
9a799d71
AK
2759}
2760
e8e26350 2761#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
cc41ac7c 2762
a6616b42 2763static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
e8e9f696 2764 struct ixgbe_ring *rx_ring)
cc41ac7c 2765{
cc41ac7c 2766 u32 srrctl;
bf29ee6c 2767 u8 reg_idx = rx_ring->reg_idx;
3be1adfb 2768
bd508178
AD
2769 switch (adapter->hw.mac.type) {
2770 case ixgbe_mac_82598EB: {
2771 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2772 const int mask = feature[RING_F_RSS].mask;
bf29ee6c 2773 reg_idx = reg_idx & mask;
cc41ac7c 2774 }
bd508178
AD
2775 break;
2776 case ixgbe_mac_82599EB:
b93a2226 2777 case ixgbe_mac_X540:
bd508178
AD
2778 default:
2779 break;
2780 }
2781
bf29ee6c 2782 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
cc41ac7c
JB
2783
2784 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2785 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
9e10e045
AD
2786 if (adapter->num_vfs)
2787 srrctl |= IXGBE_SRRCTL_DROP_EN;
cc41ac7c 2788
afafd5b0
AD
2789 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2790 IXGBE_SRRCTL_BSIZEHDR_MASK;
2791
f800326d
AD
2792#if PAGE_SIZE > IXGBE_MAX_RXBUFFER
2793 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
afafd5b0 2794#else
f800326d 2795 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
afafd5b0 2796#endif
f800326d 2797 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
e8e26350 2798
bf29ee6c 2799 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
cc41ac7c 2800}
9a799d71 2801
05abb126 2802static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
0cefafad 2803{
05abb126
AD
2804 struct ixgbe_hw *hw = &adapter->hw;
2805 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
e8e9f696
JP
2806 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2807 0x6A3E67EA, 0x14364D17, 0x3BED200D};
05abb126
AD
2808 u32 mrqc = 0, reta = 0;
2809 u32 rxcsum;
2810 int i, j;
8b1c0b24 2811 u8 tcs = netdev_get_num_tc(adapter->netdev);
86b4db3b
JF
2812 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2813
2814 if (tcs)
2815 maxq = min(maxq, adapter->num_tx_queues / tcs);
0cefafad 2816
05abb126
AD
2817 /* Fill out hash function seeds */
2818 for (i = 0; i < 10; i++)
2819 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
2820
2821 /* Fill out redirection table */
2822 for (i = 0, j = 0; i < 128; i++, j++) {
86b4db3b 2823 if (j == maxq)
05abb126
AD
2824 j = 0;
2825 /* reta = 4-byte sliding window of
2826 * 0x00..(indices-1)(indices-1)00..etc. */
2827 reta = (reta << 8) | (j * 0x11);
2828 if ((i & 3) == 3)
2829 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2830 }
0cefafad 2831
05abb126
AD
2832 /* Disable indicating checksum in descriptor, enables RSS hash */
2833 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2834 rxcsum |= IXGBE_RXCSUM_PCSD;
2835 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2836
8b1c0b24
JF
2837 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2838 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
0cefafad 2839 mrqc = IXGBE_MRQC_RSSEN;
8b1c0b24
JF
2840 } else {
2841 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2842 | IXGBE_FLAG_SRIOV_ENABLED);
2843
2844 switch (mask) {
2845 case (IXGBE_FLAG_RSS_ENABLED):
2846 if (!tcs)
2847 mrqc = IXGBE_MRQC_RSSEN;
2848 else if (tcs <= 4)
2849 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2850 else
2851 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2852 break;
2853 case (IXGBE_FLAG_SRIOV_ENABLED):
2854 mrqc = IXGBE_MRQC_VMDQEN;
2855 break;
2856 default:
2857 break;
2858 }
0cefafad
JB
2859 }
2860
05abb126
AD
2861 /* Perform hash on these packet types */
2862 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2863 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2864 | IXGBE_MRQC_RSS_FIELD_IPV6
2865 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2866
ef6afc0c
AD
2867 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
2868 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
2869 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
2870 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
2871
05abb126 2872 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
0cefafad
JB
2873}
2874
bb5a9ad2
NS
2875/**
2876 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2877 * @adapter: address of board private structure
2878 * @index: index of ring to set
bb5a9ad2 2879 **/
082757af 2880static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
7367096a 2881 struct ixgbe_ring *ring)
bb5a9ad2 2882{
bb5a9ad2 2883 struct ixgbe_hw *hw = &adapter->hw;
bb5a9ad2 2884 u32 rscctrl;
bf29ee6c 2885 u8 reg_idx = ring->reg_idx;
7367096a 2886
7d637bcc 2887 if (!ring_is_rsc_enabled(ring))
7367096a 2888 return;
bb5a9ad2 2889
7367096a 2890 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
bb5a9ad2
NS
2891 rscctrl |= IXGBE_RSCCTL_RSCEN;
2892 /*
2893 * we must limit the number of descriptors so that the
2894 * total size of max desc * buf_len is not greater
642c680e 2895 * than 65536
bb5a9ad2 2896 */
f800326d
AD
2897#if (PAGE_SIZE <= 8192)
2898 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2899#elif (PAGE_SIZE <= 16384)
2900 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
bb5a9ad2 2901#else
f800326d 2902 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
bb5a9ad2 2903#endif
7367096a 2904 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
bb5a9ad2
NS
2905}
2906
9e10e045
AD
2907#define IXGBE_MAX_RX_DESC_POLL 10
2908static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2909 struct ixgbe_ring *ring)
2910{
2911 struct ixgbe_hw *hw = &adapter->hw;
9e10e045
AD
2912 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2913 u32 rxdctl;
bf29ee6c 2914 u8 reg_idx = ring->reg_idx;
9e10e045
AD
2915
2916 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2917 if (hw->mac.type == ixgbe_mac_82598EB &&
2918 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2919 return;
2920
2921 do {
032b4325 2922 usleep_range(1000, 2000);
9e10e045
AD
2923 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2924 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2925
2926 if (!wait_loop) {
2927 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2928 "the polling period\n", reg_idx);
2929 }
2930}
2931
2d39d576
YZ
2932void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2933 struct ixgbe_ring *ring)
2934{
2935 struct ixgbe_hw *hw = &adapter->hw;
2936 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2937 u32 rxdctl;
2938 u8 reg_idx = ring->reg_idx;
2939
2940 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2941 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2942
2943 /* write value back with RXDCTL.ENABLE bit cleared */
2944 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2945
2946 if (hw->mac.type == ixgbe_mac_82598EB &&
2947 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2948 return;
2949
2950 /* the hardware may take up to 100us to really disable the rx queue */
2951 do {
2952 udelay(10);
2953 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2954 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2955
2956 if (!wait_loop) {
2957 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2958 "the polling period\n", reg_idx);
2959 }
2960}
2961
84418e3b
AD
2962void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2963 struct ixgbe_ring *ring)
acd37177
AD
2964{
2965 struct ixgbe_hw *hw = &adapter->hw;
2966 u64 rdba = ring->dma;
9e10e045 2967 u32 rxdctl;
bf29ee6c 2968 u8 reg_idx = ring->reg_idx;
acd37177 2969
9e10e045
AD
2970 /* disable queue to avoid issues while updating state */
2971 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2d39d576 2972 ixgbe_disable_rx_queue(adapter, ring);
9e10e045 2973
acd37177
AD
2974 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2975 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2976 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2977 ring->count * sizeof(union ixgbe_adv_rx_desc));
2978 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2979 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
84ea2591 2980 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
9e10e045
AD
2981
2982 ixgbe_configure_srrctl(adapter, ring);
2983 ixgbe_configure_rscctl(adapter, ring);
2984
e9f98072
GR
2985 /* If operating in IOV mode set RLPML for X540 */
2986 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2987 hw->mac.type == ixgbe_mac_X540) {
2988 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2989 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2990 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2991 }
2992
9e10e045
AD
2993 if (hw->mac.type == ixgbe_mac_82598EB) {
2994 /*
2995 * enable cache line friendly hardware writes:
2996 * PTHRESH=32 descriptors (half the internal cache),
2997 * this also removes ugly rx_no_buffer_count increment
2998 * HTHRESH=4 descriptors (to minimize latency on fetch)
2999 * WTHRESH=8 burst writeback up to two cache lines
3000 */
3001 rxdctl &= ~0x3FFFFF;
3002 rxdctl |= 0x080420;
3003 }
3004
3005 /* enable receive descriptor ring */
3006 rxdctl |= IXGBE_RXDCTL_ENABLE;
3007 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3008
3009 ixgbe_rx_desc_queue_enable(adapter, ring);
7d4987de 3010 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
acd37177
AD
3011}
3012
48654521
AD
3013static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3014{
3015 struct ixgbe_hw *hw = &adapter->hw;
3016 int p;
3017
3018 /* PSRTYPE must be initialized in non 82598 adapters */
3019 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
e8e9f696
JP
3020 IXGBE_PSRTYPE_UDPHDR |
3021 IXGBE_PSRTYPE_IPV4HDR |
48654521 3022 IXGBE_PSRTYPE_L2HDR |
e8e9f696 3023 IXGBE_PSRTYPE_IPV6HDR;
48654521
AD
3024
3025 if (hw->mac.type == ixgbe_mac_82598EB)
3026 return;
3027
3028 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3029 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3030
3031 for (p = 0; p < adapter->num_rx_pools; p++)
3032 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3033 psrtype);
3034}
3035
f5b4a52e
AD
3036static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3037{
3038 struct ixgbe_hw *hw = &adapter->hw;
3039 u32 gcr_ext;
3040 u32 vt_reg_bits;
3041 u32 reg_offset, vf_shift;
3042 u32 vmdctl;
de4c7f65 3043 int i;
f5b4a52e
AD
3044
3045 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3046 return;
3047
3048 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3049 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3050 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3051 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3052
3053 vf_shift = adapter->num_vfs % 32;
4cd6923d 3054 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
f5b4a52e
AD
3055
3056 /* Enable only the PF's pool for Tx/Rx */
3057 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3058 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3059 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3060 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3061 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3062
3063 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3064 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3065
3066 /*
3067 * Set up VF register offsets for selected VT Mode,
3068 * i.e. 32 or 64 VFs for SR-IOV
3069 */
3070 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3071 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3072 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3073 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3074
3075 /* enable Tx loopback for VF/PF communication */
3076 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
a985b6c3 3077 /* Enable MAC Anti-Spoofing */
a1cbb15c 3078 hw->mac.ops.set_mac_anti_spoofing(hw,
de4c7f65 3079 (adapter->num_vfs != 0),
a985b6c3 3080 adapter->num_vfs);
de4c7f65
GR
3081 /* For VFs that have spoof checking turned off */
3082 for (i = 0; i < adapter->num_vfs; i++) {
3083 if (!adapter->vfinfo[i].spoofchk_enabled)
3084 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3085 }
f5b4a52e
AD
3086}
3087
477de6ed 3088static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
9a799d71 3089{
9a799d71
AK
3090 struct ixgbe_hw *hw = &adapter->hw;
3091 struct net_device *netdev = adapter->netdev;
3092 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
477de6ed
AD
3093 struct ixgbe_ring *rx_ring;
3094 int i;
3095 u32 mhadd, hlreg0;
48654521 3096
63f39bd1 3097#ifdef IXGBE_FCOE
477de6ed
AD
3098 /* adjust max frame to be able to do baby jumbo for FCoE */
3099 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3100 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3101 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
9a799d71 3102
477de6ed
AD
3103#endif /* IXGBE_FCOE */
3104 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3105 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3106 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3107 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3108
3109 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
3110 }
3111
919e78a6
AD
3112 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3113 max_frame += VLAN_HLEN;
3114
477de6ed
AD
3115 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3116 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3117 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
3118 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
9a799d71 3119
0cefafad
JB
3120 /*
3121 * Setup the HW Rx Head and Tail Descriptor Pointers and
3122 * the Base and Length of the Rx Descriptor Ring
3123 */
9a799d71 3124 for (i = 0; i < adapter->num_rx_queues; i++) {
4a0b9ca0 3125 rx_ring = adapter->rx_ring[i];
7d637bcc
AD
3126 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3127 set_ring_rsc_enabled(rx_ring);
1b3ff02e 3128 else
7d637bcc 3129 clear_ring_rsc_enabled(rx_ring);
477de6ed 3130 }
477de6ed
AD
3131}
3132
7367096a
AD
3133static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3134{
3135 struct ixgbe_hw *hw = &adapter->hw;
3136 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3137
3138 switch (hw->mac.type) {
3139 case ixgbe_mac_82598EB:
3140 /*
3141 * For VMDq support of different descriptor types or
3142 * buffer sizes through the use of multiple SRRCTL
3143 * registers, RDRXCTL.MVMEN must be set to 1
3144 *
3145 * also, the manual doesn't mention it clearly but DCA hints
3146 * will only use queue 0's tags unless this bit is set. Side
3147 * effects of setting this bit are only that SRRCTL must be
3148 * fully programmed [0..15]
3149 */
3150 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3151 break;
3152 case ixgbe_mac_82599EB:
b93a2226 3153 case ixgbe_mac_X540:
7367096a
AD
3154 /* Disable RSC for ACK packets */
3155 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3156 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3157 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3158 /* hardware requires some bits to be set by default */
3159 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3160 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3161 break;
3162 default:
3163 /* We should do nothing since we don't know this hardware */
3164 return;
3165 }
3166
3167 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3168}
3169
477de6ed
AD
3170/**
3171 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3172 * @adapter: board private structure
3173 *
3174 * Configure the Rx unit of the MAC after a reset.
3175 **/
3176static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3177{
3178 struct ixgbe_hw *hw = &adapter->hw;
477de6ed
AD
3179 int i;
3180 u32 rxctrl;
477de6ed
AD
3181
3182 /* disable receives while setting up the descriptors */
3183 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3184 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3185
3186 ixgbe_setup_psrtype(adapter);
7367096a 3187 ixgbe_setup_rdrxctl(adapter);
477de6ed 3188
9e10e045 3189 /* Program registers for the distribution of queues */
f5b4a52e 3190 ixgbe_setup_mrqc(adapter);
f5b4a52e 3191
477de6ed
AD
3192 /* set_rx_buffer_len must be called before ring initialization */
3193 ixgbe_set_rx_buffer_len(adapter);
3194
3195 /*
3196 * Setup the HW Rx Head and Tail Descriptor Pointers and
3197 * the Base and Length of the Rx Descriptor Ring
3198 */
9e10e045
AD
3199 for (i = 0; i < adapter->num_rx_queues; i++)
3200 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
177db6ff 3201
9e10e045
AD
3202 /* disable drop enable for 82598 parts */
3203 if (hw->mac.type == ixgbe_mac_82598EB)
3204 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3205
3206 /* enable all receives */
3207 rxctrl |= IXGBE_RXCTRL_RXEN;
3208 hw->mac.ops.enable_rx_dma(hw, rxctrl);
9a799d71
AK
3209}
3210
8e586137 3211static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
068c89b0
DS
3212{
3213 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3214 struct ixgbe_hw *hw = &adapter->hw;
1ada1b1b 3215 int pool_ndx = adapter->num_vfs;
068c89b0
DS
3216
3217 /* add VID to filter table */
1ada1b1b 3218 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
f62bbb5e 3219 set_bit(vid, adapter->active_vlans);
8e586137
JP
3220
3221 return 0;
068c89b0
DS
3222}
3223
8e586137 3224static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
068c89b0
DS
3225{
3226 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3227 struct ixgbe_hw *hw = &adapter->hw;
1ada1b1b 3228 int pool_ndx = adapter->num_vfs;
068c89b0 3229
068c89b0 3230 /* remove VID from filter table */
1ada1b1b 3231 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
f62bbb5e 3232 clear_bit(vid, adapter->active_vlans);
8e586137
JP
3233
3234 return 0;
068c89b0
DS
3235}
3236
5f6c0181
JB
3237/**
3238 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3239 * @adapter: driver data
3240 */
3241static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3242{
3243 struct ixgbe_hw *hw = &adapter->hw;
f62bbb5e
JG
3244 u32 vlnctrl;
3245
3246 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3247 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3248 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3249}
3250
3251/**
3252 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3253 * @adapter: driver data
3254 */
3255static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3256{
3257 struct ixgbe_hw *hw = &adapter->hw;
3258 u32 vlnctrl;
3259
3260 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3261 vlnctrl |= IXGBE_VLNCTRL_VFE;
3262 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3263 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3264}
3265
3266/**
3267 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3268 * @adapter: driver data
3269 */
3270static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3271{
3272 struct ixgbe_hw *hw = &adapter->hw;
3273 u32 vlnctrl;
5f6c0181
JB
3274 int i, j;
3275
3276 switch (hw->mac.type) {
3277 case ixgbe_mac_82598EB:
f62bbb5e
JG
3278 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3279 vlnctrl &= ~IXGBE_VLNCTRL_VME;
5f6c0181
JB
3280 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3281 break;
3282 case ixgbe_mac_82599EB:
b93a2226 3283 case ixgbe_mac_X540:
5f6c0181
JB
3284 for (i = 0; i < adapter->num_rx_queues; i++) {
3285 j = adapter->rx_ring[i]->reg_idx;
3286 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3287 vlnctrl &= ~IXGBE_RXDCTL_VME;
3288 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3289 }
3290 break;
3291 default:
3292 break;
3293 }
3294}
3295
3296/**
f62bbb5e 3297 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
5f6c0181
JB
3298 * @adapter: driver data
3299 */
f62bbb5e 3300static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
5f6c0181
JB
3301{
3302 struct ixgbe_hw *hw = &adapter->hw;
f62bbb5e 3303 u32 vlnctrl;
5f6c0181
JB
3304 int i, j;
3305
3306 switch (hw->mac.type) {
3307 case ixgbe_mac_82598EB:
f62bbb5e
JG
3308 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3309 vlnctrl |= IXGBE_VLNCTRL_VME;
5f6c0181
JB
3310 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3311 break;
3312 case ixgbe_mac_82599EB:
b93a2226 3313 case ixgbe_mac_X540:
5f6c0181
JB
3314 for (i = 0; i < adapter->num_rx_queues; i++) {
3315 j = adapter->rx_ring[i]->reg_idx;
3316 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3317 vlnctrl |= IXGBE_RXDCTL_VME;
3318 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3319 }
3320 break;
3321 default:
3322 break;
3323 }
3324}
3325
9a799d71
AK
3326static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3327{
f62bbb5e 3328 u16 vid;
9a799d71 3329
f62bbb5e
JG
3330 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3331
3332 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3333 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
9a799d71
AK
3334}
3335
2850062a
AD
3336/**
3337 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3338 * @netdev: network interface device structure
3339 *
3340 * Writes unicast address list to the RAR table.
3341 * Returns: -ENOMEM on failure/insufficient address space
3342 * 0 on no addresses written
3343 * X on writing X addresses to the RAR table
3344 **/
3345static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3346{
3347 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3348 struct ixgbe_hw *hw = &adapter->hw;
3349 unsigned int vfn = adapter->num_vfs;
a1cbb15c 3350 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
2850062a
AD
3351 int count = 0;
3352
3353 /* return ENOMEM indicating insufficient memory for addresses */
3354 if (netdev_uc_count(netdev) > rar_entries)
3355 return -ENOMEM;
3356
3357 if (!netdev_uc_empty(netdev) && rar_entries) {
3358 struct netdev_hw_addr *ha;
3359 /* return error if we do not support writing to RAR table */
3360 if (!hw->mac.ops.set_rar)
3361 return -ENOMEM;
3362
3363 netdev_for_each_uc_addr(ha, netdev) {
3364 if (!rar_entries)
3365 break;
3366 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3367 vfn, IXGBE_RAH_AV);
3368 count++;
3369 }
3370 }
3371 /* write the addresses in reverse order to avoid write combining */
3372 for (; rar_entries > 0 ; rar_entries--)
3373 hw->mac.ops.clear_rar(hw, rar_entries);
3374
3375 return count;
3376}
3377
9a799d71 3378/**
2c5645cf 3379 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
9a799d71
AK
3380 * @netdev: network interface device structure
3381 *
2c5645cf
CL
3382 * The set_rx_method entry point is called whenever the unicast/multicast
3383 * address list or the network interface flags are updated. This routine is
3384 * responsible for configuring the hardware for proper unicast, multicast and
3385 * promiscuous mode.
9a799d71 3386 **/
7f870475 3387void ixgbe_set_rx_mode(struct net_device *netdev)
9a799d71
AK
3388{
3389 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3390 struct ixgbe_hw *hw = &adapter->hw;
2850062a
AD
3391 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3392 int count;
9a799d71
AK
3393
3394 /* Check for Promiscuous and All Multicast modes */
3395
3396 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3397
f5dc442b 3398 /* set all bits that we expect to always be set */
3f2d1c0f 3399 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
f5dc442b
AD
3400 fctrl |= IXGBE_FCTRL_BAM;
3401 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3402 fctrl |= IXGBE_FCTRL_PMCF;
3403
2850062a
AD
3404 /* clear the bits we are changing the status of */
3405 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3406
9a799d71 3407 if (netdev->flags & IFF_PROMISC) {
e433ea1f 3408 hw->addr_ctrl.user_set_promisc = true;
9a799d71 3409 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2850062a 3410 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
5f6c0181
JB
3411 /* don't hardware filter vlans in promisc mode */
3412 ixgbe_vlan_filter_disable(adapter);
9a799d71 3413 } else {
746b9f02
PM
3414 if (netdev->flags & IFF_ALLMULTI) {
3415 fctrl |= IXGBE_FCTRL_MPE;
2850062a
AD
3416 vmolr |= IXGBE_VMOLR_MPE;
3417 } else {
3418 /*
3419 * Write addresses to the MTA, if the attempt fails
25985edc 3420 * then we should just turn on promiscuous mode so
2850062a
AD
3421 * that we can at least receive multicast traffic
3422 */
3423 hw->mac.ops.update_mc_addr_list(hw, netdev);
3424 vmolr |= IXGBE_VMOLR_ROMPE;
746b9f02 3425 }
5f6c0181 3426 ixgbe_vlan_filter_enable(adapter);
e433ea1f 3427 hw->addr_ctrl.user_set_promisc = false;
9dcb373c
JF
3428 }
3429
3430 /*
3431 * Write addresses to available RAR registers, if there is not
3432 * sufficient space to store all the addresses then enable
3433 * unicast promiscuous mode
3434 */
3435 count = ixgbe_write_uc_addr_list(netdev);
3436 if (count < 0) {
3437 fctrl |= IXGBE_FCTRL_UPE;
3438 vmolr |= IXGBE_VMOLR_ROPE;
9a799d71
AK
3439 }
3440
2850062a 3441 if (adapter->num_vfs) {
1cdd1ec8 3442 ixgbe_restore_vf_multicasts(adapter);
2850062a
AD
3443 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3444 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3445 IXGBE_VMOLR_ROPE);
3446 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
3447 }
3448
3f2d1c0f
BG
3449 /* This is useful for sniffing bad packets. */
3450 if (adapter->netdev->features & NETIF_F_RXALL) {
3451 /* UPE and MPE will be handled by normal PROMISC logic
3452 * in e1000e_set_rx_mode */
3453 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3454 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3455 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3456
3457 fctrl &= ~(IXGBE_FCTRL_DPF);
3458 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3459 }
3460
2850062a 3461 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
f62bbb5e
JG
3462
3463 if (netdev->features & NETIF_F_HW_VLAN_RX)
3464 ixgbe_vlan_strip_enable(adapter);
3465 else
3466 ixgbe_vlan_strip_disable(adapter);
9a799d71
AK
3467}
3468
021230d4
AV
3469static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3470{
3471 int q_idx;
3472 struct ixgbe_q_vector *q_vector;
3473 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3474
3475 /* legacy and MSI only use one vector */
3476 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3477 q_vectors = 1;
3478
3479 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
7a921c93 3480 q_vector = adapter->q_vector[q_idx];
4ff7fb12 3481 napi_enable(&q_vector->napi);
021230d4
AV
3482 }
3483}
3484
3485static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3486{
3487 int q_idx;
3488 struct ixgbe_q_vector *q_vector;
3489 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3490
3491 /* legacy and MSI only use one vector */
3492 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3493 q_vectors = 1;
3494
3495 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
7a921c93 3496 q_vector = adapter->q_vector[q_idx];
021230d4
AV
3497 napi_disable(&q_vector->napi);
3498 }
3499}
3500
7a6b6f51 3501#ifdef CONFIG_IXGBE_DCB
2f90b865
AD
3502/*
3503 * ixgbe_configure_dcb - Configure DCB hardware
3504 * @adapter: ixgbe adapter struct
3505 *
3506 * This is called by the driver on open to configure the DCB hardware.
3507 * This is also called by the gennetlink interface when reconfiguring
3508 * the DCB state.
3509 */
3510static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3511{
3512 struct ixgbe_hw *hw = &adapter->hw;
9806307a 3513 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2f90b865 3514
67ebd791
AD
3515 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3516 if (hw->mac.type == ixgbe_mac_82598EB)
3517 netif_set_gso_max_size(adapter->netdev, 65536);
3518 return;
3519 }
3520
3521 if (hw->mac.type == ixgbe_mac_82598EB)
3522 netif_set_gso_max_size(adapter->netdev, 32768);
3523
2f90b865 3524
2f90b865 3525 /* Enable VLAN tag insert/strip */
f62bbb5e 3526 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
5f6c0181 3527
2f90b865 3528 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
01fa7d90 3529
971060b1 3530#ifdef IXGBE_FCOE
b120818e
JF
3531 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3532 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
c27931da 3533#endif
b120818e
JF
3534
3535 /* reconfigure the hardware */
3536 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
c27931da
JF
3537 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3538 DCB_TX_CONFIG);
3539 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3540 DCB_RX_CONFIG);
3541 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
b120818e
JF
3542 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3543 ixgbe_dcb_hw_ets(&adapter->hw,
3544 adapter->ixgbe_ieee_ets,
3545 max_frame);
3546 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3547 adapter->ixgbe_ieee_pfc->pfc_en,
3548 adapter->ixgbe_ieee_ets->prio_tc);
c27931da 3549 }
8187cd48
JF
3550
3551 /* Enable RSS Hash per TC */
3552 if (hw->mac.type != ixgbe_mac_82598EB) {
3553 int i;
3554 u32 reg = 0;
3555
3556 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3557 u8 msb = 0;
3558 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3559
3560 while (cnt >>= 1)
3561 msb++;
3562
3563 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3564 }
3565 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3566 }
2f90b865 3567}
9da712d2
JF
3568#endif
3569
3570/* Additional bittime to account for IXGBE framing */
3571#define IXGBE_ETH_FRAMING 20
3572
3573/*
3574 * ixgbe_hpbthresh - calculate high water mark for flow control
3575 *
3576 * @adapter: board private structure to calculate for
3577 * @pb - packet buffer to calculate
3578 */
3579static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3580{
3581 struct ixgbe_hw *hw = &adapter->hw;
3582 struct net_device *dev = adapter->netdev;
3583 int link, tc, kb, marker;
3584 u32 dv_id, rx_pba;
3585
3586 /* Calculate max LAN frame size */
3587 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3588
3589#ifdef IXGBE_FCOE
3590 /* FCoE traffic class uses FCOE jumbo frames */
3591 if (dev->features & NETIF_F_FCOE_MTU) {
3592 int fcoe_pb = 0;
2f90b865 3593
9da712d2
JF
3594#ifdef CONFIG_IXGBE_DCB
3595 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
3596
3597#endif
3598 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3599 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3600 }
2f90b865 3601#endif
80605c65 3602
9da712d2
JF
3603 /* Calculate delay value for device */
3604 switch (hw->mac.type) {
3605 case ixgbe_mac_X540:
3606 dv_id = IXGBE_DV_X540(link, tc);
3607 break;
3608 default:
3609 dv_id = IXGBE_DV(link, tc);
3610 break;
3611 }
3612
3613 /* Loopback switch introduces additional latency */
3614 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3615 dv_id += IXGBE_B2BT(tc);
3616
3617 /* Delay value is calculated in bit times convert to KB */
3618 kb = IXGBE_BT2KB(dv_id);
3619 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3620
3621 marker = rx_pba - kb;
3622
3623 /* It is possible that the packet buffer is not large enough
3624 * to provide required headroom. In this case throw an error
3625 * to user and a do the best we can.
3626 */
3627 if (marker < 0) {
3628 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3629 "headroom to support flow control."
3630 "Decrease MTU or number of traffic classes\n", pb);
3631 marker = tc + 1;
3632 }
3633
3634 return marker;
3635}
3636
3637/*
3638 * ixgbe_lpbthresh - calculate low water mark for for flow control
3639 *
3640 * @adapter: board private structure to calculate for
3641 * @pb - packet buffer to calculate
3642 */
3643static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3644{
3645 struct ixgbe_hw *hw = &adapter->hw;
3646 struct net_device *dev = adapter->netdev;
3647 int tc;
3648 u32 dv_id;
3649
3650 /* Calculate max LAN frame size */
3651 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3652
3653 /* Calculate delay value for device */
3654 switch (hw->mac.type) {
3655 case ixgbe_mac_X540:
3656 dv_id = IXGBE_LOW_DV_X540(tc);
3657 break;
3658 default:
3659 dv_id = IXGBE_LOW_DV(tc);
3660 break;
3661 }
3662
3663 /* Delay value is calculated in bit times convert to KB */
3664 return IXGBE_BT2KB(dv_id);
3665}
3666
3667/*
3668 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3669 */
3670static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3671{
3672 struct ixgbe_hw *hw = &adapter->hw;
3673 int num_tc = netdev_get_num_tc(adapter->netdev);
3674 int i;
3675
3676 if (!num_tc)
3677 num_tc = 1;
3678
3679 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3680
3681 for (i = 0; i < num_tc; i++) {
3682 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3683
3684 /* Low water marks must not be larger than high water marks */
3685 if (hw->fc.low_water > hw->fc.high_water[i])
3686 hw->fc.low_water = 0;
3687 }
3688}
3689
80605c65
JF
3690static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3691{
80605c65 3692 struct ixgbe_hw *hw = &adapter->hw;
f7e1027f
AD
3693 int hdrm;
3694 u8 tc = netdev_get_num_tc(adapter->netdev);
80605c65
JF
3695
3696 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3697 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
f7e1027f
AD
3698 hdrm = 32 << adapter->fdir_pballoc;
3699 else
3700 hdrm = 0;
80605c65 3701
f7e1027f 3702 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
9da712d2 3703 ixgbe_pbthresh_setup(adapter);
80605c65
JF
3704}
3705
e4911d57
AD
3706static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3707{
3708 struct ixgbe_hw *hw = &adapter->hw;
3709 struct hlist_node *node, *node2;
3710 struct ixgbe_fdir_filter *filter;
3711
3712 spin_lock(&adapter->fdir_perfect_lock);
3713
3714 if (!hlist_empty(&adapter->fdir_filter_list))
3715 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3716
3717 hlist_for_each_entry_safe(filter, node, node2,
3718 &adapter->fdir_filter_list, fdir_node) {
3719 ixgbe_fdir_write_perfect_filter_82599(hw,
1f4d5183
AD
3720 &filter->filter,
3721 filter->sw_idx,
3722 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3723 IXGBE_FDIR_DROP_QUEUE :
3724 adapter->rx_ring[filter->action]->reg_idx);
e4911d57
AD
3725 }
3726
3727 spin_unlock(&adapter->fdir_perfect_lock);
3728}
3729
9a799d71
AK
3730static void ixgbe_configure(struct ixgbe_adapter *adapter)
3731{
d2f5e7f3
AS
3732 struct ixgbe_hw *hw = &adapter->hw;
3733
80605c65 3734 ixgbe_configure_pb(adapter);
7a6b6f51 3735#ifdef CONFIG_IXGBE_DCB
67ebd791 3736 ixgbe_configure_dcb(adapter);
2f90b865 3737#endif
9a799d71 3738
4c1d7b4b 3739 ixgbe_set_rx_mode(adapter->netdev);
f62bbb5e
JG
3740 ixgbe_restore_vlan(adapter);
3741
eacd73f7
YZ
3742#ifdef IXGBE_FCOE
3743 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3744 ixgbe_configure_fcoe(adapter);
3745
3746#endif /* IXGBE_FCOE */
d2f5e7f3
AS
3747
3748 switch (hw->mac.type) {
3749 case ixgbe_mac_82599EB:
3750 case ixgbe_mac_X540:
3751 hw->mac.ops.disable_rx_buff(hw);
3752 break;
3753 default:
3754 break;
3755 }
3756
c4cf55e5 3757 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4c1d7b4b
AD
3758 ixgbe_init_fdir_signature_82599(&adapter->hw,
3759 adapter->fdir_pballoc);
e4911d57
AD
3760 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3761 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3762 adapter->fdir_pballoc);
3763 ixgbe_fdir_filter_restore(adapter);
c4cf55e5 3764 }
4c1d7b4b 3765
d2f5e7f3
AS
3766 switch (hw->mac.type) {
3767 case ixgbe_mac_82599EB:
3768 case ixgbe_mac_X540:
3769 hw->mac.ops.enable_rx_buff(hw);
3770 break;
3771 default:
3772 break;
3773 }
3774
933d41f1 3775 ixgbe_configure_virtualization(adapter);
c4cf55e5 3776
9a799d71
AK
3777 ixgbe_configure_tx(adapter);
3778 ixgbe_configure_rx(adapter);
9a799d71
AK
3779}
3780
e8e26350
PW
3781static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3782{
3783 switch (hw->phy.type) {
3784 case ixgbe_phy_sfp_avago:
3785 case ixgbe_phy_sfp_ftl:
3786 case ixgbe_phy_sfp_intel:
3787 case ixgbe_phy_sfp_unknown:
ea0a04df
DS
3788 case ixgbe_phy_sfp_passive_tyco:
3789 case ixgbe_phy_sfp_passive_unknown:
3790 case ixgbe_phy_sfp_active_unknown:
3791 case ixgbe_phy_sfp_ftl_active:
e8e26350 3792 return true;
8917b447
AD
3793 case ixgbe_phy_nl:
3794 if (hw->mac.type == ixgbe_mac_82598EB)
3795 return true;
e8e26350
PW
3796 default:
3797 return false;
3798 }
3799}
3800
0ecc061d 3801/**
e8e26350
PW
3802 * ixgbe_sfp_link_config - set up SFP+ link
3803 * @adapter: pointer to private adapter struct
3804 **/
3805static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3806{
7086400d 3807 /*
52f33af8 3808 * We are assuming the worst case scenario here, and that
7086400d
AD
3809 * is that an SFP was inserted/removed after the reset
3810 * but before SFP detection was enabled. As such the best
3811 * solution is to just start searching as soon as we start
3812 */
3813 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3814 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
e8e26350 3815
7086400d 3816 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
e8e26350
PW
3817}
3818
3819/**
3820 * ixgbe_non_sfp_link_config - set up non-SFP+ link
0ecc061d
PWJ
3821 * @hw: pointer to private hardware struct
3822 *
3823 * Returns 0 on success, negative on failure
3824 **/
e8e26350 3825static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
0ecc061d
PWJ
3826{
3827 u32 autoneg;
8620a103 3828 bool negotiation, link_up = false;
0ecc061d
PWJ
3829 u32 ret = IXGBE_ERR_LINK_SETUP;
3830
3831 if (hw->mac.ops.check_link)
3832 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3833
3834 if (ret)
3835 goto link_cfg_out;
3836
0b0c2b31
ET
3837 autoneg = hw->phy.autoneg_advertised;
3838 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
e8e9f696
JP
3839 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3840 &negotiation);
0ecc061d
PWJ
3841 if (ret)
3842 goto link_cfg_out;
3843
8620a103
MC
3844 if (hw->mac.ops.setup_link)
3845 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
0ecc061d
PWJ
3846link_cfg_out:
3847 return ret;
3848}
3849
a34bcfff 3850static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
9a799d71 3851{
9a799d71 3852 struct ixgbe_hw *hw = &adapter->hw;
a34bcfff 3853 u32 gpie = 0;
9a799d71 3854
9b471446 3855 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
a34bcfff
AD
3856 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3857 IXGBE_GPIE_OCD;
3858 gpie |= IXGBE_GPIE_EIAME;
9b471446
JB
3859 /*
3860 * use EIAM to auto-mask when MSI-X interrupt is asserted
3861 * this saves a register write for every interrupt
3862 */
3863 switch (hw->mac.type) {
3864 case ixgbe_mac_82598EB:
3865 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3866 break;
9b471446 3867 case ixgbe_mac_82599EB:
b93a2226
DS
3868 case ixgbe_mac_X540:
3869 default:
9b471446
JB
3870 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3871 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3872 break;
3873 }
3874 } else {
021230d4
AV
3875 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3876 * specifically only auto mask tx and rx interrupts */
3877 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3878 }
9a799d71 3879
a34bcfff
AD
3880 /* XXX: to interrupt immediately for EICS writes, enable this */
3881 /* gpie |= IXGBE_GPIE_EIMEN; */
3882
3883 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3884 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3885 gpie |= IXGBE_GPIE_VTMODE_64;
119fc60a
MC
3886 }
3887
5fdd31f9 3888 /* Enable Thermal over heat sensor interrupt */
f3df98ec
DS
3889 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3890 switch (adapter->hw.mac.type) {
3891 case ixgbe_mac_82599EB:
3892 gpie |= IXGBE_SDP0_GPIEN;
3893 break;
3894 case ixgbe_mac_X540:
3895 gpie |= IXGBE_EIMS_TS;
3896 break;
3897 default:
3898 break;
3899 }
3900 }
5fdd31f9 3901
a34bcfff
AD
3902 /* Enable fan failure interrupt */
3903 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
0befdb3e 3904 gpie |= IXGBE_SDP1_GPIEN;
0befdb3e 3905
2698b208 3906 if (hw->mac.type == ixgbe_mac_82599EB) {
e8e26350
PW
3907 gpie |= IXGBE_SDP1_GPIEN;
3908 gpie |= IXGBE_SDP2_GPIEN;
2698b208 3909 }
a34bcfff
AD
3910
3911 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3912}
3913
c7ccde0f 3914static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
a34bcfff
AD
3915{
3916 struct ixgbe_hw *hw = &adapter->hw;
a34bcfff 3917 int err;
a34bcfff
AD
3918 u32 ctrl_ext;
3919
3920 ixgbe_get_hw_control(adapter);
3921 ixgbe_setup_gpie(adapter);
e8e26350 3922
9a799d71
AK
3923 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3924 ixgbe_configure_msix(adapter);
3925 else
3926 ixgbe_configure_msi_and_legacy(adapter);
3927
c6ecf39a
DS
3928 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3929 if (hw->mac.ops.enable_tx_laser &&
3930 ((hw->phy.multispeed_fiber) ||
9f911707 3931 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
c6ecf39a 3932 (hw->mac.type == ixgbe_mac_82599EB))))
61fac744
PW
3933 hw->mac.ops.enable_tx_laser(hw);
3934
9a799d71 3935 clear_bit(__IXGBE_DOWN, &adapter->state);
021230d4
AV
3936 ixgbe_napi_enable_all(adapter);
3937
73c4b7cd
AD
3938 if (ixgbe_is_sfp(hw)) {
3939 ixgbe_sfp_link_config(adapter);
3940 } else {
3941 err = ixgbe_non_sfp_link_config(hw);
3942 if (err)
3943 e_err(probe, "link_config FAILED %d\n", err);
3944 }
3945
021230d4
AV
3946 /* clear any pending interrupts, may auto mask */
3947 IXGBE_READ_REG(hw, IXGBE_EICR);
6af3b9eb 3948 ixgbe_irq_enable(adapter, true, true);
9a799d71 3949
bf069c97
DS
3950 /*
3951 * If this adapter has a fan, check to see if we had a failure
3952 * before we enabled the interrupt.
3953 */
3954 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3955 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3956 if (esdp & IXGBE_ESDP_SDP1)
396e799c 3957 e_crit(drv, "Fan has stopped, replace the adapter\n");
bf069c97
DS
3958 }
3959
1da100bb 3960 /* enable transmits */
477de6ed 3961 netif_tx_start_all_queues(adapter->netdev);
1da100bb 3962
9a799d71
AK
3963 /* bring the link up in the watchdog, this could race with our first
3964 * link up interrupt but shouldn't be a problem */
cf8280ee
JB
3965 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3966 adapter->link_check_timeout = jiffies;
7086400d 3967 mod_timer(&adapter->service_timer, jiffies);
c9205697
GR
3968
3969 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3970 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3971 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3972 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
9a799d71
AK
3973}
3974
d4f80882
AV
3975void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3976{
3977 WARN_ON(in_interrupt());
7086400d
AD
3978 /* put off any impending NetWatchDogTimeout */
3979 adapter->netdev->trans_start = jiffies;
3980
d4f80882 3981 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
032b4325 3982 usleep_range(1000, 2000);
d4f80882 3983 ixgbe_down(adapter);
5809a1ae
GR
3984 /*
3985 * If SR-IOV enabled then wait a bit before bringing the adapter
3986 * back up to give the VFs time to respond to the reset. The
3987 * two second wait is based upon the watchdog timer cycle in
3988 * the VF driver.
3989 */
3990 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3991 msleep(2000);
d4f80882
AV
3992 ixgbe_up(adapter);
3993 clear_bit(__IXGBE_RESETTING, &adapter->state);
3994}
3995
c7ccde0f 3996void ixgbe_up(struct ixgbe_adapter *adapter)
9a799d71
AK
3997{
3998 /* hardware has been reset, we need to reload some things */
3999 ixgbe_configure(adapter);
4000
c7ccde0f 4001 ixgbe_up_complete(adapter);
9a799d71
AK
4002}
4003
4004void ixgbe_reset(struct ixgbe_adapter *adapter)
4005{
c44ade9e 4006 struct ixgbe_hw *hw = &adapter->hw;
8ca783ab
DS
4007 int err;
4008
7086400d
AD
4009 /* lock SFP init bit to prevent race conditions with the watchdog */
4010 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4011 usleep_range(1000, 2000);
4012
4013 /* clear all SFP and link config related flags while holding SFP_INIT */
4014 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4015 IXGBE_FLAG2_SFP_NEEDS_RESET);
4016 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4017
8ca783ab 4018 err = hw->mac.ops.init_hw(hw);
da4dd0f7
PWJ
4019 switch (err) {
4020 case 0:
4021 case IXGBE_ERR_SFP_NOT_PRESENT:
7086400d 4022 case IXGBE_ERR_SFP_NOT_SUPPORTED:
da4dd0f7
PWJ
4023 break;
4024 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
849c4542 4025 e_dev_err("master disable timed out\n");
da4dd0f7 4026 break;
794caeb2
PWJ
4027 case IXGBE_ERR_EEPROM_VERSION:
4028 /* We are running on a pre-production device, log a warning */
849c4542 4029 e_dev_warn("This device is a pre-production adapter/LOM. "
52f33af8 4030 "Please be aware there may be issues associated with "
849c4542
ET
4031 "your hardware. If you are experiencing problems "
4032 "please contact your Intel or hardware "
4033 "representative who provided you with this "
4034 "hardware.\n");
794caeb2 4035 break;
da4dd0f7 4036 default:
849c4542 4037 e_dev_err("Hardware Error: %d\n", err);
da4dd0f7 4038 }
9a799d71 4039
7086400d
AD
4040 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4041
9a799d71 4042 /* reprogram the RAR[0] in case user changed it. */
1cdd1ec8
GR
4043 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4044 IXGBE_RAH_AV);
9a799d71
AK
4045}
4046
f800326d
AD
4047/**
4048 * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers
4049 * @rx_ring: ring to setup
4050 *
4051 * On many IA platforms the L1 cache has a critical stride of 4K, this
4052 * results in each receive buffer starting in the same cache set. To help
4053 * reduce the pressure on this cache set we can interleave the offsets so
4054 * that only every other buffer will be in the same cache set.
4055 **/
4056static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring)
4057{
4058 struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info;
4059 u16 i;
4060
4061 for (i = 0; i < rx_ring->count; i += 2) {
4062 rx_buffer[0].page_offset = 0;
4063 rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring);
4064 rx_buffer = &rx_buffer[2];
4065 }
4066}
4067
9a799d71
AK
4068/**
4069 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
9a799d71
AK
4070 * @rx_ring: ring to free buffers from
4071 **/
b6ec895e 4072static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
9a799d71 4073{
b6ec895e 4074 struct device *dev = rx_ring->dev;
9a799d71 4075 unsigned long size;
b6ec895e 4076 u16 i;
9a799d71 4077
84418e3b
AD
4078 /* ring already cleared, nothing to do */
4079 if (!rx_ring->rx_buffer_info)
4080 return;
9a799d71 4081
84418e3b 4082 /* Free all the Rx ring sk_buffs */
9a799d71 4083 for (i = 0; i < rx_ring->count; i++) {
f800326d
AD
4084 struct ixgbe_rx_buffer *rx_buffer;
4085
4086 rx_buffer = &rx_ring->rx_buffer_info[i];
4087 if (rx_buffer->skb) {
4088 struct sk_buff *skb = rx_buffer->skb;
4089 if (IXGBE_CB(skb)->page_released) {
4090 dma_unmap_page(dev,
4091 IXGBE_CB(skb)->dma,
4092 ixgbe_rx_bufsz(rx_ring),
4093 DMA_FROM_DEVICE);
4094 IXGBE_CB(skb)->page_released = false;
4c1975d7
AD
4095 }
4096 dev_kfree_skb(skb);
9a799d71 4097 }
f800326d
AD
4098 rx_buffer->skb = NULL;
4099 if (rx_buffer->dma)
4100 dma_unmap_page(dev, rx_buffer->dma,
4101 ixgbe_rx_pg_size(rx_ring),
4102 DMA_FROM_DEVICE);
4103 rx_buffer->dma = 0;
4104 if (rx_buffer->page)
4105 put_page(rx_buffer->page);
4106 rx_buffer->page = NULL;
9a799d71
AK
4107 }
4108
4109 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4110 memset(rx_ring->rx_buffer_info, 0, size);
4111
f800326d
AD
4112 ixgbe_init_rx_page_offset(rx_ring);
4113
9a799d71
AK
4114 /* Zero out the descriptor ring */
4115 memset(rx_ring->desc, 0, rx_ring->size);
4116
f800326d 4117 rx_ring->next_to_alloc = 0;
9a799d71
AK
4118 rx_ring->next_to_clean = 0;
4119 rx_ring->next_to_use = 0;
9a799d71
AK
4120}
4121
4122/**
4123 * ixgbe_clean_tx_ring - Free Tx Buffers
9a799d71
AK
4124 * @tx_ring: ring to be cleaned
4125 **/
b6ec895e 4126static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
9a799d71
AK
4127{
4128 struct ixgbe_tx_buffer *tx_buffer_info;
4129 unsigned long size;
b6ec895e 4130 u16 i;
9a799d71 4131
84418e3b
AD
4132 /* ring already cleared, nothing to do */
4133 if (!tx_ring->tx_buffer_info)
4134 return;
9a799d71 4135
84418e3b 4136 /* Free all the Tx ring sk_buffs */
9a799d71
AK
4137 for (i = 0; i < tx_ring->count; i++) {
4138 tx_buffer_info = &tx_ring->tx_buffer_info[i];
b6ec895e 4139 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
9a799d71
AK
4140 }
4141
4142 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4143 memset(tx_ring->tx_buffer_info, 0, size);
4144
4145 /* Zero out the descriptor ring */
4146 memset(tx_ring->desc, 0, tx_ring->size);
4147
4148 tx_ring->next_to_use = 0;
4149 tx_ring->next_to_clean = 0;
9a799d71
AK
4150}
4151
4152/**
021230d4 4153 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
9a799d71
AK
4154 * @adapter: board private structure
4155 **/
021230d4 4156static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
9a799d71
AK
4157{
4158 int i;
4159
021230d4 4160 for (i = 0; i < adapter->num_rx_queues; i++)
b6ec895e 4161 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
9a799d71
AK
4162}
4163
4164/**
021230d4 4165 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
9a799d71
AK
4166 * @adapter: board private structure
4167 **/
021230d4 4168static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
9a799d71
AK
4169{
4170 int i;
4171
021230d4 4172 for (i = 0; i < adapter->num_tx_queues; i++)
b6ec895e 4173 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
9a799d71
AK
4174}
4175
e4911d57
AD
4176static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4177{
4178 struct hlist_node *node, *node2;
4179 struct ixgbe_fdir_filter *filter;
4180
4181 spin_lock(&adapter->fdir_perfect_lock);
4182
4183 hlist_for_each_entry_safe(filter, node, node2,
4184 &adapter->fdir_filter_list, fdir_node) {
4185 hlist_del(&filter->fdir_node);
4186 kfree(filter);
4187 }
4188 adapter->fdir_filter_count = 0;
4189
4190 spin_unlock(&adapter->fdir_perfect_lock);
4191}
4192
9a799d71
AK
4193void ixgbe_down(struct ixgbe_adapter *adapter)
4194{
4195 struct net_device *netdev = adapter->netdev;
7f821875 4196 struct ixgbe_hw *hw = &adapter->hw;
9a799d71 4197 u32 rxctrl;
bf29ee6c 4198 int i;
9a799d71
AK
4199
4200 /* signal that we are down to the interrupt handler */
4201 set_bit(__IXGBE_DOWN, &adapter->state);
4202
4203 /* disable receives */
7f821875
JB
4204 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4205 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
9a799d71 4206
2d39d576
YZ
4207 /* disable all enabled rx queues */
4208 for (i = 0; i < adapter->num_rx_queues; i++)
4209 /* this call also flushes the previous write */
4210 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4211
032b4325 4212 usleep_range(10000, 20000);
9a799d71 4213
7f821875
JB
4214 netif_tx_stop_all_queues(netdev);
4215
7086400d 4216 /* call carrier off first to avoid false dev_watchdog timeouts */
c0dfb90e
JF
4217 netif_carrier_off(netdev);
4218 netif_tx_disable(netdev);
4219
4220 ixgbe_irq_disable(adapter);
4221
4222 ixgbe_napi_disable_all(adapter);
4223
d034acf1
AD
4224 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4225 IXGBE_FLAG2_RESET_REQUESTED);
7086400d
AD
4226 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4227
4228 del_timer_sync(&adapter->service_timer);
4229
34cecbbf 4230 if (adapter->num_vfs) {
8e34d1aa
AD
4231 /* Clear EITR Select mapping */
4232 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
34cecbbf
AD
4233
4234 /* Mark all the VFs as inactive */
4235 for (i = 0 ; i < adapter->num_vfs; i++)
3db1cd5c 4236 adapter->vfinfo[i].clear_to_send = false;
34cecbbf 4237
34cecbbf
AD
4238 /* ping all the active vfs to let them know we are going down */
4239 ixgbe_ping_all_vfs(adapter);
4240
4241 /* Disable all VFTE/VFRE TX/RX */
4242 ixgbe_disable_tx_rx(adapter);
b25ebfd2
PW
4243 }
4244
7f821875
JB
4245 /* disable transmits in the hardware now that interrupts are off */
4246 for (i = 0; i < adapter->num_tx_queues; i++) {
bf29ee6c 4247 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
34cecbbf 4248 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
7f821875 4249 }
34cecbbf
AD
4250
4251 /* Disable the Tx DMA engine on 82599 and X540 */
bd508178
AD
4252 switch (hw->mac.type) {
4253 case ixgbe_mac_82599EB:
b93a2226 4254 case ixgbe_mac_X540:
88512539 4255 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
e8e9f696
JP
4256 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4257 ~IXGBE_DMATXCTL_TE));
bd508178
AD
4258 break;
4259 default:
4260 break;
4261 }
7f821875 4262
6f4a0e45
PL
4263 if (!pci_channel_offline(adapter->pdev))
4264 ixgbe_reset(adapter);
c6ecf39a
DS
4265
4266 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4267 if (hw->mac.ops.disable_tx_laser &&
4268 ((hw->phy.multispeed_fiber) ||
9f911707 4269 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
c6ecf39a
DS
4270 (hw->mac.type == ixgbe_mac_82599EB))))
4271 hw->mac.ops.disable_tx_laser(hw);
4272
9a799d71
AK
4273 ixgbe_clean_all_tx_rings(adapter);
4274 ixgbe_clean_all_rx_rings(adapter);
4275
5dd2d332 4276#ifdef CONFIG_IXGBE_DCA
96b0e0f6 4277 /* since we reset the hardware DCA settings were cleared */
e35ec126 4278 ixgbe_setup_dca(adapter);
96b0e0f6 4279#endif
9a799d71
AK
4280}
4281
9a799d71
AK
4282/**
4283 * ixgbe_tx_timeout - Respond to a Tx Hang
4284 * @netdev: network interface device structure
4285 **/
4286static void ixgbe_tx_timeout(struct net_device *netdev)
4287{
4288 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4289
4290 /* Do the reset outside of interrupt context */
c83c6cbd 4291 ixgbe_tx_timeout_reset(adapter);
9a799d71
AK
4292}
4293
9a799d71
AK
4294/**
4295 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4296 * @adapter: board private structure to initialize
4297 *
4298 * ixgbe_sw_init initializes the Adapter private data structure.
4299 * Fields are initialized based on PCI device information and
4300 * OS network device settings (MTU size).
4301 **/
4302static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4303{
4304 struct ixgbe_hw *hw = &adapter->hw;
4305 struct pci_dev *pdev = adapter->pdev;
021230d4 4306 unsigned int rss;
7a6b6f51 4307#ifdef CONFIG_IXGBE_DCB
2f90b865
AD
4308 int j;
4309 struct tc_configuration *tc;
4310#endif
021230d4 4311
c44ade9e
JB
4312 /* PCI config space info */
4313
4314 hw->vendor_id = pdev->vendor;
4315 hw->device_id = pdev->device;
4316 hw->revision_id = pdev->revision;
4317 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4318 hw->subsystem_device_id = pdev->subsystem_device;
4319
021230d4 4320 /* Set capability flags */
3ed69d7e 4321 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
021230d4
AV
4322 adapter->ring_feature[RING_F_RSS].indices = rss;
4323 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
bd508178
AD
4324 switch (hw->mac.type) {
4325 case ixgbe_mac_82598EB:
bf069c97
DS
4326 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4327 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
e8e26350 4328 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
bd508178 4329 break;
b93a2226 4330 case ixgbe_mac_X540:
4f51bf70
JK
4331 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4332 case ixgbe_mac_82599EB:
e8e26350 4333 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
0c19d6af
PWJ
4334 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4335 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
119fc60a
MC
4336 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4337 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
45b9f509
AD
4338 /* Flow Director hash filters enabled */
4339 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
4340 adapter->atr_sample_rate = 20;
c4cf55e5 4341 adapter->ring_feature[RING_F_FDIR].indices =
e8e9f696 4342 IXGBE_MAX_FDIR_INDICES;
c04f6ca8 4343 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
eacd73f7 4344#ifdef IXGBE_FCOE
0d551589
YZ
4345 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4346 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4347 adapter->ring_feature[RING_F_FCOE].indices = 0;
61a0f421 4348#ifdef CONFIG_IXGBE_DCB
6ee16520 4349 /* Default traffic class to use for FCoE */
56075a98 4350 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
61a0f421 4351#endif
eacd73f7 4352#endif /* IXGBE_FCOE */
bd508178
AD
4353 break;
4354 default:
4355 break;
f8212f97 4356 }
2f90b865 4357
1fc5f038
AD
4358 /* n-tuple support exists, always init our spinlock */
4359 spin_lock_init(&adapter->fdir_perfect_lock);
4360
7a6b6f51 4361#ifdef CONFIG_IXGBE_DCB
4de2a022
JF
4362 switch (hw->mac.type) {
4363 case ixgbe_mac_X540:
4364 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4365 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4366 break;
4367 default:
4368 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4369 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4370 break;
4371 }
4372
2f90b865
AD
4373 /* Configure DCB traffic classes */
4374 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4375 tc = &adapter->dcb_cfg.tc_config[j];
4376 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4377 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4378 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4379 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4380 tc->dcb_pfc = pfc_disabled;
4381 }
4de2a022
JF
4382
4383 /* Initialize default user to priority mapping, UPx->TC0 */
4384 tc = &adapter->dcb_cfg.tc_config[0];
4385 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4386 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4387
2f90b865
AD
4388 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4389 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
264857b8 4390 adapter->dcb_cfg.pfc_mode_enable = false;
2f90b865 4391 adapter->dcb_set_bitmap = 0x00;
3032309b 4392 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
2f90b865 4393 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
e5b64635 4394 MAX_TRAFFIC_CLASS);
2f90b865
AD
4395
4396#endif
9a799d71
AK
4397
4398 /* default flow control settings */
cd7664f6 4399 hw->fc.requested_mode = ixgbe_fc_full;
71fd570b 4400 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
264857b8
PWJ
4401#ifdef CONFIG_DCB
4402 adapter->last_lfc_mode = hw->fc.current_mode;
4403#endif
9da712d2 4404 ixgbe_pbthresh_setup(adapter);
2b9ade93
JB
4405 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4406 hw->fc.send_xon = true;
71fd570b 4407 hw->fc.disable_fc_autoneg = false;
9a799d71 4408
30efa5a3 4409 /* enable itr by default in dynamic mode */
f7554a2b 4410 adapter->rx_itr_setting = 1;
f7554a2b 4411 adapter->tx_itr_setting = 1;
30efa5a3 4412
30efa5a3
JB
4413 /* set default ring sizes */
4414 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4415 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4416
bd198058 4417 /* set default work limits */
59224555 4418 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
bd198058 4419
9a799d71 4420 /* initialize eeprom parameters */
c44ade9e 4421 if (ixgbe_init_eeprom_params_generic(hw)) {
849c4542 4422 e_dev_err("EEPROM initialization failed\n");
9a799d71
AK
4423 return -EIO;
4424 }
4425
9a799d71
AK
4426 set_bit(__IXGBE_DOWN, &adapter->state);
4427
4428 return 0;
4429}
4430
4431/**
4432 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3a581073 4433 * @tx_ring: tx descriptor ring (for a specific queue) to setup
9a799d71
AK
4434 *
4435 * Return 0 on success, negative on failure
4436 **/
b6ec895e 4437int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
9a799d71 4438{
b6ec895e 4439 struct device *dev = tx_ring->dev;
de88eeeb
AD
4440 int orig_node = dev_to_node(dev);
4441 int numa_node = -1;
9a799d71
AK
4442 int size;
4443
3a581073 4444 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
de88eeeb
AD
4445
4446 if (tx_ring->q_vector)
4447 numa_node = tx_ring->q_vector->numa_node;
4448
4449 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
1a6c14a2 4450 if (!tx_ring->tx_buffer_info)
89bf67f1 4451 tx_ring->tx_buffer_info = vzalloc(size);
e01c31a5
JB
4452 if (!tx_ring->tx_buffer_info)
4453 goto err;
9a799d71
AK
4454
4455 /* round up to nearest 4K */
12207e49 4456 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
3a581073 4457 tx_ring->size = ALIGN(tx_ring->size, 4096);
9a799d71 4458
de88eeeb
AD
4459 set_dev_node(dev, numa_node);
4460 tx_ring->desc = dma_alloc_coherent(dev,
4461 tx_ring->size,
4462 &tx_ring->dma,
4463 GFP_KERNEL);
4464 set_dev_node(dev, orig_node);
4465 if (!tx_ring->desc)
4466 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4467 &tx_ring->dma, GFP_KERNEL);
e01c31a5
JB
4468 if (!tx_ring->desc)
4469 goto err;
9a799d71 4470
3a581073
JB
4471 tx_ring->next_to_use = 0;
4472 tx_ring->next_to_clean = 0;
9a799d71 4473 return 0;
e01c31a5
JB
4474
4475err:
4476 vfree(tx_ring->tx_buffer_info);
4477 tx_ring->tx_buffer_info = NULL;
b6ec895e 4478 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
e01c31a5 4479 return -ENOMEM;
9a799d71
AK
4480}
4481
69888674
AD
4482/**
4483 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4484 * @adapter: board private structure
4485 *
4486 * If this function returns with an error, then it's possible one or
4487 * more of the rings is populated (while the rest are not). It is the
4488 * callers duty to clean those orphaned rings.
4489 *
4490 * Return 0 on success, negative on failure
4491 **/
4492static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4493{
4494 int i, err = 0;
4495
4496 for (i = 0; i < adapter->num_tx_queues; i++) {
b6ec895e 4497 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
69888674
AD
4498 if (!err)
4499 continue;
396e799c 4500 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
69888674
AD
4501 break;
4502 }
4503
4504 return err;
4505}
4506
9a799d71
AK
4507/**
4508 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3a581073 4509 * @rx_ring: rx descriptor ring (for a specific queue) to setup
9a799d71
AK
4510 *
4511 * Returns 0 on success, negative on failure
4512 **/
b6ec895e 4513int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
9a799d71 4514{
b6ec895e 4515 struct device *dev = rx_ring->dev;
de88eeeb
AD
4516 int orig_node = dev_to_node(dev);
4517 int numa_node = -1;
021230d4 4518 int size;
9a799d71 4519
3a581073 4520 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
de88eeeb
AD
4521
4522 if (rx_ring->q_vector)
4523 numa_node = rx_ring->q_vector->numa_node;
4524
4525 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
1a6c14a2 4526 if (!rx_ring->rx_buffer_info)
89bf67f1 4527 rx_ring->rx_buffer_info = vzalloc(size);
b6ec895e
AD
4528 if (!rx_ring->rx_buffer_info)
4529 goto err;
9a799d71 4530
9a799d71 4531 /* Round up to nearest 4K */
3a581073
JB
4532 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4533 rx_ring->size = ALIGN(rx_ring->size, 4096);
9a799d71 4534
de88eeeb
AD
4535 set_dev_node(dev, numa_node);
4536 rx_ring->desc = dma_alloc_coherent(dev,
4537 rx_ring->size,
4538 &rx_ring->dma,
4539 GFP_KERNEL);
4540 set_dev_node(dev, orig_node);
4541 if (!rx_ring->desc)
4542 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4543 &rx_ring->dma, GFP_KERNEL);
b6ec895e
AD
4544 if (!rx_ring->desc)
4545 goto err;
9a799d71 4546
3a581073
JB
4547 rx_ring->next_to_clean = 0;
4548 rx_ring->next_to_use = 0;
9a799d71 4549
f800326d
AD
4550 ixgbe_init_rx_page_offset(rx_ring);
4551
9a799d71 4552 return 0;
b6ec895e
AD
4553err:
4554 vfree(rx_ring->rx_buffer_info);
4555 rx_ring->rx_buffer_info = NULL;
4556 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
177db6ff 4557 return -ENOMEM;
9a799d71
AK
4558}
4559
69888674
AD
4560/**
4561 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4562 * @adapter: board private structure
4563 *
4564 * If this function returns with an error, then it's possible one or
4565 * more of the rings is populated (while the rest are not). It is the
4566 * callers duty to clean those orphaned rings.
4567 *
4568 * Return 0 on success, negative on failure
4569 **/
69888674
AD
4570static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4571{
4572 int i, err = 0;
4573
4574 for (i = 0; i < adapter->num_rx_queues; i++) {
b6ec895e 4575 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
69888674
AD
4576 if (!err)
4577 continue;
396e799c 4578 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
69888674
AD
4579 break;
4580 }
4581
4582 return err;
4583}
4584
9a799d71
AK
4585/**
4586 * ixgbe_free_tx_resources - Free Tx Resources per Queue
9a799d71
AK
4587 * @tx_ring: Tx descriptor ring for a specific queue
4588 *
4589 * Free all transmit software resources
4590 **/
b6ec895e 4591void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
9a799d71 4592{
b6ec895e 4593 ixgbe_clean_tx_ring(tx_ring);
9a799d71
AK
4594
4595 vfree(tx_ring->tx_buffer_info);
4596 tx_ring->tx_buffer_info = NULL;
4597
b6ec895e
AD
4598 /* if not set, then don't free */
4599 if (!tx_ring->desc)
4600 return;
4601
4602 dma_free_coherent(tx_ring->dev, tx_ring->size,
4603 tx_ring->desc, tx_ring->dma);
9a799d71
AK
4604
4605 tx_ring->desc = NULL;
4606}
4607
4608/**
4609 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4610 * @adapter: board private structure
4611 *
4612 * Free all transmit software resources
4613 **/
4614static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4615{
4616 int i;
4617
4618 for (i = 0; i < adapter->num_tx_queues; i++)
4a0b9ca0 4619 if (adapter->tx_ring[i]->desc)
b6ec895e 4620 ixgbe_free_tx_resources(adapter->tx_ring[i]);
9a799d71
AK
4621}
4622
4623/**
b4617240 4624 * ixgbe_free_rx_resources - Free Rx Resources
9a799d71
AK
4625 * @rx_ring: ring to clean the resources from
4626 *
4627 * Free all receive software resources
4628 **/
b6ec895e 4629void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
9a799d71 4630{
b6ec895e 4631 ixgbe_clean_rx_ring(rx_ring);
9a799d71
AK
4632
4633 vfree(rx_ring->rx_buffer_info);
4634 rx_ring->rx_buffer_info = NULL;
4635
b6ec895e
AD
4636 /* if not set, then don't free */
4637 if (!rx_ring->desc)
4638 return;
4639
4640 dma_free_coherent(rx_ring->dev, rx_ring->size,
4641 rx_ring->desc, rx_ring->dma);
9a799d71
AK
4642
4643 rx_ring->desc = NULL;
4644}
4645
4646/**
4647 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4648 * @adapter: board private structure
4649 *
4650 * Free all receive software resources
4651 **/
4652static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4653{
4654 int i;
4655
4656 for (i = 0; i < adapter->num_rx_queues; i++)
4a0b9ca0 4657 if (adapter->rx_ring[i]->desc)
b6ec895e 4658 ixgbe_free_rx_resources(adapter->rx_ring[i]);
9a799d71
AK
4659}
4660
9a799d71
AK
4661/**
4662 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4663 * @netdev: network interface device structure
4664 * @new_mtu: new value for maximum frame size
4665 *
4666 * Returns 0 on success, negative on failure
4667 **/
4668static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4669{
4670 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4671 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4672
42c783c5 4673 /* MTU < 68 is an error and causes problems on some kernels */
655309e9
AD
4674 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4675 return -EINVAL;
4676
4677 /*
4678 * For 82599EB we cannot allow PF to change MTU greater than 1500
4679 * in SR-IOV mode as it may cause buffer overruns in guest VFs that
4680 * don't allocate and chain buffers correctly.
4681 */
4682 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4683 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4684 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
e9f98072 4685 return -EINVAL;
9a799d71 4686
396e799c 4687 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
655309e9 4688
021230d4 4689 /* must set new MTU before calling down or up */
9a799d71
AK
4690 netdev->mtu = new_mtu;
4691
d4f80882
AV
4692 if (netif_running(netdev))
4693 ixgbe_reinit_locked(adapter);
9a799d71
AK
4694
4695 return 0;
4696}
4697
4698/**
4699 * ixgbe_open - Called when a network interface is made active
4700 * @netdev: network interface device structure
4701 *
4702 * Returns 0 on success, negative value on failure
4703 *
4704 * The open entry point is called when a network interface is made
4705 * active by the system (IFF_UP). At this point all resources needed
4706 * for transmit and receive operations are allocated, the interrupt
4707 * handler is registered with the OS, the watchdog timer is started,
4708 * and the stack is notified that the interface is ready.
4709 **/
4710static int ixgbe_open(struct net_device *netdev)
4711{
4712 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4713 int err;
4bebfaa5
AK
4714
4715 /* disallow open during test */
4716 if (test_bit(__IXGBE_TESTING, &adapter->state))
4717 return -EBUSY;
9a799d71 4718
54386467
JB
4719 netif_carrier_off(netdev);
4720
9a799d71
AK
4721 /* allocate transmit descriptors */
4722 err = ixgbe_setup_all_tx_resources(adapter);
4723 if (err)
4724 goto err_setup_tx;
4725
9a799d71
AK
4726 /* allocate receive descriptors */
4727 err = ixgbe_setup_all_rx_resources(adapter);
4728 if (err)
4729 goto err_setup_rx;
4730
4731 ixgbe_configure(adapter);
4732
021230d4 4733 err = ixgbe_request_irq(adapter);
9a799d71
AK
4734 if (err)
4735 goto err_req_irq;
4736
c7ccde0f 4737 ixgbe_up_complete(adapter);
9a799d71
AK
4738
4739 return 0;
4740
9a799d71 4741err_req_irq:
9a799d71 4742err_setup_rx:
a20a1199 4743 ixgbe_free_all_rx_resources(adapter);
9a799d71 4744err_setup_tx:
a20a1199 4745 ixgbe_free_all_tx_resources(adapter);
9a799d71
AK
4746 ixgbe_reset(adapter);
4747
4748 return err;
4749}
4750
4751/**
4752 * ixgbe_close - Disables a network interface
4753 * @netdev: network interface device structure
4754 *
4755 * Returns 0, this is not allowed to fail
4756 *
4757 * The close entry point is called when an interface is de-activated
4758 * by the OS. The hardware is still under the drivers control, but
4759 * needs to be disabled. A global MAC reset is issued to stop the
4760 * hardware, and all transmit and receive resources are freed.
4761 **/
4762static int ixgbe_close(struct net_device *netdev)
4763{
4764 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9a799d71
AK
4765
4766 ixgbe_down(adapter);
4767 ixgbe_free_irq(adapter);
4768
e4911d57
AD
4769 ixgbe_fdir_filter_exit(adapter);
4770
9a799d71
AK
4771 ixgbe_free_all_tx_resources(adapter);
4772 ixgbe_free_all_rx_resources(adapter);
4773
5eba3699 4774 ixgbe_release_hw_control(adapter);
9a799d71
AK
4775
4776 return 0;
4777}
4778
b3c8b4ba
AD
4779#ifdef CONFIG_PM
4780static int ixgbe_resume(struct pci_dev *pdev)
4781{
c60fbb00
AD
4782 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4783 struct net_device *netdev = adapter->netdev;
b3c8b4ba
AD
4784 u32 err;
4785
4786 pci_set_power_state(pdev, PCI_D0);
4787 pci_restore_state(pdev);
656ab817
DS
4788 /*
4789 * pci_restore_state clears dev->state_saved so call
4790 * pci_save_state to restore it.
4791 */
4792 pci_save_state(pdev);
9ce77666 4793
4794 err = pci_enable_device_mem(pdev);
b3c8b4ba 4795 if (err) {
849c4542 4796 e_dev_err("Cannot enable PCI device from suspend\n");
b3c8b4ba
AD
4797 return err;
4798 }
4799 pci_set_master(pdev);
4800
dd4d8ca6 4801 pci_wake_from_d3(pdev, false);
b3c8b4ba 4802
34948a94 4803 rtnl_lock();
b3c8b4ba 4804 err = ixgbe_init_interrupt_scheme(adapter);
34948a94 4805 rtnl_unlock();
b3c8b4ba 4806 if (err) {
849c4542 4807 e_dev_err("Cannot initialize interrupts for device\n");
b3c8b4ba
AD
4808 return err;
4809 }
4810
b3c8b4ba
AD
4811 ixgbe_reset(adapter);
4812
495dce12
WJP
4813 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4814
b3c8b4ba 4815 if (netif_running(netdev)) {
c60fbb00 4816 err = ixgbe_open(netdev);
b3c8b4ba
AD
4817 if (err)
4818 return err;
4819 }
4820
4821 netif_device_attach(netdev);
4822
4823 return 0;
4824}
b3c8b4ba 4825#endif /* CONFIG_PM */
9d8d05ae
RW
4826
4827static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
b3c8b4ba 4828{
c60fbb00
AD
4829 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4830 struct net_device *netdev = adapter->netdev;
e8e26350
PW
4831 struct ixgbe_hw *hw = &adapter->hw;
4832 u32 ctrl, fctrl;
4833 u32 wufc = adapter->wol;
b3c8b4ba
AD
4834#ifdef CONFIG_PM
4835 int retval = 0;
4836#endif
4837
4838 netif_device_detach(netdev);
4839
4840 if (netif_running(netdev)) {
4841 ixgbe_down(adapter);
4842 ixgbe_free_irq(adapter);
4843 ixgbe_free_all_tx_resources(adapter);
4844 ixgbe_free_all_rx_resources(adapter);
4845 }
b3c8b4ba 4846
5f5ae6fc 4847 ixgbe_clear_interrupt_scheme(adapter);
d033d526
JF
4848#ifdef CONFIG_DCB
4849 kfree(adapter->ixgbe_ieee_pfc);
4850 kfree(adapter->ixgbe_ieee_ets);
4851#endif
5f5ae6fc 4852
b3c8b4ba
AD
4853#ifdef CONFIG_PM
4854 retval = pci_save_state(pdev);
4855 if (retval)
4856 return retval;
4df10466 4857
b3c8b4ba 4858#endif
e8e26350
PW
4859 if (wufc) {
4860 ixgbe_set_rx_mode(netdev);
b3c8b4ba 4861
c509e754
DS
4862 /*
4863 * enable the optics for both mult-speed fiber and
4864 * 82599 SFP+ fiber as we can WoL.
4865 */
4866 if (hw->mac.ops.enable_tx_laser &&
4867 (hw->phy.multispeed_fiber ||
4868 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber &&
4869 hw->mac.type == ixgbe_mac_82599EB)))
4870 hw->mac.ops.enable_tx_laser(hw);
4871
e8e26350
PW
4872 /* turn on all-multi mode if wake on multicast is enabled */
4873 if (wufc & IXGBE_WUFC_MC) {
4874 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4875 fctrl |= IXGBE_FCTRL_MPE;
4876 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4877 }
4878
4879 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4880 ctrl |= IXGBE_CTRL_GIO_DIS;
4881 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4882
4883 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4884 } else {
4885 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4886 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4887 }
4888
bd508178
AD
4889 switch (hw->mac.type) {
4890 case ixgbe_mac_82598EB:
dd4d8ca6 4891 pci_wake_from_d3(pdev, false);
bd508178
AD
4892 break;
4893 case ixgbe_mac_82599EB:
b93a2226 4894 case ixgbe_mac_X540:
bd508178
AD
4895 pci_wake_from_d3(pdev, !!wufc);
4896 break;
4897 default:
4898 break;
4899 }
b3c8b4ba 4900
9d8d05ae
RW
4901 *enable_wake = !!wufc;
4902
b3c8b4ba
AD
4903 ixgbe_release_hw_control(adapter);
4904
4905 pci_disable_device(pdev);
4906
9d8d05ae
RW
4907 return 0;
4908}
4909
4910#ifdef CONFIG_PM
4911static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4912{
4913 int retval;
4914 bool wake;
4915
4916 retval = __ixgbe_shutdown(pdev, &wake);
4917 if (retval)
4918 return retval;
4919
4920 if (wake) {
4921 pci_prepare_to_sleep(pdev);
4922 } else {
4923 pci_wake_from_d3(pdev, false);
4924 pci_set_power_state(pdev, PCI_D3hot);
4925 }
b3c8b4ba
AD
4926
4927 return 0;
4928}
9d8d05ae 4929#endif /* CONFIG_PM */
b3c8b4ba
AD
4930
4931static void ixgbe_shutdown(struct pci_dev *pdev)
4932{
9d8d05ae
RW
4933 bool wake;
4934
4935 __ixgbe_shutdown(pdev, &wake);
4936
4937 if (system_state == SYSTEM_POWER_OFF) {
4938 pci_wake_from_d3(pdev, wake);
4939 pci_set_power_state(pdev, PCI_D3hot);
4940 }
b3c8b4ba
AD
4941}
4942
9a799d71
AK
4943/**
4944 * ixgbe_update_stats - Update the board statistics counters.
4945 * @adapter: board private structure
4946 **/
4947void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4948{
2d86f139 4949 struct net_device *netdev = adapter->netdev;
9a799d71 4950 struct ixgbe_hw *hw = &adapter->hw;
5b7da515 4951 struct ixgbe_hw_stats *hwstats = &adapter->stats;
6f11eef7
AV
4952 u64 total_mpc = 0;
4953 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
5b7da515
AD
4954 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
4955 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
8a0da21b 4956 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
7b859ebc
AH
4957#ifdef IXGBE_FCOE
4958 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
4959 unsigned int cpu;
4960 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
4961#endif /* IXGBE_FCOE */
9a799d71 4962
d08935c2
DS
4963 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
4964 test_bit(__IXGBE_RESETTING, &adapter->state))
4965 return;
4966
94b982b2 4967 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
f8212f97 4968 u64 rsc_count = 0;
94b982b2 4969 u64 rsc_flush = 0;
94b982b2 4970 for (i = 0; i < adapter->num_rx_queues; i++) {
5b7da515
AD
4971 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
4972 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
94b982b2
MC
4973 }
4974 adapter->rsc_total_count = rsc_count;
4975 adapter->rsc_total_flush = rsc_flush;
d51019a4
PW
4976 }
4977
5b7da515
AD
4978 for (i = 0; i < adapter->num_rx_queues; i++) {
4979 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
4980 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
4981 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
4982 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
8a0da21b 4983 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
5b7da515
AD
4984 bytes += rx_ring->stats.bytes;
4985 packets += rx_ring->stats.packets;
4986 }
4987 adapter->non_eop_descs = non_eop_descs;
4988 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
4989 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
8a0da21b 4990 adapter->hw_csum_rx_error = hw_csum_rx_error;
5b7da515
AD
4991 netdev->stats.rx_bytes = bytes;
4992 netdev->stats.rx_packets = packets;
4993
4994 bytes = 0;
4995 packets = 0;
7ca3bc58 4996 /* gather some stats to the adapter struct that are per queue */
5b7da515
AD
4997 for (i = 0; i < adapter->num_tx_queues; i++) {
4998 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
4999 restart_queue += tx_ring->tx_stats.restart_queue;
5000 tx_busy += tx_ring->tx_stats.tx_busy;
5001 bytes += tx_ring->stats.bytes;
5002 packets += tx_ring->stats.packets;
5003 }
eb985f09 5004 adapter->restart_queue = restart_queue;
5b7da515
AD
5005 adapter->tx_busy = tx_busy;
5006 netdev->stats.tx_bytes = bytes;
5007 netdev->stats.tx_packets = packets;
7ca3bc58 5008
7ca647bd 5009 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
1a70db4b
ET
5010
5011 /* 8 register reads */
6f11eef7
AV
5012 for (i = 0; i < 8; i++) {
5013 /* for packet buffers not used, the register should read 0 */
5014 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5015 missed_rx += mpc;
7ca647bd
JP
5016 hwstats->mpc[i] += mpc;
5017 total_mpc += hwstats->mpc[i];
1a70db4b
ET
5018 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5019 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
bd508178
AD
5020 switch (hw->mac.type) {
5021 case ixgbe_mac_82598EB:
1a70db4b
ET
5022 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5023 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5024 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
7ca647bd
JP
5025 hwstats->pxonrxc[i] +=
5026 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
bd508178
AD
5027 break;
5028 case ixgbe_mac_82599EB:
b93a2226 5029 case ixgbe_mac_X540:
bd508178
AD
5030 hwstats->pxonrxc[i] +=
5031 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
bd508178
AD
5032 break;
5033 default:
5034 break;
e8e26350 5035 }
6f11eef7 5036 }
1a70db4b
ET
5037
5038 /*16 register reads */
5039 for (i = 0; i < 16; i++) {
5040 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5041 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5042 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5043 (hw->mac.type == ixgbe_mac_X540)) {
5044 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5045 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5046 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5047 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5048 }
5049 }
5050
7ca647bd 5051 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
6f11eef7 5052 /* work around hardware counting issue */
7ca647bd 5053 hwstats->gprc -= missed_rx;
6f11eef7 5054
c84d324c
JF
5055 ixgbe_update_xoff_received(adapter);
5056
6f11eef7 5057 /* 82598 hardware only has a 32 bit counter in the high register */
bd508178
AD
5058 switch (hw->mac.type) {
5059 case ixgbe_mac_82598EB:
5060 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
bd508178
AD
5061 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5062 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5063 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5064 break;
b93a2226 5065 case ixgbe_mac_X540:
58f6bcf9
ET
5066 /* OS2BMC stats are X540 only*/
5067 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5068 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5069 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5070 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5071 case ixgbe_mac_82599EB:
a4d4f629
AD
5072 for (i = 0; i < 16; i++)
5073 adapter->hw_rx_no_dma_resources +=
5074 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
7ca647bd 5075 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
bd508178 5076 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
7ca647bd 5077 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
bd508178 5078 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
7ca647bd 5079 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
bd508178 5080 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
7ca647bd 5081 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
7ca647bd
JP
5082 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5083 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
6d45522c 5084#ifdef IXGBE_FCOE
7ca647bd
JP
5085 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5086 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5087 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5088 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5089 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5090 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
7b859ebc
AH
5091 /* Add up per cpu counters for total ddp aloc fail */
5092 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5093 for_each_possible_cpu(cpu) {
5094 fcoe_noddp_counts_sum +=
5095 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5096 fcoe_noddp_ext_buff_counts_sum +=
5097 *per_cpu_ptr(fcoe->
5098 pcpu_noddp_ext_buff, cpu);
5099 }
5100 }
5101 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5102 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
6d45522c 5103#endif /* IXGBE_FCOE */
bd508178
AD
5104 break;
5105 default:
5106 break;
e8e26350 5107 }
9a799d71 5108 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
7ca647bd
JP
5109 hwstats->bprc += bprc;
5110 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
e8e26350 5111 if (hw->mac.type == ixgbe_mac_82598EB)
7ca647bd
JP
5112 hwstats->mprc -= bprc;
5113 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5114 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5115 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5116 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5117 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5118 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5119 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5120 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
6f11eef7 5121 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
7ca647bd 5122 hwstats->lxontxc += lxon;
6f11eef7 5123 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
7ca647bd 5124 hwstats->lxofftxc += lxoff;
7ca647bd
JP
5125 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5126 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
6f11eef7
AV
5127 /*
5128 * 82598 errata - tx of flow control packets is included in tx counters
5129 */
5130 xon_off_tot = lxon + lxoff;
7ca647bd
JP
5131 hwstats->gptc -= xon_off_tot;
5132 hwstats->mptc -= xon_off_tot;
5133 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5134 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5135 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5136 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5137 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5138 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5139 hwstats->ptc64 -= xon_off_tot;
5140 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5141 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5142 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5143 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5144 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5145 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
9a799d71
AK
5146
5147 /* Fill out the OS statistics structure */
7ca647bd 5148 netdev->stats.multicast = hwstats->mprc;
9a799d71
AK
5149
5150 /* Rx Errors */
7ca647bd 5151 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
2d86f139 5152 netdev->stats.rx_dropped = 0;
7ca647bd
JP
5153 netdev->stats.rx_length_errors = hwstats->rlec;
5154 netdev->stats.rx_crc_errors = hwstats->crcerrs;
2d86f139 5155 netdev->stats.rx_missed_errors = total_mpc;
9a799d71
AK
5156}
5157
5158/**
d034acf1
AD
5159 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5160 * @adapter - pointer to the device adapter structure
9a799d71 5161 **/
d034acf1 5162static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
9a799d71 5163{
cf8280ee 5164 struct ixgbe_hw *hw = &adapter->hw;
fe49f04a 5165 int i;
cf8280ee 5166
d034acf1
AD
5167 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5168 return;
5169
5170 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
22d5a71b 5171
d034acf1 5172 /* if interface is down do nothing */
fe49f04a 5173 if (test_bit(__IXGBE_DOWN, &adapter->state))
d034acf1
AD
5174 return;
5175
5176 /* do nothing if we are not using signature filters */
5177 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5178 return;
5179
5180 adapter->fdir_overflow++;
5181
93c52dd0
AD
5182 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5183 for (i = 0; i < adapter->num_tx_queues; i++)
5184 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
f0f9778d 5185 &(adapter->tx_ring[i]->state));
d034acf1
AD
5186 /* re-enable flow director interrupts */
5187 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
93c52dd0
AD
5188 } else {
5189 e_err(probe, "failed to finish FDIR re-initialization, "
5190 "ignored adding FDIR ATR filters\n");
5191 }
93c52dd0
AD
5192}
5193
5194/**
5195 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5196 * @adapter - pointer to the device adapter structure
5197 *
5198 * This function serves two purposes. First it strobes the interrupt lines
52f33af8 5199 * in order to make certain interrupts are occurring. Secondly it sets the
93c52dd0 5200 * bits needed to check for TX hangs. As a result we should immediately
52f33af8 5201 * determine if a hang has occurred.
93c52dd0
AD
5202 */
5203static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
9a799d71 5204{
cf8280ee 5205 struct ixgbe_hw *hw = &adapter->hw;
fe49f04a
AD
5206 u64 eics = 0;
5207 int i;
cf8280ee 5208
93c52dd0
AD
5209 /* If we're down or resetting, just bail */
5210 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5211 test_bit(__IXGBE_RESETTING, &adapter->state))
5212 return;
22d5a71b 5213
93c52dd0
AD
5214 /* Force detection of hung controller */
5215 if (netif_carrier_ok(adapter->netdev)) {
5216 for (i = 0; i < adapter->num_tx_queues; i++)
5217 set_check_for_tx_hang(adapter->tx_ring[i]);
5218 }
22d5a71b 5219
fe49f04a
AD
5220 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
5221 /*
5222 * for legacy and MSI interrupts don't set any bits
5223 * that are enabled for EIAM, because this operation
5224 * would set *both* EIMS and EICS for any bit in EIAM
5225 */
5226 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5227 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
93c52dd0
AD
5228 } else {
5229 /* get one bit for every active tx/rx interrupt vector */
5230 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5231 struct ixgbe_q_vector *qv = adapter->q_vector[i];
efe3d3c8 5232 if (qv->rx.ring || qv->tx.ring)
93c52dd0
AD
5233 eics |= ((u64)1 << i);
5234 }
cf8280ee 5235 }
9a799d71 5236
93c52dd0 5237 /* Cause software interrupt to ensure rings are cleaned */
fe49f04a
AD
5238 ixgbe_irq_rearm_queues(adapter, eics);
5239
cf8280ee
JB
5240}
5241
e8e26350 5242/**
93c52dd0
AD
5243 * ixgbe_watchdog_update_link - update the link status
5244 * @adapter - pointer to the device adapter structure
5245 * @link_speed - pointer to a u32 to store the link_speed
e8e26350 5246 **/
93c52dd0 5247static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
e8e26350 5248{
e8e26350 5249 struct ixgbe_hw *hw = &adapter->hw;
93c52dd0
AD
5250 u32 link_speed = adapter->link_speed;
5251 bool link_up = adapter->link_up;
c4cf55e5 5252 int i;
e8e26350 5253
93c52dd0
AD
5254 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5255 return;
5256
5257 if (hw->mac.ops.check_link) {
5258 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
c4cf55e5 5259 } else {
93c52dd0
AD
5260 /* always assume link is up, if no check link function */
5261 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5262 link_up = true;
c4cf55e5 5263 }
93c52dd0
AD
5264 if (link_up) {
5265 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5266 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5267 hw->mac.ops.fc_enable(hw, i);
5268 } else {
5269 hw->mac.ops.fc_enable(hw, 0);
5270 }
5271 }
5272
5273 if (link_up ||
5274 time_after(jiffies, (adapter->link_check_timeout +
5275 IXGBE_TRY_LINK_TIMEOUT))) {
5276 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5277 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5278 IXGBE_WRITE_FLUSH(hw);
5279 }
5280
5281 adapter->link_up = link_up;
5282 adapter->link_speed = link_speed;
e8e26350
PW
5283}
5284
5285/**
93c52dd0
AD
5286 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5287 * print link up message
5288 * @adapter - pointer to the device adapter structure
e8e26350 5289 **/
93c52dd0 5290static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
e8e26350 5291{
93c52dd0 5292 struct net_device *netdev = adapter->netdev;
e8e26350 5293 struct ixgbe_hw *hw = &adapter->hw;
93c52dd0
AD
5294 u32 link_speed = adapter->link_speed;
5295 bool flow_rx, flow_tx;
e8e26350 5296
93c52dd0
AD
5297 /* only continue if link was previously down */
5298 if (netif_carrier_ok(netdev))
a985b6c3 5299 return;
63d6e1d8 5300
93c52dd0 5301 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
63d6e1d8 5302
93c52dd0
AD
5303 switch (hw->mac.type) {
5304 case ixgbe_mac_82598EB: {
5305 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5306 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5307 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5308 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5309 }
5310 break;
5311 case ixgbe_mac_X540:
5312 case ixgbe_mac_82599EB: {
5313 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5314 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5315 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5316 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5317 }
5318 break;
5319 default:
5320 flow_tx = false;
5321 flow_rx = false;
5322 break;
e8e26350 5323 }
93c52dd0
AD
5324 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5325 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5326 "10 Gbps" :
5327 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5328 "1 Gbps" :
5329 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5330 "100 Mbps" :
5331 "unknown speed"))),
5332 ((flow_rx && flow_tx) ? "RX/TX" :
5333 (flow_rx ? "RX" :
5334 (flow_tx ? "TX" : "None"))));
e8e26350 5335
93c52dd0 5336 netif_carrier_on(netdev);
93c52dd0 5337 ixgbe_check_vf_rate_limit(adapter);
e8e26350
PW
5338}
5339
c4cf55e5 5340/**
93c52dd0
AD
5341 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5342 * print link down message
5343 * @adapter - pointer to the adapter structure
c4cf55e5 5344 **/
581330ba 5345static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
c4cf55e5 5346{
cf8280ee 5347 struct net_device *netdev = adapter->netdev;
c4cf55e5 5348 struct ixgbe_hw *hw = &adapter->hw;
10eec955 5349
93c52dd0
AD
5350 adapter->link_up = false;
5351 adapter->link_speed = 0;
cf8280ee 5352
93c52dd0
AD
5353 /* only continue if link was up previously */
5354 if (!netif_carrier_ok(netdev))
5355 return;
264857b8 5356
93c52dd0
AD
5357 /* poll for SFP+ cable when link is down */
5358 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5359 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
9a799d71 5360
93c52dd0
AD
5361 e_info(drv, "NIC Link is Down\n");
5362 netif_carrier_off(netdev);
5363}
e8e26350 5364
93c52dd0
AD
5365/**
5366 * ixgbe_watchdog_flush_tx - flush queues on link down
5367 * @adapter - pointer to the device adapter structure
5368 **/
5369static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5370{
c4cf55e5 5371 int i;
93c52dd0 5372 int some_tx_pending = 0;
c4cf55e5 5373
93c52dd0 5374 if (!netif_carrier_ok(adapter->netdev)) {
bc59fcda 5375 for (i = 0; i < adapter->num_tx_queues; i++) {
93c52dd0 5376 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
bc59fcda
NS
5377 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5378 some_tx_pending = 1;
5379 break;
5380 }
5381 }
5382
5383 if (some_tx_pending) {
5384 /* We've lost link, so the controller stops DMA,
5385 * but we've got queued Tx work that's never going
5386 * to get done, so reset controller to flush Tx.
5387 * (Do the reset outside of interrupt context).
5388 */
c83c6cbd 5389 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
bc59fcda 5390 }
c4cf55e5 5391 }
c4cf55e5
PWJ
5392}
5393
a985b6c3
GR
5394static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5395{
5396 u32 ssvpc;
5397
5398 /* Do not perform spoof check for 82598 */
5399 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5400 return;
5401
5402 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5403
5404 /*
5405 * ssvpc register is cleared on read, if zero then no
5406 * spoofed packets in the last interval.
5407 */
5408 if (!ssvpc)
5409 return;
5410
5411 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
5412}
5413
93c52dd0
AD
5414/**
5415 * ixgbe_watchdog_subtask - check and bring link up
5416 * @adapter - pointer to the device adapter structure
5417 **/
5418static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
5419{
5420 /* if interface is down do nothing */
7edebf9a
ET
5421 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5422 test_bit(__IXGBE_RESETTING, &adapter->state))
93c52dd0
AD
5423 return;
5424
5425 ixgbe_watchdog_update_link(adapter);
5426
5427 if (adapter->link_up)
5428 ixgbe_watchdog_link_is_up(adapter);
5429 else
5430 ixgbe_watchdog_link_is_down(adapter);
bc59fcda 5431
a985b6c3 5432 ixgbe_spoof_check(adapter);
9a799d71 5433 ixgbe_update_stats(adapter);
93c52dd0
AD
5434
5435 ixgbe_watchdog_flush_tx(adapter);
9a799d71 5436}
10eec955 5437
cf8280ee 5438/**
7086400d
AD
5439 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
5440 * @adapter - the ixgbe adapter structure
cf8280ee 5441 **/
7086400d 5442static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
cf8280ee 5443{
cf8280ee 5444 struct ixgbe_hw *hw = &adapter->hw;
7086400d 5445 s32 err;
cf8280ee 5446
7086400d
AD
5447 /* not searching for SFP so there is nothing to do here */
5448 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5449 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5450 return;
10eec955 5451
7086400d
AD
5452 /* someone else is in init, wait until next service event */
5453 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5454 return;
cf8280ee 5455
7086400d
AD
5456 err = hw->phy.ops.identify_sfp(hw);
5457 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5458 goto sfp_out;
264857b8 5459
7086400d
AD
5460 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5461 /* If no cable is present, then we need to reset
5462 * the next time we find a good cable. */
5463 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
cf8280ee 5464 }
9a799d71 5465
7086400d
AD
5466 /* exit on error */
5467 if (err)
5468 goto sfp_out;
e8e26350 5469
7086400d
AD
5470 /* exit if reset not needed */
5471 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5472 goto sfp_out;
9a799d71 5473
7086400d 5474 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
bc59fcda 5475
7086400d
AD
5476 /*
5477 * A module may be identified correctly, but the EEPROM may not have
5478 * support for that module. setup_sfp() will fail in that case, so
5479 * we should not allow that module to load.
5480 */
5481 if (hw->mac.type == ixgbe_mac_82598EB)
5482 err = hw->phy.ops.reset(hw);
5483 else
5484 err = hw->mac.ops.setup_sfp(hw);
5485
5486 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5487 goto sfp_out;
5488
5489 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5490 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5491
5492sfp_out:
5493 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5494
5495 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5496 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5497 e_dev_err("failed to initialize because an unsupported "
5498 "SFP+ module type was detected.\n");
5499 e_dev_err("Reload the driver after installing a "
5500 "supported module.\n");
5501 unregister_netdev(adapter->netdev);
bc59fcda 5502 }
7086400d 5503}
bc59fcda 5504
7086400d
AD
5505/**
5506 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
5507 * @adapter - the ixgbe adapter structure
5508 **/
5509static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5510{
5511 struct ixgbe_hw *hw = &adapter->hw;
5512 u32 autoneg;
5513 bool negotiation;
5514
5515 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5516 return;
5517
5518 /* someone else is in init, wait until next service event */
5519 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5520 return;
5521
5522 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5523
5524 autoneg = hw->phy.autoneg_advertised;
5525 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5526 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
7086400d
AD
5527 if (hw->mac.ops.setup_link)
5528 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5529
5530 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5531 adapter->link_check_timeout = jiffies;
5532 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5533}
5534
83c61fa9
GR
5535#ifdef CONFIG_PCI_IOV
5536static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5537{
5538 int vf;
5539 struct ixgbe_hw *hw = &adapter->hw;
5540 struct net_device *netdev = adapter->netdev;
5541 u32 gpc;
5542 u32 ciaa, ciad;
5543
5544 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5545 if (gpc) /* If incrementing then no need for the check below */
5546 return;
5547 /*
5548 * Check to see if a bad DMA write target from an errant or
5549 * malicious VF has caused a PCIe error. If so then we can
5550 * issue a VFLR to the offending VF(s) and then resume without
5551 * requesting a full slot reset.
5552 */
5553
5554 for (vf = 0; vf < adapter->num_vfs; vf++) {
5555 ciaa = (vf << 16) | 0x80000000;
5556 /* 32 bit read so align, we really want status at offset 6 */
5557 ciaa |= PCI_COMMAND;
5558 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5559 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5560 ciaa &= 0x7FFFFFFF;
5561 /* disable debug mode asap after reading data */
5562 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5563 /* Get the upper 16 bits which will be the PCI status reg */
5564 ciad >>= 16;
5565 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5566 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5567 /* Issue VFLR */
5568 ciaa = (vf << 16) | 0x80000000;
5569 ciaa |= 0xA8;
5570 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5571 ciad = 0x00008000; /* VFLR */
5572 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5573 ciaa &= 0x7FFFFFFF;
5574 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5575 }
5576 }
5577}
5578
5579#endif
7086400d
AD
5580/**
5581 * ixgbe_service_timer - Timer Call-back
5582 * @data: pointer to adapter cast into an unsigned long
5583 **/
5584static void ixgbe_service_timer(unsigned long data)
5585{
5586 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5587 unsigned long next_event_offset;
83c61fa9 5588 bool ready = true;
7086400d 5589
6bb78cfb
AD
5590 /* poll faster when waiting for link */
5591 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5592 next_event_offset = HZ / 10;
5593 else
5594 next_event_offset = HZ * 2;
83c61fa9 5595
6bb78cfb 5596#ifdef CONFIG_PCI_IOV
83c61fa9
GR
5597 /*
5598 * don't bother with SR-IOV VF DMA hang check if there are
5599 * no VFs or the link is down
5600 */
5601 if (!adapter->num_vfs ||
6bb78cfb 5602 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
83c61fa9 5603 goto normal_timer_service;
83c61fa9
GR
5604
5605 /* If we have VFs allocated then we must check for DMA hangs */
5606 ixgbe_check_for_bad_vf(adapter);
5607 next_event_offset = HZ / 50;
5608 adapter->timer_event_accumulator++;
5609
6bb78cfb 5610 if (adapter->timer_event_accumulator >= 100)
83c61fa9 5611 adapter->timer_event_accumulator = 0;
7086400d 5612 else
6bb78cfb 5613 ready = false;
7086400d 5614
6bb78cfb 5615normal_timer_service:
83c61fa9 5616#endif
7086400d
AD
5617 /* Reset the timer */
5618 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5619
83c61fa9
GR
5620 if (ready)
5621 ixgbe_service_event_schedule(adapter);
7086400d
AD
5622}
5623
c83c6cbd
AD
5624static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5625{
5626 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5627 return;
5628
5629 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5630
5631 /* If we're already down or resetting, just bail */
5632 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5633 test_bit(__IXGBE_RESETTING, &adapter->state))
5634 return;
5635
5636 ixgbe_dump(adapter);
5637 netdev_err(adapter->netdev, "Reset adapter\n");
5638 adapter->tx_timeout_count++;
5639
5640 ixgbe_reinit_locked(adapter);
5641}
5642
7086400d
AD
5643/**
5644 * ixgbe_service_task - manages and runs subtasks
5645 * @work: pointer to work_struct containing our data
5646 **/
5647static void ixgbe_service_task(struct work_struct *work)
5648{
5649 struct ixgbe_adapter *adapter = container_of(work,
5650 struct ixgbe_adapter,
5651 service_task);
5652
c83c6cbd 5653 ixgbe_reset_subtask(adapter);
7086400d
AD
5654 ixgbe_sfp_detection_subtask(adapter);
5655 ixgbe_sfp_link_config_subtask(adapter);
f0f9778d 5656 ixgbe_check_overtemp_subtask(adapter);
93c52dd0 5657 ixgbe_watchdog_subtask(adapter);
d034acf1 5658 ixgbe_fdir_reinit_subtask(adapter);
93c52dd0 5659 ixgbe_check_hang_subtask(adapter);
7086400d
AD
5660
5661 ixgbe_service_event_complete(adapter);
9a799d71
AK
5662}
5663
fd0db0ed
AD
5664static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5665 struct ixgbe_tx_buffer *first,
244e27ad 5666 u8 *hdr_len)
897ab156 5667{
fd0db0ed 5668 struct sk_buff *skb = first->skb;
897ab156
AD
5669 u32 vlan_macip_lens, type_tucmd;
5670 u32 mss_l4len_idx, l4len;
9a799d71 5671
897ab156
AD
5672 if (!skb_is_gso(skb))
5673 return 0;
9a799d71 5674
897ab156 5675 if (skb_header_cloned(skb)) {
244e27ad 5676 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
897ab156
AD
5677 if (err)
5678 return err;
9a799d71 5679 }
9a799d71 5680
897ab156
AD
5681 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5682 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5683
244e27ad 5684 if (first->protocol == __constant_htons(ETH_P_IP)) {
897ab156
AD
5685 struct iphdr *iph = ip_hdr(skb);
5686 iph->tot_len = 0;
5687 iph->check = 0;
5688 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5689 iph->daddr, 0,
5690 IPPROTO_TCP,
5691 0);
5692 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
244e27ad
AD
5693 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5694 IXGBE_TX_FLAGS_CSUM |
5695 IXGBE_TX_FLAGS_IPV4;
897ab156
AD
5696 } else if (skb_is_gso_v6(skb)) {
5697 ipv6_hdr(skb)->payload_len = 0;
5698 tcp_hdr(skb)->check =
5699 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5700 &ipv6_hdr(skb)->daddr,
5701 0, IPPROTO_TCP, 0);
244e27ad
AD
5702 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5703 IXGBE_TX_FLAGS_CSUM;
897ab156
AD
5704 }
5705
091a6246 5706 /* compute header lengths */
897ab156
AD
5707 l4len = tcp_hdrlen(skb);
5708 *hdr_len = skb_transport_offset(skb) + l4len;
5709
091a6246
AD
5710 /* update gso size and bytecount with header size */
5711 first->gso_segs = skb_shinfo(skb)->gso_segs;
5712 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5713
897ab156
AD
5714 /* mss_l4len_id: use 1 as index for TSO */
5715 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5716 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5717 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5718
5719 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5720 vlan_macip_lens = skb_network_header_len(skb);
5721 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
244e27ad 5722 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
897ab156
AD
5723
5724 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
244e27ad 5725 mss_l4len_idx);
897ab156
AD
5726
5727 return 1;
5728}
5729
244e27ad
AD
5730static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5731 struct ixgbe_tx_buffer *first)
7ca647bd 5732{
fd0db0ed 5733 struct sk_buff *skb = first->skb;
897ab156
AD
5734 u32 vlan_macip_lens = 0;
5735 u32 mss_l4len_idx = 0;
5736 u32 type_tucmd = 0;
7ca647bd 5737
897ab156 5738 if (skb->ip_summed != CHECKSUM_PARTIAL) {
244e27ad
AD
5739 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
5740 !(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5741 return;
897ab156
AD
5742 } else {
5743 u8 l4_hdr = 0;
244e27ad 5744 switch (first->protocol) {
897ab156
AD
5745 case __constant_htons(ETH_P_IP):
5746 vlan_macip_lens |= skb_network_header_len(skb);
5747 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5748 l4_hdr = ip_hdr(skb)->protocol;
7ca647bd 5749 break;
897ab156
AD
5750 case __constant_htons(ETH_P_IPV6):
5751 vlan_macip_lens |= skb_network_header_len(skb);
5752 l4_hdr = ipv6_hdr(skb)->nexthdr;
5753 break;
5754 default:
5755 if (unlikely(net_ratelimit())) {
5756 dev_warn(tx_ring->dev,
5757 "partial checksum but proto=%x!\n",
244e27ad 5758 first->protocol);
897ab156 5759 }
7ca647bd
JP
5760 break;
5761 }
897ab156
AD
5762
5763 switch (l4_hdr) {
7ca647bd 5764 case IPPROTO_TCP:
897ab156
AD
5765 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5766 mss_l4len_idx = tcp_hdrlen(skb) <<
5767 IXGBE_ADVTXD_L4LEN_SHIFT;
7ca647bd
JP
5768 break;
5769 case IPPROTO_SCTP:
897ab156
AD
5770 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
5771 mss_l4len_idx = sizeof(struct sctphdr) <<
5772 IXGBE_ADVTXD_L4LEN_SHIFT;
5773 break;
5774 case IPPROTO_UDP:
5775 mss_l4len_idx = sizeof(struct udphdr) <<
5776 IXGBE_ADVTXD_L4LEN_SHIFT;
5777 break;
5778 default:
5779 if (unlikely(net_ratelimit())) {
5780 dev_warn(tx_ring->dev,
5781 "partial checksum but l4 proto=%x!\n",
244e27ad 5782 l4_hdr);
897ab156 5783 }
7ca647bd
JP
5784 break;
5785 }
244e27ad
AD
5786
5787 /* update TX checksum flag */
5788 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7ca647bd
JP
5789 }
5790
244e27ad 5791 /* vlan_macip_lens: MACLEN, VLAN tag */
897ab156 5792 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
244e27ad 5793 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
9a799d71 5794
897ab156
AD
5795 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
5796 type_tucmd, mss_l4len_idx);
9a799d71
AK
5797}
5798
d3d00239 5799static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
9a799d71 5800{
d3d00239
AD
5801 /* set type for advanced descriptor with frame checksum insertion */
5802 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
5803 IXGBE_ADVTXD_DCMD_IFCS |
5804 IXGBE_ADVTXD_DCMD_DEXT);
9a799d71 5805
d3d00239 5806 /* set HW vlan bit if vlan is present */
66f32a8b 5807 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
d3d00239 5808 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
9a799d71 5809
d3d00239
AD
5810 /* set segmentation enable bits for TSO/FSO */
5811#ifdef IXGBE_FCOE
93f5b3c1 5812 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
d3d00239
AD
5813#else
5814 if (tx_flags & IXGBE_TX_FLAGS_TSO)
5815#endif
5816 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
eacd73f7 5817
d3d00239
AD
5818 return cmd_type;
5819}
9a799d71 5820
729739b7
AD
5821static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
5822 u32 tx_flags, unsigned int paylen)
d3d00239 5823{
93f5b3c1 5824 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
9a799d71 5825
d3d00239
AD
5826 /* enable L4 checksum for TSO and TX checksum offload */
5827 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
5828 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
9a799d71 5829
93f5b3c1
AD
5830 /* enble IPv4 checksum for TSO */
5831 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
5832 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
9a799d71 5833
93f5b3c1
AD
5834 /* use index 1 context for TSO/FSO/FCOE */
5835#ifdef IXGBE_FCOE
5836 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
5837#else
5838 if (tx_flags & IXGBE_TX_FLAGS_TSO)
d3d00239 5839#endif
93f5b3c1
AD
5840 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
5841
7f9643fd
AD
5842 /*
5843 * Check Context must be set if Tx switch is enabled, which it
5844 * always is for case where virtual functions are running
5845 */
93f5b3c1
AD
5846#ifdef IXGBE_FCOE
5847 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
5848#else
7f9643fd 5849 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
93f5b3c1 5850#endif
7f9643fd
AD
5851 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
5852
729739b7 5853 tx_desc->read.olinfo_status = olinfo_status;
d3d00239 5854}
44df32c5 5855
d3d00239
AD
5856#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
5857 IXGBE_TXD_CMD_RS)
5858
5859static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
d3d00239 5860 struct ixgbe_tx_buffer *first,
d3d00239
AD
5861 const u8 hdr_len)
5862{
729739b7 5863 dma_addr_t dma;
fd0db0ed 5864 struct sk_buff *skb = first->skb;
729739b7 5865 struct ixgbe_tx_buffer *tx_buffer;
d3d00239 5866 union ixgbe_adv_tx_desc *tx_desc;
729739b7 5867 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
d3d00239
AD
5868 unsigned int data_len = skb->data_len;
5869 unsigned int size = skb_headlen(skb);
729739b7 5870 unsigned int paylen = skb->len - hdr_len;
244e27ad 5871 u32 tx_flags = first->tx_flags;
729739b7 5872 __le32 cmd_type;
d3d00239 5873 u16 i = tx_ring->next_to_use;
d3d00239 5874
729739b7
AD
5875 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5876
5877 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
5878 cmd_type = ixgbe_tx_cmd_type(tx_flags);
5879
d3d00239
AD
5880#ifdef IXGBE_FCOE
5881 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
729739b7 5882 if (data_len < sizeof(struct fcoe_crc_eof)) {
d3d00239
AD
5883 size -= sizeof(struct fcoe_crc_eof) - data_len;
5884 data_len = 0;
729739b7
AD
5885 } else {
5886 data_len -= sizeof(struct fcoe_crc_eof);
9a799d71
AK
5887 }
5888 }
44df32c5 5889
d3d00239 5890#endif
729739b7
AD
5891 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
5892 if (dma_mapping_error(tx_ring->dev, dma))
d3d00239 5893 goto dma_error;
8ad494b0 5894
729739b7
AD
5895 /* record length, and DMA address */
5896 dma_unmap_len_set(first, len, size);
5897 dma_unmap_addr_set(first, dma, dma);
9a799d71 5898
729739b7 5899 tx_desc->read.buffer_addr = cpu_to_le64(dma);
e5a43549 5900
d3d00239 5901 for (;;) {
729739b7 5902 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
d3d00239
AD
5903 tx_desc->read.cmd_type_len =
5904 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
e5a43549 5905
d3d00239 5906 i++;
729739b7 5907 tx_desc++;
d3d00239 5908 if (i == tx_ring->count) {
e4f74028 5909 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
d3d00239
AD
5910 i = 0;
5911 }
729739b7
AD
5912
5913 dma += IXGBE_MAX_DATA_PER_TXD;
5914 size -= IXGBE_MAX_DATA_PER_TXD;
5915
5916 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5917 tx_desc->read.olinfo_status = 0;
d3d00239 5918 }
e5a43549 5919
729739b7
AD
5920 if (likely(!data_len))
5921 break;
9a799d71 5922
f43f313e
BG
5923 if (unlikely(skb->no_fcs))
5924 cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS));
d3d00239 5925 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
9a799d71 5926
729739b7
AD
5927 i++;
5928 tx_desc++;
5929 if (i == tx_ring->count) {
5930 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5931 i = 0;
5932 }
9a799d71 5933
d3d00239 5934#ifdef IXGBE_FCOE
9e903e08 5935 size = min_t(unsigned int, data_len, skb_frag_size(frag));
d3d00239 5936#else
9e903e08 5937 size = skb_frag_size(frag);
d3d00239
AD
5938#endif
5939 data_len -= size;
9a799d71 5940
729739b7
AD
5941 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
5942 DMA_TO_DEVICE);
5943 if (dma_mapping_error(tx_ring->dev, dma))
d3d00239 5944 goto dma_error;
9a799d71 5945
729739b7
AD
5946 tx_buffer = &tx_ring->tx_buffer_info[i];
5947 dma_unmap_len_set(tx_buffer, len, size);
5948 dma_unmap_addr_set(tx_buffer, dma, dma);
9a799d71 5949
729739b7
AD
5950 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5951 tx_desc->read.olinfo_status = 0;
9a799d71 5952
729739b7
AD
5953 frag++;
5954 }
9a799d71 5955
729739b7
AD
5956 /* write last descriptor with RS and EOP bits */
5957 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
5958 tx_desc->read.cmd_type_len = cmd_type;
eacd73f7 5959
091a6246 5960 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
b2d96e0a 5961
d3d00239
AD
5962 /* set the timestamp */
5963 first->time_stamp = jiffies;
9a799d71
AK
5964
5965 /*
729739b7
AD
5966 * Force memory writes to complete before letting h/w know there
5967 * are new descriptors to fetch. (Only applicable for weak-ordered
5968 * memory model archs, such as IA-64).
5969 *
5970 * We also need this memory barrier to make certain all of the
5971 * status bits have been updated before next_to_watch is written.
9a799d71
AK
5972 */
5973 wmb();
5974
d3d00239
AD
5975 /* set next_to_watch value indicating a packet is present */
5976 first->next_to_watch = tx_desc;
5977
729739b7
AD
5978 i++;
5979 if (i == tx_ring->count)
5980 i = 0;
5981
5982 tx_ring->next_to_use = i;
5983
d3d00239 5984 /* notify HW of packet */
84ea2591 5985 writel(i, tx_ring->tail);
d3d00239
AD
5986
5987 return;
5988dma_error:
729739b7 5989 dev_err(tx_ring->dev, "TX DMA map failed\n");
d3d00239
AD
5990
5991 /* clear dma mappings for failed tx_buffer_info map */
5992 for (;;) {
729739b7
AD
5993 tx_buffer = &tx_ring->tx_buffer_info[i];
5994 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
5995 if (tx_buffer == first)
d3d00239
AD
5996 break;
5997 if (i == 0)
5998 i = tx_ring->count;
5999 i--;
6000 }
6001
d3d00239 6002 tx_ring->next_to_use = i;
9a799d71
AK
6003}
6004
fd0db0ed 6005static void ixgbe_atr(struct ixgbe_ring *ring,
244e27ad 6006 struct ixgbe_tx_buffer *first)
69830529
AD
6007{
6008 struct ixgbe_q_vector *q_vector = ring->q_vector;
6009 union ixgbe_atr_hash_dword input = { .dword = 0 };
6010 union ixgbe_atr_hash_dword common = { .dword = 0 };
6011 union {
6012 unsigned char *network;
6013 struct iphdr *ipv4;
6014 struct ipv6hdr *ipv6;
6015 } hdr;
ee9e0f0b 6016 struct tcphdr *th;
905e4a41 6017 __be16 vlan_id;
c4cf55e5 6018
69830529
AD
6019 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6020 if (!q_vector)
6021 return;
6022
6023 /* do nothing if sampling is disabled */
6024 if (!ring->atr_sample_rate)
d3ead241 6025 return;
c4cf55e5 6026
69830529 6027 ring->atr_count++;
c4cf55e5 6028
69830529 6029 /* snag network header to get L4 type and address */
fd0db0ed 6030 hdr.network = skb_network_header(first->skb);
69830529
AD
6031
6032 /* Currently only IPv4/IPv6 with TCP is supported */
244e27ad 6033 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
69830529 6034 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
244e27ad 6035 (first->protocol != __constant_htons(ETH_P_IP) ||
69830529
AD
6036 hdr.ipv4->protocol != IPPROTO_TCP))
6037 return;
ee9e0f0b 6038
fd0db0ed 6039 th = tcp_hdr(first->skb);
c4cf55e5 6040
66f32a8b
AD
6041 /* skip this packet since it is invalid or the socket is closing */
6042 if (!th || th->fin)
69830529
AD
6043 return;
6044
6045 /* sample on all syn packets or once every atr sample count */
6046 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6047 return;
6048
6049 /* reset sample count */
6050 ring->atr_count = 0;
6051
244e27ad 6052 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
69830529
AD
6053
6054 /*
6055 * src and dst are inverted, think how the receiver sees them
6056 *
6057 * The input is broken into two sections, a non-compressed section
6058 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6059 * is XORed together and stored in the compressed dword.
6060 */
6061 input.formatted.vlan_id = vlan_id;
6062
6063 /*
6064 * since src port and flex bytes occupy the same word XOR them together
6065 * and write the value to source port portion of compressed dword
6066 */
244e27ad 6067 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
69830529
AD
6068 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6069 else
244e27ad 6070 common.port.src ^= th->dest ^ first->protocol;
69830529
AD
6071 common.port.dst ^= th->source;
6072
244e27ad 6073 if (first->protocol == __constant_htons(ETH_P_IP)) {
69830529
AD
6074 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6075 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6076 } else {
6077 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6078 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6079 hdr.ipv6->saddr.s6_addr32[1] ^
6080 hdr.ipv6->saddr.s6_addr32[2] ^
6081 hdr.ipv6->saddr.s6_addr32[3] ^
6082 hdr.ipv6->daddr.s6_addr32[0] ^
6083 hdr.ipv6->daddr.s6_addr32[1] ^
6084 hdr.ipv6->daddr.s6_addr32[2] ^
6085 hdr.ipv6->daddr.s6_addr32[3];
6086 }
c4cf55e5
PWJ
6087
6088 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
69830529
AD
6089 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6090 input, common, ring->queue_index);
c4cf55e5
PWJ
6091}
6092
63544e9c 6093static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
e092be60 6094{
fc77dc3c 6095 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
e092be60
AV
6096 /* Herbert's original patch had:
6097 * smp_mb__after_netif_stop_queue();
6098 * but since that doesn't exist yet, just open code it. */
6099 smp_mb();
6100
6101 /* We need to check again in a case another CPU has just
6102 * made room available. */
7d4987de 6103 if (likely(ixgbe_desc_unused(tx_ring) < size))
e092be60
AV
6104 return -EBUSY;
6105
6106 /* A reprieve! - use start_queue because it doesn't call schedule */
fc77dc3c 6107 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
5b7da515 6108 ++tx_ring->tx_stats.restart_queue;
e092be60
AV
6109 return 0;
6110}
6111
82d4e46e 6112static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
e092be60 6113{
7d4987de 6114 if (likely(ixgbe_desc_unused(tx_ring) >= size))
e092be60 6115 return 0;
fc77dc3c 6116 return __ixgbe_maybe_stop_tx(tx_ring, size);
e092be60
AV
6117}
6118
09a3b1f8
SH
6119static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6120{
6121 struct ixgbe_adapter *adapter = netdev_priv(dev);
6440752c
AD
6122 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6123 smp_processor_id();
56075a98 6124#ifdef IXGBE_FCOE
6440752c 6125 __be16 protocol = vlan_get_protocol(skb);
5e09a105 6126
e5b64635
JF
6127 if (((protocol == htons(ETH_P_FCOE)) ||
6128 (protocol == htons(ETH_P_FIP))) &&
6129 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6130 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6131 txq += adapter->ring_feature[RING_F_FCOE].mask;
6132 return txq;
56075a98
JF
6133 }
6134#endif
6135
fdd3d631
KK
6136 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6137 while (unlikely(txq >= dev->real_num_tx_queues))
6138 txq -= dev->real_num_tx_queues;
5f715823 6139 return txq;
fdd3d631 6140 }
c4cf55e5 6141
09a3b1f8
SH
6142 return skb_tx_hash(dev, skb);
6143}
6144
fc77dc3c 6145netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
84418e3b
AD
6146 struct ixgbe_adapter *adapter,
6147 struct ixgbe_ring *tx_ring)
9a799d71 6148{
d3d00239 6149 struct ixgbe_tx_buffer *first;
5f715823 6150 int tso;
d3d00239 6151 u32 tx_flags = 0;
a535c30e
AD
6152#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6153 unsigned short f;
6154#endif
a535c30e 6155 u16 count = TXD_USE_COUNT(skb_headlen(skb));
66f32a8b 6156 __be16 protocol = skb->protocol;
63544e9c 6157 u8 hdr_len = 0;
5e09a105 6158
a535c30e
AD
6159 /*
6160 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
24ddd967 6161 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
a535c30e
AD
6162 * + 2 desc gap to keep tail from touching head,
6163 * + 1 desc for context descriptor,
6164 * otherwise try next time
6165 */
6166#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6167 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6168 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6169#else
6170 count += skb_shinfo(skb)->nr_frags;
6171#endif
6172 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6173 tx_ring->tx_stats.tx_busy++;
6174 return NETDEV_TX_BUSY;
6175 }
6176
fd0db0ed
AD
6177 /* record the location of the first descriptor for this packet */
6178 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6179 first->skb = skb;
091a6246
AD
6180 first->bytecount = skb->len;
6181 first->gso_segs = 1;
fd0db0ed 6182
66f32a8b 6183 /* if we have a HW VLAN tag being added default to the HW one */
eab6d18d 6184 if (vlan_tx_tag_present(skb)) {
66f32a8b
AD
6185 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6186 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6187 /* else if it is a SW VLAN check the next protocol and store the tag */
6188 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6189 struct vlan_hdr *vhdr, _vhdr;
6190 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6191 if (!vhdr)
6192 goto out_drop;
6193
6194 protocol = vhdr->h_vlan_encapsulated_proto;
9e0c5648
AD
6195 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6196 IXGBE_TX_FLAGS_VLAN_SHIFT;
66f32a8b
AD
6197 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
6198 }
6199
9e0c5648
AD
6200#ifdef CONFIG_PCI_IOV
6201 /*
6202 * Use the l2switch_enable flag - would be false if the DMA
6203 * Tx switch had been disabled.
6204 */
6205 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6206 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6207
6208#endif
32701dc2 6209 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
66f32a8b 6210 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
09dca476
AD
6211 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6212 (skb->priority != TC_PRIO_CONTROL))) {
66f32a8b 6213 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
32701dc2
JF
6214 tx_flags |= (skb->priority & 0x7) <<
6215 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
66f32a8b
AD
6216 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6217 struct vlan_ethhdr *vhdr;
6218 if (skb_header_cloned(skb) &&
6219 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6220 goto out_drop;
6221 vhdr = (struct vlan_ethhdr *)skb->data;
6222 vhdr->h_vlan_TCI = htons(tx_flags >>
6223 IXGBE_TX_FLAGS_VLAN_SHIFT);
6224 } else {
6225 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
2f90b865 6226 }
9a799d71 6227 }
eacd73f7 6228
244e27ad
AD
6229 /* record initial flags and protocol */
6230 first->tx_flags = tx_flags;
6231 first->protocol = protocol;
6232
eacd73f7 6233#ifdef IXGBE_FCOE
66f32a8b
AD
6234 /* setup tx offload for FCoE */
6235 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6236 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
244e27ad 6237 tso = ixgbe_fso(tx_ring, first, &hdr_len);
897ab156
AD
6238 if (tso < 0)
6239 goto out_drop;
9a799d71 6240
66f32a8b 6241 goto xmit_fcoe;
eacd73f7 6242 }
9a799d71 6243
66f32a8b 6244#endif /* IXGBE_FCOE */
244e27ad 6245 tso = ixgbe_tso(tx_ring, first, &hdr_len);
66f32a8b 6246 if (tso < 0)
897ab156 6247 goto out_drop;
244e27ad
AD
6248 else if (!tso)
6249 ixgbe_tx_csum(tx_ring, first);
66f32a8b
AD
6250
6251 /* add the ATR filter if ATR is on */
6252 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
244e27ad 6253 ixgbe_atr(tx_ring, first);
66f32a8b
AD
6254
6255#ifdef IXGBE_FCOE
6256xmit_fcoe:
6257#endif /* IXGBE_FCOE */
244e27ad 6258 ixgbe_tx_map(tx_ring, first, hdr_len);
d3d00239
AD
6259
6260 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
9a799d71
AK
6261
6262 return NETDEV_TX_OK;
897ab156
AD
6263
6264out_drop:
fd0db0ed
AD
6265 dev_kfree_skb_any(first->skb);
6266 first->skb = NULL;
6267
897ab156 6268 return NETDEV_TX_OK;
9a799d71
AK
6269}
6270
a50c29dd
AD
6271static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6272 struct net_device *netdev)
84418e3b
AD
6273{
6274 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6275 struct ixgbe_ring *tx_ring;
6276
a50c29dd
AD
6277 if (skb->len <= 0) {
6278 dev_kfree_skb_any(skb);
6279 return NETDEV_TX_OK;
6280 }
6281
6282 /*
6283 * The minimum packet size for olinfo paylen is 17 so pad the skb
6284 * in order to meet this minimum size requirement.
6285 */
6286 if (skb->len < 17) {
6287 if (skb_padto(skb, 17))
6288 return NETDEV_TX_OK;
6289 skb->len = 17;
6290 }
6291
84418e3b 6292 tx_ring = adapter->tx_ring[skb->queue_mapping];
fc77dc3c 6293 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
84418e3b
AD
6294}
6295
9a799d71
AK
6296/**
6297 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6298 * @netdev: network interface device structure
6299 * @p: pointer to an address structure
6300 *
6301 * Returns 0 on success, negative on failure
6302 **/
6303static int ixgbe_set_mac(struct net_device *netdev, void *p)
6304{
6305 struct ixgbe_adapter *adapter = netdev_priv(netdev);
b4617240 6306 struct ixgbe_hw *hw = &adapter->hw;
9a799d71
AK
6307 struct sockaddr *addr = p;
6308
6309 if (!is_valid_ether_addr(addr->sa_data))
6310 return -EADDRNOTAVAIL;
6311
6312 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
b4617240 6313 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
9a799d71 6314
1cdd1ec8
GR
6315 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6316 IXGBE_RAH_AV);
9a799d71
AK
6317
6318 return 0;
6319}
6320
6b73e10d
BH
6321static int
6322ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6323{
6324 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6325 struct ixgbe_hw *hw = &adapter->hw;
6326 u16 value;
6327 int rc;
6328
6329 if (prtad != hw->phy.mdio.prtad)
6330 return -EINVAL;
6331 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6332 if (!rc)
6333 rc = value;
6334 return rc;
6335}
6336
6337static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6338 u16 addr, u16 value)
6339{
6340 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6341 struct ixgbe_hw *hw = &adapter->hw;
6342
6343 if (prtad != hw->phy.mdio.prtad)
6344 return -EINVAL;
6345 return hw->phy.ops.write_reg(hw, addr, devad, value);
6346}
6347
6348static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6349{
6350 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6351
6352 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6353}
6354
0365e6e4
PW
6355/**
6356 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
31278e71 6357 * netdev->dev_addrs
0365e6e4
PW
6358 * @netdev: network interface device structure
6359 *
6360 * Returns non-zero on failure
6361 **/
6362static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6363{
6364 int err = 0;
6365 struct ixgbe_adapter *adapter = netdev_priv(dev);
6366 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6367
6368 if (is_valid_ether_addr(mac->san_addr)) {
6369 rtnl_lock();
6370 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6371 rtnl_unlock();
6372 }
6373 return err;
6374}
6375
6376/**
6377 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
31278e71 6378 * netdev->dev_addrs
0365e6e4
PW
6379 * @netdev: network interface device structure
6380 *
6381 * Returns non-zero on failure
6382 **/
6383static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6384{
6385 int err = 0;
6386 struct ixgbe_adapter *adapter = netdev_priv(dev);
6387 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6388
6389 if (is_valid_ether_addr(mac->san_addr)) {
6390 rtnl_lock();
6391 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6392 rtnl_unlock();
6393 }
6394 return err;
6395}
6396
9a799d71
AK
6397#ifdef CONFIG_NET_POLL_CONTROLLER
6398/*
6399 * Polling 'interrupt' - used by things like netconsole to send skbs
6400 * without having to re-enable interrupts. It's not called while
6401 * the interrupt routine is executing.
6402 */
6403static void ixgbe_netpoll(struct net_device *netdev)
6404{
6405 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8f9a7167 6406 int i;
9a799d71 6407
1a647bd2
AD
6408 /* if interface is down do nothing */
6409 if (test_bit(__IXGBE_DOWN, &adapter->state))
6410 return;
6411
9a799d71 6412 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
8f9a7167
PWJ
6413 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
6414 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
6415 for (i = 0; i < num_q_vectors; i++) {
6416 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4ff7fb12 6417 ixgbe_msix_clean_rings(0, q_vector);
8f9a7167
PWJ
6418 }
6419 } else {
6420 ixgbe_intr(adapter->pdev->irq, netdev);
6421 }
9a799d71 6422 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
9a799d71 6423}
9a799d71 6424
581330ba 6425#endif
de1036b1
ED
6426static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6427 struct rtnl_link_stats64 *stats)
6428{
6429 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6430 int i;
6431
1a51502b 6432 rcu_read_lock();
de1036b1 6433 for (i = 0; i < adapter->num_rx_queues; i++) {
1a51502b 6434 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
de1036b1
ED
6435 u64 bytes, packets;
6436 unsigned int start;
6437
1a51502b
ED
6438 if (ring) {
6439 do {
6440 start = u64_stats_fetch_begin_bh(&ring->syncp);
6441 packets = ring->stats.packets;
6442 bytes = ring->stats.bytes;
6443 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6444 stats->rx_packets += packets;
6445 stats->rx_bytes += bytes;
6446 }
de1036b1 6447 }
1ac9ad13
ED
6448
6449 for (i = 0; i < adapter->num_tx_queues; i++) {
6450 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6451 u64 bytes, packets;
6452 unsigned int start;
6453
6454 if (ring) {
6455 do {
6456 start = u64_stats_fetch_begin_bh(&ring->syncp);
6457 packets = ring->stats.packets;
6458 bytes = ring->stats.bytes;
6459 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6460 stats->tx_packets += packets;
6461 stats->tx_bytes += bytes;
6462 }
6463 }
1a51502b 6464 rcu_read_unlock();
de1036b1
ED
6465 /* following stats updated by ixgbe_watchdog_task() */
6466 stats->multicast = netdev->stats.multicast;
6467 stats->rx_errors = netdev->stats.rx_errors;
6468 stats->rx_length_errors = netdev->stats.rx_length_errors;
6469 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6470 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6471 return stats;
6472}
6473
8af3c33f 6474#ifdef CONFIG_IXGBE_DCB
8b1c0b24
JF
6475/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6476 * #adapter: pointer to ixgbe_adapter
6477 * @tc: number of traffic classes currently enabled
6478 *
6479 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6480 * 802.1Q priority maps to a packet buffer that exists.
6481 */
6482static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6483{
6484 struct ixgbe_hw *hw = &adapter->hw;
6485 u32 reg, rsave;
6486 int i;
6487
6488 /* 82598 have a static priority to TC mapping that can not
6489 * be changed so no validation is needed.
6490 */
6491 if (hw->mac.type == ixgbe_mac_82598EB)
6492 return;
6493
6494 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6495 rsave = reg;
6496
6497 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6498 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6499
6500 /* If up2tc is out of bounds default to zero */
6501 if (up2tc > tc)
6502 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6503 }
6504
6505 if (reg != rsave)
6506 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6507
6508 return;
6509}
6510
8b1c0b24
JF
6511/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
6512 * classes.
6513 *
6514 * @netdev: net device to configure
6515 * @tc: number of traffic classes to enable
6516 */
6517int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6518{
8b1c0b24
JF
6519 struct ixgbe_adapter *adapter = netdev_priv(dev);
6520 struct ixgbe_hw *hw = &adapter->hw;
8b1c0b24 6521
e7589eab
JF
6522 /* Multiple traffic classes requires multiple queues */
6523 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6524 e_err(drv, "Enable failed, needs MSI-X\n");
6525 return -EINVAL;
6526 }
8b1c0b24
JF
6527
6528 /* Hardware supports up to 8 traffic classes */
4de2a022 6529 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
581330ba
AD
6530 (hw->mac.type == ixgbe_mac_82598EB &&
6531 tc < MAX_TRAFFIC_CLASS))
8b1c0b24
JF
6532 return -EINVAL;
6533
6534 /* Hardware has to reinitialize queues and interrupts to
52f33af8 6535 * match packet buffer alignment. Unfortunately, the
8b1c0b24
JF
6536 * hardware is not flexible enough to do this dynamically.
6537 */
6538 if (netif_running(dev))
6539 ixgbe_close(dev);
6540 ixgbe_clear_interrupt_scheme(adapter);
6541
e7589eab 6542 if (tc) {
8b1c0b24 6543 netdev_set_num_tc(dev, tc);
e7589eab 6544 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
e7589eab
JF
6545 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
6546 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6547
6548 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6549 adapter->hw.fc.requested_mode = ixgbe_fc_none;
6550 } else {
8b1c0b24 6551 netdev_reset_tc(dev);
e7589eab
JF
6552 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
6553
6554 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6555 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6556
6557 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6558 adapter->dcb_cfg.pfc_mode_enable = false;
6559 }
6560
8b1c0b24
JF
6561 ixgbe_init_interrupt_scheme(adapter);
6562 ixgbe_validate_rtr(adapter, tc);
6563 if (netif_running(dev))
6564 ixgbe_open(dev);
6565
6566 return 0;
6567}
de1036b1 6568
8af3c33f 6569#endif /* CONFIG_IXGBE_DCB */
082757af
DS
6570void ixgbe_do_reset(struct net_device *netdev)
6571{
6572 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6573
6574 if (netif_running(netdev))
6575 ixgbe_reinit_locked(adapter);
6576 else
6577 ixgbe_reset(adapter);
6578}
6579
c8f44aff 6580static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
567d2de2 6581 netdev_features_t features)
082757af
DS
6582{
6583 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6584
6585#ifdef CONFIG_DCB
6586 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
567d2de2 6587 features &= ~NETIF_F_HW_VLAN_RX;
082757af
DS
6588#endif
6589
6590 /* return error if RXHASH is being enabled when RSS is not supported */
6591 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
567d2de2 6592 features &= ~NETIF_F_RXHASH;
082757af
DS
6593
6594 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
567d2de2
AD
6595 if (!(features & NETIF_F_RXCSUM))
6596 features &= ~NETIF_F_LRO;
082757af 6597
567d2de2
AD
6598 /* Turn off LRO if not RSC capable */
6599 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6600 features &= ~NETIF_F_LRO;
8e2813f5 6601
082757af 6602
567d2de2 6603 return features;
082757af
DS
6604}
6605
c8f44aff 6606static int ixgbe_set_features(struct net_device *netdev,
567d2de2 6607 netdev_features_t features)
082757af
DS
6608{
6609 struct ixgbe_adapter *adapter = netdev_priv(netdev);
567d2de2 6610 netdev_features_t changed = netdev->features ^ features;
082757af
DS
6611 bool need_reset = false;
6612
082757af 6613 /* Make sure RSC matches LRO, reset if change */
567d2de2
AD
6614 if (!(features & NETIF_F_LRO)) {
6615 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
082757af 6616 need_reset = true;
567d2de2
AD
6617 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6618 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6619 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6620 if (adapter->rx_itr_setting == 1 ||
6621 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6622 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6623 need_reset = true;
6624 } else if ((changed ^ features) & NETIF_F_LRO) {
6625 e_info(probe, "rx-usecs set too low, "
6626 "disabling RSC\n");
082757af
DS
6627 }
6628 }
6629
6630 /*
6631 * Check if Flow Director n-tuple support was enabled or disabled. If
6632 * the state changed, we need to reset.
6633 */
567d2de2
AD
6634 if (!(features & NETIF_F_NTUPLE)) {
6635 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
6636 /* turn off Flow Director, set ATR and reset */
6637 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
6638 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
6639 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
082757af
DS
6640 need_reset = true;
6641 }
082757af 6642 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
567d2de2
AD
6643 } else if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
6644 /* turn off ATR, enable perfect filters and reset */
6645 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6646 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
082757af
DS
6647 need_reset = true;
6648 }
6649
3f2d1c0f
BG
6650 if (changed & NETIF_F_RXALL)
6651 need_reset = true;
6652
567d2de2 6653 netdev->features = features;
082757af
DS
6654 if (need_reset)
6655 ixgbe_do_reset(netdev);
6656
6657 return 0;
082757af
DS
6658}
6659
0f4b0add
JF
6660static int ixgbe_ndo_fdb_add(struct ndmsg *ndm,
6661 struct net_device *dev,
6662 unsigned char *addr,
6663 u16 flags)
6664{
6665 struct ixgbe_adapter *adapter = netdev_priv(dev);
6666 int err = -EOPNOTSUPP;
6667
6668 if (ndm->ndm_state & NUD_PERMANENT) {
6669 pr_info("%s: FDB only supports static addresses\n",
6670 ixgbe_driver_name);
6671 return -EINVAL;
6672 }
6673
6674 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6675 if (is_unicast_ether_addr(addr))
6676 err = dev_uc_add_excl(dev, addr);
6677 else if (is_multicast_ether_addr(addr))
6678 err = dev_mc_add_excl(dev, addr);
6679 else
6680 err = -EINVAL;
6681 }
6682
6683 /* Only return duplicate errors if NLM_F_EXCL is set */
6684 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6685 err = 0;
6686
6687 return err;
6688}
6689
6690static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6691 struct net_device *dev,
6692 unsigned char *addr)
6693{
6694 struct ixgbe_adapter *adapter = netdev_priv(dev);
6695 int err = -EOPNOTSUPP;
6696
6697 if (ndm->ndm_state & NUD_PERMANENT) {
6698 pr_info("%s: FDB only supports static addresses\n",
6699 ixgbe_driver_name);
6700 return -EINVAL;
6701 }
6702
6703 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6704 if (is_unicast_ether_addr(addr))
6705 err = dev_uc_del(dev, addr);
6706 else if (is_multicast_ether_addr(addr))
6707 err = dev_mc_del(dev, addr);
6708 else
6709 err = -EINVAL;
6710 }
6711
6712 return err;
6713}
6714
6715static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
6716 struct netlink_callback *cb,
6717 struct net_device *dev,
6718 int idx)
6719{
6720 struct ixgbe_adapter *adapter = netdev_priv(dev);
6721
6722 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6723 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
6724
6725 return idx;
6726}
6727
0edc3527 6728static const struct net_device_ops ixgbe_netdev_ops = {
e8e9f696 6729 .ndo_open = ixgbe_open,
0edc3527 6730 .ndo_stop = ixgbe_close,
00829823 6731 .ndo_start_xmit = ixgbe_xmit_frame,
09a3b1f8 6732 .ndo_select_queue = ixgbe_select_queue,
581330ba 6733 .ndo_set_rx_mode = ixgbe_set_rx_mode,
0edc3527
SH
6734 .ndo_validate_addr = eth_validate_addr,
6735 .ndo_set_mac_address = ixgbe_set_mac,
6736 .ndo_change_mtu = ixgbe_change_mtu,
6737 .ndo_tx_timeout = ixgbe_tx_timeout,
0edc3527
SH
6738 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
6739 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
6b73e10d 6740 .ndo_do_ioctl = ixgbe_ioctl,
7f01648a
GR
6741 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
6742 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
6743 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
581330ba 6744 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
7f01648a 6745 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
de1036b1 6746 .ndo_get_stats64 = ixgbe_get_stats64,
8af3c33f 6747#ifdef CONFIG_IXGBE_DCB
24095aa3 6748 .ndo_setup_tc = ixgbe_setup_tc,
8af3c33f 6749#endif
0edc3527
SH
6750#ifdef CONFIG_NET_POLL_CONTROLLER
6751 .ndo_poll_controller = ixgbe_netpoll,
6752#endif
332d4a7d
YZ
6753#ifdef IXGBE_FCOE
6754 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
68a683cf 6755 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
332d4a7d 6756 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
8450ff8c
YZ
6757 .ndo_fcoe_enable = ixgbe_fcoe_enable,
6758 .ndo_fcoe_disable = ixgbe_fcoe_disable,
61a1fa10 6759 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
ea81875a 6760 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
332d4a7d 6761#endif /* IXGBE_FCOE */
082757af
DS
6762 .ndo_set_features = ixgbe_set_features,
6763 .ndo_fix_features = ixgbe_fix_features,
0f4b0add
JF
6764 .ndo_fdb_add = ixgbe_ndo_fdb_add,
6765 .ndo_fdb_del = ixgbe_ndo_fdb_del,
6766 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
0edc3527
SH
6767};
6768
1cdd1ec8 6769static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
567d2de2 6770 const struct ixgbe_info *ii)
1cdd1ec8
GR
6771{
6772#ifdef CONFIG_PCI_IOV
6773 struct ixgbe_hw *hw = &adapter->hw;
1cdd1ec8 6774
c6bda30a 6775 if (hw->mac.type == ixgbe_mac_82598EB)
1cdd1ec8
GR
6776 return;
6777
6778 /* The 82599 supports up to 64 VFs per physical function
6779 * but this implementation limits allocation to 63 so that
6780 * basic networking resources are still available to the
6b42a9c5
GR
6781 * physical function. If the user requests greater thn
6782 * 63 VFs then it is an error - reset to default of zero.
1cdd1ec8 6783 */
6b42a9c5 6784 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
c6bda30a 6785 ixgbe_enable_sriov(adapter, ii);
1cdd1ec8
GR
6786#endif /* CONFIG_PCI_IOV */
6787}
6788
8e2813f5
JK
6789/**
6790 * ixgbe_wol_supported - Check whether device supports WoL
6791 * @hw: hw specific details
6792 * @device_id: the device ID
6793 * @subdev_id: the subsystem device ID
6794 *
6795 * This function is used by probe and ethtool to determine
6796 * which devices have WoL support
6797 *
6798 **/
6799int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
6800 u16 subdevice_id)
6801{
6802 struct ixgbe_hw *hw = &adapter->hw;
6803 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
6804 int is_wol_supported = 0;
6805
6806 switch (device_id) {
6807 case IXGBE_DEV_ID_82599_SFP:
6808 /* Only these subdevices could supports WOL */
6809 switch (subdevice_id) {
6810 case IXGBE_SUBDEV_ID_82599_560FLR:
6811 /* only support first port */
6812 if (hw->bus.func != 0)
6813 break;
6814 case IXGBE_SUBDEV_ID_82599_SFP:
6815 is_wol_supported = 1;
6816 break;
6817 }
6818 break;
6819 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
6820 /* All except this subdevice support WOL */
6821 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
6822 is_wol_supported = 1;
6823 break;
6824 case IXGBE_DEV_ID_82599_KX4:
6825 is_wol_supported = 1;
6826 break;
6827 case IXGBE_DEV_ID_X540T:
6828 /* check eeprom to see if enabled wol */
6829 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
6830 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
6831 (hw->bus.func == 0))) {
6832 is_wol_supported = 1;
6833 }
6834 break;
6835 }
6836
6837 return is_wol_supported;
6838}
6839
9a799d71
AK
6840/**
6841 * ixgbe_probe - Device Initialization Routine
6842 * @pdev: PCI device information struct
6843 * @ent: entry in ixgbe_pci_tbl
6844 *
6845 * Returns 0 on success, negative on failure
6846 *
6847 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
6848 * The OS initialization, configuring of the adapter private structure,
6849 * and a hardware reset occur.
6850 **/
6851static int __devinit ixgbe_probe(struct pci_dev *pdev,
e8e9f696 6852 const struct pci_device_id *ent)
9a799d71
AK
6853{
6854 struct net_device *netdev;
6855 struct ixgbe_adapter *adapter = NULL;
6856 struct ixgbe_hw *hw;
6857 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
9a799d71
AK
6858 static int cards_found;
6859 int i, err, pci_using_dac;
289700db 6860 u8 part_str[IXGBE_PBANUM_LENGTH];
c85a2618 6861 unsigned int indices = num_possible_cpus();
eacd73f7
YZ
6862#ifdef IXGBE_FCOE
6863 u16 device_caps;
6864#endif
289700db 6865 u32 eec;
9a799d71 6866
bded64a7
AG
6867 /* Catch broken hardware that put the wrong VF device ID in
6868 * the PCIe SR-IOV capability.
6869 */
6870 if (pdev->is_virtfn) {
6871 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
6872 pci_name(pdev), pdev->vendor, pdev->device);
6873 return -EINVAL;
6874 }
6875
9ce77666 6876 err = pci_enable_device_mem(pdev);
9a799d71
AK
6877 if (err)
6878 return err;
6879
1b507730
NN
6880 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
6881 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
9a799d71
AK
6882 pci_using_dac = 1;
6883 } else {
1b507730 6884 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
9a799d71 6885 if (err) {
1b507730
NN
6886 err = dma_set_coherent_mask(&pdev->dev,
6887 DMA_BIT_MASK(32));
9a799d71 6888 if (err) {
b8bc0421
DC
6889 dev_err(&pdev->dev,
6890 "No usable DMA configuration, aborting\n");
9a799d71
AK
6891 goto err_dma;
6892 }
6893 }
6894 pci_using_dac = 0;
6895 }
6896
9ce77666 6897 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
e8e9f696 6898 IORESOURCE_MEM), ixgbe_driver_name);
9a799d71 6899 if (err) {
b8bc0421
DC
6900 dev_err(&pdev->dev,
6901 "pci_request_selected_regions failed 0x%x\n", err);
9a799d71
AK
6902 goto err_pci_reg;
6903 }
6904
19d5afd4 6905 pci_enable_pcie_error_reporting(pdev);
6fabd715 6906
9a799d71 6907 pci_set_master(pdev);
fb3b27bc 6908 pci_save_state(pdev);
9a799d71 6909
e901acd6
JF
6910#ifdef CONFIG_IXGBE_DCB
6911 indices *= MAX_TRAFFIC_CLASS;
6912#endif
6913
c85a2618
JF
6914 if (ii->mac == ixgbe_mac_82598EB)
6915 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
6916 else
6917 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
6918
e901acd6 6919#ifdef IXGBE_FCOE
c85a2618
JF
6920 indices += min_t(unsigned int, num_possible_cpus(),
6921 IXGBE_MAX_FCOE_INDICES);
6922#endif
c85a2618 6923 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
9a799d71
AK
6924 if (!netdev) {
6925 err = -ENOMEM;
6926 goto err_alloc_etherdev;
6927 }
6928
9a799d71
AK
6929 SET_NETDEV_DEV(netdev, &pdev->dev);
6930
9a799d71 6931 adapter = netdev_priv(netdev);
c60fbb00 6932 pci_set_drvdata(pdev, adapter);
9a799d71
AK
6933
6934 adapter->netdev = netdev;
6935 adapter->pdev = pdev;
6936 hw = &adapter->hw;
6937 hw->back = adapter;
b3f4d599 6938 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
9a799d71 6939
05857980 6940 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
e8e9f696 6941 pci_resource_len(pdev, 0));
9a799d71
AK
6942 if (!hw->hw_addr) {
6943 err = -EIO;
6944 goto err_ioremap;
6945 }
6946
6947 for (i = 1; i <= 5; i++) {
6948 if (pci_resource_len(pdev, i) == 0)
6949 continue;
6950 }
6951
0edc3527 6952 netdev->netdev_ops = &ixgbe_netdev_ops;
9a799d71 6953 ixgbe_set_ethtool_ops(netdev);
9a799d71 6954 netdev->watchdog_timeo = 5 * HZ;
9fe93afd 6955 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
9a799d71 6956
9a799d71
AK
6957 adapter->bd_number = cards_found;
6958
9a799d71
AK
6959 /* Setup hw api */
6960 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
021230d4 6961 hw->mac.type = ii->mac;
9a799d71 6962
c44ade9e
JB
6963 /* EEPROM */
6964 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
6965 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
6966 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
6967 if (!(eec & (1 << 8)))
6968 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
6969
6970 /* PHY */
6971 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
c4900be0 6972 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
6b73e10d
BH
6973 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
6974 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
6975 hw->phy.mdio.mmds = 0;
6976 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
6977 hw->phy.mdio.dev = netdev;
6978 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
6979 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
c4900be0 6980
8ca783ab 6981 ii->get_invariants(hw);
9a799d71
AK
6982
6983 /* setup the private structure */
6984 err = ixgbe_sw_init(adapter);
6985 if (err)
6986 goto err_sw_init;
6987
e86bff0e 6988 /* Make it possible the adapter to be woken up via WOL */
b93a2226
DS
6989 switch (adapter->hw.mac.type) {
6990 case ixgbe_mac_82599EB:
6991 case ixgbe_mac_X540:
e86bff0e 6992 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
b93a2226
DS
6993 break;
6994 default:
6995 break;
6996 }
e86bff0e 6997
bf069c97
DS
6998 /*
6999 * If there is a fan on this device and it has failed log the
7000 * failure.
7001 */
7002 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7003 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7004 if (esdp & IXGBE_ESDP_SDP1)
396e799c 7005 e_crit(probe, "Fan has stopped, replace the adapter\n");
bf069c97
DS
7006 }
7007
8ef78adc
PWJ
7008 if (allow_unsupported_sfp)
7009 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7010
c44ade9e 7011 /* reset_hw fills in the perm_addr as well */
119fc60a 7012 hw->phy.reset_if_overtemp = true;
c44ade9e 7013 err = hw->mac.ops.reset_hw(hw);
119fc60a 7014 hw->phy.reset_if_overtemp = false;
8ca783ab
DS
7015 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7016 hw->mac.type == ixgbe_mac_82598EB) {
8ca783ab
DS
7017 err = 0;
7018 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
7086400d 7019 e_dev_err("failed to load because an unsupported SFP+ "
849c4542
ET
7020 "module type was detected.\n");
7021 e_dev_err("Reload the driver after installing a supported "
7022 "module.\n");
04f165ef
PW
7023 goto err_sw_init;
7024 } else if (err) {
849c4542 7025 e_dev_err("HW Init failed: %d\n", err);
c44ade9e
JB
7026 goto err_sw_init;
7027 }
7028
1cdd1ec8
GR
7029 ixgbe_probe_vf(adapter, ii);
7030
396e799c 7031 netdev->features = NETIF_F_SG |
e8e9f696 7032 NETIF_F_IP_CSUM |
082757af 7033 NETIF_F_IPV6_CSUM |
e8e9f696
JP
7034 NETIF_F_HW_VLAN_TX |
7035 NETIF_F_HW_VLAN_RX |
082757af
DS
7036 NETIF_F_HW_VLAN_FILTER |
7037 NETIF_F_TSO |
7038 NETIF_F_TSO6 |
082757af
DS
7039 NETIF_F_RXHASH |
7040 NETIF_F_RXCSUM;
9a799d71 7041
082757af 7042 netdev->hw_features = netdev->features;
ad31c402 7043
58be7666
DS
7044 switch (adapter->hw.mac.type) {
7045 case ixgbe_mac_82599EB:
7046 case ixgbe_mac_X540:
45a5ead0 7047 netdev->features |= NETIF_F_SCTP_CSUM;
082757af
DS
7048 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7049 NETIF_F_NTUPLE;
58be7666
DS
7050 break;
7051 default:
7052 break;
7053 }
45a5ead0 7054
3f2d1c0f
BG
7055 netdev->hw_features |= NETIF_F_RXALL;
7056
ad31c402
JK
7057 netdev->vlan_features |= NETIF_F_TSO;
7058 netdev->vlan_features |= NETIF_F_TSO6;
22f32b7a 7059 netdev->vlan_features |= NETIF_F_IP_CSUM;
cd1da503 7060 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
ad31c402
JK
7061 netdev->vlan_features |= NETIF_F_SG;
7062
01789349 7063 netdev->priv_flags |= IFF_UNICAST_FLT;
f43f313e 7064 netdev->priv_flags |= IFF_SUPP_NOFCS;
01789349 7065
1cdd1ec8
GR
7066 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7067 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7068 IXGBE_FLAG_DCB_ENABLED);
2f90b865 7069
7a6b6f51 7070#ifdef CONFIG_IXGBE_DCB
2f90b865
AD
7071 netdev->dcbnl_ops = &dcbnl_ops;
7072#endif
7073
eacd73f7 7074#ifdef IXGBE_FCOE
0d551589 7075 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
eacd73f7
YZ
7076 if (hw->mac.ops.get_device_caps) {
7077 hw->mac.ops.get_device_caps(hw, &device_caps);
0d551589
YZ
7078 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7079 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
eacd73f7
YZ
7080 }
7081 }
5e09d7f6
YZ
7082 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7083 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7084 netdev->vlan_features |= NETIF_F_FSO;
7085 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7086 }
eacd73f7 7087#endif /* IXGBE_FCOE */
7b872a55 7088 if (pci_using_dac) {
9a799d71 7089 netdev->features |= NETIF_F_HIGHDMA;
7b872a55
YZ
7090 netdev->vlan_features |= NETIF_F_HIGHDMA;
7091 }
9a799d71 7092
082757af
DS
7093 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7094 netdev->hw_features |= NETIF_F_LRO;
0c19d6af 7095 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
f8212f97
AD
7096 netdev->features |= NETIF_F_LRO;
7097
9a799d71 7098 /* make sure the EEPROM is good */
c44ade9e 7099 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
849c4542 7100 e_dev_err("The EEPROM Checksum Is Not Valid\n");
9a799d71 7101 err = -EIO;
35937c05 7102 goto err_sw_init;
9a799d71
AK
7103 }
7104
7105 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7106 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7107
c44ade9e 7108 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
849c4542 7109 e_dev_err("invalid MAC address\n");
9a799d71 7110 err = -EIO;
35937c05 7111 goto err_sw_init;
9a799d71
AK
7112 }
7113
7086400d 7114 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
581330ba 7115 (unsigned long) adapter);
9a799d71 7116
7086400d
AD
7117 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7118 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
9a799d71 7119
021230d4
AV
7120 err = ixgbe_init_interrupt_scheme(adapter);
7121 if (err)
7122 goto err_sw_init;
9a799d71 7123
082757af
DS
7124 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7125 netdev->hw_features &= ~NETIF_F_RXHASH;
67a74ee2 7126 netdev->features &= ~NETIF_F_RXHASH;
082757af 7127 }
67a74ee2 7128
8e2813f5 7129 /* WOL not supported for all devices */
c23f5b6b 7130 adapter->wol = 0;
8e2813f5
JK
7131 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7132 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
9417c464 7133 adapter->wol = IXGBE_WUFC_MAG;
c23f5b6b 7134
e8e26350
PW
7135 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7136
15e5209f
ET
7137 /* save off EEPROM version number */
7138 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7139 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7140
04f165ef
PW
7141 /* pick up the PCI bus settings for reporting later */
7142 hw->mac.ops.get_bus_info(hw);
7143
9a799d71 7144 /* print bus type/speed/width info */
849c4542 7145 e_dev_info("(PCI Express:%s:%s) %pM\n",
6716344c
DS
7146 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7147 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
e8e9f696
JP
7148 "Unknown"),
7149 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7150 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7151 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7152 "Unknown"),
7153 netdev->dev_addr);
289700db
DS
7154
7155 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7156 if (err)
9fe93afd 7157 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
e8e26350 7158 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
289700db 7159 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
849c4542 7160 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
289700db 7161 part_str);
e8e26350 7162 else
289700db
DS
7163 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7164 hw->mac.type, hw->phy.type, part_str);
9a799d71 7165
e8e26350 7166 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
849c4542
ET
7167 e_dev_warn("PCI-Express bandwidth available for this card is "
7168 "not sufficient for optimal performance.\n");
7169 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7170 "is required.\n");
0c254d86
AK
7171 }
7172
9a799d71 7173 /* reset the hardware with the new settings */
794caeb2 7174 err = hw->mac.ops.start_hw(hw);
794caeb2
PWJ
7175 if (err == IXGBE_ERR_EEPROM_VERSION) {
7176 /* We are running on a pre-production device, log a warning */
849c4542
ET
7177 e_dev_warn("This device is a pre-production adapter/LOM. "
7178 "Please be aware there may be issues associated "
7179 "with your hardware. If you are experiencing "
7180 "problems please contact your Intel or hardware "
7181 "representative who provided you with this "
7182 "hardware.\n");
794caeb2 7183 }
9a799d71
AK
7184 strcpy(netdev->name, "eth%d");
7185 err = register_netdev(netdev);
7186 if (err)
7187 goto err_register;
7188
93d3ce8f
ET
7189 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7190 if (hw->mac.ops.disable_tx_laser &&
7191 ((hw->phy.multispeed_fiber) ||
7192 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7193 (hw->mac.type == ixgbe_mac_82599EB))))
7194 hw->mac.ops.disable_tx_laser(hw);
7195
54386467
JB
7196 /* carrier off reporting is important to ethtool even BEFORE open */
7197 netif_carrier_off(netdev);
7198
5dd2d332 7199#ifdef CONFIG_IXGBE_DCA
652f093f 7200 if (dca_add_requester(&pdev->dev) == 0) {
bd0362dd 7201 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
bd0362dd
JC
7202 ixgbe_setup_dca(adapter);
7203 }
7204#endif
1cdd1ec8 7205 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
396e799c 7206 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
1cdd1ec8
GR
7207 for (i = 0; i < adapter->num_vfs; i++)
7208 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7209 }
7210
2466dd9c
JK
7211 /* firmware requires driver version to be 0xFFFFFFFF
7212 * since os does not support feature
7213 */
9612de92 7214 if (hw->mac.ops.set_fw_drv_ver)
2466dd9c
JK
7215 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7216 0xFF);
9612de92 7217
0365e6e4
PW
7218 /* add san mac addr to netdev */
7219 ixgbe_add_sanmac_netdev(netdev);
9a799d71 7220
ea81875a 7221 e_dev_info("%s\n", ixgbe_default_device_descr);
9a799d71 7222 cards_found++;
3ca8bc6d
DS
7223
7224 if (ixgbe_sysfs_init(adapter))
7225 e_err(probe, "failed to allocate sysfs resources\n");
7226
9a799d71
AK
7227 return 0;
7228
7229err_register:
5eba3699 7230 ixgbe_release_hw_control(adapter);
7a921c93 7231 ixgbe_clear_interrupt_scheme(adapter);
9a799d71 7232err_sw_init:
1cdd1ec8
GR
7233 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7234 ixgbe_disable_sriov(adapter);
7086400d 7235 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
9a799d71
AK
7236 iounmap(hw->hw_addr);
7237err_ioremap:
7238 free_netdev(netdev);
7239err_alloc_etherdev:
e8e9f696
JP
7240 pci_release_selected_regions(pdev,
7241 pci_select_bars(pdev, IORESOURCE_MEM));
9a799d71
AK
7242err_pci_reg:
7243err_dma:
7244 pci_disable_device(pdev);
7245 return err;
7246}
7247
7248/**
7249 * ixgbe_remove - Device Removal Routine
7250 * @pdev: PCI device information struct
7251 *
7252 * ixgbe_remove is called by the PCI subsystem to alert the driver
7253 * that it should release a PCI device. The could be caused by a
7254 * Hot-Plug event, or because the driver is going to be removed from
7255 * memory.
7256 **/
7257static void __devexit ixgbe_remove(struct pci_dev *pdev)
7258{
c60fbb00
AD
7259 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7260 struct net_device *netdev = adapter->netdev;
9a799d71
AK
7261
7262 set_bit(__IXGBE_DOWN, &adapter->state);
7086400d 7263 cancel_work_sync(&adapter->service_task);
9a799d71 7264
5dd2d332 7265#ifdef CONFIG_IXGBE_DCA
bd0362dd
JC
7266 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7267 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7268 dca_remove_requester(&pdev->dev);
7269 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7270 }
7271
7272#endif
3ca8bc6d
DS
7273 ixgbe_sysfs_exit(adapter);
7274
332d4a7d
YZ
7275#ifdef IXGBE_FCOE
7276 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7277 ixgbe_cleanup_fcoe(adapter);
7278
7279#endif /* IXGBE_FCOE */
0365e6e4
PW
7280
7281 /* remove the added san mac */
7282 ixgbe_del_sanmac_netdev(netdev);
7283
c4900be0
DS
7284 if (netdev->reg_state == NETREG_REGISTERED)
7285 unregister_netdev(netdev);
9a799d71 7286
c6bda30a
GR
7287 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7288 if (!(ixgbe_check_vf_assignment(adapter)))
7289 ixgbe_disable_sriov(adapter);
7290 else
7291 e_dev_warn("Unloading driver while VFs are assigned "
7292 "- VFs will not be deallocated\n");
7293 }
1cdd1ec8 7294
7a921c93 7295 ixgbe_clear_interrupt_scheme(adapter);
5eba3699 7296
021230d4 7297 ixgbe_release_hw_control(adapter);
9a799d71
AK
7298
7299 iounmap(adapter->hw.hw_addr);
9ce77666 7300 pci_release_selected_regions(pdev, pci_select_bars(pdev,
e8e9f696 7301 IORESOURCE_MEM));
9a799d71 7302
849c4542 7303 e_dev_info("complete\n");
021230d4 7304
9a799d71
AK
7305 free_netdev(netdev);
7306
19d5afd4 7307 pci_disable_pcie_error_reporting(pdev);
6fabd715 7308
9a799d71
AK
7309 pci_disable_device(pdev);
7310}
7311
7312/**
7313 * ixgbe_io_error_detected - called when PCI error is detected
7314 * @pdev: Pointer to PCI device
7315 * @state: The current pci connection state
7316 *
7317 * This function is called after a PCI bus error affecting
7318 * this device has been detected.
7319 */
7320static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
e8e9f696 7321 pci_channel_state_t state)
9a799d71 7322{
c60fbb00
AD
7323 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7324 struct net_device *netdev = adapter->netdev;
9a799d71 7325
83c61fa9
GR
7326#ifdef CONFIG_PCI_IOV
7327 struct pci_dev *bdev, *vfdev;
7328 u32 dw0, dw1, dw2, dw3;
7329 int vf, pos;
7330 u16 req_id, pf_func;
7331
7332 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7333 adapter->num_vfs == 0)
7334 goto skip_bad_vf_detection;
7335
7336 bdev = pdev->bus->self;
7337 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
7338 bdev = bdev->bus->self;
7339
7340 if (!bdev)
7341 goto skip_bad_vf_detection;
7342
7343 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7344 if (!pos)
7345 goto skip_bad_vf_detection;
7346
7347 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7348 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7349 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7350 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7351
7352 req_id = dw1 >> 16;
7353 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7354 if (!(req_id & 0x0080))
7355 goto skip_bad_vf_detection;
7356
7357 pf_func = req_id & 0x01;
7358 if ((pf_func & 1) == (pdev->devfn & 1)) {
7359 unsigned int device_id;
7360
7361 vf = (req_id & 0x7F) >> 1;
7362 e_dev_err("VF %d has caused a PCIe error\n", vf);
7363 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7364 "%8.8x\tdw3: %8.8x\n",
7365 dw0, dw1, dw2, dw3);
7366 switch (adapter->hw.mac.type) {
7367 case ixgbe_mac_82599EB:
7368 device_id = IXGBE_82599_VF_DEVICE_ID;
7369 break;
7370 case ixgbe_mac_X540:
7371 device_id = IXGBE_X540_VF_DEVICE_ID;
7372 break;
7373 default:
7374 device_id = 0;
7375 break;
7376 }
7377
7378 /* Find the pci device of the offending VF */
7379 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
7380 while (vfdev) {
7381 if (vfdev->devfn == (req_id & 0xFF))
7382 break;
7383 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
7384 device_id, vfdev);
7385 }
7386 /*
7387 * There's a slim chance the VF could have been hot plugged,
7388 * so if it is no longer present we don't need to issue the
7389 * VFLR. Just clean up the AER in that case.
7390 */
7391 if (vfdev) {
7392 e_dev_err("Issuing VFLR to VF %d\n", vf);
7393 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7394 }
7395
7396 pci_cleanup_aer_uncorrect_error_status(pdev);
7397 }
7398
7399 /*
7400 * Even though the error may have occurred on the other port
7401 * we still need to increment the vf error reference count for
7402 * both ports because the I/O resume function will be called
7403 * for both of them.
7404 */
7405 adapter->vferr_refcount++;
7406
7407 return PCI_ERS_RESULT_RECOVERED;
7408
7409skip_bad_vf_detection:
7410#endif /* CONFIG_PCI_IOV */
9a799d71
AK
7411 netif_device_detach(netdev);
7412
3044b8d1
BL
7413 if (state == pci_channel_io_perm_failure)
7414 return PCI_ERS_RESULT_DISCONNECT;
7415
9a799d71
AK
7416 if (netif_running(netdev))
7417 ixgbe_down(adapter);
7418 pci_disable_device(pdev);
7419
b4617240 7420 /* Request a slot reset. */
9a799d71
AK
7421 return PCI_ERS_RESULT_NEED_RESET;
7422}
7423
7424/**
7425 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7426 * @pdev: Pointer to PCI device
7427 *
7428 * Restart the card from scratch, as if from a cold-boot.
7429 */
7430static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7431{
c60fbb00 7432 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6fabd715
PWJ
7433 pci_ers_result_t result;
7434 int err;
9a799d71 7435
9ce77666 7436 if (pci_enable_device_mem(pdev)) {
396e799c 7437 e_err(probe, "Cannot re-enable PCI device after reset.\n");
6fabd715
PWJ
7438 result = PCI_ERS_RESULT_DISCONNECT;
7439 } else {
7440 pci_set_master(pdev);
7441 pci_restore_state(pdev);
c0e1f68b 7442 pci_save_state(pdev);
9a799d71 7443
dd4d8ca6 7444 pci_wake_from_d3(pdev, false);
9a799d71 7445
6fabd715 7446 ixgbe_reset(adapter);
88512539 7447 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6fabd715
PWJ
7448 result = PCI_ERS_RESULT_RECOVERED;
7449 }
7450
7451 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7452 if (err) {
849c4542
ET
7453 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7454 "failed 0x%0x\n", err);
6fabd715
PWJ
7455 /* non-fatal, continue */
7456 }
9a799d71 7457
6fabd715 7458 return result;
9a799d71
AK
7459}
7460
7461/**
7462 * ixgbe_io_resume - called when traffic can start flowing again.
7463 * @pdev: Pointer to PCI device
7464 *
7465 * This callback is called when the error recovery driver tells us that
7466 * its OK to resume normal operation.
7467 */
7468static void ixgbe_io_resume(struct pci_dev *pdev)
7469{
c60fbb00
AD
7470 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7471 struct net_device *netdev = adapter->netdev;
9a799d71 7472
83c61fa9
GR
7473#ifdef CONFIG_PCI_IOV
7474 if (adapter->vferr_refcount) {
7475 e_info(drv, "Resuming after VF err\n");
7476 adapter->vferr_refcount--;
7477 return;
7478 }
7479
7480#endif
c7ccde0f
AD
7481 if (netif_running(netdev))
7482 ixgbe_up(adapter);
9a799d71
AK
7483
7484 netif_device_attach(netdev);
9a799d71
AK
7485}
7486
7487static struct pci_error_handlers ixgbe_err_handler = {
7488 .error_detected = ixgbe_io_error_detected,
7489 .slot_reset = ixgbe_io_slot_reset,
7490 .resume = ixgbe_io_resume,
7491};
7492
7493static struct pci_driver ixgbe_driver = {
7494 .name = ixgbe_driver_name,
7495 .id_table = ixgbe_pci_tbl,
7496 .probe = ixgbe_probe,
7497 .remove = __devexit_p(ixgbe_remove),
7498#ifdef CONFIG_PM
7499 .suspend = ixgbe_suspend,
7500 .resume = ixgbe_resume,
7501#endif
7502 .shutdown = ixgbe_shutdown,
7503 .err_handler = &ixgbe_err_handler
7504};
7505
7506/**
7507 * ixgbe_init_module - Driver Registration Routine
7508 *
7509 * ixgbe_init_module is the first routine called when the driver is
7510 * loaded. All it does is register with the PCI subsystem.
7511 **/
7512static int __init ixgbe_init_module(void)
7513{
7514 int ret;
c7689578 7515 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
849c4542 7516 pr_info("%s\n", ixgbe_copyright);
9a799d71 7517
5dd2d332 7518#ifdef CONFIG_IXGBE_DCA
bd0362dd 7519 dca_register_notify(&dca_notifier);
bd0362dd 7520#endif
5dd2d332 7521
9a799d71
AK
7522 ret = pci_register_driver(&ixgbe_driver);
7523 return ret;
7524}
b4617240 7525
9a799d71
AK
7526module_init(ixgbe_init_module);
7527
7528/**
7529 * ixgbe_exit_module - Driver Exit Cleanup Routine
7530 *
7531 * ixgbe_exit_module is called just before the driver is removed
7532 * from memory.
7533 **/
7534static void __exit ixgbe_exit_module(void)
7535{
5dd2d332 7536#ifdef CONFIG_IXGBE_DCA
bd0362dd
JC
7537 dca_unregister_notify(&dca_notifier);
7538#endif
9a799d71 7539 pci_unregister_driver(&ixgbe_driver);
1a51502b 7540 rcu_barrier(); /* Wait for completion of call_rcu()'s */
9a799d71 7541}
bd0362dd 7542
5dd2d332 7543#ifdef CONFIG_IXGBE_DCA
bd0362dd 7544static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
e8e9f696 7545 void *p)
bd0362dd
JC
7546{
7547 int ret_val;
7548
7549 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
e8e9f696 7550 __ixgbe_notify_dca);
bd0362dd
JC
7551
7552 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7553}
b453368d 7554
5dd2d332 7555#endif /* CONFIG_IXGBE_DCA */
849c4542 7556
9a799d71
AK
7557module_exit(ixgbe_exit_module);
7558
7559/* ixgbe_main.c */
This page took 2.29884 seconds and 5 git commands to generate.