1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2011 Intel Corporation.
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.
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
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
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>
35 #include <linux/interrupt.h>
37 #include <linux/tcp.h>
38 #include <linux/sctp.h>
39 #include <linux/pkt_sched.h>
40 #include <linux/ipv6.h>
41 #include <linux/slab.h>
42 #include <net/checksum.h>
43 #include <net/ip6_checksum.h>
44 #include <linux/ethtool.h>
46 #include <linux/if_vlan.h>
47 #include <linux/prefetch.h>
48 #include <scsi/fc/fc_fcoe.h>
51 #include "ixgbe_common.h"
52 #include "ixgbe_dcb_82599.h"
53 #include "ixgbe_sriov.h"
55 char ixgbe_driver_name
[] = "ixgbe";
56 static const char ixgbe_driver_string
[] =
57 "Intel(R) 10 Gigabit PCI Express Network Driver";
61 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
62 __stringify(BUILD) "-k"
63 const char ixgbe_driver_version
[] = DRV_VERSION
;
64 static const char ixgbe_copyright
[] =
65 "Copyright (c) 1999-2011 Intel Corporation.";
67 static const struct ixgbe_info
*ixgbe_info_tbl
[] = {
68 [board_82598
] = &ixgbe_82598_info
,
69 [board_82599
] = &ixgbe_82599_info
,
70 [board_X540
] = &ixgbe_X540_info
,
73 /* ixgbe_pci_tbl - PCI Device ID Table
75 * Wildcard entries (PCI_ANY_ID) should come last
76 * Last entry must be all 0s
78 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
79 * Class, Class Mask, private data (not used) }
81 static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl
) = {
82 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598
), board_82598
},
83 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_DUAL_PORT
), board_82598
},
84 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_SINGLE_PORT
), board_82598
},
85 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT
), board_82598
},
86 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT2
), board_82598
},
87 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_CX4
), board_82598
},
88 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_CX4_DUAL_PORT
), board_82598
},
89 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_DA_DUAL_PORT
), board_82598
},
90 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM
), board_82598
},
91 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_XF_LR
), board_82598
},
92 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_SFP_LOM
), board_82598
},
93 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_BX
), board_82598
},
94 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4
), board_82599
},
95 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_XAUI_LOM
), board_82599
},
96 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KR
), board_82599
},
97 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP
), board_82599
},
98 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_EM
), board_82599
},
99 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4_MEZZ
), board_82599
},
100 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_CX4
), board_82599
},
101 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_BACKPLANE_FCOE
), board_82599
},
102 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_FCOE
), board_82599
},
103 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_T3_LOM
), board_82599
},
104 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_COMBO_BACKPLANE
), board_82599
},
105 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X540T
), board_X540
},
106 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_SF2
), board_82599
},
107 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_LS
), board_82599
},
108 /* required last entry */
111 MODULE_DEVICE_TABLE(pci
, ixgbe_pci_tbl
);
113 #ifdef CONFIG_IXGBE_DCA
114 static int ixgbe_notify_dca(struct notifier_block
*, unsigned long event
,
116 static struct notifier_block dca_notifier
= {
117 .notifier_call
= ixgbe_notify_dca
,
123 #ifdef CONFIG_PCI_IOV
124 static unsigned int max_vfs
;
125 module_param(max_vfs
, uint
, 0);
126 MODULE_PARM_DESC(max_vfs
,
127 "Maximum number of virtual functions to allocate per physical function");
128 #endif /* CONFIG_PCI_IOV */
130 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
131 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
132 MODULE_LICENSE("GPL");
133 MODULE_VERSION(DRV_VERSION
);
135 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
137 static void ixgbe_service_event_schedule(struct ixgbe_adapter
*adapter
)
139 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
) &&
140 !test_and_set_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
))
141 schedule_work(&adapter
->service_task
);
144 static void ixgbe_service_event_complete(struct ixgbe_adapter
*adapter
)
146 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
));
148 /* flush memory to make sure state is correct before next watchog */
149 smp_mb__before_clear_bit();
150 clear_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
);
153 struct ixgbe_reg_info
{
158 static const struct ixgbe_reg_info ixgbe_reg_info_tbl
[] = {
160 /* General Registers */
161 {IXGBE_CTRL
, "CTRL"},
162 {IXGBE_STATUS
, "STATUS"},
163 {IXGBE_CTRL_EXT
, "CTRL_EXT"},
165 /* Interrupt Registers */
166 {IXGBE_EICR
, "EICR"},
169 {IXGBE_SRRCTL(0), "SRRCTL"},
170 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
171 {IXGBE_RDLEN(0), "RDLEN"},
172 {IXGBE_RDH(0), "RDH"},
173 {IXGBE_RDT(0), "RDT"},
174 {IXGBE_RXDCTL(0), "RXDCTL"},
175 {IXGBE_RDBAL(0), "RDBAL"},
176 {IXGBE_RDBAH(0), "RDBAH"},
179 {IXGBE_TDBAL(0), "TDBAL"},
180 {IXGBE_TDBAH(0), "TDBAH"},
181 {IXGBE_TDLEN(0), "TDLEN"},
182 {IXGBE_TDH(0), "TDH"},
183 {IXGBE_TDT(0), "TDT"},
184 {IXGBE_TXDCTL(0), "TXDCTL"},
186 /* List Terminator */
192 * ixgbe_regdump - register printout routine
194 static void ixgbe_regdump(struct ixgbe_hw
*hw
, struct ixgbe_reg_info
*reginfo
)
200 switch (reginfo
->ofs
) {
201 case IXGBE_SRRCTL(0):
202 for (i
= 0; i
< 64; i
++)
203 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_SRRCTL(i
));
205 case IXGBE_DCA_RXCTRL(0):
206 for (i
= 0; i
< 64; i
++)
207 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_DCA_RXCTRL(i
));
210 for (i
= 0; i
< 64; i
++)
211 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDLEN(i
));
214 for (i
= 0; i
< 64; i
++)
215 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDH(i
));
218 for (i
= 0; i
< 64; i
++)
219 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDT(i
));
221 case IXGBE_RXDCTL(0):
222 for (i
= 0; i
< 64; i
++)
223 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RXDCTL(i
));
226 for (i
= 0; i
< 64; i
++)
227 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDBAL(i
));
230 for (i
= 0; i
< 64; i
++)
231 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDBAH(i
));
234 for (i
= 0; i
< 64; i
++)
235 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDBAL(i
));
238 for (i
= 0; i
< 64; i
++)
239 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDBAH(i
));
242 for (i
= 0; i
< 64; i
++)
243 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDLEN(i
));
246 for (i
= 0; i
< 64; i
++)
247 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDH(i
));
250 for (i
= 0; i
< 64; i
++)
251 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDT(i
));
253 case IXGBE_TXDCTL(0):
254 for (i
= 0; i
< 64; i
++)
255 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TXDCTL(i
));
258 pr_info("%-15s %08x\n", reginfo
->name
,
259 IXGBE_READ_REG(hw
, reginfo
->ofs
));
263 for (i
= 0; i
< 8; i
++) {
264 snprintf(rname
, 16, "%s[%d-%d]", reginfo
->name
, i
*8, i
*8+7);
265 pr_err("%-15s", rname
);
266 for (j
= 0; j
< 8; j
++)
267 pr_cont(" %08x", regs
[i
*8+j
]);
274 * ixgbe_dump - Print registers, tx-rings and rx-rings
276 static void ixgbe_dump(struct ixgbe_adapter
*adapter
)
278 struct net_device
*netdev
= adapter
->netdev
;
279 struct ixgbe_hw
*hw
= &adapter
->hw
;
280 struct ixgbe_reg_info
*reginfo
;
282 struct ixgbe_ring
*tx_ring
;
283 struct ixgbe_tx_buffer
*tx_buffer_info
;
284 union ixgbe_adv_tx_desc
*tx_desc
;
285 struct my_u0
{ u64 a
; u64 b
; } *u0
;
286 struct ixgbe_ring
*rx_ring
;
287 union ixgbe_adv_rx_desc
*rx_desc
;
288 struct ixgbe_rx_buffer
*rx_buffer_info
;
292 if (!netif_msg_hw(adapter
))
295 /* Print netdevice Info */
297 dev_info(&adapter
->pdev
->dev
, "Net device Info\n");
298 pr_info("Device Name state "
299 "trans_start last_rx\n");
300 pr_info("%-15s %016lX %016lX %016lX\n",
307 /* Print Registers */
308 dev_info(&adapter
->pdev
->dev
, "Register Dump\n");
309 pr_info(" Register Name Value\n");
310 for (reginfo
= (struct ixgbe_reg_info
*)ixgbe_reg_info_tbl
;
311 reginfo
->name
; reginfo
++) {
312 ixgbe_regdump(hw
, reginfo
);
315 /* Print TX Ring Summary */
316 if (!netdev
|| !netif_running(netdev
))
319 dev_info(&adapter
->pdev
->dev
, "TX Rings Summary\n");
320 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
321 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
322 tx_ring
= adapter
->tx_ring
[n
];
324 &tx_ring
->tx_buffer_info
[tx_ring
->next_to_clean
];
325 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
326 n
, tx_ring
->next_to_use
, tx_ring
->next_to_clean
,
327 (u64
)tx_buffer_info
->dma
,
328 tx_buffer_info
->length
,
329 tx_buffer_info
->next_to_watch
,
330 (u64
)tx_buffer_info
->time_stamp
);
334 if (!netif_msg_tx_done(adapter
))
335 goto rx_ring_summary
;
337 dev_info(&adapter
->pdev
->dev
, "TX Rings Dump\n");
339 /* Transmit Descriptor Formats
341 * Advanced Transmit Descriptor
342 * +--------------------------------------------------------------+
343 * 0 | Buffer Address [63:0] |
344 * +--------------------------------------------------------------+
345 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
346 * +--------------------------------------------------------------+
347 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
350 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
351 tx_ring
= adapter
->tx_ring
[n
];
352 pr_info("------------------------------------\n");
353 pr_info("TX QUEUE INDEX = %d\n", tx_ring
->queue_index
);
354 pr_info("------------------------------------\n");
355 pr_info("T [desc] [address 63:0 ] "
356 "[PlPOIdStDDt Ln] [bi->dma ] "
357 "leng ntw timestamp bi->skb\n");
359 for (i
= 0; tx_ring
->desc
&& (i
< tx_ring
->count
); i
++) {
360 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, i
);
361 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
362 u0
= (struct my_u0
*)tx_desc
;
363 pr_info("T [0x%03X] %016llX %016llX %016llX"
364 " %04X %p %016llX %p", i
,
367 (u64
)tx_buffer_info
->dma
,
368 tx_buffer_info
->length
,
369 tx_buffer_info
->next_to_watch
,
370 (u64
)tx_buffer_info
->time_stamp
,
371 tx_buffer_info
->skb
);
372 if (i
== tx_ring
->next_to_use
&&
373 i
== tx_ring
->next_to_clean
)
375 else if (i
== tx_ring
->next_to_use
)
377 else if (i
== tx_ring
->next_to_clean
)
382 if (netif_msg_pktdata(adapter
) &&
383 tx_buffer_info
->dma
!= 0)
384 print_hex_dump(KERN_INFO
, "",
385 DUMP_PREFIX_ADDRESS
, 16, 1,
386 phys_to_virt(tx_buffer_info
->dma
),
387 tx_buffer_info
->length
, true);
391 /* Print RX Rings Summary */
393 dev_info(&adapter
->pdev
->dev
, "RX Rings Summary\n");
394 pr_info("Queue [NTU] [NTC]\n");
395 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
396 rx_ring
= adapter
->rx_ring
[n
];
397 pr_info("%5d %5X %5X\n",
398 n
, rx_ring
->next_to_use
, rx_ring
->next_to_clean
);
402 if (!netif_msg_rx_status(adapter
))
405 dev_info(&adapter
->pdev
->dev
, "RX Rings Dump\n");
407 /* Advanced Receive Descriptor (Read) Format
409 * +-----------------------------------------------------+
410 * 0 | Packet Buffer Address [63:1] |A0/NSE|
411 * +----------------------------------------------+------+
412 * 8 | Header Buffer Address [63:1] | DD |
413 * +-----------------------------------------------------+
416 * Advanced Receive Descriptor (Write-Back) Format
418 * 63 48 47 32 31 30 21 20 16 15 4 3 0
419 * +------------------------------------------------------+
420 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
421 * | Checksum Ident | | | | Type | Type |
422 * +------------------------------------------------------+
423 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
424 * +------------------------------------------------------+
425 * 63 48 47 32 31 20 19 0
427 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
428 rx_ring
= adapter
->rx_ring
[n
];
429 pr_info("------------------------------------\n");
430 pr_info("RX QUEUE INDEX = %d\n", rx_ring
->queue_index
);
431 pr_info("------------------------------------\n");
432 pr_info("R [desc] [ PktBuf A0] "
433 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
434 "<-- Adv Rx Read format\n");
435 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
436 "[vl er S cks ln] ---------------- [bi->skb] "
437 "<-- Adv Rx Write-Back format\n");
439 for (i
= 0; i
< rx_ring
->count
; i
++) {
440 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
441 rx_desc
= IXGBE_RX_DESC_ADV(rx_ring
, i
);
442 u0
= (struct my_u0
*)rx_desc
;
443 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
444 if (staterr
& IXGBE_RXD_STAT_DD
) {
445 /* Descriptor Done */
446 pr_info("RWB[0x%03X] %016llX "
447 "%016llX ---------------- %p", i
,
450 rx_buffer_info
->skb
);
452 pr_info("R [0x%03X] %016llX "
453 "%016llX %016llX %p", i
,
456 (u64
)rx_buffer_info
->dma
,
457 rx_buffer_info
->skb
);
459 if (netif_msg_pktdata(adapter
)) {
460 print_hex_dump(KERN_INFO
, "",
461 DUMP_PREFIX_ADDRESS
, 16, 1,
462 phys_to_virt(rx_buffer_info
->dma
),
463 rx_ring
->rx_buf_len
, true);
465 if (rx_ring
->rx_buf_len
467 print_hex_dump(KERN_INFO
, "",
468 DUMP_PREFIX_ADDRESS
, 16, 1,
470 rx_buffer_info
->page_dma
+
471 rx_buffer_info
->page_offset
477 if (i
== rx_ring
->next_to_use
)
479 else if (i
== rx_ring
->next_to_clean
)
491 static void ixgbe_release_hw_control(struct ixgbe_adapter
*adapter
)
495 /* Let firmware take over control of h/w */
496 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
497 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
498 ctrl_ext
& ~IXGBE_CTRL_EXT_DRV_LOAD
);
501 static void ixgbe_get_hw_control(struct ixgbe_adapter
*adapter
)
505 /* Let firmware know the driver has taken over */
506 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
507 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
508 ctrl_ext
| IXGBE_CTRL_EXT_DRV_LOAD
);
512 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
513 * @adapter: pointer to adapter struct
514 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
515 * @queue: queue to map the corresponding interrupt to
516 * @msix_vector: the vector to map to the corresponding queue
519 static void ixgbe_set_ivar(struct ixgbe_adapter
*adapter
, s8 direction
,
520 u8 queue
, u8 msix_vector
)
523 struct ixgbe_hw
*hw
= &adapter
->hw
;
524 switch (hw
->mac
.type
) {
525 case ixgbe_mac_82598EB
:
526 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
529 index
= (((direction
* 64) + queue
) >> 2) & 0x1F;
530 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(index
));
531 ivar
&= ~(0xFF << (8 * (queue
& 0x3)));
532 ivar
|= (msix_vector
<< (8 * (queue
& 0x3)));
533 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(index
), ivar
);
535 case ixgbe_mac_82599EB
:
537 if (direction
== -1) {
539 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
540 index
= ((queue
& 1) * 8);
541 ivar
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_IVAR_MISC
);
542 ivar
&= ~(0xFF << index
);
543 ivar
|= (msix_vector
<< index
);
544 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_IVAR_MISC
, ivar
);
547 /* tx or rx causes */
548 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
549 index
= ((16 * (queue
& 1)) + (8 * direction
));
550 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(queue
>> 1));
551 ivar
&= ~(0xFF << index
);
552 ivar
|= (msix_vector
<< index
);
553 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(queue
>> 1), ivar
);
561 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter
*adapter
,
566 switch (adapter
->hw
.mac
.type
) {
567 case ixgbe_mac_82598EB
:
568 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
569 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS
, mask
);
571 case ixgbe_mac_82599EB
:
573 mask
= (qmask
& 0xFFFFFFFF);
574 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(0), mask
);
575 mask
= (qmask
>> 32);
576 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(1), mask
);
583 static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring
*ring
,
584 struct ixgbe_tx_buffer
*tx_buffer
)
586 if (tx_buffer
->dma
) {
587 if (tx_buffer
->tx_flags
& IXGBE_TX_FLAGS_MAPPED_AS_PAGE
)
588 dma_unmap_page(ring
->dev
,
593 dma_unmap_single(ring
->dev
,
601 void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring
*tx_ring
,
602 struct ixgbe_tx_buffer
*tx_buffer_info
)
604 ixgbe_unmap_tx_resource(tx_ring
, tx_buffer_info
);
605 if (tx_buffer_info
->skb
)
606 dev_kfree_skb_any(tx_buffer_info
->skb
);
607 tx_buffer_info
->skb
= NULL
;
608 /* tx_buffer_info must be completely set up in the transmit path */
611 static void ixgbe_update_xoff_received(struct ixgbe_adapter
*adapter
)
613 struct ixgbe_hw
*hw
= &adapter
->hw
;
614 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
619 if ((hw
->fc
.current_mode
== ixgbe_fc_full
) ||
620 (hw
->fc
.current_mode
== ixgbe_fc_rx_pause
)) {
621 switch (hw
->mac
.type
) {
622 case ixgbe_mac_82598EB
:
623 data
= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXC
);
626 data
= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXCNT
);
628 hwstats
->lxoffrxc
+= data
;
630 /* refill credits (no tx hang) if we received xoff */
634 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
635 clear_bit(__IXGBE_HANG_CHECK_ARMED
,
636 &adapter
->tx_ring
[i
]->state
);
638 } else if (!(adapter
->dcb_cfg
.pfc_mode_enable
))
641 /* update stats for each tc, only valid with PFC enabled */
642 for (i
= 0; i
< MAX_TX_PACKET_BUFFERS
; i
++) {
643 switch (hw
->mac
.type
) {
644 case ixgbe_mac_82598EB
:
645 xoff
[i
] = IXGBE_READ_REG(hw
, IXGBE_PXOFFRXC(i
));
648 xoff
[i
] = IXGBE_READ_REG(hw
, IXGBE_PXOFFRXCNT(i
));
650 hwstats
->pxoffrxc
[i
] += xoff
[i
];
653 /* disarm tx queues that have received xoff frames */
654 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
655 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
656 u8 tc
= tx_ring
->dcb_tc
;
659 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &tx_ring
->state
);
663 static u64
ixgbe_get_tx_completed(struct ixgbe_ring
*ring
)
665 return ring
->tx_stats
.completed
;
668 static u64
ixgbe_get_tx_pending(struct ixgbe_ring
*ring
)
670 struct ixgbe_adapter
*adapter
= netdev_priv(ring
->netdev
);
671 struct ixgbe_hw
*hw
= &adapter
->hw
;
673 u32 head
= IXGBE_READ_REG(hw
, IXGBE_TDH(ring
->reg_idx
));
674 u32 tail
= IXGBE_READ_REG(hw
, IXGBE_TDT(ring
->reg_idx
));
677 return (head
< tail
) ?
678 tail
- head
: (tail
+ ring
->count
- head
);
683 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring
*tx_ring
)
685 u32 tx_done
= ixgbe_get_tx_completed(tx_ring
);
686 u32 tx_done_old
= tx_ring
->tx_stats
.tx_done_old
;
687 u32 tx_pending
= ixgbe_get_tx_pending(tx_ring
);
690 clear_check_for_tx_hang(tx_ring
);
693 * Check for a hung queue, but be thorough. This verifies
694 * that a transmit has been completed since the previous
695 * check AND there is at least one packet pending. The
696 * ARMED bit is set to indicate a potential hang. The
697 * bit is cleared if a pause frame is received to remove
698 * false hang detection due to PFC or 802.3x frames. By
699 * requiring this to fail twice we avoid races with
700 * pfc clearing the ARMED bit and conditions where we
701 * run the check_tx_hang logic with a transmit completion
702 * pending but without time to complete it yet.
704 if ((tx_done_old
== tx_done
) && tx_pending
) {
705 /* make sure it is true for two checks in a row */
706 ret
= test_and_set_bit(__IXGBE_HANG_CHECK_ARMED
,
709 /* update completed stats and continue */
710 tx_ring
->tx_stats
.tx_done_old
= tx_done
;
711 /* reset the countdown */
712 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &tx_ring
->state
);
719 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
720 * @adapter: driver private struct
722 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter
*adapter
)
725 /* Do the reset outside of interrupt context */
726 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
727 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
728 ixgbe_service_event_schedule(adapter
);
733 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
734 * @q_vector: structure containing interrupt and ring information
735 * @tx_ring: tx ring to clean
737 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector
*q_vector
,
738 struct ixgbe_ring
*tx_ring
)
740 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
741 struct ixgbe_tx_buffer
*tx_buffer
;
742 union ixgbe_adv_tx_desc
*tx_desc
;
743 unsigned int total_bytes
= 0, total_packets
= 0;
744 unsigned int budget
= q_vector
->tx
.work_limit
;
745 u16 i
= tx_ring
->next_to_clean
;
747 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
748 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, i
);
750 for (; budget
; budget
--) {
751 union ixgbe_adv_tx_desc
*eop_desc
= tx_buffer
->next_to_watch
;
753 /* if next_to_watch is not set then there is no work pending */
757 /* if DD is not set pending work has not been completed */
758 if (!(eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)))
761 /* count the packet as being completed */
762 tx_ring
->tx_stats
.completed
++;
764 /* clear next_to_watch to prevent false hangs */
765 tx_buffer
->next_to_watch
= NULL
;
767 /* prevent any other reads prior to eop_desc being verified */
771 ixgbe_unmap_tx_resource(tx_ring
, tx_buffer
);
772 tx_desc
->wb
.status
= 0;
773 if (likely(tx_desc
== eop_desc
)) {
775 dev_kfree_skb_any(tx_buffer
->skb
);
776 tx_buffer
->skb
= NULL
;
778 total_bytes
+= tx_buffer
->bytecount
;
779 total_packets
+= tx_buffer
->gso_segs
;
785 if (unlikely(i
== tx_ring
->count
)) {
788 tx_buffer
= tx_ring
->tx_buffer_info
;
789 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, 0);
795 tx_ring
->next_to_clean
= i
;
796 u64_stats_update_begin(&tx_ring
->syncp
);
797 tx_ring
->stats
.bytes
+= total_bytes
;
798 tx_ring
->stats
.packets
+= total_packets
;
799 u64_stats_update_end(&tx_ring
->syncp
);
800 q_vector
->tx
.total_bytes
+= total_bytes
;
801 q_vector
->tx
.total_packets
+= total_packets
;
803 if (check_for_tx_hang(tx_ring
) && ixgbe_check_tx_hang(tx_ring
)) {
804 /* schedule immediate reset if we believe we hung */
805 struct ixgbe_hw
*hw
= &adapter
->hw
;
806 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, i
);
807 e_err(drv
, "Detected Tx Unit Hang\n"
809 " TDH, TDT <%x>, <%x>\n"
810 " next_to_use <%x>\n"
811 " next_to_clean <%x>\n"
812 "tx_buffer_info[next_to_clean]\n"
813 " time_stamp <%lx>\n"
815 tx_ring
->queue_index
,
816 IXGBE_READ_REG(hw
, IXGBE_TDH(tx_ring
->reg_idx
)),
817 IXGBE_READ_REG(hw
, IXGBE_TDT(tx_ring
->reg_idx
)),
818 tx_ring
->next_to_use
, i
,
819 tx_ring
->tx_buffer_info
[i
].time_stamp
, jiffies
);
821 netif_stop_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
824 "tx hang %d detected on queue %d, resetting adapter\n",
825 adapter
->tx_timeout_count
+ 1, tx_ring
->queue_index
);
827 /* schedule immediate reset if we believe we hung */
828 ixgbe_tx_timeout_reset(adapter
);
830 /* the adapter is about to reset, no point in enabling stuff */
834 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
835 if (unlikely(total_packets
&& netif_carrier_ok(tx_ring
->netdev
) &&
836 (ixgbe_desc_unused(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
837 /* Make sure that anybody stopping the queue after this
838 * sees the new next_to_clean.
841 if (__netif_subqueue_stopped(tx_ring
->netdev
, tx_ring
->queue_index
) &&
842 !test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
843 netif_wake_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
844 ++tx_ring
->tx_stats
.restart_queue
;
851 #ifdef CONFIG_IXGBE_DCA
852 static void ixgbe_update_rx_dca(struct ixgbe_adapter
*adapter
,
853 struct ixgbe_ring
*rx_ring
,
856 struct ixgbe_hw
*hw
= &adapter
->hw
;
858 u8 reg_idx
= rx_ring
->reg_idx
;
860 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_RXCTRL(reg_idx
));
861 switch (hw
->mac
.type
) {
862 case ixgbe_mac_82598EB
:
863 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK
;
864 rxctrl
|= dca3_get_tag(rx_ring
->dev
, cpu
);
866 case ixgbe_mac_82599EB
:
868 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599
;
869 rxctrl
|= (dca3_get_tag(rx_ring
->dev
, cpu
) <<
870 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599
);
875 rxctrl
|= IXGBE_DCA_RXCTRL_DESC_DCA_EN
;
876 rxctrl
|= IXGBE_DCA_RXCTRL_HEAD_DCA_EN
;
877 rxctrl
&= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN
);
878 IXGBE_WRITE_REG(hw
, IXGBE_DCA_RXCTRL(reg_idx
), rxctrl
);
881 static void ixgbe_update_tx_dca(struct ixgbe_adapter
*adapter
,
882 struct ixgbe_ring
*tx_ring
,
885 struct ixgbe_hw
*hw
= &adapter
->hw
;
887 u8 reg_idx
= tx_ring
->reg_idx
;
889 switch (hw
->mac
.type
) {
890 case ixgbe_mac_82598EB
:
891 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL(reg_idx
));
892 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK
;
893 txctrl
|= dca3_get_tag(tx_ring
->dev
, cpu
);
894 txctrl
|= IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
895 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL(reg_idx
), txctrl
);
897 case ixgbe_mac_82599EB
:
899 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL_82599(reg_idx
));
900 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599
;
901 txctrl
|= (dca3_get_tag(tx_ring
->dev
, cpu
) <<
902 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599
);
903 txctrl
|= IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
904 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL_82599(reg_idx
), txctrl
);
911 static void ixgbe_update_dca(struct ixgbe_q_vector
*q_vector
)
913 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
914 struct ixgbe_ring
*ring
;
917 if (q_vector
->cpu
== cpu
)
920 for (ring
= q_vector
->tx
.ring
; ring
!= NULL
; ring
= ring
->next
)
921 ixgbe_update_tx_dca(adapter
, ring
, cpu
);
923 for (ring
= q_vector
->rx
.ring
; ring
!= NULL
; ring
= ring
->next
)
924 ixgbe_update_rx_dca(adapter
, ring
, cpu
);
931 static void ixgbe_setup_dca(struct ixgbe_adapter
*adapter
)
936 if (!(adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
))
939 /* always use CB2 mode, difference is masked in the CB driver */
940 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 2);
942 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
943 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
947 for (i
= 0; i
< num_q_vectors
; i
++) {
948 adapter
->q_vector
[i
]->cpu
= -1;
949 ixgbe_update_dca(adapter
->q_vector
[i
]);
953 static int __ixgbe_notify_dca(struct device
*dev
, void *data
)
955 struct ixgbe_adapter
*adapter
= dev_get_drvdata(dev
);
956 unsigned long event
= *(unsigned long *)data
;
958 if (!(adapter
->flags
& IXGBE_FLAG_DCA_CAPABLE
))
962 case DCA_PROVIDER_ADD
:
963 /* if we're already enabled, don't do it again */
964 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
966 if (dca_add_requester(dev
) == 0) {
967 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
968 ixgbe_setup_dca(adapter
);
971 /* Fall Through since DCA is disabled. */
972 case DCA_PROVIDER_REMOVE
:
973 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
974 dca_remove_requester(dev
);
975 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
976 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
983 #endif /* CONFIG_IXGBE_DCA */
985 static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc
*rx_desc
,
988 skb
->rxhash
= le32_to_cpu(rx_desc
->wb
.lower
.hi_dword
.rss
);
992 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
993 * @adapter: address of board private structure
994 * @rx_desc: advanced rx descriptor
996 * Returns : true if it is FCoE pkt
998 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter
*adapter
,
999 union ixgbe_adv_rx_desc
*rx_desc
)
1001 __le16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1003 return (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
1004 ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK
)) ==
1005 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE
<<
1006 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT
)));
1010 * ixgbe_receive_skb - Send a completed packet up the stack
1011 * @adapter: board private structure
1012 * @skb: packet to send up
1013 * @status: hardware indication of status of receive
1014 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1015 * @rx_desc: rx descriptor
1017 static void ixgbe_receive_skb(struct ixgbe_q_vector
*q_vector
,
1018 struct sk_buff
*skb
, u8 status
,
1019 struct ixgbe_ring
*ring
,
1020 union ixgbe_adv_rx_desc
*rx_desc
)
1022 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1023 struct napi_struct
*napi
= &q_vector
->napi
;
1024 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
1025 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
1027 if (is_vlan
&& (tag
& VLAN_VID_MASK
))
1028 __vlan_hwaccel_put_tag(skb
, tag
);
1030 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
))
1031 napi_gro_receive(napi
, skb
);
1037 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1038 * @adapter: address of board private structure
1039 * @status_err: hardware indication of status of receive
1040 * @skb: skb currently being received and modified
1041 * @status_err: status error value of last descriptor in packet
1043 static inline void ixgbe_rx_checksum(struct ixgbe_adapter
*adapter
,
1044 union ixgbe_adv_rx_desc
*rx_desc
,
1045 struct sk_buff
*skb
,
1048 skb
->ip_summed
= CHECKSUM_NONE
;
1050 /* Rx csum disabled */
1051 if (!(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
1054 /* if IP and error */
1055 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
1056 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
1057 adapter
->hw_csum_rx_error
++;
1061 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
1064 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
1065 u16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1068 * 82599 errata, UDP frames with a 0 checksum can be marked as
1071 if ((pkt_info
& IXGBE_RXDADV_PKTTYPE_UDP
) &&
1072 (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
))
1075 adapter
->hw_csum_rx_error
++;
1079 /* It must be a TCP or UDP packet with a valid checksum */
1080 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1083 static inline void ixgbe_release_rx_desc(struct ixgbe_ring
*rx_ring
, u32 val
)
1086 * Force memory writes to complete before letting h/w
1087 * know there are new descriptors to fetch. (Only
1088 * applicable for weak-ordered memory model archs,
1092 writel(val
, rx_ring
->tail
);
1096 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
1097 * @rx_ring: ring to place buffers on
1098 * @cleaned_count: number of buffers to replace
1100 void ixgbe_alloc_rx_buffers(struct ixgbe_ring
*rx_ring
, u16 cleaned_count
)
1102 union ixgbe_adv_rx_desc
*rx_desc
;
1103 struct ixgbe_rx_buffer
*bi
;
1104 struct sk_buff
*skb
;
1105 u16 i
= rx_ring
->next_to_use
;
1107 /* do nothing if no valid netdev defined */
1108 if (!rx_ring
->netdev
)
1111 while (cleaned_count
--) {
1112 rx_desc
= IXGBE_RX_DESC_ADV(rx_ring
, i
);
1113 bi
= &rx_ring
->rx_buffer_info
[i
];
1117 skb
= netdev_alloc_skb_ip_align(rx_ring
->netdev
,
1118 rx_ring
->rx_buf_len
);
1120 rx_ring
->rx_stats
.alloc_rx_buff_failed
++;
1123 /* initialize queue mapping */
1124 skb_record_rx_queue(skb
, rx_ring
->queue_index
);
1129 bi
->dma
= dma_map_single(rx_ring
->dev
,
1131 rx_ring
->rx_buf_len
,
1133 if (dma_mapping_error(rx_ring
->dev
, bi
->dma
)) {
1134 rx_ring
->rx_stats
.alloc_rx_buff_failed
++;
1140 if (ring_is_ps_enabled(rx_ring
)) {
1142 bi
->page
= netdev_alloc_page(rx_ring
->netdev
);
1144 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1149 if (!bi
->page_dma
) {
1150 /* use a half page if we're re-using */
1151 bi
->page_offset
^= PAGE_SIZE
/ 2;
1152 bi
->page_dma
= dma_map_page(rx_ring
->dev
,
1157 if (dma_mapping_error(rx_ring
->dev
,
1159 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1165 /* Refresh the desc even if buffer_addrs didn't change
1166 * because each write-back erases this info. */
1167 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->page_dma
);
1168 rx_desc
->read
.hdr_addr
= cpu_to_le64(bi
->dma
);
1170 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
1171 rx_desc
->read
.hdr_addr
= 0;
1175 if (i
== rx_ring
->count
)
1180 if (rx_ring
->next_to_use
!= i
) {
1181 rx_ring
->next_to_use
= i
;
1182 ixgbe_release_rx_desc(rx_ring
, i
);
1186 static inline u16
ixgbe_get_hlen(union ixgbe_adv_rx_desc
*rx_desc
)
1188 /* HW will not DMA in data larger than the given buffer, even if it
1189 * parses the (NFS, of course) header to be larger. In that case, it
1190 * fills the header buffer and spills the rest into the page.
1192 u16 hdr_info
= le16_to_cpu(rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
);
1193 u16 hlen
= (hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
1194 IXGBE_RXDADV_HDRBUFLEN_SHIFT
;
1195 if (hlen
> IXGBE_RX_HDR_SIZE
)
1196 hlen
= IXGBE_RX_HDR_SIZE
;
1201 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1202 * @skb: pointer to the last skb in the rsc queue
1204 * This function changes a queue full of hw rsc buffers into a completed
1205 * packet. It uses the ->prev pointers to find the first packet and then
1206 * turns it into the frag list owner.
1208 static inline struct sk_buff
*ixgbe_transform_rsc_queue(struct sk_buff
*skb
)
1210 unsigned int frag_list_size
= 0;
1211 unsigned int skb_cnt
= 1;
1214 struct sk_buff
*prev
= skb
->prev
;
1215 frag_list_size
+= skb
->len
;
1221 skb_shinfo(skb
)->frag_list
= skb
->next
;
1223 skb
->len
+= frag_list_size
;
1224 skb
->data_len
+= frag_list_size
;
1225 skb
->truesize
+= frag_list_size
;
1226 IXGBE_RSC_CB(skb
)->skb_cnt
= skb_cnt
;
1231 static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc
*rx_desc
)
1233 return !!(le32_to_cpu(rx_desc
->wb
.lower
.lo_dword
.data
) &
1234 IXGBE_RXDADV_RSCCNT_MASK
);
1237 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector
*q_vector
,
1238 struct ixgbe_ring
*rx_ring
,
1241 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1242 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
1243 struct ixgbe_rx_buffer
*rx_buffer_info
, *next_buffer
;
1244 struct sk_buff
*skb
;
1245 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
1246 const int current_node
= numa_node_id();
1249 #endif /* IXGBE_FCOE */
1252 u16 cleaned_count
= 0;
1253 bool pkt_is_rsc
= false;
1255 i
= rx_ring
->next_to_clean
;
1256 rx_desc
= IXGBE_RX_DESC_ADV(rx_ring
, i
);
1257 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1259 while (staterr
& IXGBE_RXD_STAT_DD
) {
1262 rmb(); /* read descriptor and rx_buffer_info after status DD */
1264 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
1266 skb
= rx_buffer_info
->skb
;
1267 rx_buffer_info
->skb
= NULL
;
1268 prefetch(skb
->data
);
1270 if (ring_is_rsc_enabled(rx_ring
))
1271 pkt_is_rsc
= ixgbe_get_rsc_state(rx_desc
);
1273 /* linear means we are building an skb from multiple pages */
1274 if (!skb_is_nonlinear(skb
)) {
1277 !(staterr
& IXGBE_RXD_STAT_EOP
) &&
1280 * When HWRSC is enabled, delay unmapping
1281 * of the first packet. It carries the
1282 * header information, HW may still
1283 * access the header after the writeback.
1284 * Only unmap it when EOP is reached
1286 IXGBE_RSC_CB(skb
)->delay_unmap
= true;
1287 IXGBE_RSC_CB(skb
)->dma
= rx_buffer_info
->dma
;
1289 dma_unmap_single(rx_ring
->dev
,
1290 rx_buffer_info
->dma
,
1291 rx_ring
->rx_buf_len
,
1294 rx_buffer_info
->dma
= 0;
1296 if (ring_is_ps_enabled(rx_ring
)) {
1297 hlen
= ixgbe_get_hlen(rx_desc
);
1298 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
1300 hlen
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
1305 /* assume packet split since header is unmapped */
1306 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
1310 dma_unmap_page(rx_ring
->dev
,
1311 rx_buffer_info
->page_dma
,
1314 rx_buffer_info
->page_dma
= 0;
1315 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
1316 rx_buffer_info
->page
,
1317 rx_buffer_info
->page_offset
,
1320 if ((page_count(rx_buffer_info
->page
) == 1) &&
1321 (page_to_nid(rx_buffer_info
->page
) == current_node
))
1322 get_page(rx_buffer_info
->page
);
1324 rx_buffer_info
->page
= NULL
;
1326 skb
->len
+= upper_len
;
1327 skb
->data_len
+= upper_len
;
1328 skb
->truesize
+= upper_len
;
1332 if (i
== rx_ring
->count
)
1335 next_rxd
= IXGBE_RX_DESC_ADV(rx_ring
, i
);
1340 u32 nextp
= (staterr
& IXGBE_RXDADV_NEXTP_MASK
) >>
1341 IXGBE_RXDADV_NEXTP_SHIFT
;
1342 next_buffer
= &rx_ring
->rx_buffer_info
[nextp
];
1344 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
1347 if (!(staterr
& IXGBE_RXD_STAT_EOP
)) {
1348 if (ring_is_ps_enabled(rx_ring
)) {
1349 rx_buffer_info
->skb
= next_buffer
->skb
;
1350 rx_buffer_info
->dma
= next_buffer
->dma
;
1351 next_buffer
->skb
= skb
;
1352 next_buffer
->dma
= 0;
1354 skb
->next
= next_buffer
->skb
;
1355 skb
->next
->prev
= skb
;
1357 rx_ring
->rx_stats
.non_eop_descs
++;
1362 skb
= ixgbe_transform_rsc_queue(skb
);
1363 /* if we got here without RSC the packet is invalid */
1365 __pskb_trim(skb
, 0);
1366 rx_buffer_info
->skb
= skb
;
1371 if (ring_is_rsc_enabled(rx_ring
)) {
1372 if (IXGBE_RSC_CB(skb
)->delay_unmap
) {
1373 dma_unmap_single(rx_ring
->dev
,
1374 IXGBE_RSC_CB(skb
)->dma
,
1375 rx_ring
->rx_buf_len
,
1377 IXGBE_RSC_CB(skb
)->dma
= 0;
1378 IXGBE_RSC_CB(skb
)->delay_unmap
= false;
1382 if (ring_is_ps_enabled(rx_ring
))
1383 rx_ring
->rx_stats
.rsc_count
+=
1384 skb_shinfo(skb
)->nr_frags
;
1386 rx_ring
->rx_stats
.rsc_count
+=
1387 IXGBE_RSC_CB(skb
)->skb_cnt
;
1388 rx_ring
->rx_stats
.rsc_flush
++;
1391 /* ERR_MASK will only have valid bits if EOP set */
1392 if (unlikely(staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
)) {
1393 dev_kfree_skb_any(skb
);
1397 ixgbe_rx_checksum(adapter
, rx_desc
, skb
, staterr
);
1398 if (adapter
->netdev
->features
& NETIF_F_RXHASH
)
1399 ixgbe_rx_hash(rx_desc
, skb
);
1401 /* probably a little skewed due to removing CRC */
1402 total_rx_bytes
+= skb
->len
;
1405 skb
->protocol
= eth_type_trans(skb
, rx_ring
->netdev
);
1407 /* if ddp, not passing to ULD unless for FCP_RSP or error */
1408 if (ixgbe_rx_is_fcoe(adapter
, rx_desc
)) {
1409 ddp_bytes
= ixgbe_fcoe_ddp(adapter
, rx_desc
, skb
,
1412 dev_kfree_skb_any(skb
);
1416 #endif /* IXGBE_FCOE */
1417 ixgbe_receive_skb(q_vector
, skb
, staterr
, rx_ring
, rx_desc
);
1421 rx_desc
->wb
.upper
.status_error
= 0;
1426 /* return some buffers to hardware, one at a time is too slow */
1427 if (cleaned_count
>= IXGBE_RX_BUFFER_WRITE
) {
1428 ixgbe_alloc_rx_buffers(rx_ring
, cleaned_count
);
1432 /* use prefetched values */
1434 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1437 rx_ring
->next_to_clean
= i
;
1438 cleaned_count
= ixgbe_desc_unused(rx_ring
);
1441 ixgbe_alloc_rx_buffers(rx_ring
, cleaned_count
);
1444 /* include DDPed FCoE data */
1445 if (ddp_bytes
> 0) {
1448 mss
= rx_ring
->netdev
->mtu
- sizeof(struct fcoe_hdr
) -
1449 sizeof(struct fc_frame_header
) -
1450 sizeof(struct fcoe_crc_eof
);
1453 total_rx_bytes
+= ddp_bytes
;
1454 total_rx_packets
+= DIV_ROUND_UP(ddp_bytes
, mss
);
1456 #endif /* IXGBE_FCOE */
1458 u64_stats_update_begin(&rx_ring
->syncp
);
1459 rx_ring
->stats
.packets
+= total_rx_packets
;
1460 rx_ring
->stats
.bytes
+= total_rx_bytes
;
1461 u64_stats_update_end(&rx_ring
->syncp
);
1462 q_vector
->rx
.total_packets
+= total_rx_packets
;
1463 q_vector
->rx
.total_bytes
+= total_rx_bytes
;
1469 * ixgbe_configure_msix - Configure MSI-X hardware
1470 * @adapter: board private structure
1472 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1475 static void ixgbe_configure_msix(struct ixgbe_adapter
*adapter
)
1477 struct ixgbe_q_vector
*q_vector
;
1478 int q_vectors
, v_idx
;
1481 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1483 /* Populate MSIX to EITR Select */
1484 if (adapter
->num_vfs
> 32) {
1485 u32 eitrsel
= (1 << (adapter
->num_vfs
- 32)) - 1;
1486 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, eitrsel
);
1490 * Populate the IVAR table and set the ITR values to the
1491 * corresponding register.
1493 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
1494 struct ixgbe_ring
*ring
;
1495 q_vector
= adapter
->q_vector
[v_idx
];
1497 for (ring
= q_vector
->rx
.ring
; ring
!= NULL
; ring
= ring
->next
)
1498 ixgbe_set_ivar(adapter
, 0, ring
->reg_idx
, v_idx
);
1500 for (ring
= q_vector
->tx
.ring
; ring
!= NULL
; ring
= ring
->next
)
1501 ixgbe_set_ivar(adapter
, 1, ring
->reg_idx
, v_idx
);
1503 if (q_vector
->tx
.ring
&& !q_vector
->rx
.ring
) {
1504 /* tx only vector */
1505 if (adapter
->tx_itr_setting
== 1)
1506 q_vector
->itr
= IXGBE_10K_ITR
;
1508 q_vector
->itr
= adapter
->tx_itr_setting
;
1510 /* rx or rx/tx vector */
1511 if (adapter
->rx_itr_setting
== 1)
1512 q_vector
->itr
= IXGBE_20K_ITR
;
1514 q_vector
->itr
= adapter
->rx_itr_setting
;
1517 ixgbe_write_eitr(q_vector
);
1520 switch (adapter
->hw
.mac
.type
) {
1521 case ixgbe_mac_82598EB
:
1522 ixgbe_set_ivar(adapter
, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX
,
1525 case ixgbe_mac_82599EB
:
1526 case ixgbe_mac_X540
:
1527 ixgbe_set_ivar(adapter
, -1, 1, v_idx
);
1532 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITR(v_idx
), 1950);
1534 /* set up to autoclear timer, and the vectors */
1535 mask
= IXGBE_EIMS_ENABLE_MASK
;
1536 mask
&= ~(IXGBE_EIMS_OTHER
|
1537 IXGBE_EIMS_MAILBOX
|
1540 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIAC
, mask
);
1543 enum latency_range
{
1547 latency_invalid
= 255
1551 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1552 * @q_vector: structure containing interrupt and ring information
1553 * @ring_container: structure containing ring performance data
1555 * Stores a new ITR value based on packets and byte
1556 * counts during the last interrupt. The advantage of per interrupt
1557 * computation is faster updates and more accurate ITR for the current
1558 * traffic pattern. Constants in this function were computed
1559 * based on theoretical maximum wire speed and thresholds were set based
1560 * on testing data as well as attempting to minimize response time
1561 * while increasing bulk throughput.
1562 * this functionality is controlled by the InterruptThrottleRate module
1563 * parameter (see ixgbe_param.c)
1565 static void ixgbe_update_itr(struct ixgbe_q_vector
*q_vector
,
1566 struct ixgbe_ring_container
*ring_container
)
1569 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1570 int bytes
= ring_container
->total_bytes
;
1571 int packets
= ring_container
->total_packets
;
1573 u8 itr_setting
= ring_container
->itr
;
1578 /* simple throttlerate management
1579 * 0-20MB/s lowest (100000 ints/s)
1580 * 20-100MB/s low (20000 ints/s)
1581 * 100-1249MB/s bulk (8000 ints/s)
1583 /* what was last interrupt timeslice? */
1584 timepassed_us
= q_vector
->itr
>> 2;
1585 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
1587 switch (itr_setting
) {
1588 case lowest_latency
:
1589 if (bytes_perint
> adapter
->eitr_low
)
1590 itr_setting
= low_latency
;
1593 if (bytes_perint
> adapter
->eitr_high
)
1594 itr_setting
= bulk_latency
;
1595 else if (bytes_perint
<= adapter
->eitr_low
)
1596 itr_setting
= lowest_latency
;
1599 if (bytes_perint
<= adapter
->eitr_high
)
1600 itr_setting
= low_latency
;
1604 /* clear work counters since we have the values we need */
1605 ring_container
->total_bytes
= 0;
1606 ring_container
->total_packets
= 0;
1608 /* write updated itr to ring container */
1609 ring_container
->itr
= itr_setting
;
1613 * ixgbe_write_eitr - write EITR register in hardware specific way
1614 * @q_vector: structure containing interrupt and ring information
1616 * This function is made to be called by ethtool and by the driver
1617 * when it needs to update EITR registers at runtime. Hardware
1618 * specific quirks/differences are taken care of here.
1620 void ixgbe_write_eitr(struct ixgbe_q_vector
*q_vector
)
1622 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1623 struct ixgbe_hw
*hw
= &adapter
->hw
;
1624 int v_idx
= q_vector
->v_idx
;
1625 u32 itr_reg
= q_vector
->itr
;
1627 switch (adapter
->hw
.mac
.type
) {
1628 case ixgbe_mac_82598EB
:
1629 /* must write high and low 16 bits to reset counter */
1630 itr_reg
|= (itr_reg
<< 16);
1632 case ixgbe_mac_82599EB
:
1633 case ixgbe_mac_X540
:
1635 * set the WDIS bit to not clear the timer bits and cause an
1636 * immediate assertion of the interrupt
1638 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
1643 IXGBE_WRITE_REG(hw
, IXGBE_EITR(v_idx
), itr_reg
);
1646 static void ixgbe_set_itr(struct ixgbe_q_vector
*q_vector
)
1648 u32 new_itr
= q_vector
->itr
;
1651 ixgbe_update_itr(q_vector
, &q_vector
->tx
);
1652 ixgbe_update_itr(q_vector
, &q_vector
->rx
);
1654 current_itr
= max(q_vector
->rx
.itr
, q_vector
->tx
.itr
);
1656 switch (current_itr
) {
1657 /* counts and packets in update_itr are dependent on these numbers */
1658 case lowest_latency
:
1659 new_itr
= IXGBE_100K_ITR
;
1662 new_itr
= IXGBE_20K_ITR
;
1665 new_itr
= IXGBE_8K_ITR
;
1671 if (new_itr
!= q_vector
->itr
) {
1672 /* do an exponential smoothing */
1673 new_itr
= (10 * new_itr
* q_vector
->itr
) /
1674 ((9 * new_itr
) + q_vector
->itr
);
1676 /* save the algorithm value here */
1677 q_vector
->itr
= new_itr
& IXGBE_MAX_EITR
;
1679 ixgbe_write_eitr(q_vector
);
1684 * ixgbe_check_overtemp_subtask - check for over tempurature
1685 * @adapter: pointer to adapter
1687 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter
*adapter
)
1689 struct ixgbe_hw
*hw
= &adapter
->hw
;
1690 u32 eicr
= adapter
->interrupt_event
;
1692 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
1695 if (!(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) &&
1696 !(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_EVENT
))
1699 adapter
->flags2
&= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
1701 switch (hw
->device_id
) {
1702 case IXGBE_DEV_ID_82599_T3_LOM
:
1704 * Since the warning interrupt is for both ports
1705 * we don't have to check if:
1706 * - This interrupt wasn't for our port.
1707 * - We may have missed the interrupt so always have to
1708 * check if we got a LSC
1710 if (!(eicr
& IXGBE_EICR_GPI_SDP0
) &&
1711 !(eicr
& IXGBE_EICR_LSC
))
1714 if (!(eicr
& IXGBE_EICR_LSC
) && hw
->mac
.ops
.check_link
) {
1716 bool link_up
= false;
1718 hw
->mac
.ops
.check_link(hw
, &autoneg
, &link_up
, false);
1724 /* Check if this is not due to overtemp */
1725 if (hw
->phy
.ops
.check_overtemp(hw
) != IXGBE_ERR_OVERTEMP
)
1730 if (!(eicr
& IXGBE_EICR_GPI_SDP0
))
1735 "Network adapter has been stopped because it has over heated. "
1736 "Restart the computer. If the problem persists, "
1737 "power off the system and replace the adapter\n");
1739 adapter
->interrupt_event
= 0;
1742 static void ixgbe_check_fan_failure(struct ixgbe_adapter
*adapter
, u32 eicr
)
1744 struct ixgbe_hw
*hw
= &adapter
->hw
;
1746 if ((adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) &&
1747 (eicr
& IXGBE_EICR_GPI_SDP1
)) {
1748 e_crit(probe
, "Fan has stopped, replace the adapter\n");
1749 /* write to clear the interrupt */
1750 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1754 static void ixgbe_check_overtemp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
1756 if (!(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
))
1759 switch (adapter
->hw
.mac
.type
) {
1760 case ixgbe_mac_82599EB
:
1762 * Need to check link state so complete overtemp check
1765 if (((eicr
& IXGBE_EICR_GPI_SDP0
) || (eicr
& IXGBE_EICR_LSC
)) &&
1766 (!test_bit(__IXGBE_DOWN
, &adapter
->state
))) {
1767 adapter
->interrupt_event
= eicr
;
1768 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
1769 ixgbe_service_event_schedule(adapter
);
1773 case ixgbe_mac_X540
:
1774 if (!(eicr
& IXGBE_EICR_TS
))
1782 "Network adapter has been stopped because it has over heated. "
1783 "Restart the computer. If the problem persists, "
1784 "power off the system and replace the adapter\n");
1787 static void ixgbe_check_sfp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
1789 struct ixgbe_hw
*hw
= &adapter
->hw
;
1791 if (eicr
& IXGBE_EICR_GPI_SDP2
) {
1792 /* Clear the interrupt */
1793 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP2
);
1794 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1795 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
1796 ixgbe_service_event_schedule(adapter
);
1800 if (eicr
& IXGBE_EICR_GPI_SDP1
) {
1801 /* Clear the interrupt */
1802 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1803 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1804 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
1805 ixgbe_service_event_schedule(adapter
);
1810 static void ixgbe_check_lsc(struct ixgbe_adapter
*adapter
)
1812 struct ixgbe_hw
*hw
= &adapter
->hw
;
1815 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
1816 adapter
->link_check_timeout
= jiffies
;
1817 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1818 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_LSC
);
1819 IXGBE_WRITE_FLUSH(hw
);
1820 ixgbe_service_event_schedule(adapter
);
1824 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter
*adapter
,
1828 struct ixgbe_hw
*hw
= &adapter
->hw
;
1830 switch (hw
->mac
.type
) {
1831 case ixgbe_mac_82598EB
:
1832 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1833 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, mask
);
1835 case ixgbe_mac_82599EB
:
1836 case ixgbe_mac_X540
:
1837 mask
= (qmask
& 0xFFFFFFFF);
1839 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(0), mask
);
1840 mask
= (qmask
>> 32);
1842 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(1), mask
);
1847 /* skip the flush */
1850 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter
*adapter
,
1854 struct ixgbe_hw
*hw
= &adapter
->hw
;
1856 switch (hw
->mac
.type
) {
1857 case ixgbe_mac_82598EB
:
1858 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1859 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, mask
);
1861 case ixgbe_mac_82599EB
:
1862 case ixgbe_mac_X540
:
1863 mask
= (qmask
& 0xFFFFFFFF);
1865 IXGBE_WRITE_REG(hw
, IXGBE_EIMC_EX(0), mask
);
1866 mask
= (qmask
>> 32);
1868 IXGBE_WRITE_REG(hw
, IXGBE_EIMC_EX(1), mask
);
1873 /* skip the flush */
1877 * ixgbe_irq_enable - Enable default interrupt generation settings
1878 * @adapter: board private structure
1880 static inline void ixgbe_irq_enable(struct ixgbe_adapter
*adapter
, bool queues
,
1883 u32 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
1885 /* don't reenable LSC while waiting for link */
1886 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
)
1887 mask
&= ~IXGBE_EIMS_LSC
;
1889 if (adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
)
1890 switch (adapter
->hw
.mac
.type
) {
1891 case ixgbe_mac_82599EB
:
1892 mask
|= IXGBE_EIMS_GPI_SDP0
;
1894 case ixgbe_mac_X540
:
1895 mask
|= IXGBE_EIMS_TS
;
1900 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
1901 mask
|= IXGBE_EIMS_GPI_SDP1
;
1902 switch (adapter
->hw
.mac
.type
) {
1903 case ixgbe_mac_82599EB
:
1904 mask
|= IXGBE_EIMS_GPI_SDP1
;
1905 mask
|= IXGBE_EIMS_GPI_SDP2
;
1906 case ixgbe_mac_X540
:
1907 mask
|= IXGBE_EIMS_ECC
;
1908 mask
|= IXGBE_EIMS_MAILBOX
;
1913 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) &&
1914 !(adapter
->flags2
& IXGBE_FLAG2_FDIR_REQUIRES_REINIT
))
1915 mask
|= IXGBE_EIMS_FLOW_DIR
;
1917 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
1919 ixgbe_irq_enable_queues(adapter
, ~0);
1921 IXGBE_WRITE_FLUSH(&adapter
->hw
);
1924 static irqreturn_t
ixgbe_msix_other(int irq
, void *data
)
1926 struct ixgbe_adapter
*adapter
= data
;
1927 struct ixgbe_hw
*hw
= &adapter
->hw
;
1931 * Workaround for Silicon errata. Use clear-by-write instead
1932 * of clear-by-read. Reading with EICS will return the
1933 * interrupt causes without clearing, which later be done
1934 * with the write to EICR.
1936 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICS
);
1937 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr
);
1939 if (eicr
& IXGBE_EICR_LSC
)
1940 ixgbe_check_lsc(adapter
);
1942 if (eicr
& IXGBE_EICR_MAILBOX
)
1943 ixgbe_msg_task(adapter
);
1945 switch (hw
->mac
.type
) {
1946 case ixgbe_mac_82599EB
:
1947 case ixgbe_mac_X540
:
1948 if (eicr
& IXGBE_EICR_ECC
)
1949 e_info(link
, "Received unrecoverable ECC Err, please "
1951 /* Handle Flow Director Full threshold interrupt */
1952 if (eicr
& IXGBE_EICR_FLOW_DIR
) {
1953 int reinit_count
= 0;
1955 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1956 struct ixgbe_ring
*ring
= adapter
->tx_ring
[i
];
1957 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE
,
1962 /* no more flow director interrupts until after init */
1963 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_FLOW_DIR
);
1964 adapter
->flags2
|= IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
1965 ixgbe_service_event_schedule(adapter
);
1968 ixgbe_check_sfp_event(adapter
, eicr
);
1969 ixgbe_check_overtemp_event(adapter
, eicr
);
1975 ixgbe_check_fan_failure(adapter
, eicr
);
1977 /* re-enable the original interrupt state, no lsc, no queues */
1978 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1979 ixgbe_irq_enable(adapter
, false, false);
1984 static irqreturn_t
ixgbe_msix_clean_rings(int irq
, void *data
)
1986 struct ixgbe_q_vector
*q_vector
= data
;
1988 /* EIAM disabled interrupts (on this vector) for us */
1990 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
1991 napi_schedule(&q_vector
->napi
);
1996 static inline void map_vector_to_rxq(struct ixgbe_adapter
*a
, int v_idx
,
1999 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
2000 struct ixgbe_ring
*rx_ring
= a
->rx_ring
[r_idx
];
2002 rx_ring
->q_vector
= q_vector
;
2003 rx_ring
->next
= q_vector
->rx
.ring
;
2004 q_vector
->rx
.ring
= rx_ring
;
2005 q_vector
->rx
.count
++;
2008 static inline void map_vector_to_txq(struct ixgbe_adapter
*a
, int v_idx
,
2011 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
2012 struct ixgbe_ring
*tx_ring
= a
->tx_ring
[t_idx
];
2014 tx_ring
->q_vector
= q_vector
;
2015 tx_ring
->next
= q_vector
->tx
.ring
;
2016 q_vector
->tx
.ring
= tx_ring
;
2017 q_vector
->tx
.count
++;
2018 q_vector
->tx
.work_limit
= a
->tx_work_limit
;
2022 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2023 * @adapter: board private structure to initialize
2025 * This function maps descriptor rings to the queue-specific vectors
2026 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2027 * one vector per ring/queue, but on a constrained vector budget, we
2028 * group the rings as "efficiently" as possible. You would add new
2029 * mapping configurations in here.
2031 static void ixgbe_map_rings_to_vectors(struct ixgbe_adapter
*adapter
)
2033 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2034 int rxr_remaining
= adapter
->num_rx_queues
, rxr_idx
= 0;
2035 int txr_remaining
= adapter
->num_tx_queues
, txr_idx
= 0;
2038 /* only one q_vector if MSI-X is disabled. */
2039 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
2043 * If we don't have enough vectors for a 1-to-1 mapping, we'll have to
2044 * group them so there are multiple queues per vector.
2046 * Re-adjusting *qpv takes care of the remainder.
2048 for (; v_start
< q_vectors
&& rxr_remaining
; v_start
++) {
2049 int rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- v_start
);
2050 for (; rqpv
; rqpv
--, rxr_idx
++, rxr_remaining
--)
2051 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
2055 * If there are not enough q_vectors for each ring to have it's own
2056 * vector then we must pair up Rx/Tx on a each vector
2058 if ((v_start
+ txr_remaining
) > q_vectors
)
2061 for (; v_start
< q_vectors
&& txr_remaining
; v_start
++) {
2062 int tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- v_start
);
2063 for (; tqpv
; tqpv
--, txr_idx
++, txr_remaining
--)
2064 map_vector_to_txq(adapter
, v_start
, txr_idx
);
2069 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2070 * @adapter: board private structure
2072 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2073 * interrupts from the kernel.
2075 static int ixgbe_request_msix_irqs(struct ixgbe_adapter
*adapter
)
2077 struct net_device
*netdev
= adapter
->netdev
;
2078 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2082 for (vector
= 0; vector
< q_vectors
; vector
++) {
2083 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[vector
];
2084 struct msix_entry
*entry
= &adapter
->msix_entries
[vector
];
2086 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
2087 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2088 "%s-%s-%d", netdev
->name
, "TxRx", ri
++);
2090 } else if (q_vector
->rx
.ring
) {
2091 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2092 "%s-%s-%d", netdev
->name
, "rx", ri
++);
2093 } else if (q_vector
->tx
.ring
) {
2094 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2095 "%s-%s-%d", netdev
->name
, "tx", ti
++);
2097 /* skip this unused q_vector */
2100 err
= request_irq(entry
->vector
, &ixgbe_msix_clean_rings
, 0,
2101 q_vector
->name
, q_vector
);
2103 e_err(probe
, "request_irq failed for MSIX interrupt "
2104 "Error: %d\n", err
);
2105 goto free_queue_irqs
;
2107 /* If Flow Director is enabled, set interrupt affinity */
2108 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
2109 /* assign the mask for this irq */
2110 irq_set_affinity_hint(entry
->vector
,
2111 q_vector
->affinity_mask
);
2115 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
2116 ixgbe_msix_other
, 0, netdev
->name
, adapter
);
2118 e_err(probe
, "request_irq for msix_lsc failed: %d\n", err
);
2119 goto free_queue_irqs
;
2127 irq_set_affinity_hint(adapter
->msix_entries
[vector
].vector
,
2129 free_irq(adapter
->msix_entries
[vector
].vector
,
2130 adapter
->q_vector
[vector
]);
2132 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
2133 pci_disable_msix(adapter
->pdev
);
2134 kfree(adapter
->msix_entries
);
2135 adapter
->msix_entries
= NULL
;
2140 * ixgbe_intr - legacy mode Interrupt Handler
2141 * @irq: interrupt number
2142 * @data: pointer to a network interface device structure
2144 static irqreturn_t
ixgbe_intr(int irq
, void *data
)
2146 struct ixgbe_adapter
*adapter
= data
;
2147 struct ixgbe_hw
*hw
= &adapter
->hw
;
2148 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
2152 * Workaround for silicon errata on 82598. Mask the interrupts
2153 * before the read of EICR.
2155 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_IRQ_CLEAR_MASK
);
2157 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2158 * therefore no explict interrupt disable is necessary */
2159 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
2162 * shared interrupt alert!
2163 * make sure interrupts are enabled because the read will
2164 * have disabled interrupts due to EIAM
2165 * finish the workaround of silicon errata on 82598. Unmask
2166 * the interrupt that we masked before the EICR read.
2168 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2169 ixgbe_irq_enable(adapter
, true, true);
2170 return IRQ_NONE
; /* Not our interrupt */
2173 if (eicr
& IXGBE_EICR_LSC
)
2174 ixgbe_check_lsc(adapter
);
2176 switch (hw
->mac
.type
) {
2177 case ixgbe_mac_82599EB
:
2178 case ixgbe_mac_X540
:
2179 ixgbe_check_sfp_event(adapter
, eicr
);
2180 ixgbe_check_overtemp_event(adapter
, eicr
);
2186 ixgbe_check_fan_failure(adapter
, eicr
);
2188 if (napi_schedule_prep(&(q_vector
->napi
))) {
2189 /* would disable interrupts here but EIAM disabled it */
2190 __napi_schedule(&(q_vector
->napi
));
2194 * re-enable link(maybe) and non-queue interrupts, no flush.
2195 * ixgbe_poll will re-enable the queue interrupts
2198 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2199 ixgbe_irq_enable(adapter
, false, false);
2204 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter
*adapter
)
2206 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2209 /* legacy and MSI only use one vector */
2210 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
2213 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2214 adapter
->rx_ring
[i
]->q_vector
= NULL
;
2215 adapter
->rx_ring
[i
]->next
= NULL
;
2217 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2218 adapter
->tx_ring
[i
]->q_vector
= NULL
;
2219 adapter
->tx_ring
[i
]->next
= NULL
;
2222 for (i
= 0; i
< q_vectors
; i
++) {
2223 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
2224 memset(&q_vector
->rx
, 0, sizeof(struct ixgbe_ring_container
));
2225 memset(&q_vector
->tx
, 0, sizeof(struct ixgbe_ring_container
));
2230 * ixgbe_request_irq - initialize interrupts
2231 * @adapter: board private structure
2233 * Attempts to configure interrupts using the best available
2234 * capabilities of the hardware and kernel.
2236 static int ixgbe_request_irq(struct ixgbe_adapter
*adapter
)
2238 struct net_device
*netdev
= adapter
->netdev
;
2241 /* map all of the rings to the q_vectors */
2242 ixgbe_map_rings_to_vectors(adapter
);
2244 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
2245 err
= ixgbe_request_msix_irqs(adapter
);
2246 else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
)
2247 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, 0,
2248 netdev
->name
, adapter
);
2250 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, IRQF_SHARED
,
2251 netdev
->name
, adapter
);
2254 e_err(probe
, "request_irq failed, Error %d\n", err
);
2256 /* place q_vectors and rings back into a known good state */
2257 ixgbe_reset_q_vectors(adapter
);
2263 static void ixgbe_free_irq(struct ixgbe_adapter
*adapter
)
2265 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2268 q_vectors
= adapter
->num_msix_vectors
;
2270 free_irq(adapter
->msix_entries
[i
].vector
, adapter
);
2273 for (; i
>= 0; i
--) {
2274 /* free only the irqs that were actually requested */
2275 if (!adapter
->q_vector
[i
]->rx
.ring
&&
2276 !adapter
->q_vector
[i
]->tx
.ring
)
2279 /* clear the affinity_mask in the IRQ descriptor */
2280 irq_set_affinity_hint(adapter
->msix_entries
[i
].vector
,
2283 free_irq(adapter
->msix_entries
[i
].vector
,
2284 adapter
->q_vector
[i
]);
2287 free_irq(adapter
->pdev
->irq
, adapter
);
2290 /* clear q_vector state information */
2291 ixgbe_reset_q_vectors(adapter
);
2295 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2296 * @adapter: board private structure
2298 static inline void ixgbe_irq_disable(struct ixgbe_adapter
*adapter
)
2300 switch (adapter
->hw
.mac
.type
) {
2301 case ixgbe_mac_82598EB
:
2302 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
2304 case ixgbe_mac_82599EB
:
2305 case ixgbe_mac_X540
:
2306 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, 0xFFFF0000);
2307 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), ~0);
2308 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), ~0);
2313 IXGBE_WRITE_FLUSH(&adapter
->hw
);
2314 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2316 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
2317 synchronize_irq(adapter
->msix_entries
[i
].vector
);
2319 synchronize_irq(adapter
->pdev
->irq
);
2324 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2327 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter
*adapter
)
2329 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
2332 if (adapter
->rx_itr_setting
== 1)
2333 q_vector
->itr
= IXGBE_20K_ITR
;
2335 q_vector
->itr
= adapter
->rx_itr_setting
;
2337 ixgbe_write_eitr(q_vector
);
2339 ixgbe_set_ivar(adapter
, 0, 0, 0);
2340 ixgbe_set_ivar(adapter
, 1, 0, 0);
2342 e_info(hw
, "Legacy interrupt IVAR setup done\n");
2346 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2347 * @adapter: board private structure
2348 * @ring: structure containing ring specific data
2350 * Configure the Tx descriptor ring after a reset.
2352 void ixgbe_configure_tx_ring(struct ixgbe_adapter
*adapter
,
2353 struct ixgbe_ring
*ring
)
2355 struct ixgbe_hw
*hw
= &adapter
->hw
;
2356 u64 tdba
= ring
->dma
;
2358 u32 txdctl
= IXGBE_TXDCTL_ENABLE
;
2359 u8 reg_idx
= ring
->reg_idx
;
2361 /* disable queue to avoid issues while updating state */
2362 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), 0);
2363 IXGBE_WRITE_FLUSH(hw
);
2365 IXGBE_WRITE_REG(hw
, IXGBE_TDBAL(reg_idx
),
2366 (tdba
& DMA_BIT_MASK(32)));
2367 IXGBE_WRITE_REG(hw
, IXGBE_TDBAH(reg_idx
), (tdba
>> 32));
2368 IXGBE_WRITE_REG(hw
, IXGBE_TDLEN(reg_idx
),
2369 ring
->count
* sizeof(union ixgbe_adv_tx_desc
));
2370 IXGBE_WRITE_REG(hw
, IXGBE_TDH(reg_idx
), 0);
2371 IXGBE_WRITE_REG(hw
, IXGBE_TDT(reg_idx
), 0);
2372 ring
->tail
= hw
->hw_addr
+ IXGBE_TDT(reg_idx
);
2375 * set WTHRESH to encourage burst writeback, it should not be set
2376 * higher than 1 when ITR is 0 as it could cause false TX hangs
2378 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2379 * to or less than the number of on chip descriptors, which is
2382 if (!adapter
->tx_itr_setting
|| !adapter
->rx_itr_setting
)
2383 txdctl
|= (1 << 16); /* WTHRESH = 1 */
2385 txdctl
|= (8 << 16); /* WTHRESH = 8 */
2387 /* PTHRESH=32 is needed to avoid a Tx hang with DFP enabled. */
2388 txdctl
|= (1 << 8) | /* HTHRESH = 1 */
2389 32; /* PTHRESH = 32 */
2391 /* reinitialize flowdirector state */
2392 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) &&
2393 adapter
->atr_sample_rate
) {
2394 ring
->atr_sample_rate
= adapter
->atr_sample_rate
;
2395 ring
->atr_count
= 0;
2396 set_bit(__IXGBE_TX_FDIR_INIT_DONE
, &ring
->state
);
2398 ring
->atr_sample_rate
= 0;
2401 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &ring
->state
);
2404 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), txdctl
);
2406 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2407 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
2408 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
2411 /* poll to verify queue is enabled */
2413 usleep_range(1000, 2000);
2414 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(reg_idx
));
2415 } while (--wait_loop
&& !(txdctl
& IXGBE_TXDCTL_ENABLE
));
2417 e_err(drv
, "Could not enable Tx Queue %d\n", reg_idx
);
2420 static void ixgbe_setup_mtqc(struct ixgbe_adapter
*adapter
)
2422 struct ixgbe_hw
*hw
= &adapter
->hw
;
2425 u8 tcs
= netdev_get_num_tc(adapter
->netdev
);
2427 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2430 /* disable the arbiter while setting MTQC */
2431 rttdcs
= IXGBE_READ_REG(hw
, IXGBE_RTTDCS
);
2432 rttdcs
|= IXGBE_RTTDCS_ARBDIS
;
2433 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
2435 /* set transmit pool layout */
2436 switch (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
2437 case (IXGBE_FLAG_SRIOV_ENABLED
):
2438 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
,
2439 (IXGBE_MTQC_VT_ENA
| IXGBE_MTQC_64VF
));
2443 reg
= IXGBE_MTQC_64Q_1PB
;
2445 reg
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
2447 reg
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
;
2449 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
, reg
);
2451 /* Enable Security TX Buffer IFG for multiple pb */
2453 reg
= IXGBE_READ_REG(hw
, IXGBE_SECTXMINIFG
);
2454 reg
|= IXGBE_SECTX_DCB
;
2455 IXGBE_WRITE_REG(hw
, IXGBE_SECTXMINIFG
, reg
);
2460 /* re-enable the arbiter */
2461 rttdcs
&= ~IXGBE_RTTDCS_ARBDIS
;
2462 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
2466 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
2467 * @adapter: board private structure
2469 * Configure the Tx unit of the MAC after a reset.
2471 static void ixgbe_configure_tx(struct ixgbe_adapter
*adapter
)
2473 struct ixgbe_hw
*hw
= &adapter
->hw
;
2477 ixgbe_setup_mtqc(adapter
);
2479 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
2480 /* DMATXCTL.EN must be before Tx queues are enabled */
2481 dmatxctl
= IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
);
2482 dmatxctl
|= IXGBE_DMATXCTL_TE
;
2483 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
, dmatxctl
);
2486 /* Setup the HW Tx Head and Tail descriptor pointers */
2487 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2488 ixgbe_configure_tx_ring(adapter
, adapter
->tx_ring
[i
]);
2491 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
2493 static void ixgbe_configure_srrctl(struct ixgbe_adapter
*adapter
,
2494 struct ixgbe_ring
*rx_ring
)
2497 u8 reg_idx
= rx_ring
->reg_idx
;
2499 switch (adapter
->hw
.mac
.type
) {
2500 case ixgbe_mac_82598EB
: {
2501 struct ixgbe_ring_feature
*feature
= adapter
->ring_feature
;
2502 const int mask
= feature
[RING_F_RSS
].mask
;
2503 reg_idx
= reg_idx
& mask
;
2506 case ixgbe_mac_82599EB
:
2507 case ixgbe_mac_X540
:
2512 srrctl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SRRCTL(reg_idx
));
2514 srrctl
&= ~IXGBE_SRRCTL_BSIZEHDR_MASK
;
2515 srrctl
&= ~IXGBE_SRRCTL_BSIZEPKT_MASK
;
2516 if (adapter
->num_vfs
)
2517 srrctl
|= IXGBE_SRRCTL_DROP_EN
;
2519 srrctl
|= (IXGBE_RX_HDR_SIZE
<< IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
2520 IXGBE_SRRCTL_BSIZEHDR_MASK
;
2522 if (ring_is_ps_enabled(rx_ring
)) {
2523 #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2524 srrctl
|= IXGBE_MAX_RXBUFFER
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
2526 srrctl
|= (PAGE_SIZE
/ 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
2528 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
2530 srrctl
|= ALIGN(rx_ring
->rx_buf_len
, 1024) >>
2531 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
2532 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
2535 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
2538 static void ixgbe_setup_mrqc(struct ixgbe_adapter
*adapter
)
2540 struct ixgbe_hw
*hw
= &adapter
->hw
;
2541 static const u32 seed
[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2542 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2543 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2544 u32 mrqc
= 0, reta
= 0;
2547 u8 tcs
= netdev_get_num_tc(adapter
->netdev
);
2548 int maxq
= adapter
->ring_feature
[RING_F_RSS
].indices
;
2551 maxq
= min(maxq
, adapter
->num_tx_queues
/ tcs
);
2553 /* Fill out hash function seeds */
2554 for (i
= 0; i
< 10; i
++)
2555 IXGBE_WRITE_REG(hw
, IXGBE_RSSRK(i
), seed
[i
]);
2557 /* Fill out redirection table */
2558 for (i
= 0, j
= 0; i
< 128; i
++, j
++) {
2561 /* reta = 4-byte sliding window of
2562 * 0x00..(indices-1)(indices-1)00..etc. */
2563 reta
= (reta
<< 8) | (j
* 0x11);
2565 IXGBE_WRITE_REG(hw
, IXGBE_RETA(i
>> 2), reta
);
2568 /* Disable indicating checksum in descriptor, enables RSS hash */
2569 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
2570 rxcsum
|= IXGBE_RXCSUM_PCSD
;
2571 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
2573 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
&&
2574 (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
)) {
2575 mrqc
= IXGBE_MRQC_RSSEN
;
2577 int mask
= adapter
->flags
& (IXGBE_FLAG_RSS_ENABLED
2578 | IXGBE_FLAG_SRIOV_ENABLED
);
2581 case (IXGBE_FLAG_RSS_ENABLED
):
2583 mrqc
= IXGBE_MRQC_RSSEN
;
2585 mrqc
= IXGBE_MRQC_RTRSS4TCEN
;
2587 mrqc
= IXGBE_MRQC_RTRSS8TCEN
;
2589 case (IXGBE_FLAG_SRIOV_ENABLED
):
2590 mrqc
= IXGBE_MRQC_VMDQEN
;
2597 /* Perform hash on these packet types */
2598 mrqc
|= IXGBE_MRQC_RSS_FIELD_IPV4
2599 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2600 | IXGBE_MRQC_RSS_FIELD_IPV6
2601 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
;
2603 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
2607 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2608 * @adapter: address of board private structure
2609 * @index: index of ring to set
2611 static void ixgbe_configure_rscctl(struct ixgbe_adapter
*adapter
,
2612 struct ixgbe_ring
*ring
)
2614 struct ixgbe_hw
*hw
= &adapter
->hw
;
2617 u8 reg_idx
= ring
->reg_idx
;
2619 if (!ring_is_rsc_enabled(ring
))
2622 rx_buf_len
= ring
->rx_buf_len
;
2623 rscctrl
= IXGBE_READ_REG(hw
, IXGBE_RSCCTL(reg_idx
));
2624 rscctrl
|= IXGBE_RSCCTL_RSCEN
;
2626 * we must limit the number of descriptors so that the
2627 * total size of max desc * buf_len is not greater
2630 if (ring_is_ps_enabled(ring
)) {
2631 #if (MAX_SKB_FRAGS > 16)
2632 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2633 #elif (MAX_SKB_FRAGS > 8)
2634 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2635 #elif (MAX_SKB_FRAGS > 4)
2636 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2638 rscctrl
|= IXGBE_RSCCTL_MAXDESC_1
;
2641 if (rx_buf_len
< IXGBE_RXBUFFER_4K
)
2642 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2643 else if (rx_buf_len
< IXGBE_RXBUFFER_8K
)
2644 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2646 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2648 IXGBE_WRITE_REG(hw
, IXGBE_RSCCTL(reg_idx
), rscctrl
);
2652 * ixgbe_set_uta - Set unicast filter table address
2653 * @adapter: board private structure
2655 * The unicast table address is a register array of 32-bit registers.
2656 * The table is meant to be used in a way similar to how the MTA is used
2657 * however due to certain limitations in the hardware it is necessary to
2658 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2659 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2661 static void ixgbe_set_uta(struct ixgbe_adapter
*adapter
)
2663 struct ixgbe_hw
*hw
= &adapter
->hw
;
2666 /* The UTA table only exists on 82599 hardware and newer */
2667 if (hw
->mac
.type
< ixgbe_mac_82599EB
)
2670 /* we only need to do this if VMDq is enabled */
2671 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
2674 for (i
= 0; i
< 128; i
++)
2675 IXGBE_WRITE_REG(hw
, IXGBE_UTA(i
), ~0);
2678 #define IXGBE_MAX_RX_DESC_POLL 10
2679 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter
*adapter
,
2680 struct ixgbe_ring
*ring
)
2682 struct ixgbe_hw
*hw
= &adapter
->hw
;
2683 int wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
2685 u8 reg_idx
= ring
->reg_idx
;
2687 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2688 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
2689 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
2693 usleep_range(1000, 2000);
2694 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
2695 } while (--wait_loop
&& !(rxdctl
& IXGBE_RXDCTL_ENABLE
));
2698 e_err(drv
, "RXDCTL.ENABLE on Rx queue %d not set within "
2699 "the polling period\n", reg_idx
);
2703 void ixgbe_disable_rx_queue(struct ixgbe_adapter
*adapter
,
2704 struct ixgbe_ring
*ring
)
2706 struct ixgbe_hw
*hw
= &adapter
->hw
;
2707 int wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
2709 u8 reg_idx
= ring
->reg_idx
;
2711 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
2712 rxdctl
&= ~IXGBE_RXDCTL_ENABLE
;
2714 /* write value back with RXDCTL.ENABLE bit cleared */
2715 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
2717 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
2718 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
2721 /* the hardware may take up to 100us to really disable the rx queue */
2724 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
2725 } while (--wait_loop
&& (rxdctl
& IXGBE_RXDCTL_ENABLE
));
2728 e_err(drv
, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2729 "the polling period\n", reg_idx
);
2733 void ixgbe_configure_rx_ring(struct ixgbe_adapter
*adapter
,
2734 struct ixgbe_ring
*ring
)
2736 struct ixgbe_hw
*hw
= &adapter
->hw
;
2737 u64 rdba
= ring
->dma
;
2739 u8 reg_idx
= ring
->reg_idx
;
2741 /* disable queue to avoid issues while updating state */
2742 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
2743 ixgbe_disable_rx_queue(adapter
, ring
);
2745 IXGBE_WRITE_REG(hw
, IXGBE_RDBAL(reg_idx
), (rdba
& DMA_BIT_MASK(32)));
2746 IXGBE_WRITE_REG(hw
, IXGBE_RDBAH(reg_idx
), (rdba
>> 32));
2747 IXGBE_WRITE_REG(hw
, IXGBE_RDLEN(reg_idx
),
2748 ring
->count
* sizeof(union ixgbe_adv_rx_desc
));
2749 IXGBE_WRITE_REG(hw
, IXGBE_RDH(reg_idx
), 0);
2750 IXGBE_WRITE_REG(hw
, IXGBE_RDT(reg_idx
), 0);
2751 ring
->tail
= hw
->hw_addr
+ IXGBE_RDT(reg_idx
);
2753 ixgbe_configure_srrctl(adapter
, ring
);
2754 ixgbe_configure_rscctl(adapter
, ring
);
2756 /* If operating in IOV mode set RLPML for X540 */
2757 if ((adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) &&
2758 hw
->mac
.type
== ixgbe_mac_X540
) {
2759 rxdctl
&= ~IXGBE_RXDCTL_RLPMLMASK
;
2760 rxdctl
|= ((ring
->netdev
->mtu
+ ETH_HLEN
+
2761 ETH_FCS_LEN
+ VLAN_HLEN
) | IXGBE_RXDCTL_RLPML_EN
);
2764 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
2766 * enable cache line friendly hardware writes:
2767 * PTHRESH=32 descriptors (half the internal cache),
2768 * this also removes ugly rx_no_buffer_count increment
2769 * HTHRESH=4 descriptors (to minimize latency on fetch)
2770 * WTHRESH=8 burst writeback up to two cache lines
2772 rxdctl
&= ~0x3FFFFF;
2776 /* enable receive descriptor ring */
2777 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
2778 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
2780 ixgbe_rx_desc_queue_enable(adapter
, ring
);
2781 ixgbe_alloc_rx_buffers(ring
, ixgbe_desc_unused(ring
));
2784 static void ixgbe_setup_psrtype(struct ixgbe_adapter
*adapter
)
2786 struct ixgbe_hw
*hw
= &adapter
->hw
;
2789 /* PSRTYPE must be initialized in non 82598 adapters */
2790 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
2791 IXGBE_PSRTYPE_UDPHDR
|
2792 IXGBE_PSRTYPE_IPV4HDR
|
2793 IXGBE_PSRTYPE_L2HDR
|
2794 IXGBE_PSRTYPE_IPV6HDR
;
2796 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2799 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
)
2800 psrtype
|= (adapter
->num_rx_queues_per_pool
<< 29);
2802 for (p
= 0; p
< adapter
->num_rx_pools
; p
++)
2803 IXGBE_WRITE_REG(hw
, IXGBE_PSRTYPE(adapter
->num_vfs
+ p
),
2807 static void ixgbe_configure_virtualization(struct ixgbe_adapter
*adapter
)
2809 struct ixgbe_hw
*hw
= &adapter
->hw
;
2812 u32 reg_offset
, vf_shift
;
2815 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
2818 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VT_CTL
);
2819 vt_reg_bits
= IXGBE_VMD_CTL_VMDQ_EN
| IXGBE_VT_CTL_REPLEN
;
2820 vt_reg_bits
|= (adapter
->num_vfs
<< IXGBE_VT_CTL_POOL_SHIFT
);
2821 IXGBE_WRITE_REG(hw
, IXGBE_VT_CTL
, vmdctl
| vt_reg_bits
);
2823 vf_shift
= adapter
->num_vfs
% 32;
2824 reg_offset
= (adapter
->num_vfs
> 32) ? 1 : 0;
2826 /* Enable only the PF's pool for Tx/Rx */
2827 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
), (1 << vf_shift
));
2828 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
^ 1), 0);
2829 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
), (1 << vf_shift
));
2830 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
^ 1), 0);
2831 IXGBE_WRITE_REG(hw
, IXGBE_PFDTXGSWC
, IXGBE_PFDTXGSWC_VT_LBEN
);
2833 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
2834 hw
->mac
.ops
.set_vmdq(hw
, 0, adapter
->num_vfs
);
2837 * Set up VF register offsets for selected VT Mode,
2838 * i.e. 32 or 64 VFs for SR-IOV
2840 gcr_ext
= IXGBE_READ_REG(hw
, IXGBE_GCR_EXT
);
2841 gcr_ext
|= IXGBE_GCR_EXT_MSIX_EN
;
2842 gcr_ext
|= IXGBE_GCR_EXT_VT_MODE_64
;
2843 IXGBE_WRITE_REG(hw
, IXGBE_GCR_EXT
, gcr_ext
);
2845 /* enable Tx loopback for VF/PF communication */
2846 IXGBE_WRITE_REG(hw
, IXGBE_PFDTXGSWC
, IXGBE_PFDTXGSWC_VT_LBEN
);
2847 /* Enable MAC Anti-Spoofing */
2848 hw
->mac
.ops
.set_mac_anti_spoofing(hw
,
2849 (adapter
->antispoofing_enabled
=
2850 (adapter
->num_vfs
!= 0)),
2854 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter
*adapter
)
2856 struct ixgbe_hw
*hw
= &adapter
->hw
;
2857 struct net_device
*netdev
= adapter
->netdev
;
2858 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2860 struct ixgbe_ring
*rx_ring
;
2864 /* Decide whether to use packet split mode or not */
2866 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
2868 /* Do not use packet split if we're in SR-IOV Mode */
2869 if (adapter
->num_vfs
)
2870 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
2872 /* Disable packet split due to 82599 erratum #45 */
2873 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
2874 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
2877 /* adjust max frame to be able to do baby jumbo for FCoE */
2878 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
2879 (max_frame
< IXGBE_FCOE_JUMBO_FRAME_SIZE
))
2880 max_frame
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
2882 #endif /* IXGBE_FCOE */
2883 mhadd
= IXGBE_READ_REG(hw
, IXGBE_MHADD
);
2884 if (max_frame
!= (mhadd
>> IXGBE_MHADD_MFS_SHIFT
)) {
2885 mhadd
&= ~IXGBE_MHADD_MFS_MASK
;
2886 mhadd
|= max_frame
<< IXGBE_MHADD_MFS_SHIFT
;
2888 IXGBE_WRITE_REG(hw
, IXGBE_MHADD
, mhadd
);
2891 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
2892 max_frame
+= VLAN_HLEN
;
2894 /* Set the RX buffer length according to the mode */
2895 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
2896 rx_buf_len
= IXGBE_RX_HDR_SIZE
;
2898 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) &&
2899 (netdev
->mtu
<= ETH_DATA_LEN
))
2900 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
2902 * Make best use of allocation by using all but 1K of a
2903 * power of 2 allocation that will be used for skb->head.
2905 else if (max_frame
<= IXGBE_RXBUFFER_3K
)
2906 rx_buf_len
= IXGBE_RXBUFFER_3K
;
2907 else if (max_frame
<= IXGBE_RXBUFFER_7K
)
2908 rx_buf_len
= IXGBE_RXBUFFER_7K
;
2909 else if (max_frame
<= IXGBE_RXBUFFER_15K
)
2910 rx_buf_len
= IXGBE_RXBUFFER_15K
;
2912 rx_buf_len
= IXGBE_MAX_RXBUFFER
;
2915 hlreg0
= IXGBE_READ_REG(hw
, IXGBE_HLREG0
);
2916 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
2917 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
2918 IXGBE_WRITE_REG(hw
, IXGBE_HLREG0
, hlreg0
);
2921 * Setup the HW Rx Head and Tail Descriptor Pointers and
2922 * the Base and Length of the Rx Descriptor Ring
2924 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2925 rx_ring
= adapter
->rx_ring
[i
];
2926 rx_ring
->rx_buf_len
= rx_buf_len
;
2928 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)
2929 set_ring_ps_enabled(rx_ring
);
2931 clear_ring_ps_enabled(rx_ring
);
2933 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
2934 set_ring_rsc_enabled(rx_ring
);
2936 clear_ring_rsc_enabled(rx_ring
);
2939 if (netdev
->features
& NETIF_F_FCOE_MTU
) {
2940 struct ixgbe_ring_feature
*f
;
2941 f
= &adapter
->ring_feature
[RING_F_FCOE
];
2942 if ((i
>= f
->mask
) && (i
< f
->mask
+ f
->indices
)) {
2943 clear_ring_ps_enabled(rx_ring
);
2944 if (rx_buf_len
< IXGBE_FCOE_JUMBO_FRAME_SIZE
)
2945 rx_ring
->rx_buf_len
=
2946 IXGBE_FCOE_JUMBO_FRAME_SIZE
;
2947 } else if (!ring_is_rsc_enabled(rx_ring
) &&
2948 !ring_is_ps_enabled(rx_ring
)) {
2949 rx_ring
->rx_buf_len
=
2950 IXGBE_FCOE_JUMBO_FRAME_SIZE
;
2953 #endif /* IXGBE_FCOE */
2957 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter
*adapter
)
2959 struct ixgbe_hw
*hw
= &adapter
->hw
;
2960 u32 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
2962 switch (hw
->mac
.type
) {
2963 case ixgbe_mac_82598EB
:
2965 * For VMDq support of different descriptor types or
2966 * buffer sizes through the use of multiple SRRCTL
2967 * registers, RDRXCTL.MVMEN must be set to 1
2969 * also, the manual doesn't mention it clearly but DCA hints
2970 * will only use queue 0's tags unless this bit is set. Side
2971 * effects of setting this bit are only that SRRCTL must be
2972 * fully programmed [0..15]
2974 rdrxctl
|= IXGBE_RDRXCTL_MVMEN
;
2976 case ixgbe_mac_82599EB
:
2977 case ixgbe_mac_X540
:
2978 /* Disable RSC for ACK packets */
2979 IXGBE_WRITE_REG(hw
, IXGBE_RSCDBU
,
2980 (IXGBE_RSCDBU_RSCACKDIS
| IXGBE_READ_REG(hw
, IXGBE_RSCDBU
)));
2981 rdrxctl
&= ~IXGBE_RDRXCTL_RSCFRSTSIZE
;
2982 /* hardware requires some bits to be set by default */
2983 rdrxctl
|= (IXGBE_RDRXCTL_RSCACKC
| IXGBE_RDRXCTL_FCOE_WRFIX
);
2984 rdrxctl
|= IXGBE_RDRXCTL_CRCSTRIP
;
2987 /* We should do nothing since we don't know this hardware */
2991 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
2995 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
2996 * @adapter: board private structure
2998 * Configure the Rx unit of the MAC after a reset.
3000 static void ixgbe_configure_rx(struct ixgbe_adapter
*adapter
)
3002 struct ixgbe_hw
*hw
= &adapter
->hw
;
3006 /* disable receives while setting up the descriptors */
3007 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
3008 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
3010 ixgbe_setup_psrtype(adapter
);
3011 ixgbe_setup_rdrxctl(adapter
);
3013 /* Program registers for the distribution of queues */
3014 ixgbe_setup_mrqc(adapter
);
3016 ixgbe_set_uta(adapter
);
3018 /* set_rx_buffer_len must be called before ring initialization */
3019 ixgbe_set_rx_buffer_len(adapter
);
3022 * Setup the HW Rx Head and Tail Descriptor Pointers and
3023 * the Base and Length of the Rx Descriptor Ring
3025 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3026 ixgbe_configure_rx_ring(adapter
, adapter
->rx_ring
[i
]);
3028 /* disable drop enable for 82598 parts */
3029 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3030 rxctrl
|= IXGBE_RXCTRL_DMBYPS
;
3032 /* enable all receives */
3033 rxctrl
|= IXGBE_RXCTRL_RXEN
;
3034 hw
->mac
.ops
.enable_rx_dma(hw
, rxctrl
);
3037 static void ixgbe_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
3039 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3040 struct ixgbe_hw
*hw
= &adapter
->hw
;
3041 int pool_ndx
= adapter
->num_vfs
;
3043 /* add VID to filter table */
3044 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, pool_ndx
, true);
3045 set_bit(vid
, adapter
->active_vlans
);
3048 static void ixgbe_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
3050 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3051 struct ixgbe_hw
*hw
= &adapter
->hw
;
3052 int pool_ndx
= adapter
->num_vfs
;
3054 /* remove VID from filter table */
3055 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, pool_ndx
, false);
3056 clear_bit(vid
, adapter
->active_vlans
);
3060 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3061 * @adapter: driver data
3063 static void ixgbe_vlan_filter_disable(struct ixgbe_adapter
*adapter
)
3065 struct ixgbe_hw
*hw
= &adapter
->hw
;
3068 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
3069 vlnctrl
&= ~(IXGBE_VLNCTRL_VFE
| IXGBE_VLNCTRL_CFIEN
);
3070 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
3074 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3075 * @adapter: driver data
3077 static void ixgbe_vlan_filter_enable(struct ixgbe_adapter
*adapter
)
3079 struct ixgbe_hw
*hw
= &adapter
->hw
;
3082 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
3083 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
3084 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
3085 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
3089 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3090 * @adapter: driver data
3092 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter
*adapter
)
3094 struct ixgbe_hw
*hw
= &adapter
->hw
;
3098 switch (hw
->mac
.type
) {
3099 case ixgbe_mac_82598EB
:
3100 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
3101 vlnctrl
&= ~IXGBE_VLNCTRL_VME
;
3102 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
3104 case ixgbe_mac_82599EB
:
3105 case ixgbe_mac_X540
:
3106 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3107 j
= adapter
->rx_ring
[i
]->reg_idx
;
3108 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
3109 vlnctrl
&= ~IXGBE_RXDCTL_VME
;
3110 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
3119 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
3120 * @adapter: driver data
3122 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter
*adapter
)
3124 struct ixgbe_hw
*hw
= &adapter
->hw
;
3128 switch (hw
->mac
.type
) {
3129 case ixgbe_mac_82598EB
:
3130 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
3131 vlnctrl
|= IXGBE_VLNCTRL_VME
;
3132 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
3134 case ixgbe_mac_82599EB
:
3135 case ixgbe_mac_X540
:
3136 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3137 j
= adapter
->rx_ring
[i
]->reg_idx
;
3138 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
3139 vlnctrl
|= IXGBE_RXDCTL_VME
;
3140 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
3148 static void ixgbe_restore_vlan(struct ixgbe_adapter
*adapter
)
3152 ixgbe_vlan_rx_add_vid(adapter
->netdev
, 0);
3154 for_each_set_bit(vid
, adapter
->active_vlans
, VLAN_N_VID
)
3155 ixgbe_vlan_rx_add_vid(adapter
->netdev
, vid
);
3159 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3160 * @netdev: network interface device structure
3162 * Writes unicast address list to the RAR table.
3163 * Returns: -ENOMEM on failure/insufficient address space
3164 * 0 on no addresses written
3165 * X on writing X addresses to the RAR table
3167 static int ixgbe_write_uc_addr_list(struct net_device
*netdev
)
3169 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3170 struct ixgbe_hw
*hw
= &adapter
->hw
;
3171 unsigned int vfn
= adapter
->num_vfs
;
3172 unsigned int rar_entries
= IXGBE_MAX_PF_MACVLANS
;
3175 /* return ENOMEM indicating insufficient memory for addresses */
3176 if (netdev_uc_count(netdev
) > rar_entries
)
3179 if (!netdev_uc_empty(netdev
) && rar_entries
) {
3180 struct netdev_hw_addr
*ha
;
3181 /* return error if we do not support writing to RAR table */
3182 if (!hw
->mac
.ops
.set_rar
)
3185 netdev_for_each_uc_addr(ha
, netdev
) {
3188 hw
->mac
.ops
.set_rar(hw
, rar_entries
--, ha
->addr
,
3193 /* write the addresses in reverse order to avoid write combining */
3194 for (; rar_entries
> 0 ; rar_entries
--)
3195 hw
->mac
.ops
.clear_rar(hw
, rar_entries
);
3201 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
3202 * @netdev: network interface device structure
3204 * The set_rx_method entry point is called whenever the unicast/multicast
3205 * address list or the network interface flags are updated. This routine is
3206 * responsible for configuring the hardware for proper unicast, multicast and
3209 void ixgbe_set_rx_mode(struct net_device
*netdev
)
3211 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3212 struct ixgbe_hw
*hw
= &adapter
->hw
;
3213 u32 fctrl
, vmolr
= IXGBE_VMOLR_BAM
| IXGBE_VMOLR_AUPE
;
3216 /* Check for Promiscuous and All Multicast modes */
3218 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
3220 /* set all bits that we expect to always be set */
3221 fctrl
|= IXGBE_FCTRL_BAM
;
3222 fctrl
|= IXGBE_FCTRL_DPF
; /* discard pause frames when FC enabled */
3223 fctrl
|= IXGBE_FCTRL_PMCF
;
3225 /* clear the bits we are changing the status of */
3226 fctrl
&= ~(IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
3228 if (netdev
->flags
& IFF_PROMISC
) {
3229 hw
->addr_ctrl
.user_set_promisc
= true;
3230 fctrl
|= (IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
3231 vmolr
|= (IXGBE_VMOLR_ROPE
| IXGBE_VMOLR_MPE
);
3232 /* don't hardware filter vlans in promisc mode */
3233 ixgbe_vlan_filter_disable(adapter
);
3235 if (netdev
->flags
& IFF_ALLMULTI
) {
3236 fctrl
|= IXGBE_FCTRL_MPE
;
3237 vmolr
|= IXGBE_VMOLR_MPE
;
3240 * Write addresses to the MTA, if the attempt fails
3241 * then we should just turn on promiscuous mode so
3242 * that we can at least receive multicast traffic
3244 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
3245 vmolr
|= IXGBE_VMOLR_ROMPE
;
3247 ixgbe_vlan_filter_enable(adapter
);
3248 hw
->addr_ctrl
.user_set_promisc
= false;
3250 * Write addresses to available RAR registers, if there is not
3251 * sufficient space to store all the addresses then enable
3252 * unicast promiscuous mode
3254 count
= ixgbe_write_uc_addr_list(netdev
);
3256 fctrl
|= IXGBE_FCTRL_UPE
;
3257 vmolr
|= IXGBE_VMOLR_ROPE
;
3261 if (adapter
->num_vfs
) {
3262 ixgbe_restore_vf_multicasts(adapter
);
3263 vmolr
|= IXGBE_READ_REG(hw
, IXGBE_VMOLR(adapter
->num_vfs
)) &
3264 ~(IXGBE_VMOLR_MPE
| IXGBE_VMOLR_ROMPE
|
3266 IXGBE_WRITE_REG(hw
, IXGBE_VMOLR(adapter
->num_vfs
), vmolr
);
3269 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
3271 if (netdev
->features
& NETIF_F_HW_VLAN_RX
)
3272 ixgbe_vlan_strip_enable(adapter
);
3274 ixgbe_vlan_strip_disable(adapter
);
3277 static void ixgbe_napi_enable_all(struct ixgbe_adapter
*adapter
)
3280 struct ixgbe_q_vector
*q_vector
;
3281 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
3283 /* legacy and MSI only use one vector */
3284 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
3287 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
3288 q_vector
= adapter
->q_vector
[q_idx
];
3289 napi_enable(&q_vector
->napi
);
3293 static void ixgbe_napi_disable_all(struct ixgbe_adapter
*adapter
)
3296 struct ixgbe_q_vector
*q_vector
;
3297 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
3299 /* legacy and MSI only use one vector */
3300 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
3303 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
3304 q_vector
= adapter
->q_vector
[q_idx
];
3305 napi_disable(&q_vector
->napi
);
3309 #ifdef CONFIG_IXGBE_DCB
3311 * ixgbe_configure_dcb - Configure DCB hardware
3312 * @adapter: ixgbe adapter struct
3314 * This is called by the driver on open to configure the DCB hardware.
3315 * This is also called by the gennetlink interface when reconfiguring
3318 static void ixgbe_configure_dcb(struct ixgbe_adapter
*adapter
)
3320 struct ixgbe_hw
*hw
= &adapter
->hw
;
3321 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3323 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)) {
3324 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3325 netif_set_gso_max_size(adapter
->netdev
, 65536);
3329 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3330 netif_set_gso_max_size(adapter
->netdev
, 32768);
3333 /* Enable VLAN tag insert/strip */
3334 adapter
->netdev
->features
|= NETIF_F_HW_VLAN_RX
;
3336 hw
->mac
.ops
.set_vfta(&adapter
->hw
, 0, 0, true);
3338 /* reconfigure the hardware */
3339 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
) {
3341 if (adapter
->netdev
->features
& NETIF_F_FCOE_MTU
)
3342 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
3344 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
3346 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
3348 ixgbe_dcb_hw_config(hw
, &adapter
->dcb_cfg
);
3350 struct net_device
*dev
= adapter
->netdev
;
3352 if (adapter
->ixgbe_ieee_ets
) {
3353 struct ieee_ets
*ets
= adapter
->ixgbe_ieee_ets
;
3354 int max_frame
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3356 ixgbe_dcb_hw_ets(&adapter
->hw
, ets
, max_frame
);
3359 if (adapter
->ixgbe_ieee_pfc
) {
3360 struct ieee_pfc
*pfc
= adapter
->ixgbe_ieee_pfc
;
3362 ixgbe_dcb_hw_pfc_config(&adapter
->hw
, pfc
->pfc_en
);
3366 /* Enable RSS Hash per TC */
3367 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
3371 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
3373 u8 cnt
= adapter
->netdev
->tc_to_txq
[i
].count
;
3378 reg
|= msb
<< IXGBE_RQTC_SHIFT_TC(i
);
3380 IXGBE_WRITE_REG(hw
, IXGBE_RQTC
, reg
);
3385 /* Additional bittime to account for IXGBE framing */
3386 #define IXGBE_ETH_FRAMING 20
3389 * ixgbe_hpbthresh - calculate high water mark for flow control
3391 * @adapter: board private structure to calculate for
3392 * @pb - packet buffer to calculate
3394 static int ixgbe_hpbthresh(struct ixgbe_adapter
*adapter
, int pb
)
3396 struct ixgbe_hw
*hw
= &adapter
->hw
;
3397 struct net_device
*dev
= adapter
->netdev
;
3398 int link
, tc
, kb
, marker
;
3401 /* Calculate max LAN frame size */
3402 tc
= link
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ IXGBE_ETH_FRAMING
;
3405 /* FCoE traffic class uses FCOE jumbo frames */
3406 if (dev
->features
& NETIF_F_FCOE_MTU
) {
3409 #ifdef CONFIG_IXGBE_DCB
3410 fcoe_pb
= netdev_get_prio_tc_map(dev
, adapter
->fcoe
.up
);
3413 if (fcoe_pb
== pb
&& tc
< IXGBE_FCOE_JUMBO_FRAME_SIZE
)
3414 tc
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
3418 /* Calculate delay value for device */
3419 switch (hw
->mac
.type
) {
3420 case ixgbe_mac_X540
:
3421 dv_id
= IXGBE_DV_X540(link
, tc
);
3424 dv_id
= IXGBE_DV(link
, tc
);
3428 /* Loopback switch introduces additional latency */
3429 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
3430 dv_id
+= IXGBE_B2BT(tc
);
3432 /* Delay value is calculated in bit times convert to KB */
3433 kb
= IXGBE_BT2KB(dv_id
);
3434 rx_pba
= IXGBE_READ_REG(hw
, IXGBE_RXPBSIZE(pb
)) >> 10;
3436 marker
= rx_pba
- kb
;
3438 /* It is possible that the packet buffer is not large enough
3439 * to provide required headroom. In this case throw an error
3440 * to user and a do the best we can.
3443 e_warn(drv
, "Packet Buffer(%i) can not provide enough"
3444 "headroom to support flow control."
3445 "Decrease MTU or number of traffic classes\n", pb
);
3453 * ixgbe_lpbthresh - calculate low water mark for for flow control
3455 * @adapter: board private structure to calculate for
3456 * @pb - packet buffer to calculate
3458 static int ixgbe_lpbthresh(struct ixgbe_adapter
*adapter
)
3460 struct ixgbe_hw
*hw
= &adapter
->hw
;
3461 struct net_device
*dev
= adapter
->netdev
;
3465 /* Calculate max LAN frame size */
3466 tc
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3468 /* Calculate delay value for device */
3469 switch (hw
->mac
.type
) {
3470 case ixgbe_mac_X540
:
3471 dv_id
= IXGBE_LOW_DV_X540(tc
);
3474 dv_id
= IXGBE_LOW_DV(tc
);
3478 /* Delay value is calculated in bit times convert to KB */
3479 return IXGBE_BT2KB(dv_id
);
3483 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3485 static void ixgbe_pbthresh_setup(struct ixgbe_adapter
*adapter
)
3487 struct ixgbe_hw
*hw
= &adapter
->hw
;
3488 int num_tc
= netdev_get_num_tc(adapter
->netdev
);
3494 hw
->fc
.low_water
= ixgbe_lpbthresh(adapter
);
3496 for (i
= 0; i
< num_tc
; i
++) {
3497 hw
->fc
.high_water
[i
] = ixgbe_hpbthresh(adapter
, i
);
3499 /* Low water marks must not be larger than high water marks */
3500 if (hw
->fc
.low_water
> hw
->fc
.high_water
[i
])
3501 hw
->fc
.low_water
= 0;
3505 static void ixgbe_configure_pb(struct ixgbe_adapter
*adapter
)
3507 struct ixgbe_hw
*hw
= &adapter
->hw
;
3509 u8 tc
= netdev_get_num_tc(adapter
->netdev
);
3511 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
3512 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
3513 hdrm
= 32 << adapter
->fdir_pballoc
;
3517 hw
->mac
.ops
.set_rxpba(hw
, tc
, hdrm
, PBA_STRATEGY_EQUAL
);
3518 ixgbe_pbthresh_setup(adapter
);
3521 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter
*adapter
)
3523 struct ixgbe_hw
*hw
= &adapter
->hw
;
3524 struct hlist_node
*node
, *node2
;
3525 struct ixgbe_fdir_filter
*filter
;
3527 spin_lock(&adapter
->fdir_perfect_lock
);
3529 if (!hlist_empty(&adapter
->fdir_filter_list
))
3530 ixgbe_fdir_set_input_mask_82599(hw
, &adapter
->fdir_mask
);
3532 hlist_for_each_entry_safe(filter
, node
, node2
,
3533 &adapter
->fdir_filter_list
, fdir_node
) {
3534 ixgbe_fdir_write_perfect_filter_82599(hw
,
3537 (filter
->action
== IXGBE_FDIR_DROP_QUEUE
) ?
3538 IXGBE_FDIR_DROP_QUEUE
:
3539 adapter
->rx_ring
[filter
->action
]->reg_idx
);
3542 spin_unlock(&adapter
->fdir_perfect_lock
);
3545 static void ixgbe_configure(struct ixgbe_adapter
*adapter
)
3547 ixgbe_configure_pb(adapter
);
3548 #ifdef CONFIG_IXGBE_DCB
3549 ixgbe_configure_dcb(adapter
);
3552 ixgbe_set_rx_mode(adapter
->netdev
);
3553 ixgbe_restore_vlan(adapter
);
3556 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
3557 ixgbe_configure_fcoe(adapter
);
3559 #endif /* IXGBE_FCOE */
3560 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
3561 ixgbe_init_fdir_signature_82599(&adapter
->hw
,
3562 adapter
->fdir_pballoc
);
3563 } else if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
) {
3564 ixgbe_init_fdir_perfect_82599(&adapter
->hw
,
3565 adapter
->fdir_pballoc
);
3566 ixgbe_fdir_filter_restore(adapter
);
3569 ixgbe_configure_virtualization(adapter
);
3571 ixgbe_configure_tx(adapter
);
3572 ixgbe_configure_rx(adapter
);
3575 static inline bool ixgbe_is_sfp(struct ixgbe_hw
*hw
)
3577 switch (hw
->phy
.type
) {
3578 case ixgbe_phy_sfp_avago
:
3579 case ixgbe_phy_sfp_ftl
:
3580 case ixgbe_phy_sfp_intel
:
3581 case ixgbe_phy_sfp_unknown
:
3582 case ixgbe_phy_sfp_passive_tyco
:
3583 case ixgbe_phy_sfp_passive_unknown
:
3584 case ixgbe_phy_sfp_active_unknown
:
3585 case ixgbe_phy_sfp_ftl_active
:
3588 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3596 * ixgbe_sfp_link_config - set up SFP+ link
3597 * @adapter: pointer to private adapter struct
3599 static void ixgbe_sfp_link_config(struct ixgbe_adapter
*adapter
)
3602 * We are assuming the worst case scenerio here, and that
3603 * is that an SFP was inserted/removed after the reset
3604 * but before SFP detection was enabled. As such the best
3605 * solution is to just start searching as soon as we start
3607 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
3608 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
3610 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
3614 * ixgbe_non_sfp_link_config - set up non-SFP+ link
3615 * @hw: pointer to private hardware struct
3617 * Returns 0 on success, negative on failure
3619 static int ixgbe_non_sfp_link_config(struct ixgbe_hw
*hw
)
3622 bool negotiation
, link_up
= false;
3623 u32 ret
= IXGBE_ERR_LINK_SETUP
;
3625 if (hw
->mac
.ops
.check_link
)
3626 ret
= hw
->mac
.ops
.check_link(hw
, &autoneg
, &link_up
, false);
3631 autoneg
= hw
->phy
.autoneg_advertised
;
3632 if ((!autoneg
) && (hw
->mac
.ops
.get_link_capabilities
))
3633 ret
= hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
,
3638 if (hw
->mac
.ops
.setup_link
)
3639 ret
= hw
->mac
.ops
.setup_link(hw
, autoneg
, negotiation
, link_up
);
3644 static void ixgbe_setup_gpie(struct ixgbe_adapter
*adapter
)
3646 struct ixgbe_hw
*hw
= &adapter
->hw
;
3649 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3650 gpie
= IXGBE_GPIE_MSIX_MODE
| IXGBE_GPIE_PBA_SUPPORT
|
3652 gpie
|= IXGBE_GPIE_EIAME
;
3654 * use EIAM to auto-mask when MSI-X interrupt is asserted
3655 * this saves a register write for every interrupt
3657 switch (hw
->mac
.type
) {
3658 case ixgbe_mac_82598EB
:
3659 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
3661 case ixgbe_mac_82599EB
:
3662 case ixgbe_mac_X540
:
3664 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3665 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3669 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3670 * specifically only auto mask tx and rx interrupts */
3671 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
3674 /* XXX: to interrupt immediately for EICS writes, enable this */
3675 /* gpie |= IXGBE_GPIE_EIMEN; */
3677 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
3678 gpie
&= ~IXGBE_GPIE_VTMODE_MASK
;
3679 gpie
|= IXGBE_GPIE_VTMODE_64
;
3682 /* Enable Thermal over heat sensor interrupt */
3683 if (adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) {
3684 switch (adapter
->hw
.mac
.type
) {
3685 case ixgbe_mac_82599EB
:
3686 gpie
|= IXGBE_SDP0_GPIEN
;
3688 case ixgbe_mac_X540
:
3689 gpie
|= IXGBE_EIMS_TS
;
3696 /* Enable fan failure interrupt */
3697 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
3698 gpie
|= IXGBE_SDP1_GPIEN
;
3700 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
3701 gpie
|= IXGBE_SDP1_GPIEN
;
3702 gpie
|= IXGBE_SDP2_GPIEN
;
3705 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
3708 static void ixgbe_up_complete(struct ixgbe_adapter
*adapter
)
3710 struct ixgbe_hw
*hw
= &adapter
->hw
;
3714 ixgbe_get_hw_control(adapter
);
3715 ixgbe_setup_gpie(adapter
);
3717 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3718 ixgbe_configure_msix(adapter
);
3720 ixgbe_configure_msi_and_legacy(adapter
);
3722 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3723 if (hw
->mac
.ops
.enable_tx_laser
&&
3724 ((hw
->phy
.multispeed_fiber
) ||
3725 ((hw
->mac
.ops
.get_media_type(hw
) == ixgbe_media_type_fiber
) &&
3726 (hw
->mac
.type
== ixgbe_mac_82599EB
))))
3727 hw
->mac
.ops
.enable_tx_laser(hw
);
3729 clear_bit(__IXGBE_DOWN
, &adapter
->state
);
3730 ixgbe_napi_enable_all(adapter
);
3732 if (ixgbe_is_sfp(hw
)) {
3733 ixgbe_sfp_link_config(adapter
);
3735 err
= ixgbe_non_sfp_link_config(hw
);
3737 e_err(probe
, "link_config FAILED %d\n", err
);
3740 /* clear any pending interrupts, may auto mask */
3741 IXGBE_READ_REG(hw
, IXGBE_EICR
);
3742 ixgbe_irq_enable(adapter
, true, true);
3745 * If this adapter has a fan, check to see if we had a failure
3746 * before we enabled the interrupt.
3748 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
3749 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
3750 if (esdp
& IXGBE_ESDP_SDP1
)
3751 e_crit(drv
, "Fan has stopped, replace the adapter\n");
3754 /* enable transmits */
3755 netif_tx_start_all_queues(adapter
->netdev
);
3757 /* bring the link up in the watchdog, this could race with our first
3758 * link up interrupt but shouldn't be a problem */
3759 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
3760 adapter
->link_check_timeout
= jiffies
;
3761 mod_timer(&adapter
->service_timer
, jiffies
);
3763 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3764 ctrl_ext
= IXGBE_READ_REG(hw
, IXGBE_CTRL_EXT
);
3765 ctrl_ext
|= IXGBE_CTRL_EXT_PFRSTD
;
3766 IXGBE_WRITE_REG(hw
, IXGBE_CTRL_EXT
, ctrl_ext
);
3769 void ixgbe_reinit_locked(struct ixgbe_adapter
*adapter
)
3771 WARN_ON(in_interrupt());
3772 /* put off any impending NetWatchDogTimeout */
3773 adapter
->netdev
->trans_start
= jiffies
;
3775 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
3776 usleep_range(1000, 2000);
3777 ixgbe_down(adapter
);
3779 * If SR-IOV enabled then wait a bit before bringing the adapter
3780 * back up to give the VFs time to respond to the reset. The
3781 * two second wait is based upon the watchdog timer cycle in
3784 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
3787 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
3790 void ixgbe_up(struct ixgbe_adapter
*adapter
)
3792 /* hardware has been reset, we need to reload some things */
3793 ixgbe_configure(adapter
);
3795 ixgbe_up_complete(adapter
);
3798 void ixgbe_reset(struct ixgbe_adapter
*adapter
)
3800 struct ixgbe_hw
*hw
= &adapter
->hw
;
3803 /* lock SFP init bit to prevent race conditions with the watchdog */
3804 while (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
3805 usleep_range(1000, 2000);
3807 /* clear all SFP and link config related flags while holding SFP_INIT */
3808 adapter
->flags2
&= ~(IXGBE_FLAG2_SEARCH_FOR_SFP
|
3809 IXGBE_FLAG2_SFP_NEEDS_RESET
);
3810 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
3812 err
= hw
->mac
.ops
.init_hw(hw
);
3815 case IXGBE_ERR_SFP_NOT_PRESENT
:
3816 case IXGBE_ERR_SFP_NOT_SUPPORTED
:
3818 case IXGBE_ERR_MASTER_REQUESTS_PENDING
:
3819 e_dev_err("master disable timed out\n");
3821 case IXGBE_ERR_EEPROM_VERSION
:
3822 /* We are running on a pre-production device, log a warning */
3823 e_dev_warn("This device is a pre-production adapter/LOM. "
3824 "Please be aware there may be issuesassociated with "
3825 "your hardware. If you are experiencing problems "
3826 "please contact your Intel or hardware "
3827 "representative who provided you with this "
3831 e_dev_err("Hardware Error: %d\n", err
);
3834 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
3836 /* reprogram the RAR[0] in case user changed it. */
3837 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, adapter
->num_vfs
,
3842 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
3843 * @rx_ring: ring to free buffers from
3845 static void ixgbe_clean_rx_ring(struct ixgbe_ring
*rx_ring
)
3847 struct device
*dev
= rx_ring
->dev
;
3851 /* ring already cleared, nothing to do */
3852 if (!rx_ring
->rx_buffer_info
)
3855 /* Free all the Rx ring sk_buffs */
3856 for (i
= 0; i
< rx_ring
->count
; i
++) {
3857 struct ixgbe_rx_buffer
*rx_buffer_info
;
3859 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
3860 if (rx_buffer_info
->dma
) {
3861 dma_unmap_single(rx_ring
->dev
, rx_buffer_info
->dma
,
3862 rx_ring
->rx_buf_len
,
3864 rx_buffer_info
->dma
= 0;
3866 if (rx_buffer_info
->skb
) {
3867 struct sk_buff
*skb
= rx_buffer_info
->skb
;
3868 rx_buffer_info
->skb
= NULL
;
3870 struct sk_buff
*this = skb
;
3871 if (IXGBE_RSC_CB(this)->delay_unmap
) {
3872 dma_unmap_single(dev
,
3873 IXGBE_RSC_CB(this)->dma
,
3874 rx_ring
->rx_buf_len
,
3876 IXGBE_RSC_CB(this)->dma
= 0;
3877 IXGBE_RSC_CB(skb
)->delay_unmap
= false;
3880 dev_kfree_skb(this);
3883 if (!rx_buffer_info
->page
)
3885 if (rx_buffer_info
->page_dma
) {
3886 dma_unmap_page(dev
, rx_buffer_info
->page_dma
,
3887 PAGE_SIZE
/ 2, DMA_FROM_DEVICE
);
3888 rx_buffer_info
->page_dma
= 0;
3890 put_page(rx_buffer_info
->page
);
3891 rx_buffer_info
->page
= NULL
;
3892 rx_buffer_info
->page_offset
= 0;
3895 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
3896 memset(rx_ring
->rx_buffer_info
, 0, size
);
3898 /* Zero out the descriptor ring */
3899 memset(rx_ring
->desc
, 0, rx_ring
->size
);
3901 rx_ring
->next_to_clean
= 0;
3902 rx_ring
->next_to_use
= 0;
3906 * ixgbe_clean_tx_ring - Free Tx Buffers
3907 * @tx_ring: ring to be cleaned
3909 static void ixgbe_clean_tx_ring(struct ixgbe_ring
*tx_ring
)
3911 struct ixgbe_tx_buffer
*tx_buffer_info
;
3915 /* ring already cleared, nothing to do */
3916 if (!tx_ring
->tx_buffer_info
)
3919 /* Free all the Tx ring sk_buffs */
3920 for (i
= 0; i
< tx_ring
->count
; i
++) {
3921 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
3922 ixgbe_unmap_and_free_tx_resource(tx_ring
, tx_buffer_info
);
3925 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
3926 memset(tx_ring
->tx_buffer_info
, 0, size
);
3928 /* Zero out the descriptor ring */
3929 memset(tx_ring
->desc
, 0, tx_ring
->size
);
3931 tx_ring
->next_to_use
= 0;
3932 tx_ring
->next_to_clean
= 0;
3936 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
3937 * @adapter: board private structure
3939 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter
*adapter
)
3943 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3944 ixgbe_clean_rx_ring(adapter
->rx_ring
[i
]);
3948 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
3949 * @adapter: board private structure
3951 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter
*adapter
)
3955 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3956 ixgbe_clean_tx_ring(adapter
->tx_ring
[i
]);
3959 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter
*adapter
)
3961 struct hlist_node
*node
, *node2
;
3962 struct ixgbe_fdir_filter
*filter
;
3964 spin_lock(&adapter
->fdir_perfect_lock
);
3966 hlist_for_each_entry_safe(filter
, node
, node2
,
3967 &adapter
->fdir_filter_list
, fdir_node
) {
3968 hlist_del(&filter
->fdir_node
);
3971 adapter
->fdir_filter_count
= 0;
3973 spin_unlock(&adapter
->fdir_perfect_lock
);
3976 void ixgbe_down(struct ixgbe_adapter
*adapter
)
3978 struct net_device
*netdev
= adapter
->netdev
;
3979 struct ixgbe_hw
*hw
= &adapter
->hw
;
3983 /* signal that we are down to the interrupt handler */
3984 set_bit(__IXGBE_DOWN
, &adapter
->state
);
3986 /* disable receives */
3987 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
3988 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
3990 /* disable all enabled rx queues */
3991 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3992 /* this call also flushes the previous write */
3993 ixgbe_disable_rx_queue(adapter
, adapter
->rx_ring
[i
]);
3995 usleep_range(10000, 20000);
3997 netif_tx_stop_all_queues(netdev
);
3999 /* call carrier off first to avoid false dev_watchdog timeouts */
4000 netif_carrier_off(netdev
);
4001 netif_tx_disable(netdev
);
4003 ixgbe_irq_disable(adapter
);
4005 ixgbe_napi_disable_all(adapter
);
4007 adapter
->flags2
&= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT
|
4008 IXGBE_FLAG2_RESET_REQUESTED
);
4009 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
4011 del_timer_sync(&adapter
->service_timer
);
4013 if (adapter
->num_vfs
) {
4014 /* Clear EITR Select mapping */
4015 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, 0);
4017 /* Mark all the VFs as inactive */
4018 for (i
= 0 ; i
< adapter
->num_vfs
; i
++)
4019 adapter
->vfinfo
[i
].clear_to_send
= 0;
4021 /* ping all the active vfs to let them know we are going down */
4022 ixgbe_ping_all_vfs(adapter
);
4024 /* Disable all VFTE/VFRE TX/RX */
4025 ixgbe_disable_tx_rx(adapter
);
4028 /* disable transmits in the hardware now that interrupts are off */
4029 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
4030 u8 reg_idx
= adapter
->tx_ring
[i
]->reg_idx
;
4031 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), IXGBE_TXDCTL_SWFLSH
);
4034 /* Disable the Tx DMA engine on 82599 and X540 */
4035 switch (hw
->mac
.type
) {
4036 case ixgbe_mac_82599EB
:
4037 case ixgbe_mac_X540
:
4038 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
,
4039 (IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
) &
4040 ~IXGBE_DMATXCTL_TE
));
4046 if (!pci_channel_offline(adapter
->pdev
))
4047 ixgbe_reset(adapter
);
4049 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4050 if (hw
->mac
.ops
.disable_tx_laser
&&
4051 ((hw
->phy
.multispeed_fiber
) ||
4052 ((hw
->mac
.ops
.get_media_type(hw
) == ixgbe_media_type_fiber
) &&
4053 (hw
->mac
.type
== ixgbe_mac_82599EB
))))
4054 hw
->mac
.ops
.disable_tx_laser(hw
);
4056 ixgbe_clean_all_tx_rings(adapter
);
4057 ixgbe_clean_all_rx_rings(adapter
);
4059 #ifdef CONFIG_IXGBE_DCA
4060 /* since we reset the hardware DCA settings were cleared */
4061 ixgbe_setup_dca(adapter
);
4066 * ixgbe_poll - NAPI Rx polling callback
4067 * @napi: structure for representing this polling device
4068 * @budget: how many packets driver is allowed to clean
4070 * This function is used for legacy and MSI, NAPI mode
4072 static int ixgbe_poll(struct napi_struct
*napi
, int budget
)
4074 struct ixgbe_q_vector
*q_vector
=
4075 container_of(napi
, struct ixgbe_q_vector
, napi
);
4076 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
4077 struct ixgbe_ring
*ring
;
4078 int per_ring_budget
;
4079 bool clean_complete
= true;
4081 #ifdef CONFIG_IXGBE_DCA
4082 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
4083 ixgbe_update_dca(q_vector
);
4086 for (ring
= q_vector
->tx
.ring
; ring
!= NULL
; ring
= ring
->next
)
4087 clean_complete
&= !!ixgbe_clean_tx_irq(q_vector
, ring
);
4089 /* attempt to distribute budget to each queue fairly, but don't allow
4090 * the budget to go below 1 because we'll exit polling */
4091 if (q_vector
->rx
.count
> 1)
4092 per_ring_budget
= max(budget
/q_vector
->rx
.count
, 1);
4094 per_ring_budget
= budget
;
4096 for (ring
= q_vector
->rx
.ring
; ring
!= NULL
; ring
= ring
->next
)
4097 clean_complete
&= ixgbe_clean_rx_irq(q_vector
, ring
,
4100 /* If all work not completed, return budget and keep polling */
4101 if (!clean_complete
)
4104 /* all work done, exit the polling mode */
4105 napi_complete(napi
);
4106 if (adapter
->rx_itr_setting
& 1)
4107 ixgbe_set_itr(q_vector
);
4108 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
4109 ixgbe_irq_enable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
4115 * ixgbe_tx_timeout - Respond to a Tx Hang
4116 * @netdev: network interface device structure
4118 static void ixgbe_tx_timeout(struct net_device
*netdev
)
4120 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4122 /* Do the reset outside of interrupt context */
4123 ixgbe_tx_timeout_reset(adapter
);
4127 * ixgbe_set_rss_queues: Allocate queues for RSS
4128 * @adapter: board private structure to initialize
4130 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4131 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4134 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter
*adapter
)
4137 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_RSS
];
4139 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
4141 adapter
->num_rx_queues
= f
->indices
;
4142 adapter
->num_tx_queues
= f
->indices
;
4152 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4153 * @adapter: board private structure to initialize
4155 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4156 * to the original CPU that initiated the Tx session. This runs in addition
4157 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4158 * Rx load across CPUs using RSS.
4161 static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter
*adapter
)
4164 struct ixgbe_ring_feature
*f_fdir
= &adapter
->ring_feature
[RING_F_FDIR
];
4166 f_fdir
->indices
= min((int)num_online_cpus(), f_fdir
->indices
);
4169 /* Flow Director must have RSS enabled */
4170 if ((adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) &&
4171 (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)) {
4172 adapter
->num_tx_queues
= f_fdir
->indices
;
4173 adapter
->num_rx_queues
= f_fdir
->indices
;
4176 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
4183 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4184 * @adapter: board private structure to initialize
4186 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4187 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4188 * rx queues out of the max number of rx queues, instead, it is used as the
4189 * index of the first rx queue used by FCoE.
4192 static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter
*adapter
)
4194 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
4196 if (!(adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
))
4199 f
->indices
= min((int)num_online_cpus(), f
->indices
);
4201 adapter
->num_rx_queues
= 1;
4202 adapter
->num_tx_queues
= 1;
4204 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
4205 e_info(probe
, "FCoE enabled with RSS\n");
4206 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)
4207 ixgbe_set_fdir_queues(adapter
);
4209 ixgbe_set_rss_queues(adapter
);
4212 /* adding FCoE rx rings to the end */
4213 f
->mask
= adapter
->num_rx_queues
;
4214 adapter
->num_rx_queues
+= f
->indices
;
4215 adapter
->num_tx_queues
+= f
->indices
;
4219 #endif /* IXGBE_FCOE */
4221 /* Artificial max queue cap per traffic class in DCB mode */
4222 #define DCB_QUEUE_CAP 8
4224 #ifdef CONFIG_IXGBE_DCB
4225 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter
*adapter
)
4227 int per_tc_q
, q
, i
, offset
= 0;
4228 struct net_device
*dev
= adapter
->netdev
;
4229 int tcs
= netdev_get_num_tc(dev
);
4234 /* Map queue offset and counts onto allocated tx queues */
4235 per_tc_q
= min(dev
->num_tx_queues
/ tcs
, (unsigned int)DCB_QUEUE_CAP
);
4236 q
= min((int)num_online_cpus(), per_tc_q
);
4238 for (i
= 0; i
< tcs
; i
++) {
4239 netdev_set_prio_tc_map(dev
, i
, i
);
4240 netdev_set_tc_queue(dev
, i
, q
, offset
);
4244 adapter
->num_tx_queues
= q
* tcs
;
4245 adapter
->num_rx_queues
= q
* tcs
;
4248 /* FCoE enabled queues require special configuration indexed
4249 * by feature specific indices and mask. Here we map FCoE
4250 * indices onto the DCB queue pairs allowing FCoE to own
4251 * configuration later.
4253 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
4255 struct ixgbe_ring_feature
*f
=
4256 &adapter
->ring_feature
[RING_F_FCOE
];
4258 tc
= netdev_get_prio_tc_map(dev
, adapter
->fcoe
.up
);
4259 f
->indices
= dev
->tc_to_txq
[tc
].count
;
4260 f
->mask
= dev
->tc_to_txq
[tc
].offset
;
4269 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4270 * @adapter: board private structure to initialize
4272 * IOV doesn't actually use anything, so just NAK the
4273 * request for now and let the other queue routines
4274 * figure out what to do.
4276 static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter
*adapter
)
4282 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
4283 * @adapter: board private structure to initialize
4285 * This is the top level queue allocation routine. The order here is very
4286 * important, starting with the "most" number of features turned on at once,
4287 * and ending with the smallest set of features. This way large combinations
4288 * can be allocated if they're turned on, and smaller combinations are the
4289 * fallthrough conditions.
4292 static int ixgbe_set_num_queues(struct ixgbe_adapter
*adapter
)
4294 /* Start with base case */
4295 adapter
->num_rx_queues
= 1;
4296 adapter
->num_tx_queues
= 1;
4297 adapter
->num_rx_pools
= adapter
->num_rx_queues
;
4298 adapter
->num_rx_queues_per_pool
= 1;
4300 if (ixgbe_set_sriov_queues(adapter
))
4303 #ifdef CONFIG_IXGBE_DCB
4304 if (ixgbe_set_dcb_queues(adapter
))
4309 if (ixgbe_set_fcoe_queues(adapter
))
4312 #endif /* IXGBE_FCOE */
4313 if (ixgbe_set_fdir_queues(adapter
))
4316 if (ixgbe_set_rss_queues(adapter
))
4319 /* fallback to base case */
4320 adapter
->num_rx_queues
= 1;
4321 adapter
->num_tx_queues
= 1;
4324 /* Notify the stack of the (possibly) reduced queue counts. */
4325 netif_set_real_num_tx_queues(adapter
->netdev
, adapter
->num_tx_queues
);
4326 return netif_set_real_num_rx_queues(adapter
->netdev
,
4327 adapter
->num_rx_queues
);
4330 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter
*adapter
,
4333 int err
, vector_threshold
;
4335 /* We'll want at least 3 (vector_threshold):
4338 * 3) Other (Link Status Change, etc.)
4339 * 4) TCP Timer (optional)
4341 vector_threshold
= MIN_MSIX_COUNT
;
4343 /* The more we get, the more we will assign to Tx/Rx Cleanup
4344 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4345 * Right now, we simply care about how many we'll get; we'll
4346 * set them up later while requesting irq's.
4348 while (vectors
>= vector_threshold
) {
4349 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
4351 if (!err
) /* Success in acquiring all requested vectors. */
4354 vectors
= 0; /* Nasty failure, quit now */
4355 else /* err == number of vectors we should try again with */
4359 if (vectors
< vector_threshold
) {
4360 /* Can't allocate enough MSI-X interrupts? Oh well.
4361 * This just means we'll go with either a single MSI
4362 * vector or fall back to legacy interrupts.
4364 netif_printk(adapter
, hw
, KERN_DEBUG
, adapter
->netdev
,
4365 "Unable to allocate MSI-X interrupts\n");
4366 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
4367 kfree(adapter
->msix_entries
);
4368 adapter
->msix_entries
= NULL
;
4370 adapter
->flags
|= IXGBE_FLAG_MSIX_ENABLED
; /* Woot! */
4372 * Adjust for only the vectors we'll use, which is minimum
4373 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4374 * vectors we were allocated.
4376 adapter
->num_msix_vectors
= min(vectors
,
4377 adapter
->max_msix_q_vectors
+ NON_Q_VECTORS
);
4382 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
4383 * @adapter: board private structure to initialize
4385 * Cache the descriptor ring offsets for RSS to the assigned rings.
4388 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter
*adapter
)
4392 if (!(adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
))
4395 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4396 adapter
->rx_ring
[i
]->reg_idx
= i
;
4397 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4398 adapter
->tx_ring
[i
]->reg_idx
= i
;
4403 #ifdef CONFIG_IXGBE_DCB
4405 /* ixgbe_get_first_reg_idx - Return first register index associated with ring */
4406 static void ixgbe_get_first_reg_idx(struct ixgbe_adapter
*adapter
, u8 tc
,
4407 unsigned int *tx
, unsigned int *rx
)
4409 struct net_device
*dev
= adapter
->netdev
;
4410 struct ixgbe_hw
*hw
= &adapter
->hw
;
4411 u8 num_tcs
= netdev_get_num_tc(dev
);
4416 switch (hw
->mac
.type
) {
4417 case ixgbe_mac_82598EB
:
4421 case ixgbe_mac_82599EB
:
4422 case ixgbe_mac_X540
:
4427 } else if (tc
< 5) {
4428 *tx
= ((tc
+ 2) << 4);
4430 } else if (tc
< num_tcs
) {
4431 *tx
= ((tc
+ 8) << 3);
4460 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4461 * @adapter: board private structure to initialize
4463 * Cache the descriptor ring offsets for DCB to the assigned rings.
4466 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter
*adapter
)
4468 struct net_device
*dev
= adapter
->netdev
;
4470 u8 num_tcs
= netdev_get_num_tc(dev
);
4475 for (i
= 0, k
= 0; i
< num_tcs
; i
++) {
4476 unsigned int tx_s
, rx_s
;
4477 u16 count
= dev
->tc_to_txq
[i
].count
;
4479 ixgbe_get_first_reg_idx(adapter
, i
, &tx_s
, &rx_s
);
4480 for (j
= 0; j
< count
; j
++, k
++) {
4481 adapter
->tx_ring
[k
]->reg_idx
= tx_s
+ j
;
4482 adapter
->rx_ring
[k
]->reg_idx
= rx_s
+ j
;
4483 adapter
->tx_ring
[k
]->dcb_tc
= i
;
4484 adapter
->rx_ring
[k
]->dcb_tc
= i
;
4493 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4494 * @adapter: board private structure to initialize
4496 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4499 static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter
*adapter
)
4504 if ((adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) &&
4505 (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)) {
4506 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4507 adapter
->rx_ring
[i
]->reg_idx
= i
;
4508 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4509 adapter
->tx_ring
[i
]->reg_idx
= i
;
4518 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4519 * @adapter: board private structure to initialize
4521 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4524 static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter
*adapter
)
4526 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
4528 u8 fcoe_rx_i
= 0, fcoe_tx_i
= 0;
4530 if (!(adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
))
4533 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
4534 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)
4535 ixgbe_cache_ring_fdir(adapter
);
4537 ixgbe_cache_ring_rss(adapter
);
4539 fcoe_rx_i
= f
->mask
;
4540 fcoe_tx_i
= f
->mask
;
4542 for (i
= 0; i
< f
->indices
; i
++, fcoe_rx_i
++, fcoe_tx_i
++) {
4543 adapter
->rx_ring
[f
->mask
+ i
]->reg_idx
= fcoe_rx_i
;
4544 adapter
->tx_ring
[f
->mask
+ i
]->reg_idx
= fcoe_tx_i
;
4549 #endif /* IXGBE_FCOE */
4551 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4552 * @adapter: board private structure to initialize
4554 * SR-IOV doesn't use any descriptor rings but changes the default if
4555 * no other mapping is used.
4558 static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter
*adapter
)
4560 adapter
->rx_ring
[0]->reg_idx
= adapter
->num_vfs
* 2;
4561 adapter
->tx_ring
[0]->reg_idx
= adapter
->num_vfs
* 2;
4562 if (adapter
->num_vfs
)
4569 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4570 * @adapter: board private structure to initialize
4572 * Once we know the feature-set enabled for the device, we'll cache
4573 * the register offset the descriptor ring is assigned to.
4575 * Note, the order the various feature calls is important. It must start with
4576 * the "most" features enabled at the same time, then trickle down to the
4577 * least amount of features turned on at once.
4579 static void ixgbe_cache_ring_register(struct ixgbe_adapter
*adapter
)
4581 /* start with default case */
4582 adapter
->rx_ring
[0]->reg_idx
= 0;
4583 adapter
->tx_ring
[0]->reg_idx
= 0;
4585 if (ixgbe_cache_ring_sriov(adapter
))
4588 #ifdef CONFIG_IXGBE_DCB
4589 if (ixgbe_cache_ring_dcb(adapter
))
4594 if (ixgbe_cache_ring_fcoe(adapter
))
4596 #endif /* IXGBE_FCOE */
4598 if (ixgbe_cache_ring_fdir(adapter
))
4601 if (ixgbe_cache_ring_rss(adapter
))
4606 * ixgbe_alloc_queues - Allocate memory for all rings
4607 * @adapter: board private structure to initialize
4609 * We allocate one ring per queue at run-time since we don't know the
4610 * number of queues at compile-time. The polling_netdev array is
4611 * intended for Multiqueue, but should work fine with a single queue.
4613 static int ixgbe_alloc_queues(struct ixgbe_adapter
*adapter
)
4615 int rx
= 0, tx
= 0, nid
= adapter
->node
;
4617 if (nid
< 0 || !node_online(nid
))
4618 nid
= first_online_node
;
4620 for (; tx
< adapter
->num_tx_queues
; tx
++) {
4621 struct ixgbe_ring
*ring
;
4623 ring
= kzalloc_node(sizeof(*ring
), GFP_KERNEL
, nid
);
4625 ring
= kzalloc(sizeof(*ring
), GFP_KERNEL
);
4627 goto err_allocation
;
4628 ring
->count
= adapter
->tx_ring_count
;
4629 ring
->queue_index
= tx
;
4630 ring
->numa_node
= nid
;
4631 ring
->dev
= &adapter
->pdev
->dev
;
4632 ring
->netdev
= adapter
->netdev
;
4634 adapter
->tx_ring
[tx
] = ring
;
4637 for (; rx
< adapter
->num_rx_queues
; rx
++) {
4638 struct ixgbe_ring
*ring
;
4640 ring
= kzalloc_node(sizeof(*ring
), GFP_KERNEL
, nid
);
4642 ring
= kzalloc(sizeof(*ring
), GFP_KERNEL
);
4644 goto err_allocation
;
4645 ring
->count
= adapter
->rx_ring_count
;
4646 ring
->queue_index
= rx
;
4647 ring
->numa_node
= nid
;
4648 ring
->dev
= &adapter
->pdev
->dev
;
4649 ring
->netdev
= adapter
->netdev
;
4651 adapter
->rx_ring
[rx
] = ring
;
4654 ixgbe_cache_ring_register(adapter
);
4660 kfree(adapter
->tx_ring
[--tx
]);
4663 kfree(adapter
->rx_ring
[--rx
]);
4668 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4669 * @adapter: board private structure to initialize
4671 * Attempt to configure the interrupts using the best available
4672 * capabilities of the hardware and the kernel.
4674 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter
*adapter
)
4676 struct ixgbe_hw
*hw
= &adapter
->hw
;
4678 int vector
, v_budget
;
4681 * It's easy to be greedy for MSI-X vectors, but it really
4682 * doesn't do us much good if we have a lot more vectors
4683 * than CPU's. So let's be conservative and only ask for
4684 * (roughly) the same number of vectors as there are CPU's.
4686 v_budget
= min(adapter
->num_rx_queues
+ adapter
->num_tx_queues
,
4687 (int)num_online_cpus()) + NON_Q_VECTORS
;
4690 * At the same time, hardware can only support a maximum of
4691 * hw.mac->max_msix_vectors vectors. With features
4692 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4693 * descriptor queues supported by our device. Thus, we cap it off in
4694 * those rare cases where the cpu count also exceeds our vector limit.
4696 v_budget
= min(v_budget
, (int)hw
->mac
.max_msix_vectors
);
4698 /* A failure in MSI-X entry allocation isn't fatal, but it does
4699 * mean we disable MSI-X capabilities of the adapter. */
4700 adapter
->msix_entries
= kcalloc(v_budget
,
4701 sizeof(struct msix_entry
), GFP_KERNEL
);
4702 if (adapter
->msix_entries
) {
4703 for (vector
= 0; vector
< v_budget
; vector
++)
4704 adapter
->msix_entries
[vector
].entry
= vector
;
4706 ixgbe_acquire_msix_vectors(adapter
, v_budget
);
4708 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
4712 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
4713 adapter
->flags
&= ~IXGBE_FLAG_RSS_ENABLED
;
4714 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
4716 "ATR is not supported while multiple "
4717 "queues are disabled. Disabling Flow Director\n");
4719 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
4720 adapter
->atr_sample_rate
= 0;
4721 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
4722 ixgbe_disable_sriov(adapter
);
4724 err
= ixgbe_set_num_queues(adapter
);
4728 err
= pci_enable_msi(adapter
->pdev
);
4730 adapter
->flags
|= IXGBE_FLAG_MSI_ENABLED
;
4732 netif_printk(adapter
, hw
, KERN_DEBUG
, adapter
->netdev
,
4733 "Unable to allocate MSI interrupt, "
4734 "falling back to legacy. Error: %d\n", err
);
4744 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4745 * @adapter: board private structure to initialize
4747 * We allocate one q_vector per queue interrupt. If allocation fails we
4750 static int ixgbe_alloc_q_vectors(struct ixgbe_adapter
*adapter
)
4752 int v_idx
, num_q_vectors
;
4753 struct ixgbe_q_vector
*q_vector
;
4755 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
4756 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
4760 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
4761 q_vector
= kzalloc_node(sizeof(struct ixgbe_q_vector
),
4762 GFP_KERNEL
, adapter
->node
);
4764 q_vector
= kzalloc(sizeof(struct ixgbe_q_vector
),
4769 q_vector
->adapter
= adapter
;
4770 q_vector
->v_idx
= v_idx
;
4772 /* Allocate the affinity_hint cpumask, configure the mask */
4773 if (!alloc_cpumask_var(&q_vector
->affinity_mask
, GFP_KERNEL
))
4775 cpumask_set_cpu(v_idx
, q_vector
->affinity_mask
);
4776 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
4778 adapter
->q_vector
[v_idx
] = q_vector
;
4786 q_vector
= adapter
->q_vector
[v_idx
];
4787 netif_napi_del(&q_vector
->napi
);
4788 free_cpumask_var(q_vector
->affinity_mask
);
4790 adapter
->q_vector
[v_idx
] = NULL
;
4796 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4797 * @adapter: board private structure to initialize
4799 * This function frees the memory allocated to the q_vectors. In addition if
4800 * NAPI is enabled it will delete any references to the NAPI struct prior
4801 * to freeing the q_vector.
4803 static void ixgbe_free_q_vectors(struct ixgbe_adapter
*adapter
)
4805 int v_idx
, num_q_vectors
;
4807 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
4808 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
4812 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
4813 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[v_idx
];
4814 adapter
->q_vector
[v_idx
] = NULL
;
4815 netif_napi_del(&q_vector
->napi
);
4816 free_cpumask_var(q_vector
->affinity_mask
);
4821 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter
*adapter
)
4823 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
4824 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
4825 pci_disable_msix(adapter
->pdev
);
4826 kfree(adapter
->msix_entries
);
4827 adapter
->msix_entries
= NULL
;
4828 } else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
4829 adapter
->flags
&= ~IXGBE_FLAG_MSI_ENABLED
;
4830 pci_disable_msi(adapter
->pdev
);
4835 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4836 * @adapter: board private structure to initialize
4838 * We determine which interrupt scheme to use based on...
4839 * - Kernel support (MSI, MSI-X)
4840 * - which can be user-defined (via MODULE_PARAM)
4841 * - Hardware queue count (num_*_queues)
4842 * - defined by miscellaneous hardware support/features (RSS, etc.)
4844 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter
*adapter
)
4848 /* Number of supported queues */
4849 err
= ixgbe_set_num_queues(adapter
);
4853 err
= ixgbe_set_interrupt_capability(adapter
);
4855 e_dev_err("Unable to setup interrupt capabilities\n");
4856 goto err_set_interrupt
;
4859 err
= ixgbe_alloc_q_vectors(adapter
);
4861 e_dev_err("Unable to allocate memory for queue vectors\n");
4862 goto err_alloc_q_vectors
;
4865 err
= ixgbe_alloc_queues(adapter
);
4867 e_dev_err("Unable to allocate memory for queues\n");
4868 goto err_alloc_queues
;
4871 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
4872 (adapter
->num_rx_queues
> 1) ? "Enabled" : "Disabled",
4873 adapter
->num_rx_queues
, adapter
->num_tx_queues
);
4875 set_bit(__IXGBE_DOWN
, &adapter
->state
);
4880 ixgbe_free_q_vectors(adapter
);
4881 err_alloc_q_vectors
:
4882 ixgbe_reset_interrupt_capability(adapter
);
4888 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
4889 * @adapter: board private structure to clear interrupt scheme on
4891 * We go through and clear interrupt specific resources and reset the structure
4892 * to pre-load conditions
4894 void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter
*adapter
)
4898 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
4899 kfree(adapter
->tx_ring
[i
]);
4900 adapter
->tx_ring
[i
] = NULL
;
4902 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4903 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
4905 /* ixgbe_get_stats64() might access this ring, we must wait
4906 * a grace period before freeing it.
4908 kfree_rcu(ring
, rcu
);
4909 adapter
->rx_ring
[i
] = NULL
;
4912 adapter
->num_tx_queues
= 0;
4913 adapter
->num_rx_queues
= 0;
4915 ixgbe_free_q_vectors(adapter
);
4916 ixgbe_reset_interrupt_capability(adapter
);
4920 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4921 * @adapter: board private structure to initialize
4923 * ixgbe_sw_init initializes the Adapter private data structure.
4924 * Fields are initialized based on PCI device information and
4925 * OS network device settings (MTU size).
4927 static int __devinit
ixgbe_sw_init(struct ixgbe_adapter
*adapter
)
4929 struct ixgbe_hw
*hw
= &adapter
->hw
;
4930 struct pci_dev
*pdev
= adapter
->pdev
;
4932 #ifdef CONFIG_IXGBE_DCB
4934 struct tc_configuration
*tc
;
4937 /* PCI config space info */
4939 hw
->vendor_id
= pdev
->vendor
;
4940 hw
->device_id
= pdev
->device
;
4941 hw
->revision_id
= pdev
->revision
;
4942 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
4943 hw
->subsystem_device_id
= pdev
->subsystem_device
;
4945 /* Set capability flags */
4946 rss
= min(IXGBE_MAX_RSS_INDICES
, (int)num_online_cpus());
4947 adapter
->ring_feature
[RING_F_RSS
].indices
= rss
;
4948 adapter
->flags
|= IXGBE_FLAG_RSS_ENABLED
;
4949 switch (hw
->mac
.type
) {
4950 case ixgbe_mac_82598EB
:
4951 if (hw
->device_id
== IXGBE_DEV_ID_82598AT
)
4952 adapter
->flags
|= IXGBE_FLAG_FAN_FAIL_CAPABLE
;
4953 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82598
;
4955 case ixgbe_mac_X540
:
4956 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
4957 case ixgbe_mac_82599EB
:
4958 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82599
;
4959 adapter
->flags2
|= IXGBE_FLAG2_RSC_CAPABLE
;
4960 adapter
->flags2
|= IXGBE_FLAG2_RSC_ENABLED
;
4961 if (hw
->device_id
== IXGBE_DEV_ID_82599_T3_LOM
)
4962 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
4963 /* Flow Director hash filters enabled */
4964 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
4965 adapter
->atr_sample_rate
= 20;
4966 adapter
->ring_feature
[RING_F_FDIR
].indices
=
4967 IXGBE_MAX_FDIR_INDICES
;
4968 adapter
->fdir_pballoc
= IXGBE_FDIR_PBALLOC_64K
;
4970 adapter
->flags
|= IXGBE_FLAG_FCOE_CAPABLE
;
4971 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
4972 adapter
->ring_feature
[RING_F_FCOE
].indices
= 0;
4973 #ifdef CONFIG_IXGBE_DCB
4974 /* Default traffic class to use for FCoE */
4975 adapter
->fcoe
.up
= IXGBE_FCOE_DEFTC
;
4977 #endif /* IXGBE_FCOE */
4983 /* n-tuple support exists, always init our spinlock */
4984 spin_lock_init(&adapter
->fdir_perfect_lock
);
4986 #ifdef CONFIG_IXGBE_DCB
4987 /* Configure DCB traffic classes */
4988 for (j
= 0; j
< MAX_TRAFFIC_CLASS
; j
++) {
4989 tc
= &adapter
->dcb_cfg
.tc_config
[j
];
4990 tc
->path
[DCB_TX_CONFIG
].bwg_id
= 0;
4991 tc
->path
[DCB_TX_CONFIG
].bwg_percent
= 12 + (j
& 1);
4992 tc
->path
[DCB_RX_CONFIG
].bwg_id
= 0;
4993 tc
->path
[DCB_RX_CONFIG
].bwg_percent
= 12 + (j
& 1);
4994 tc
->dcb_pfc
= pfc_disabled
;
4996 adapter
->dcb_cfg
.bw_percentage
[DCB_TX_CONFIG
][0] = 100;
4997 adapter
->dcb_cfg
.bw_percentage
[DCB_RX_CONFIG
][0] = 100;
4998 adapter
->dcb_cfg
.pfc_mode_enable
= false;
4999 adapter
->dcb_set_bitmap
= 0x00;
5000 adapter
->dcbx_cap
= DCB_CAP_DCBX_HOST
| DCB_CAP_DCBX_VER_CEE
;
5001 ixgbe_copy_dcb_cfg(&adapter
->dcb_cfg
, &adapter
->temp_dcb_cfg
,
5006 /* default flow control settings */
5007 hw
->fc
.requested_mode
= ixgbe_fc_full
;
5008 hw
->fc
.current_mode
= ixgbe_fc_full
; /* init for ethtool output */
5010 adapter
->last_lfc_mode
= hw
->fc
.current_mode
;
5012 ixgbe_pbthresh_setup(adapter
);
5013 hw
->fc
.pause_time
= IXGBE_DEFAULT_FCPAUSE
;
5014 hw
->fc
.send_xon
= true;
5015 hw
->fc
.disable_fc_autoneg
= false;
5017 /* enable itr by default in dynamic mode */
5018 adapter
->rx_itr_setting
= 1;
5019 adapter
->tx_itr_setting
= 1;
5021 /* set defaults for eitr in MegaBytes */
5022 adapter
->eitr_low
= 10;
5023 adapter
->eitr_high
= 20;
5025 /* set default ring sizes */
5026 adapter
->tx_ring_count
= IXGBE_DEFAULT_TXD
;
5027 adapter
->rx_ring_count
= IXGBE_DEFAULT_RXD
;
5029 /* set default work limits */
5030 adapter
->tx_work_limit
= IXGBE_DEFAULT_TX_WORK
;
5032 /* initialize eeprom parameters */
5033 if (ixgbe_init_eeprom_params_generic(hw
)) {
5034 e_dev_err("EEPROM initialization failed\n");
5038 /* enable rx csum by default */
5039 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
5041 /* get assigned NUMA node */
5042 adapter
->node
= dev_to_node(&pdev
->dev
);
5044 set_bit(__IXGBE_DOWN
, &adapter
->state
);
5050 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
5051 * @tx_ring: tx descriptor ring (for a specific queue) to setup
5053 * Return 0 on success, negative on failure
5055 int ixgbe_setup_tx_resources(struct ixgbe_ring
*tx_ring
)
5057 struct device
*dev
= tx_ring
->dev
;
5060 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
5061 tx_ring
->tx_buffer_info
= vzalloc_node(size
, tx_ring
->numa_node
);
5062 if (!tx_ring
->tx_buffer_info
)
5063 tx_ring
->tx_buffer_info
= vzalloc(size
);
5064 if (!tx_ring
->tx_buffer_info
)
5067 /* round up to nearest 4K */
5068 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
5069 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
5071 tx_ring
->desc
= dma_alloc_coherent(dev
, tx_ring
->size
,
5072 &tx_ring
->dma
, GFP_KERNEL
);
5076 tx_ring
->next_to_use
= 0;
5077 tx_ring
->next_to_clean
= 0;
5081 vfree(tx_ring
->tx_buffer_info
);
5082 tx_ring
->tx_buffer_info
= NULL
;
5083 dev_err(dev
, "Unable to allocate memory for the Tx descriptor ring\n");
5088 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5089 * @adapter: board private structure
5091 * If this function returns with an error, then it's possible one or
5092 * more of the rings is populated (while the rest are not). It is the
5093 * callers duty to clean those orphaned rings.
5095 * Return 0 on success, negative on failure
5097 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter
*adapter
)
5101 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5102 err
= ixgbe_setup_tx_resources(adapter
->tx_ring
[i
]);
5105 e_err(probe
, "Allocation for Tx Queue %u failed\n", i
);
5113 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
5114 * @rx_ring: rx descriptor ring (for a specific queue) to setup
5116 * Returns 0 on success, negative on failure
5118 int ixgbe_setup_rx_resources(struct ixgbe_ring
*rx_ring
)
5120 struct device
*dev
= rx_ring
->dev
;
5123 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
5124 rx_ring
->rx_buffer_info
= vzalloc_node(size
, rx_ring
->numa_node
);
5125 if (!rx_ring
->rx_buffer_info
)
5126 rx_ring
->rx_buffer_info
= vzalloc(size
);
5127 if (!rx_ring
->rx_buffer_info
)
5130 /* Round up to nearest 4K */
5131 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
5132 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
5134 rx_ring
->desc
= dma_alloc_coherent(dev
, rx_ring
->size
,
5135 &rx_ring
->dma
, GFP_KERNEL
);
5140 rx_ring
->next_to_clean
= 0;
5141 rx_ring
->next_to_use
= 0;
5145 vfree(rx_ring
->rx_buffer_info
);
5146 rx_ring
->rx_buffer_info
= NULL
;
5147 dev_err(dev
, "Unable to allocate memory for the Rx descriptor ring\n");
5152 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5153 * @adapter: board private structure
5155 * If this function returns with an error, then it's possible one or
5156 * more of the rings is populated (while the rest are not). It is the
5157 * callers duty to clean those orphaned rings.
5159 * Return 0 on success, negative on failure
5161 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter
*adapter
)
5165 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5166 err
= ixgbe_setup_rx_resources(adapter
->rx_ring
[i
]);
5169 e_err(probe
, "Allocation for Rx Queue %u failed\n", i
);
5177 * ixgbe_free_tx_resources - Free Tx Resources per Queue
5178 * @tx_ring: Tx descriptor ring for a specific queue
5180 * Free all transmit software resources
5182 void ixgbe_free_tx_resources(struct ixgbe_ring
*tx_ring
)
5184 ixgbe_clean_tx_ring(tx_ring
);
5186 vfree(tx_ring
->tx_buffer_info
);
5187 tx_ring
->tx_buffer_info
= NULL
;
5189 /* if not set, then don't free */
5193 dma_free_coherent(tx_ring
->dev
, tx_ring
->size
,
5194 tx_ring
->desc
, tx_ring
->dma
);
5196 tx_ring
->desc
= NULL
;
5200 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5201 * @adapter: board private structure
5203 * Free all transmit software resources
5205 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter
*adapter
)
5209 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5210 if (adapter
->tx_ring
[i
]->desc
)
5211 ixgbe_free_tx_resources(adapter
->tx_ring
[i
]);
5215 * ixgbe_free_rx_resources - Free Rx Resources
5216 * @rx_ring: ring to clean the resources from
5218 * Free all receive software resources
5220 void ixgbe_free_rx_resources(struct ixgbe_ring
*rx_ring
)
5222 ixgbe_clean_rx_ring(rx_ring
);
5224 vfree(rx_ring
->rx_buffer_info
);
5225 rx_ring
->rx_buffer_info
= NULL
;
5227 /* if not set, then don't free */
5231 dma_free_coherent(rx_ring
->dev
, rx_ring
->size
,
5232 rx_ring
->desc
, rx_ring
->dma
);
5234 rx_ring
->desc
= NULL
;
5238 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5239 * @adapter: board private structure
5241 * Free all receive software resources
5243 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter
*adapter
)
5247 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
5248 if (adapter
->rx_ring
[i
]->desc
)
5249 ixgbe_free_rx_resources(adapter
->rx_ring
[i
]);
5253 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5254 * @netdev: network interface device structure
5255 * @new_mtu: new value for maximum frame size
5257 * Returns 0 on success, negative on failure
5259 static int ixgbe_change_mtu(struct net_device
*netdev
, int new_mtu
)
5261 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5262 struct ixgbe_hw
*hw
= &adapter
->hw
;
5263 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5265 /* MTU < 68 is an error and causes problems on some kernels */
5266 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
&&
5267 hw
->mac
.type
!= ixgbe_mac_X540
) {
5268 if ((new_mtu
< 68) || (max_frame
> MAXIMUM_ETHERNET_VLAN_SIZE
))
5271 if ((new_mtu
< 68) || (max_frame
> IXGBE_MAX_JUMBO_FRAME_SIZE
))
5275 e_info(probe
, "changing MTU from %d to %d\n", netdev
->mtu
, new_mtu
);
5276 /* must set new MTU before calling down or up */
5277 netdev
->mtu
= new_mtu
;
5279 if (netif_running(netdev
))
5280 ixgbe_reinit_locked(adapter
);
5286 * ixgbe_open - Called when a network interface is made active
5287 * @netdev: network interface device structure
5289 * Returns 0 on success, negative value on failure
5291 * The open entry point is called when a network interface is made
5292 * active by the system (IFF_UP). At this point all resources needed
5293 * for transmit and receive operations are allocated, the interrupt
5294 * handler is registered with the OS, the watchdog timer is started,
5295 * and the stack is notified that the interface is ready.
5297 static int ixgbe_open(struct net_device
*netdev
)
5299 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5302 /* disallow open during test */
5303 if (test_bit(__IXGBE_TESTING
, &adapter
->state
))
5306 netif_carrier_off(netdev
);
5308 /* allocate transmit descriptors */
5309 err
= ixgbe_setup_all_tx_resources(adapter
);
5313 /* allocate receive descriptors */
5314 err
= ixgbe_setup_all_rx_resources(adapter
);
5318 ixgbe_configure(adapter
);
5320 err
= ixgbe_request_irq(adapter
);
5324 ixgbe_up_complete(adapter
);
5330 ixgbe_free_all_rx_resources(adapter
);
5332 ixgbe_free_all_tx_resources(adapter
);
5333 ixgbe_reset(adapter
);
5339 * ixgbe_close - Disables a network interface
5340 * @netdev: network interface device structure
5342 * Returns 0, this is not allowed to fail
5344 * The close entry point is called when an interface is de-activated
5345 * by the OS. The hardware is still under the drivers control, but
5346 * needs to be disabled. A global MAC reset is issued to stop the
5347 * hardware, and all transmit and receive resources are freed.
5349 static int ixgbe_close(struct net_device
*netdev
)
5351 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5353 ixgbe_down(adapter
);
5354 ixgbe_free_irq(adapter
);
5356 ixgbe_fdir_filter_exit(adapter
);
5358 ixgbe_free_all_tx_resources(adapter
);
5359 ixgbe_free_all_rx_resources(adapter
);
5361 ixgbe_release_hw_control(adapter
);
5367 static int ixgbe_resume(struct pci_dev
*pdev
)
5369 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
5370 struct net_device
*netdev
= adapter
->netdev
;
5373 pci_set_power_state(pdev
, PCI_D0
);
5374 pci_restore_state(pdev
);
5376 * pci_restore_state clears dev->state_saved so call
5377 * pci_save_state to restore it.
5379 pci_save_state(pdev
);
5381 err
= pci_enable_device_mem(pdev
);
5383 e_dev_err("Cannot enable PCI device from suspend\n");
5386 pci_set_master(pdev
);
5388 pci_wake_from_d3(pdev
, false);
5390 err
= ixgbe_init_interrupt_scheme(adapter
);
5392 e_dev_err("Cannot initialize interrupts for device\n");
5396 ixgbe_reset(adapter
);
5398 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
5400 if (netif_running(netdev
)) {
5401 err
= ixgbe_open(netdev
);
5406 netif_device_attach(netdev
);
5410 #endif /* CONFIG_PM */
5412 static int __ixgbe_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
5414 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
5415 struct net_device
*netdev
= adapter
->netdev
;
5416 struct ixgbe_hw
*hw
= &adapter
->hw
;
5418 u32 wufc
= adapter
->wol
;
5423 netif_device_detach(netdev
);
5425 if (netif_running(netdev
)) {
5426 ixgbe_down(adapter
);
5427 ixgbe_free_irq(adapter
);
5428 ixgbe_free_all_tx_resources(adapter
);
5429 ixgbe_free_all_rx_resources(adapter
);
5432 ixgbe_clear_interrupt_scheme(adapter
);
5434 kfree(adapter
->ixgbe_ieee_pfc
);
5435 kfree(adapter
->ixgbe_ieee_ets
);
5439 retval
= pci_save_state(pdev
);
5445 ixgbe_set_rx_mode(netdev
);
5447 /* turn on all-multi mode if wake on multicast is enabled */
5448 if (wufc
& IXGBE_WUFC_MC
) {
5449 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
5450 fctrl
|= IXGBE_FCTRL_MPE
;
5451 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
5454 ctrl
= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
5455 ctrl
|= IXGBE_CTRL_GIO_DIS
;
5456 IXGBE_WRITE_REG(hw
, IXGBE_CTRL
, ctrl
);
5458 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, wufc
);
5460 IXGBE_WRITE_REG(hw
, IXGBE_WUC
, 0);
5461 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, 0);
5464 switch (hw
->mac
.type
) {
5465 case ixgbe_mac_82598EB
:
5466 pci_wake_from_d3(pdev
, false);
5468 case ixgbe_mac_82599EB
:
5469 case ixgbe_mac_X540
:
5470 pci_wake_from_d3(pdev
, !!wufc
);
5476 *enable_wake
= !!wufc
;
5478 ixgbe_release_hw_control(adapter
);
5480 pci_disable_device(pdev
);
5486 static int ixgbe_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5491 retval
= __ixgbe_shutdown(pdev
, &wake
);
5496 pci_prepare_to_sleep(pdev
);
5498 pci_wake_from_d3(pdev
, false);
5499 pci_set_power_state(pdev
, PCI_D3hot
);
5504 #endif /* CONFIG_PM */
5506 static void ixgbe_shutdown(struct pci_dev
*pdev
)
5510 __ixgbe_shutdown(pdev
, &wake
);
5512 if (system_state
== SYSTEM_POWER_OFF
) {
5513 pci_wake_from_d3(pdev
, wake
);
5514 pci_set_power_state(pdev
, PCI_D3hot
);
5519 * ixgbe_update_stats - Update the board statistics counters.
5520 * @adapter: board private structure
5522 void ixgbe_update_stats(struct ixgbe_adapter
*adapter
)
5524 struct net_device
*netdev
= adapter
->netdev
;
5525 struct ixgbe_hw
*hw
= &adapter
->hw
;
5526 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
5528 u32 i
, missed_rx
= 0, mpc
, bprc
, lxon
, lxoff
, xon_off_tot
;
5529 u64 non_eop_descs
= 0, restart_queue
= 0, tx_busy
= 0;
5530 u64 alloc_rx_page_failed
= 0, alloc_rx_buff_failed
= 0;
5531 u64 bytes
= 0, packets
= 0;
5533 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
5534 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
5537 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) {
5540 for (i
= 0; i
< 16; i
++)
5541 adapter
->hw_rx_no_dma_resources
+=
5542 IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
5543 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5544 rsc_count
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_count
;
5545 rsc_flush
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_flush
;
5547 adapter
->rsc_total_count
= rsc_count
;
5548 adapter
->rsc_total_flush
= rsc_flush
;
5551 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5552 struct ixgbe_ring
*rx_ring
= adapter
->rx_ring
[i
];
5553 non_eop_descs
+= rx_ring
->rx_stats
.non_eop_descs
;
5554 alloc_rx_page_failed
+= rx_ring
->rx_stats
.alloc_rx_page_failed
;
5555 alloc_rx_buff_failed
+= rx_ring
->rx_stats
.alloc_rx_buff_failed
;
5556 bytes
+= rx_ring
->stats
.bytes
;
5557 packets
+= rx_ring
->stats
.packets
;
5559 adapter
->non_eop_descs
= non_eop_descs
;
5560 adapter
->alloc_rx_page_failed
= alloc_rx_page_failed
;
5561 adapter
->alloc_rx_buff_failed
= alloc_rx_buff_failed
;
5562 netdev
->stats
.rx_bytes
= bytes
;
5563 netdev
->stats
.rx_packets
= packets
;
5567 /* gather some stats to the adapter struct that are per queue */
5568 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5569 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
5570 restart_queue
+= tx_ring
->tx_stats
.restart_queue
;
5571 tx_busy
+= tx_ring
->tx_stats
.tx_busy
;
5572 bytes
+= tx_ring
->stats
.bytes
;
5573 packets
+= tx_ring
->stats
.packets
;
5575 adapter
->restart_queue
= restart_queue
;
5576 adapter
->tx_busy
= tx_busy
;
5577 netdev
->stats
.tx_bytes
= bytes
;
5578 netdev
->stats
.tx_packets
= packets
;
5580 hwstats
->crcerrs
+= IXGBE_READ_REG(hw
, IXGBE_CRCERRS
);
5582 /* 8 register reads */
5583 for (i
= 0; i
< 8; i
++) {
5584 /* for packet buffers not used, the register should read 0 */
5585 mpc
= IXGBE_READ_REG(hw
, IXGBE_MPC(i
));
5587 hwstats
->mpc
[i
] += mpc
;
5588 total_mpc
+= hwstats
->mpc
[i
];
5589 hwstats
->pxontxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXONTXC(i
));
5590 hwstats
->pxofftxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXOFFTXC(i
));
5591 switch (hw
->mac
.type
) {
5592 case ixgbe_mac_82598EB
:
5593 hwstats
->rnbc
[i
] += IXGBE_READ_REG(hw
, IXGBE_RNBC(i
));
5594 hwstats
->qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC(i
));
5595 hwstats
->qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC(i
));
5596 hwstats
->pxonrxc
[i
] +=
5597 IXGBE_READ_REG(hw
, IXGBE_PXONRXC(i
));
5599 case ixgbe_mac_82599EB
:
5600 case ixgbe_mac_X540
:
5601 hwstats
->pxonrxc
[i
] +=
5602 IXGBE_READ_REG(hw
, IXGBE_PXONRXCNT(i
));
5609 /*16 register reads */
5610 for (i
= 0; i
< 16; i
++) {
5611 hwstats
->qptc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPTC(i
));
5612 hwstats
->qprc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRC(i
));
5613 if ((hw
->mac
.type
== ixgbe_mac_82599EB
) ||
5614 (hw
->mac
.type
== ixgbe_mac_X540
)) {
5615 hwstats
->qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC_L(i
));
5616 IXGBE_READ_REG(hw
, IXGBE_QBTC_H(i
)); /* to clear */
5617 hwstats
->qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC_L(i
));
5618 IXGBE_READ_REG(hw
, IXGBE_QBRC_H(i
)); /* to clear */
5622 hwstats
->gprc
+= IXGBE_READ_REG(hw
, IXGBE_GPRC
);
5623 /* work around hardware counting issue */
5624 hwstats
->gprc
-= missed_rx
;
5626 ixgbe_update_xoff_received(adapter
);
5628 /* 82598 hardware only has a 32 bit counter in the high register */
5629 switch (hw
->mac
.type
) {
5630 case ixgbe_mac_82598EB
:
5631 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXC
);
5632 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCH
);
5633 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCH
);
5634 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORH
);
5636 case ixgbe_mac_X540
:
5637 /* OS2BMC stats are X540 only*/
5638 hwstats
->o2bgptc
+= IXGBE_READ_REG(hw
, IXGBE_O2BGPTC
);
5639 hwstats
->o2bspc
+= IXGBE_READ_REG(hw
, IXGBE_O2BSPC
);
5640 hwstats
->b2ospc
+= IXGBE_READ_REG(hw
, IXGBE_B2OSPC
);
5641 hwstats
->b2ogprc
+= IXGBE_READ_REG(hw
, IXGBE_B2OGPRC
);
5642 case ixgbe_mac_82599EB
:
5643 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCL
);
5644 IXGBE_READ_REG(hw
, IXGBE_GORCH
); /* to clear */
5645 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCL
);
5646 IXGBE_READ_REG(hw
, IXGBE_GOTCH
); /* to clear */
5647 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORL
);
5648 IXGBE_READ_REG(hw
, IXGBE_TORH
); /* to clear */
5649 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXCNT
);
5650 hwstats
->fdirmatch
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMATCH
);
5651 hwstats
->fdirmiss
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMISS
);
5653 hwstats
->fccrc
+= IXGBE_READ_REG(hw
, IXGBE_FCCRC
);
5654 hwstats
->fcoerpdc
+= IXGBE_READ_REG(hw
, IXGBE_FCOERPDC
);
5655 hwstats
->fcoeprc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPRC
);
5656 hwstats
->fcoeptc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPTC
);
5657 hwstats
->fcoedwrc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWRC
);
5658 hwstats
->fcoedwtc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWTC
);
5659 #endif /* IXGBE_FCOE */
5664 bprc
= IXGBE_READ_REG(hw
, IXGBE_BPRC
);
5665 hwstats
->bprc
+= bprc
;
5666 hwstats
->mprc
+= IXGBE_READ_REG(hw
, IXGBE_MPRC
);
5667 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
5668 hwstats
->mprc
-= bprc
;
5669 hwstats
->roc
+= IXGBE_READ_REG(hw
, IXGBE_ROC
);
5670 hwstats
->prc64
+= IXGBE_READ_REG(hw
, IXGBE_PRC64
);
5671 hwstats
->prc127
+= IXGBE_READ_REG(hw
, IXGBE_PRC127
);
5672 hwstats
->prc255
+= IXGBE_READ_REG(hw
, IXGBE_PRC255
);
5673 hwstats
->prc511
+= IXGBE_READ_REG(hw
, IXGBE_PRC511
);
5674 hwstats
->prc1023
+= IXGBE_READ_REG(hw
, IXGBE_PRC1023
);
5675 hwstats
->prc1522
+= IXGBE_READ_REG(hw
, IXGBE_PRC1522
);
5676 hwstats
->rlec
+= IXGBE_READ_REG(hw
, IXGBE_RLEC
);
5677 lxon
= IXGBE_READ_REG(hw
, IXGBE_LXONTXC
);
5678 hwstats
->lxontxc
+= lxon
;
5679 lxoff
= IXGBE_READ_REG(hw
, IXGBE_LXOFFTXC
);
5680 hwstats
->lxofftxc
+= lxoff
;
5681 hwstats
->gptc
+= IXGBE_READ_REG(hw
, IXGBE_GPTC
);
5682 hwstats
->mptc
+= IXGBE_READ_REG(hw
, IXGBE_MPTC
);
5684 * 82598 errata - tx of flow control packets is included in tx counters
5686 xon_off_tot
= lxon
+ lxoff
;
5687 hwstats
->gptc
-= xon_off_tot
;
5688 hwstats
->mptc
-= xon_off_tot
;
5689 hwstats
->gotc
-= (xon_off_tot
* (ETH_ZLEN
+ ETH_FCS_LEN
));
5690 hwstats
->ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
5691 hwstats
->rfc
+= IXGBE_READ_REG(hw
, IXGBE_RFC
);
5692 hwstats
->rjc
+= IXGBE_READ_REG(hw
, IXGBE_RJC
);
5693 hwstats
->tpr
+= IXGBE_READ_REG(hw
, IXGBE_TPR
);
5694 hwstats
->ptc64
+= IXGBE_READ_REG(hw
, IXGBE_PTC64
);
5695 hwstats
->ptc64
-= xon_off_tot
;
5696 hwstats
->ptc127
+= IXGBE_READ_REG(hw
, IXGBE_PTC127
);
5697 hwstats
->ptc255
+= IXGBE_READ_REG(hw
, IXGBE_PTC255
);
5698 hwstats
->ptc511
+= IXGBE_READ_REG(hw
, IXGBE_PTC511
);
5699 hwstats
->ptc1023
+= IXGBE_READ_REG(hw
, IXGBE_PTC1023
);
5700 hwstats
->ptc1522
+= IXGBE_READ_REG(hw
, IXGBE_PTC1522
);
5701 hwstats
->bptc
+= IXGBE_READ_REG(hw
, IXGBE_BPTC
);
5703 /* Fill out the OS statistics structure */
5704 netdev
->stats
.multicast
= hwstats
->mprc
;
5707 netdev
->stats
.rx_errors
= hwstats
->crcerrs
+ hwstats
->rlec
;
5708 netdev
->stats
.rx_dropped
= 0;
5709 netdev
->stats
.rx_length_errors
= hwstats
->rlec
;
5710 netdev
->stats
.rx_crc_errors
= hwstats
->crcerrs
;
5711 netdev
->stats
.rx_missed_errors
= total_mpc
;
5715 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5716 * @adapter - pointer to the device adapter structure
5718 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter
*adapter
)
5720 struct ixgbe_hw
*hw
= &adapter
->hw
;
5723 if (!(adapter
->flags2
& IXGBE_FLAG2_FDIR_REQUIRES_REINIT
))
5726 adapter
->flags2
&= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
5728 /* if interface is down do nothing */
5729 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
5732 /* do nothing if we are not using signature filters */
5733 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
))
5736 adapter
->fdir_overflow
++;
5738 if (ixgbe_reinit_fdir_tables_82599(hw
) == 0) {
5739 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5740 set_bit(__IXGBE_TX_FDIR_INIT_DONE
,
5741 &(adapter
->tx_ring
[i
]->state
));
5742 /* re-enable flow director interrupts */
5743 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMS_FLOW_DIR
);
5745 e_err(probe
, "failed to finish FDIR re-initialization, "
5746 "ignored adding FDIR ATR filters\n");
5751 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5752 * @adapter - pointer to the device adapter structure
5754 * This function serves two purposes. First it strobes the interrupt lines
5755 * in order to make certain interrupts are occuring. Secondly it sets the
5756 * bits needed to check for TX hangs. As a result we should immediately
5757 * determine if a hang has occured.
5759 static void ixgbe_check_hang_subtask(struct ixgbe_adapter
*adapter
)
5761 struct ixgbe_hw
*hw
= &adapter
->hw
;
5765 /* If we're down or resetting, just bail */
5766 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
5767 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
5770 /* Force detection of hung controller */
5771 if (netif_carrier_ok(adapter
->netdev
)) {
5772 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5773 set_check_for_tx_hang(adapter
->tx_ring
[i
]);
5776 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
5778 * for legacy and MSI interrupts don't set any bits
5779 * that are enabled for EIAM, because this operation
5780 * would set *both* EIMS and EICS for any bit in EIAM
5782 IXGBE_WRITE_REG(hw
, IXGBE_EICS
,
5783 (IXGBE_EICS_TCP_TIMER
| IXGBE_EICS_OTHER
));
5785 /* get one bit for every active tx/rx interrupt vector */
5786 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
5787 struct ixgbe_q_vector
*qv
= adapter
->q_vector
[i
];
5788 if (qv
->rx
.ring
|| qv
->tx
.ring
)
5789 eics
|= ((u64
)1 << i
);
5793 /* Cause software interrupt to ensure rings are cleaned */
5794 ixgbe_irq_rearm_queues(adapter
, eics
);
5799 * ixgbe_watchdog_update_link - update the link status
5800 * @adapter - pointer to the device adapter structure
5801 * @link_speed - pointer to a u32 to store the link_speed
5803 static void ixgbe_watchdog_update_link(struct ixgbe_adapter
*adapter
)
5805 struct ixgbe_hw
*hw
= &adapter
->hw
;
5806 u32 link_speed
= adapter
->link_speed
;
5807 bool link_up
= adapter
->link_up
;
5810 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
))
5813 if (hw
->mac
.ops
.check_link
) {
5814 hw
->mac
.ops
.check_link(hw
, &link_speed
, &link_up
, false);
5816 /* always assume link is up, if no check link function */
5817 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
5821 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5822 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++)
5823 hw
->mac
.ops
.fc_enable(hw
, i
);
5825 hw
->mac
.ops
.fc_enable(hw
, 0);
5830 time_after(jiffies
, (adapter
->link_check_timeout
+
5831 IXGBE_TRY_LINK_TIMEOUT
))) {
5832 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
5833 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMC_LSC
);
5834 IXGBE_WRITE_FLUSH(hw
);
5837 adapter
->link_up
= link_up
;
5838 adapter
->link_speed
= link_speed
;
5842 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5843 * print link up message
5844 * @adapter - pointer to the device adapter structure
5846 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter
*adapter
)
5848 struct net_device
*netdev
= adapter
->netdev
;
5849 struct ixgbe_hw
*hw
= &adapter
->hw
;
5850 u32 link_speed
= adapter
->link_speed
;
5851 bool flow_rx
, flow_tx
;
5853 /* only continue if link was previously down */
5854 if (netif_carrier_ok(netdev
))
5857 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
5859 switch (hw
->mac
.type
) {
5860 case ixgbe_mac_82598EB
: {
5861 u32 frctl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
5862 u32 rmcs
= IXGBE_READ_REG(hw
, IXGBE_RMCS
);
5863 flow_rx
= !!(frctl
& IXGBE_FCTRL_RFCE
);
5864 flow_tx
= !!(rmcs
& IXGBE_RMCS_TFCE_802_3X
);
5867 case ixgbe_mac_X540
:
5868 case ixgbe_mac_82599EB
: {
5869 u32 mflcn
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
5870 u32 fccfg
= IXGBE_READ_REG(hw
, IXGBE_FCCFG
);
5871 flow_rx
= !!(mflcn
& IXGBE_MFLCN_RFCE
);
5872 flow_tx
= !!(fccfg
& IXGBE_FCCFG_TFCE_802_3X
);
5880 e_info(drv
, "NIC Link is Up %s, Flow Control: %s\n",
5881 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
?
5883 (link_speed
== IXGBE_LINK_SPEED_1GB_FULL
?
5885 (link_speed
== IXGBE_LINK_SPEED_100_FULL
?
5888 ((flow_rx
&& flow_tx
) ? "RX/TX" :
5890 (flow_tx
? "TX" : "None"))));
5892 netif_carrier_on(netdev
);
5893 ixgbe_check_vf_rate_limit(adapter
);
5897 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5898 * print link down message
5899 * @adapter - pointer to the adapter structure
5901 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter
* adapter
)
5903 struct net_device
*netdev
= adapter
->netdev
;
5904 struct ixgbe_hw
*hw
= &adapter
->hw
;
5906 adapter
->link_up
= false;
5907 adapter
->link_speed
= 0;
5909 /* only continue if link was up previously */
5910 if (!netif_carrier_ok(netdev
))
5913 /* poll for SFP+ cable when link is down */
5914 if (ixgbe_is_sfp(hw
) && hw
->mac
.type
== ixgbe_mac_82598EB
)
5915 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
5917 e_info(drv
, "NIC Link is Down\n");
5918 netif_carrier_off(netdev
);
5922 * ixgbe_watchdog_flush_tx - flush queues on link down
5923 * @adapter - pointer to the device adapter structure
5925 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter
*adapter
)
5928 int some_tx_pending
= 0;
5930 if (!netif_carrier_ok(adapter
->netdev
)) {
5931 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5932 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
5933 if (tx_ring
->next_to_use
!= tx_ring
->next_to_clean
) {
5934 some_tx_pending
= 1;
5939 if (some_tx_pending
) {
5940 /* We've lost link, so the controller stops DMA,
5941 * but we've got queued Tx work that's never going
5942 * to get done, so reset controller to flush Tx.
5943 * (Do the reset outside of interrupt context).
5945 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
5950 static void ixgbe_spoof_check(struct ixgbe_adapter
*adapter
)
5954 /* Do not perform spoof check for 82598 */
5955 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
5958 ssvpc
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SSVPC
);
5961 * ssvpc register is cleared on read, if zero then no
5962 * spoofed packets in the last interval.
5967 e_warn(drv
, "%d Spoofed packets detected\n", ssvpc
);
5971 * ixgbe_watchdog_subtask - check and bring link up
5972 * @adapter - pointer to the device adapter structure
5974 static void ixgbe_watchdog_subtask(struct ixgbe_adapter
*adapter
)
5976 /* if interface is down do nothing */
5977 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
5980 ixgbe_watchdog_update_link(adapter
);
5982 if (adapter
->link_up
)
5983 ixgbe_watchdog_link_is_up(adapter
);
5985 ixgbe_watchdog_link_is_down(adapter
);
5987 ixgbe_spoof_check(adapter
);
5988 ixgbe_update_stats(adapter
);
5990 ixgbe_watchdog_flush_tx(adapter
);
5994 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
5995 * @adapter - the ixgbe adapter structure
5997 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter
*adapter
)
5999 struct ixgbe_hw
*hw
= &adapter
->hw
;
6002 /* not searching for SFP so there is nothing to do here */
6003 if (!(adapter
->flags2
& IXGBE_FLAG2_SEARCH_FOR_SFP
) &&
6004 !(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
6007 /* someone else is in init, wait until next service event */
6008 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
6011 err
= hw
->phy
.ops
.identify_sfp(hw
);
6012 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
6015 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
) {
6016 /* If no cable is present, then we need to reset
6017 * the next time we find a good cable. */
6018 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
6025 /* exit if reset not needed */
6026 if (!(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
6029 adapter
->flags2
&= ~IXGBE_FLAG2_SFP_NEEDS_RESET
;
6032 * A module may be identified correctly, but the EEPROM may not have
6033 * support for that module. setup_sfp() will fail in that case, so
6034 * we should not allow that module to load.
6036 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
6037 err
= hw
->phy
.ops
.reset(hw
);
6039 err
= hw
->mac
.ops
.setup_sfp(hw
);
6041 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
6044 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
6045 e_info(probe
, "detected SFP+: %d\n", hw
->phy
.sfp_type
);
6048 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
6050 if ((err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) &&
6051 (adapter
->netdev
->reg_state
== NETREG_REGISTERED
)) {
6052 e_dev_err("failed to initialize because an unsupported "
6053 "SFP+ module type was detected.\n");
6054 e_dev_err("Reload the driver after installing a "
6055 "supported module.\n");
6056 unregister_netdev(adapter
->netdev
);
6061 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6062 * @adapter - the ixgbe adapter structure
6064 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter
*adapter
)
6066 struct ixgbe_hw
*hw
= &adapter
->hw
;
6070 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_CONFIG
))
6073 /* someone else is in init, wait until next service event */
6074 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
6077 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
6079 autoneg
= hw
->phy
.autoneg_advertised
;
6080 if ((!autoneg
) && (hw
->mac
.ops
.get_link_capabilities
))
6081 hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
, &negotiation
);
6082 hw
->mac
.autotry_restart
= false;
6083 if (hw
->mac
.ops
.setup_link
)
6084 hw
->mac
.ops
.setup_link(hw
, autoneg
, negotiation
, true);
6086 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
6087 adapter
->link_check_timeout
= jiffies
;
6088 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
6092 * ixgbe_service_timer - Timer Call-back
6093 * @data: pointer to adapter cast into an unsigned long
6095 static void ixgbe_service_timer(unsigned long data
)
6097 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
6098 unsigned long next_event_offset
;
6100 /* poll faster when waiting for link */
6101 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
)
6102 next_event_offset
= HZ
/ 10;
6104 next_event_offset
= HZ
* 2;
6106 /* Reset the timer */
6107 mod_timer(&adapter
->service_timer
, next_event_offset
+ jiffies
);
6109 ixgbe_service_event_schedule(adapter
);
6112 static void ixgbe_reset_subtask(struct ixgbe_adapter
*adapter
)
6114 if (!(adapter
->flags2
& IXGBE_FLAG2_RESET_REQUESTED
))
6117 adapter
->flags2
&= ~IXGBE_FLAG2_RESET_REQUESTED
;
6119 /* If we're already down or resetting, just bail */
6120 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
6121 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
6124 ixgbe_dump(adapter
);
6125 netdev_err(adapter
->netdev
, "Reset adapter\n");
6126 adapter
->tx_timeout_count
++;
6128 ixgbe_reinit_locked(adapter
);
6132 * ixgbe_service_task - manages and runs subtasks
6133 * @work: pointer to work_struct containing our data
6135 static void ixgbe_service_task(struct work_struct
*work
)
6137 struct ixgbe_adapter
*adapter
= container_of(work
,
6138 struct ixgbe_adapter
,
6141 ixgbe_reset_subtask(adapter
);
6142 ixgbe_sfp_detection_subtask(adapter
);
6143 ixgbe_sfp_link_config_subtask(adapter
);
6144 ixgbe_check_overtemp_subtask(adapter
);
6145 ixgbe_watchdog_subtask(adapter
);
6146 ixgbe_fdir_reinit_subtask(adapter
);
6147 ixgbe_check_hang_subtask(adapter
);
6149 ixgbe_service_event_complete(adapter
);
6152 void ixgbe_tx_ctxtdesc(struct ixgbe_ring
*tx_ring
, u32 vlan_macip_lens
,
6153 u32 fcoe_sof_eof
, u32 type_tucmd
, u32 mss_l4len_idx
)
6155 struct ixgbe_adv_tx_context_desc
*context_desc
;
6156 u16 i
= tx_ring
->next_to_use
;
6158 context_desc
= IXGBE_TX_CTXTDESC_ADV(tx_ring
, i
);
6161 tx_ring
->next_to_use
= (i
< tx_ring
->count
) ? i
: 0;
6163 /* set bits to identify this as an advanced context descriptor */
6164 type_tucmd
|= IXGBE_TXD_CMD_DEXT
| IXGBE_ADVTXD_DTYP_CTXT
;
6166 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
6167 context_desc
->seqnum_seed
= cpu_to_le32(fcoe_sof_eof
);
6168 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd
);
6169 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
6172 static int ixgbe_tso(struct ixgbe_ring
*tx_ring
, struct sk_buff
*skb
,
6173 u32 tx_flags
, __be16 protocol
, u8
*hdr_len
)
6176 u32 vlan_macip_lens
, type_tucmd
;
6177 u32 mss_l4len_idx
, l4len
;
6179 if (!skb_is_gso(skb
))
6182 if (skb_header_cloned(skb
)) {
6183 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
6188 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6189 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
6191 if (protocol
== __constant_htons(ETH_P_IP
)) {
6192 struct iphdr
*iph
= ip_hdr(skb
);
6195 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
6199 type_tucmd
|= IXGBE_ADVTXD_TUCMD_IPV4
;
6200 } else if (skb_is_gso_v6(skb
)) {
6201 ipv6_hdr(skb
)->payload_len
= 0;
6202 tcp_hdr(skb
)->check
=
6203 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
6204 &ipv6_hdr(skb
)->daddr
,
6208 l4len
= tcp_hdrlen(skb
);
6209 *hdr_len
= skb_transport_offset(skb
) + l4len
;
6211 /* mss_l4len_id: use 1 as index for TSO */
6212 mss_l4len_idx
= l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
;
6213 mss_l4len_idx
|= skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
;
6214 mss_l4len_idx
|= 1 << IXGBE_ADVTXD_IDX_SHIFT
;
6216 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6217 vlan_macip_lens
= skb_network_header_len(skb
);
6218 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
6219 vlan_macip_lens
|= tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
6221 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, 0, type_tucmd
,
6227 static bool ixgbe_tx_csum(struct ixgbe_ring
*tx_ring
,
6228 struct sk_buff
*skb
, u32 tx_flags
,
6231 u32 vlan_macip_lens
= 0;
6232 u32 mss_l4len_idx
= 0;
6235 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
) {
6236 if (!(tx_flags
& IXGBE_TX_FLAGS_HW_VLAN
) &&
6237 !(tx_flags
& IXGBE_TX_FLAGS_TXSW
))
6242 case __constant_htons(ETH_P_IP
):
6243 vlan_macip_lens
|= skb_network_header_len(skb
);
6244 type_tucmd
|= IXGBE_ADVTXD_TUCMD_IPV4
;
6245 l4_hdr
= ip_hdr(skb
)->protocol
;
6247 case __constant_htons(ETH_P_IPV6
):
6248 vlan_macip_lens
|= skb_network_header_len(skb
);
6249 l4_hdr
= ipv6_hdr(skb
)->nexthdr
;
6252 if (unlikely(net_ratelimit())) {
6253 dev_warn(tx_ring
->dev
,
6254 "partial checksum but proto=%x!\n",
6262 type_tucmd
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
6263 mss_l4len_idx
= tcp_hdrlen(skb
) <<
6264 IXGBE_ADVTXD_L4LEN_SHIFT
;
6267 type_tucmd
|= IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
6268 mss_l4len_idx
= sizeof(struct sctphdr
) <<
6269 IXGBE_ADVTXD_L4LEN_SHIFT
;
6272 mss_l4len_idx
= sizeof(struct udphdr
) <<
6273 IXGBE_ADVTXD_L4LEN_SHIFT
;
6276 if (unlikely(net_ratelimit())) {
6277 dev_warn(tx_ring
->dev
,
6278 "partial checksum but l4 proto=%x!\n",
6285 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
6286 vlan_macip_lens
|= tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
6288 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, 0,
6289 type_tucmd
, mss_l4len_idx
);
6291 return (skb
->ip_summed
== CHECKSUM_PARTIAL
);
6294 static __le32
ixgbe_tx_cmd_type(u32 tx_flags
)
6296 /* set type for advanced descriptor with frame checksum insertion */
6297 __le32 cmd_type
= cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA
|
6298 IXGBE_ADVTXD_DCMD_IFCS
|
6299 IXGBE_ADVTXD_DCMD_DEXT
);
6301 /* set HW vlan bit if vlan is present */
6302 if (tx_flags
& IXGBE_TX_FLAGS_HW_VLAN
)
6303 cmd_type
|= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE
);
6305 /* set segmentation enable bits for TSO/FSO */
6307 if ((tx_flags
& IXGBE_TX_FLAGS_TSO
) || (tx_flags
& IXGBE_TX_FLAGS_FSO
))
6309 if (tx_flags
& IXGBE_TX_FLAGS_TSO
)
6311 cmd_type
|= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE
);
6316 static __le32
ixgbe_tx_olinfo_status(u32 tx_flags
, unsigned int paylen
)
6318 __le32 olinfo_status
=
6319 cpu_to_le32(paylen
<< IXGBE_ADVTXD_PAYLEN_SHIFT
);
6321 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
6322 olinfo_status
|= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM
|
6323 (1 << IXGBE_ADVTXD_IDX_SHIFT
));
6324 /* enble IPv4 checksum for TSO */
6325 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
6326 olinfo_status
|= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM
);
6329 /* enable L4 checksum for TSO and TX checksum offload */
6330 if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
6331 olinfo_status
|= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM
);
6334 /* use index 1 context for FCOE/FSO */
6335 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
)
6336 olinfo_status
|= cpu_to_le32(IXGBE_ADVTXD_CC
|
6337 (1 << IXGBE_ADVTXD_IDX_SHIFT
));
6341 * Check Context must be set if Tx switch is enabled, which it
6342 * always is for case where virtual functions are running
6344 if (tx_flags
& IXGBE_TX_FLAGS_TXSW
)
6345 olinfo_status
|= cpu_to_le32(IXGBE_ADVTXD_CC
);
6347 return olinfo_status
;
6350 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6353 static void ixgbe_tx_map(struct ixgbe_ring
*tx_ring
,
6354 struct sk_buff
*skb
,
6355 struct ixgbe_tx_buffer
*first
,
6359 struct device
*dev
= tx_ring
->dev
;
6360 struct ixgbe_tx_buffer
*tx_buffer_info
;
6361 union ixgbe_adv_tx_desc
*tx_desc
;
6363 __le32 cmd_type
, olinfo_status
;
6364 struct skb_frag_struct
*frag
;
6366 unsigned int data_len
= skb
->data_len
;
6367 unsigned int size
= skb_headlen(skb
);
6369 u32 paylen
= skb
->len
- hdr_len
;
6370 u16 i
= tx_ring
->next_to_use
;
6374 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
6375 if (data_len
>= sizeof(struct fcoe_crc_eof
)) {
6376 data_len
-= sizeof(struct fcoe_crc_eof
);
6378 size
-= sizeof(struct fcoe_crc_eof
) - data_len
;
6384 dma
= dma_map_single(dev
, skb
->data
, size
, DMA_TO_DEVICE
);
6385 if (dma_mapping_error(dev
, dma
))
6388 cmd_type
= ixgbe_tx_cmd_type(tx_flags
);
6389 olinfo_status
= ixgbe_tx_olinfo_status(tx_flags
, paylen
);
6391 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, i
);
6394 while (size
> IXGBE_MAX_DATA_PER_TXD
) {
6395 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
+ offset
);
6396 tx_desc
->read
.cmd_type_len
=
6397 cmd_type
| cpu_to_le32(IXGBE_MAX_DATA_PER_TXD
);
6398 tx_desc
->read
.olinfo_status
= olinfo_status
;
6400 offset
+= IXGBE_MAX_DATA_PER_TXD
;
6401 size
-= IXGBE_MAX_DATA_PER_TXD
;
6405 if (i
== tx_ring
->count
) {
6406 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, 0);
6411 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
6412 tx_buffer_info
->length
= offset
+ size
;
6413 tx_buffer_info
->tx_flags
= tx_flags
;
6414 tx_buffer_info
->dma
= dma
;
6416 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
+ offset
);
6417 tx_desc
->read
.cmd_type_len
= cmd_type
| cpu_to_le32(size
);
6418 tx_desc
->read
.olinfo_status
= olinfo_status
;
6423 frag
= &skb_shinfo(skb
)->frags
[f
];
6425 size
= min_t(unsigned int, data_len
, frag
->size
);
6433 tx_flags
|= IXGBE_TX_FLAGS_MAPPED_AS_PAGE
;
6435 dma
= skb_frag_dma_map(dev
, frag
, 0, size
, DMA_TO_DEVICE
);
6436 if (dma_mapping_error(dev
, dma
))
6441 if (i
== tx_ring
->count
) {
6442 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, 0);
6447 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(IXGBE_TXD_CMD
);
6450 if (i
== tx_ring
->count
)
6453 tx_ring
->next_to_use
= i
;
6455 if (tx_flags
& IXGBE_TX_FLAGS_TSO
)
6456 gso_segs
= skb_shinfo(skb
)->gso_segs
;
6458 /* adjust for FCoE Sequence Offload */
6459 else if (tx_flags
& IXGBE_TX_FLAGS_FSO
)
6460 gso_segs
= DIV_ROUND_UP(skb
->len
- hdr_len
,
6461 skb_shinfo(skb
)->gso_size
);
6462 #endif /* IXGBE_FCOE */
6466 /* multiply data chunks by size of headers */
6467 tx_buffer_info
->bytecount
= paylen
+ (gso_segs
* hdr_len
);
6468 tx_buffer_info
->gso_segs
= gso_segs
;
6469 tx_buffer_info
->skb
= skb
;
6471 /* set the timestamp */
6472 first
->time_stamp
= jiffies
;
6475 * Force memory writes to complete before letting h/w
6476 * know there are new descriptors to fetch. (Only
6477 * applicable for weak-ordered memory model archs,
6482 /* set next_to_watch value indicating a packet is present */
6483 first
->next_to_watch
= tx_desc
;
6485 /* notify HW of packet */
6486 writel(i
, tx_ring
->tail
);
6490 dev_err(dev
, "TX DMA map failed\n");
6492 /* clear dma mappings for failed tx_buffer_info map */
6494 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
6495 ixgbe_unmap_tx_resource(tx_ring
, tx_buffer_info
);
6496 if (tx_buffer_info
== first
)
6503 dev_kfree_skb_any(skb
);
6505 tx_ring
->next_to_use
= i
;
6508 static void ixgbe_atr(struct ixgbe_ring
*ring
, struct sk_buff
*skb
,
6509 u32 tx_flags
, __be16 protocol
)
6511 struct ixgbe_q_vector
*q_vector
= ring
->q_vector
;
6512 union ixgbe_atr_hash_dword input
= { .dword
= 0 };
6513 union ixgbe_atr_hash_dword common
= { .dword
= 0 };
6515 unsigned char *network
;
6517 struct ipv6hdr
*ipv6
;
6522 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6526 /* do nothing if sampling is disabled */
6527 if (!ring
->atr_sample_rate
)
6532 /* snag network header to get L4 type and address */
6533 hdr
.network
= skb_network_header(skb
);
6535 /* Currently only IPv4/IPv6 with TCP is supported */
6536 if ((protocol
!= __constant_htons(ETH_P_IPV6
) ||
6537 hdr
.ipv6
->nexthdr
!= IPPROTO_TCP
) &&
6538 (protocol
!= __constant_htons(ETH_P_IP
) ||
6539 hdr
.ipv4
->protocol
!= IPPROTO_TCP
))
6544 /* skip this packet since it is invalid or the socket is closing */
6548 /* sample on all syn packets or once every atr sample count */
6549 if (!th
->syn
&& (ring
->atr_count
< ring
->atr_sample_rate
))
6552 /* reset sample count */
6553 ring
->atr_count
= 0;
6555 vlan_id
= htons(tx_flags
>> IXGBE_TX_FLAGS_VLAN_SHIFT
);
6558 * src and dst are inverted, think how the receiver sees them
6560 * The input is broken into two sections, a non-compressed section
6561 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6562 * is XORed together and stored in the compressed dword.
6564 input
.formatted
.vlan_id
= vlan_id
;
6567 * since src port and flex bytes occupy the same word XOR them together
6568 * and write the value to source port portion of compressed dword
6570 if (tx_flags
& (IXGBE_TX_FLAGS_SW_VLAN
| IXGBE_TX_FLAGS_HW_VLAN
))
6571 common
.port
.src
^= th
->dest
^ __constant_htons(ETH_P_8021Q
);
6573 common
.port
.src
^= th
->dest
^ protocol
;
6574 common
.port
.dst
^= th
->source
;
6576 if (protocol
== __constant_htons(ETH_P_IP
)) {
6577 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV4
;
6578 common
.ip
^= hdr
.ipv4
->saddr
^ hdr
.ipv4
->daddr
;
6580 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV6
;
6581 common
.ip
^= hdr
.ipv6
->saddr
.s6_addr32
[0] ^
6582 hdr
.ipv6
->saddr
.s6_addr32
[1] ^
6583 hdr
.ipv6
->saddr
.s6_addr32
[2] ^
6584 hdr
.ipv6
->saddr
.s6_addr32
[3] ^
6585 hdr
.ipv6
->daddr
.s6_addr32
[0] ^
6586 hdr
.ipv6
->daddr
.s6_addr32
[1] ^
6587 hdr
.ipv6
->daddr
.s6_addr32
[2] ^
6588 hdr
.ipv6
->daddr
.s6_addr32
[3];
6591 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
6592 ixgbe_fdir_add_signature_filter_82599(&q_vector
->adapter
->hw
,
6593 input
, common
, ring
->queue_index
);
6596 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
6598 netif_stop_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
6599 /* Herbert's original patch had:
6600 * smp_mb__after_netif_stop_queue();
6601 * but since that doesn't exist yet, just open code it. */
6604 /* We need to check again in a case another CPU has just
6605 * made room available. */
6606 if (likely(ixgbe_desc_unused(tx_ring
) < size
))
6609 /* A reprieve! - use start_queue because it doesn't call schedule */
6610 netif_start_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
6611 ++tx_ring
->tx_stats
.restart_queue
;
6615 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
6617 if (likely(ixgbe_desc_unused(tx_ring
) >= size
))
6619 return __ixgbe_maybe_stop_tx(tx_ring
, size
);
6622 static u16
ixgbe_select_queue(struct net_device
*dev
, struct sk_buff
*skb
)
6624 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
6625 int txq
= skb_rx_queue_recorded(skb
) ? skb_get_rx_queue(skb
) :
6628 __be16 protocol
= vlan_get_protocol(skb
);
6630 if (((protocol
== htons(ETH_P_FCOE
)) ||
6631 (protocol
== htons(ETH_P_FIP
))) &&
6632 (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)) {
6633 txq
&= (adapter
->ring_feature
[RING_F_FCOE
].indices
- 1);
6634 txq
+= adapter
->ring_feature
[RING_F_FCOE
].mask
;
6639 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
6640 while (unlikely(txq
>= dev
->real_num_tx_queues
))
6641 txq
-= dev
->real_num_tx_queues
;
6645 return skb_tx_hash(dev
, skb
);
6648 netdev_tx_t
ixgbe_xmit_frame_ring(struct sk_buff
*skb
,
6649 struct ixgbe_adapter
*adapter
,
6650 struct ixgbe_ring
*tx_ring
)
6652 struct ixgbe_tx_buffer
*first
;
6655 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6658 u16 count
= TXD_USE_COUNT(skb_headlen(skb
));
6659 __be16 protocol
= skb
->protocol
;
6663 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6664 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6665 * + 2 desc gap to keep tail from touching head,
6666 * + 1 desc for context descriptor,
6667 * otherwise try next time
6669 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6670 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
6671 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
6673 count
+= skb_shinfo(skb
)->nr_frags
;
6675 if (ixgbe_maybe_stop_tx(tx_ring
, count
+ 3)) {
6676 tx_ring
->tx_stats
.tx_busy
++;
6677 return NETDEV_TX_BUSY
;
6680 #ifdef CONFIG_PCI_IOV
6681 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
6682 tx_flags
|= IXGBE_TX_FLAGS_TXSW
;
6685 /* if we have a HW VLAN tag being added default to the HW one */
6686 if (vlan_tx_tag_present(skb
)) {
6687 tx_flags
|= vlan_tx_tag_get(skb
) << IXGBE_TX_FLAGS_VLAN_SHIFT
;
6688 tx_flags
|= IXGBE_TX_FLAGS_HW_VLAN
;
6689 /* else if it is a SW VLAN check the next protocol and store the tag */
6690 } else if (protocol
== __constant_htons(ETH_P_8021Q
)) {
6691 struct vlan_hdr
*vhdr
, _vhdr
;
6692 vhdr
= skb_header_pointer(skb
, ETH_HLEN
, sizeof(_vhdr
), &_vhdr
);
6696 protocol
= vhdr
->h_vlan_encapsulated_proto
;
6697 tx_flags
|= ntohs(vhdr
->h_vlan_TCI
) << IXGBE_TX_FLAGS_VLAN_SHIFT
;
6698 tx_flags
|= IXGBE_TX_FLAGS_SW_VLAN
;
6701 if ((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) &&
6702 ((tx_flags
& (IXGBE_TX_FLAGS_HW_VLAN
| IXGBE_TX_FLAGS_SW_VLAN
)) ||
6703 (skb
->priority
!= TC_PRIO_CONTROL
))) {
6704 tx_flags
&= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK
;
6705 tx_flags
|= tx_ring
->dcb_tc
<<
6706 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT
;
6707 if (tx_flags
& IXGBE_TX_FLAGS_SW_VLAN
) {
6708 struct vlan_ethhdr
*vhdr
;
6709 if (skb_header_cloned(skb
) &&
6710 pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
))
6712 vhdr
= (struct vlan_ethhdr
*)skb
->data
;
6713 vhdr
->h_vlan_TCI
= htons(tx_flags
>>
6714 IXGBE_TX_FLAGS_VLAN_SHIFT
);
6716 tx_flags
|= IXGBE_TX_FLAGS_HW_VLAN
;
6720 /* record the location of the first descriptor for this packet */
6721 first
= &tx_ring
->tx_buffer_info
[tx_ring
->next_to_use
];
6724 /* setup tx offload for FCoE */
6725 if ((protocol
== __constant_htons(ETH_P_FCOE
)) &&
6726 (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)) {
6727 tso
= ixgbe_fso(tx_ring
, skb
, tx_flags
, &hdr_len
);
6731 tx_flags
|= IXGBE_TX_FLAGS_FSO
|
6732 IXGBE_TX_FLAGS_FCOE
;
6734 tx_flags
|= IXGBE_TX_FLAGS_FCOE
;
6739 #endif /* IXGBE_FCOE */
6740 /* setup IPv4/IPv6 offloads */
6741 if (protocol
== __constant_htons(ETH_P_IP
))
6742 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
6744 tso
= ixgbe_tso(tx_ring
, skb
, tx_flags
, protocol
, &hdr_len
);
6748 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
6749 else if (ixgbe_tx_csum(tx_ring
, skb
, tx_flags
, protocol
))
6750 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
6752 /* add the ATR filter if ATR is on */
6753 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE
, &tx_ring
->state
))
6754 ixgbe_atr(tx_ring
, skb
, tx_flags
, protocol
);
6758 #endif /* IXGBE_FCOE */
6759 ixgbe_tx_map(tx_ring
, skb
, first
, tx_flags
, hdr_len
);
6761 ixgbe_maybe_stop_tx(tx_ring
, DESC_NEEDED
);
6763 return NETDEV_TX_OK
;
6766 dev_kfree_skb_any(skb
);
6767 return NETDEV_TX_OK
;
6770 static netdev_tx_t
ixgbe_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
6772 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6773 struct ixgbe_ring
*tx_ring
;
6775 tx_ring
= adapter
->tx_ring
[skb
->queue_mapping
];
6776 return ixgbe_xmit_frame_ring(skb
, adapter
, tx_ring
);
6780 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6781 * @netdev: network interface device structure
6782 * @p: pointer to an address structure
6784 * Returns 0 on success, negative on failure
6786 static int ixgbe_set_mac(struct net_device
*netdev
, void *p
)
6788 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6789 struct ixgbe_hw
*hw
= &adapter
->hw
;
6790 struct sockaddr
*addr
= p
;
6792 if (!is_valid_ether_addr(addr
->sa_data
))
6793 return -EADDRNOTAVAIL
;
6795 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
6796 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
6798 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, adapter
->num_vfs
,
6805 ixgbe_mdio_read(struct net_device
*netdev
, int prtad
, int devad
, u16 addr
)
6807 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6808 struct ixgbe_hw
*hw
= &adapter
->hw
;
6812 if (prtad
!= hw
->phy
.mdio
.prtad
)
6814 rc
= hw
->phy
.ops
.read_reg(hw
, addr
, devad
, &value
);
6820 static int ixgbe_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
6821 u16 addr
, u16 value
)
6823 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6824 struct ixgbe_hw
*hw
= &adapter
->hw
;
6826 if (prtad
!= hw
->phy
.mdio
.prtad
)
6828 return hw
->phy
.ops
.write_reg(hw
, addr
, devad
, value
);
6831 static int ixgbe_ioctl(struct net_device
*netdev
, struct ifreq
*req
, int cmd
)
6833 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6835 return mdio_mii_ioctl(&adapter
->hw
.phy
.mdio
, if_mii(req
), cmd
);
6839 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6841 * @netdev: network interface device structure
6843 * Returns non-zero on failure
6845 static int ixgbe_add_sanmac_netdev(struct net_device
*dev
)
6848 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
6849 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
6851 if (is_valid_ether_addr(mac
->san_addr
)) {
6853 err
= dev_addr_add(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
6860 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6862 * @netdev: network interface device structure
6864 * Returns non-zero on failure
6866 static int ixgbe_del_sanmac_netdev(struct net_device
*dev
)
6869 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
6870 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
6872 if (is_valid_ether_addr(mac
->san_addr
)) {
6874 err
= dev_addr_del(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
6880 #ifdef CONFIG_NET_POLL_CONTROLLER
6882 * Polling 'interrupt' - used by things like netconsole to send skbs
6883 * without having to re-enable interrupts. It's not called while
6884 * the interrupt routine is executing.
6886 static void ixgbe_netpoll(struct net_device
*netdev
)
6888 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6891 /* if interface is down do nothing */
6892 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
6895 adapter
->flags
|= IXGBE_FLAG_IN_NETPOLL
;
6896 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
6897 int num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
6898 for (i
= 0; i
< num_q_vectors
; i
++) {
6899 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
6900 ixgbe_msix_clean_rings(0, q_vector
);
6903 ixgbe_intr(adapter
->pdev
->irq
, netdev
);
6905 adapter
->flags
&= ~IXGBE_FLAG_IN_NETPOLL
;
6909 static struct rtnl_link_stats64
*ixgbe_get_stats64(struct net_device
*netdev
,
6910 struct rtnl_link_stats64
*stats
)
6912 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6916 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
6917 struct ixgbe_ring
*ring
= ACCESS_ONCE(adapter
->rx_ring
[i
]);
6923 start
= u64_stats_fetch_begin_bh(&ring
->syncp
);
6924 packets
= ring
->stats
.packets
;
6925 bytes
= ring
->stats
.bytes
;
6926 } while (u64_stats_fetch_retry_bh(&ring
->syncp
, start
));
6927 stats
->rx_packets
+= packets
;
6928 stats
->rx_bytes
+= bytes
;
6932 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
6933 struct ixgbe_ring
*ring
= ACCESS_ONCE(adapter
->tx_ring
[i
]);
6939 start
= u64_stats_fetch_begin_bh(&ring
->syncp
);
6940 packets
= ring
->stats
.packets
;
6941 bytes
= ring
->stats
.bytes
;
6942 } while (u64_stats_fetch_retry_bh(&ring
->syncp
, start
));
6943 stats
->tx_packets
+= packets
;
6944 stats
->tx_bytes
+= bytes
;
6948 /* following stats updated by ixgbe_watchdog_task() */
6949 stats
->multicast
= netdev
->stats
.multicast
;
6950 stats
->rx_errors
= netdev
->stats
.rx_errors
;
6951 stats
->rx_length_errors
= netdev
->stats
.rx_length_errors
;
6952 stats
->rx_crc_errors
= netdev
->stats
.rx_crc_errors
;
6953 stats
->rx_missed_errors
= netdev
->stats
.rx_missed_errors
;
6957 /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6958 * #adapter: pointer to ixgbe_adapter
6959 * @tc: number of traffic classes currently enabled
6961 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6962 * 802.1Q priority maps to a packet buffer that exists.
6964 static void ixgbe_validate_rtr(struct ixgbe_adapter
*adapter
, u8 tc
)
6966 struct ixgbe_hw
*hw
= &adapter
->hw
;
6970 /* 82598 have a static priority to TC mapping that can not
6971 * be changed so no validation is needed.
6973 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
6976 reg
= IXGBE_READ_REG(hw
, IXGBE_RTRUP2TC
);
6979 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
6980 u8 up2tc
= reg
>> (i
* IXGBE_RTRUP2TC_UP_SHIFT
);
6982 /* If up2tc is out of bounds default to zero */
6984 reg
&= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT
);
6988 IXGBE_WRITE_REG(hw
, IXGBE_RTRUP2TC
, reg
);
6994 /* ixgbe_setup_tc - routine to configure net_device for multiple traffic
6997 * @netdev: net device to configure
6998 * @tc: number of traffic classes to enable
7000 int ixgbe_setup_tc(struct net_device
*dev
, u8 tc
)
7002 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
7003 struct ixgbe_hw
*hw
= &adapter
->hw
;
7005 /* Multiple traffic classes requires multiple queues */
7006 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
7007 e_err(drv
, "Enable failed, needs MSI-X\n");
7011 /* Hardware supports up to 8 traffic classes */
7012 if (tc
> MAX_TRAFFIC_CLASS
||
7013 (hw
->mac
.type
== ixgbe_mac_82598EB
&& tc
< MAX_TRAFFIC_CLASS
))
7016 /* Hardware has to reinitialize queues and interrupts to
7017 * match packet buffer alignment. Unfortunantly, the
7018 * hardware is not flexible enough to do this dynamically.
7020 if (netif_running(dev
))
7022 ixgbe_clear_interrupt_scheme(adapter
);
7025 netdev_set_num_tc(dev
, tc
);
7026 adapter
->last_lfc_mode
= adapter
->hw
.fc
.current_mode
;
7028 adapter
->flags
|= IXGBE_FLAG_DCB_ENABLED
;
7029 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
7031 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
7032 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_none
;
7034 netdev_reset_tc(dev
);
7036 adapter
->hw
.fc
.requested_mode
= adapter
->last_lfc_mode
;
7038 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
7039 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
7041 adapter
->temp_dcb_cfg
.pfc_mode_enable
= false;
7042 adapter
->dcb_cfg
.pfc_mode_enable
= false;
7045 ixgbe_init_interrupt_scheme(adapter
);
7046 ixgbe_validate_rtr(adapter
, tc
);
7047 if (netif_running(dev
))
7053 void ixgbe_do_reset(struct net_device
*netdev
)
7055 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7057 if (netif_running(netdev
))
7058 ixgbe_reinit_locked(adapter
);
7060 ixgbe_reset(adapter
);
7063 static u32
ixgbe_fix_features(struct net_device
*netdev
, u32 data
)
7065 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7068 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
7069 data
&= ~NETIF_F_HW_VLAN_RX
;
7072 /* return error if RXHASH is being enabled when RSS is not supported */
7073 if (!(adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
))
7074 data
&= ~NETIF_F_RXHASH
;
7076 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7077 if (!(data
& NETIF_F_RXCSUM
))
7078 data
&= ~NETIF_F_LRO
;
7080 /* Turn off LRO if not RSC capable or invalid ITR settings */
7081 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
)) {
7082 data
&= ~NETIF_F_LRO
;
7083 } else if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) &&
7084 (adapter
->rx_itr_setting
!= 1 &&
7085 adapter
->rx_itr_setting
> IXGBE_MAX_RSC_INT_RATE
)) {
7086 data
&= ~NETIF_F_LRO
;
7087 e_info(probe
, "rx-usecs set too low, not enabling RSC\n");
7093 static int ixgbe_set_features(struct net_device
*netdev
, u32 data
)
7095 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7096 bool need_reset
= false;
7098 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7099 if (!(data
& NETIF_F_RXCSUM
))
7100 adapter
->flags
&= ~IXGBE_FLAG_RX_CSUM_ENABLED
;
7102 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
7104 /* Make sure RSC matches LRO, reset if change */
7105 if (!!(data
& NETIF_F_LRO
) !=
7106 !!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)) {
7107 adapter
->flags2
^= IXGBE_FLAG2_RSC_ENABLED
;
7108 switch (adapter
->hw
.mac
.type
) {
7109 case ixgbe_mac_X540
:
7110 case ixgbe_mac_82599EB
:
7119 * Check if Flow Director n-tuple support was enabled or disabled. If
7120 * the state changed, we need to reset.
7122 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)) {
7123 /* turn off ATR, enable perfect filters and reset */
7124 if (data
& NETIF_F_NTUPLE
) {
7125 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
7126 adapter
->flags
|= IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
7129 } else if (!(data
& NETIF_F_NTUPLE
)) {
7130 /* turn off Flow Director, set ATR and reset */
7131 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
7132 if ((adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) &&
7133 !(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
))
7134 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
7139 ixgbe_do_reset(netdev
);
7145 static const struct net_device_ops ixgbe_netdev_ops
= {
7146 .ndo_open
= ixgbe_open
,
7147 .ndo_stop
= ixgbe_close
,
7148 .ndo_start_xmit
= ixgbe_xmit_frame
,
7149 .ndo_select_queue
= ixgbe_select_queue
,
7150 .ndo_set_rx_mode
= ixgbe_set_rx_mode
,
7151 .ndo_validate_addr
= eth_validate_addr
,
7152 .ndo_set_mac_address
= ixgbe_set_mac
,
7153 .ndo_change_mtu
= ixgbe_change_mtu
,
7154 .ndo_tx_timeout
= ixgbe_tx_timeout
,
7155 .ndo_vlan_rx_add_vid
= ixgbe_vlan_rx_add_vid
,
7156 .ndo_vlan_rx_kill_vid
= ixgbe_vlan_rx_kill_vid
,
7157 .ndo_do_ioctl
= ixgbe_ioctl
,
7158 .ndo_set_vf_mac
= ixgbe_ndo_set_vf_mac
,
7159 .ndo_set_vf_vlan
= ixgbe_ndo_set_vf_vlan
,
7160 .ndo_set_vf_tx_rate
= ixgbe_ndo_set_vf_bw
,
7161 .ndo_get_vf_config
= ixgbe_ndo_get_vf_config
,
7162 .ndo_get_stats64
= ixgbe_get_stats64
,
7163 .ndo_setup_tc
= ixgbe_setup_tc
,
7164 #ifdef CONFIG_NET_POLL_CONTROLLER
7165 .ndo_poll_controller
= ixgbe_netpoll
,
7168 .ndo_fcoe_ddp_setup
= ixgbe_fcoe_ddp_get
,
7169 .ndo_fcoe_ddp_target
= ixgbe_fcoe_ddp_target
,
7170 .ndo_fcoe_ddp_done
= ixgbe_fcoe_ddp_put
,
7171 .ndo_fcoe_enable
= ixgbe_fcoe_enable
,
7172 .ndo_fcoe_disable
= ixgbe_fcoe_disable
,
7173 .ndo_fcoe_get_wwn
= ixgbe_fcoe_get_wwn
,
7174 #endif /* IXGBE_FCOE */
7175 .ndo_set_features
= ixgbe_set_features
,
7176 .ndo_fix_features
= ixgbe_fix_features
,
7179 static void __devinit
ixgbe_probe_vf(struct ixgbe_adapter
*adapter
,
7180 const struct ixgbe_info
*ii
)
7182 #ifdef CONFIG_PCI_IOV
7183 struct ixgbe_hw
*hw
= &adapter
->hw
;
7185 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
7188 /* The 82599 supports up to 64 VFs per physical function
7189 * but this implementation limits allocation to 63 so that
7190 * basic networking resources are still available to the
7193 adapter
->num_vfs
= (max_vfs
> 63) ? 63 : max_vfs
;
7194 ixgbe_enable_sriov(adapter
, ii
);
7195 #endif /* CONFIG_PCI_IOV */
7199 * ixgbe_probe - Device Initialization Routine
7200 * @pdev: PCI device information struct
7201 * @ent: entry in ixgbe_pci_tbl
7203 * Returns 0 on success, negative on failure
7205 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7206 * The OS initialization, configuring of the adapter private structure,
7207 * and a hardware reset occur.
7209 static int __devinit
ixgbe_probe(struct pci_dev
*pdev
,
7210 const struct pci_device_id
*ent
)
7212 struct net_device
*netdev
;
7213 struct ixgbe_adapter
*adapter
= NULL
;
7214 struct ixgbe_hw
*hw
;
7215 const struct ixgbe_info
*ii
= ixgbe_info_tbl
[ent
->driver_data
];
7216 static int cards_found
;
7217 int i
, err
, pci_using_dac
;
7218 u8 part_str
[IXGBE_PBANUM_LENGTH
];
7219 unsigned int indices
= num_possible_cpus();
7226 /* Catch broken hardware that put the wrong VF device ID in
7227 * the PCIe SR-IOV capability.
7229 if (pdev
->is_virtfn
) {
7230 WARN(1, KERN_ERR
"%s (%hx:%hx) should not be a VF!\n",
7231 pci_name(pdev
), pdev
->vendor
, pdev
->device
);
7235 err
= pci_enable_device_mem(pdev
);
7239 if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64)) &&
7240 !dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
7243 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
7245 err
= dma_set_coherent_mask(&pdev
->dev
,
7249 "No usable DMA configuration, aborting\n");
7256 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
7257 IORESOURCE_MEM
), ixgbe_driver_name
);
7260 "pci_request_selected_regions failed 0x%x\n", err
);
7264 pci_enable_pcie_error_reporting(pdev
);
7266 pci_set_master(pdev
);
7267 pci_save_state(pdev
);
7269 #ifdef CONFIG_IXGBE_DCB
7270 indices
*= MAX_TRAFFIC_CLASS
;
7273 if (ii
->mac
== ixgbe_mac_82598EB
)
7274 indices
= min_t(unsigned int, indices
, IXGBE_MAX_RSS_INDICES
);
7276 indices
= min_t(unsigned int, indices
, IXGBE_MAX_FDIR_INDICES
);
7279 indices
+= min_t(unsigned int, num_possible_cpus(),
7280 IXGBE_MAX_FCOE_INDICES
);
7282 netdev
= alloc_etherdev_mq(sizeof(struct ixgbe_adapter
), indices
);
7285 goto err_alloc_etherdev
;
7288 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
7290 adapter
= netdev_priv(netdev
);
7291 pci_set_drvdata(pdev
, adapter
);
7293 adapter
->netdev
= netdev
;
7294 adapter
->pdev
= pdev
;
7297 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
7299 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
7300 pci_resource_len(pdev
, 0));
7306 for (i
= 1; i
<= 5; i
++) {
7307 if (pci_resource_len(pdev
, i
) == 0)
7311 netdev
->netdev_ops
= &ixgbe_netdev_ops
;
7312 ixgbe_set_ethtool_ops(netdev
);
7313 netdev
->watchdog_timeo
= 5 * HZ
;
7314 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
7316 adapter
->bd_number
= cards_found
;
7319 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
7320 hw
->mac
.type
= ii
->mac
;
7323 memcpy(&hw
->eeprom
.ops
, ii
->eeprom_ops
, sizeof(hw
->eeprom
.ops
));
7324 eec
= IXGBE_READ_REG(hw
, IXGBE_EEC
);
7325 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7326 if (!(eec
& (1 << 8)))
7327 hw
->eeprom
.ops
.read
= &ixgbe_read_eeprom_bit_bang_generic
;
7330 memcpy(&hw
->phy
.ops
, ii
->phy_ops
, sizeof(hw
->phy
.ops
));
7331 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
7332 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7333 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
7334 hw
->phy
.mdio
.mmds
= 0;
7335 hw
->phy
.mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
7336 hw
->phy
.mdio
.dev
= netdev
;
7337 hw
->phy
.mdio
.mdio_read
= ixgbe_mdio_read
;
7338 hw
->phy
.mdio
.mdio_write
= ixgbe_mdio_write
;
7340 ii
->get_invariants(hw
);
7342 /* setup the private structure */
7343 err
= ixgbe_sw_init(adapter
);
7347 /* Make it possible the adapter to be woken up via WOL */
7348 switch (adapter
->hw
.mac
.type
) {
7349 case ixgbe_mac_82599EB
:
7350 case ixgbe_mac_X540
:
7351 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
7358 * If there is a fan on this device and it has failed log the
7361 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
7362 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
7363 if (esdp
& IXGBE_ESDP_SDP1
)
7364 e_crit(probe
, "Fan has stopped, replace the adapter\n");
7367 /* reset_hw fills in the perm_addr as well */
7368 hw
->phy
.reset_if_overtemp
= true;
7369 err
= hw
->mac
.ops
.reset_hw(hw
);
7370 hw
->phy
.reset_if_overtemp
= false;
7371 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
&&
7372 hw
->mac
.type
== ixgbe_mac_82598EB
) {
7374 } else if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
7375 e_dev_err("failed to load because an unsupported SFP+ "
7376 "module type was detected.\n");
7377 e_dev_err("Reload the driver after installing a supported "
7381 e_dev_err("HW Init failed: %d\n", err
);
7385 ixgbe_probe_vf(adapter
, ii
);
7387 netdev
->features
= NETIF_F_SG
|
7390 NETIF_F_HW_VLAN_TX
|
7391 NETIF_F_HW_VLAN_RX
|
7392 NETIF_F_HW_VLAN_FILTER
|
7398 netdev
->hw_features
= netdev
->features
;
7400 switch (adapter
->hw
.mac
.type
) {
7401 case ixgbe_mac_82599EB
:
7402 case ixgbe_mac_X540
:
7403 netdev
->features
|= NETIF_F_SCTP_CSUM
;
7404 netdev
->hw_features
|= NETIF_F_SCTP_CSUM
|
7411 netdev
->vlan_features
|= NETIF_F_TSO
;
7412 netdev
->vlan_features
|= NETIF_F_TSO6
;
7413 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
7414 netdev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
7415 netdev
->vlan_features
|= NETIF_F_SG
;
7417 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
7419 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
7420 adapter
->flags
&= ~(IXGBE_FLAG_RSS_ENABLED
|
7421 IXGBE_FLAG_DCB_ENABLED
);
7423 #ifdef CONFIG_IXGBE_DCB
7424 netdev
->dcbnl_ops
= &dcbnl_ops
;
7428 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
7429 if (hw
->mac
.ops
.get_device_caps
) {
7430 hw
->mac
.ops
.get_device_caps(hw
, &device_caps
);
7431 if (device_caps
& IXGBE_DEVICE_CAPS_FCOE_OFFLOADS
)
7432 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
7435 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
7436 netdev
->vlan_features
|= NETIF_F_FCOE_CRC
;
7437 netdev
->vlan_features
|= NETIF_F_FSO
;
7438 netdev
->vlan_features
|= NETIF_F_FCOE_MTU
;
7440 #endif /* IXGBE_FCOE */
7441 if (pci_using_dac
) {
7442 netdev
->features
|= NETIF_F_HIGHDMA
;
7443 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
7446 if (adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
)
7447 netdev
->hw_features
|= NETIF_F_LRO
;
7448 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
7449 netdev
->features
|= NETIF_F_LRO
;
7451 /* make sure the EEPROM is good */
7452 if (hw
->eeprom
.ops
.validate_checksum(hw
, NULL
) < 0) {
7453 e_dev_err("The EEPROM Checksum Is Not Valid\n");
7458 memcpy(netdev
->dev_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
7459 memcpy(netdev
->perm_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
7461 if (ixgbe_validate_mac_addr(netdev
->perm_addr
)) {
7462 e_dev_err("invalid MAC address\n");
7467 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7468 if (hw
->mac
.ops
.disable_tx_laser
&&
7469 ((hw
->phy
.multispeed_fiber
) ||
7470 ((hw
->mac
.ops
.get_media_type(hw
) == ixgbe_media_type_fiber
) &&
7471 (hw
->mac
.type
== ixgbe_mac_82599EB
))))
7472 hw
->mac
.ops
.disable_tx_laser(hw
);
7474 setup_timer(&adapter
->service_timer
, &ixgbe_service_timer
,
7475 (unsigned long) adapter
);
7477 INIT_WORK(&adapter
->service_task
, ixgbe_service_task
);
7478 clear_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
);
7480 err
= ixgbe_init_interrupt_scheme(adapter
);
7484 if (!(adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
)) {
7485 netdev
->hw_features
&= ~NETIF_F_RXHASH
;
7486 netdev
->features
&= ~NETIF_F_RXHASH
;
7489 /* WOL not supported for all but the following */
7491 switch (pdev
->device
) {
7492 case IXGBE_DEV_ID_82599_SFP
:
7493 /* Only this subdevice supports WOL */
7494 if (pdev
->subsystem_device
== IXGBE_SUBDEV_ID_82599_SFP
)
7495 adapter
->wol
= IXGBE_WUFC_MAG
;
7497 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE
:
7498 /* All except this subdevice support WOL */
7499 if (pdev
->subsystem_device
!= IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ
)
7500 adapter
->wol
= IXGBE_WUFC_MAG
;
7502 case IXGBE_DEV_ID_82599_KX4
:
7503 adapter
->wol
= IXGBE_WUFC_MAG
;
7505 case IXGBE_DEV_ID_X540T
:
7506 /* Check eeprom to see if it is enabled */
7507 hw
->eeprom
.ops
.read(hw
, 0x2c, &adapter
->eeprom_cap
);
7508 wol_cap
= adapter
->eeprom_cap
& IXGBE_DEVICE_CAPS_WOL_MASK
;
7510 if ((wol_cap
== IXGBE_DEVICE_CAPS_WOL_PORT0_1
) ||
7511 ((wol_cap
== IXGBE_DEVICE_CAPS_WOL_PORT0
) &&
7512 (hw
->bus
.func
== 0)))
7513 adapter
->wol
= IXGBE_WUFC_MAG
;
7516 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
7518 /* pick up the PCI bus settings for reporting later */
7519 hw
->mac
.ops
.get_bus_info(hw
);
7521 /* print bus type/speed/width info */
7522 e_dev_info("(PCI Express:%s:%s) %pM\n",
7523 (hw
->bus
.speed
== ixgbe_bus_speed_5000
? "5.0GT/s" :
7524 hw
->bus
.speed
== ixgbe_bus_speed_2500
? "2.5GT/s" :
7526 (hw
->bus
.width
== ixgbe_bus_width_pcie_x8
? "Width x8" :
7527 hw
->bus
.width
== ixgbe_bus_width_pcie_x4
? "Width x4" :
7528 hw
->bus
.width
== ixgbe_bus_width_pcie_x1
? "Width x1" :
7532 err
= ixgbe_read_pba_string_generic(hw
, part_str
, IXGBE_PBANUM_LENGTH
);
7534 strncpy(part_str
, "Unknown", IXGBE_PBANUM_LENGTH
);
7535 if (ixgbe_is_sfp(hw
) && hw
->phy
.sfp_type
!= ixgbe_sfp_type_not_present
)
7536 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
7537 hw
->mac
.type
, hw
->phy
.type
, hw
->phy
.sfp_type
,
7540 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7541 hw
->mac
.type
, hw
->phy
.type
, part_str
);
7543 if (hw
->bus
.width
<= ixgbe_bus_width_pcie_x4
) {
7544 e_dev_warn("PCI-Express bandwidth available for this card is "
7545 "not sufficient for optimal performance.\n");
7546 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7550 /* save off EEPROM version number */
7551 hw
->eeprom
.ops
.read(hw
, 0x29, &adapter
->eeprom_version
);
7553 /* reset the hardware with the new settings */
7554 err
= hw
->mac
.ops
.start_hw(hw
);
7556 if (err
== IXGBE_ERR_EEPROM_VERSION
) {
7557 /* We are running on a pre-production device, log a warning */
7558 e_dev_warn("This device is a pre-production adapter/LOM. "
7559 "Please be aware there may be issues associated "
7560 "with your hardware. If you are experiencing "
7561 "problems please contact your Intel or hardware "
7562 "representative who provided you with this "
7565 strcpy(netdev
->name
, "eth%d");
7566 err
= register_netdev(netdev
);
7570 /* carrier off reporting is important to ethtool even BEFORE open */
7571 netif_carrier_off(netdev
);
7573 #ifdef CONFIG_IXGBE_DCA
7574 if (dca_add_requester(&pdev
->dev
) == 0) {
7575 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
7576 ixgbe_setup_dca(adapter
);
7579 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
7580 e_info(probe
, "IOV is enabled with %d VFs\n", adapter
->num_vfs
);
7581 for (i
= 0; i
< adapter
->num_vfs
; i
++)
7582 ixgbe_vf_configuration(pdev
, (i
| 0x10000000));
7585 /* Inform firmware of driver version */
7586 if (hw
->mac
.ops
.set_fw_drv_ver
)
7587 hw
->mac
.ops
.set_fw_drv_ver(hw
, MAJ
, MIN
, BUILD
,
7590 /* add san mac addr to netdev */
7591 ixgbe_add_sanmac_netdev(netdev
);
7593 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
7598 ixgbe_release_hw_control(adapter
);
7599 ixgbe_clear_interrupt_scheme(adapter
);
7602 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
7603 ixgbe_disable_sriov(adapter
);
7604 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
7605 iounmap(hw
->hw_addr
);
7607 free_netdev(netdev
);
7609 pci_release_selected_regions(pdev
,
7610 pci_select_bars(pdev
, IORESOURCE_MEM
));
7613 pci_disable_device(pdev
);
7618 * ixgbe_remove - Device Removal Routine
7619 * @pdev: PCI device information struct
7621 * ixgbe_remove is called by the PCI subsystem to alert the driver
7622 * that it should release a PCI device. The could be caused by a
7623 * Hot-Plug event, or because the driver is going to be removed from
7626 static void __devexit
ixgbe_remove(struct pci_dev
*pdev
)
7628 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
7629 struct net_device
*netdev
= adapter
->netdev
;
7631 set_bit(__IXGBE_DOWN
, &adapter
->state
);
7632 cancel_work_sync(&adapter
->service_task
);
7634 #ifdef CONFIG_IXGBE_DCA
7635 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
7636 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
7637 dca_remove_requester(&pdev
->dev
);
7638 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
7643 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
7644 ixgbe_cleanup_fcoe(adapter
);
7646 #endif /* IXGBE_FCOE */
7648 /* remove the added san mac */
7649 ixgbe_del_sanmac_netdev(netdev
);
7651 if (netdev
->reg_state
== NETREG_REGISTERED
)
7652 unregister_netdev(netdev
);
7654 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
7655 if (!(ixgbe_check_vf_assignment(adapter
)))
7656 ixgbe_disable_sriov(adapter
);
7658 e_dev_warn("Unloading driver while VFs are assigned "
7659 "- VFs will not be deallocated\n");
7662 ixgbe_clear_interrupt_scheme(adapter
);
7664 ixgbe_release_hw_control(adapter
);
7666 iounmap(adapter
->hw
.hw_addr
);
7667 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
7670 e_dev_info("complete\n");
7672 free_netdev(netdev
);
7674 pci_disable_pcie_error_reporting(pdev
);
7676 pci_disable_device(pdev
);
7680 * ixgbe_io_error_detected - called when PCI error is detected
7681 * @pdev: Pointer to PCI device
7682 * @state: The current pci connection state
7684 * This function is called after a PCI bus error affecting
7685 * this device has been detected.
7687 static pci_ers_result_t
ixgbe_io_error_detected(struct pci_dev
*pdev
,
7688 pci_channel_state_t state
)
7690 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
7691 struct net_device
*netdev
= adapter
->netdev
;
7693 netif_device_detach(netdev
);
7695 if (state
== pci_channel_io_perm_failure
)
7696 return PCI_ERS_RESULT_DISCONNECT
;
7698 if (netif_running(netdev
))
7699 ixgbe_down(adapter
);
7700 pci_disable_device(pdev
);
7702 /* Request a slot reset. */
7703 return PCI_ERS_RESULT_NEED_RESET
;
7707 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7708 * @pdev: Pointer to PCI device
7710 * Restart the card from scratch, as if from a cold-boot.
7712 static pci_ers_result_t
ixgbe_io_slot_reset(struct pci_dev
*pdev
)
7714 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
7715 pci_ers_result_t result
;
7718 if (pci_enable_device_mem(pdev
)) {
7719 e_err(probe
, "Cannot re-enable PCI device after reset.\n");
7720 result
= PCI_ERS_RESULT_DISCONNECT
;
7722 pci_set_master(pdev
);
7723 pci_restore_state(pdev
);
7724 pci_save_state(pdev
);
7726 pci_wake_from_d3(pdev
, false);
7728 ixgbe_reset(adapter
);
7729 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
7730 result
= PCI_ERS_RESULT_RECOVERED
;
7733 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
7735 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7736 "failed 0x%0x\n", err
);
7737 /* non-fatal, continue */
7744 * ixgbe_io_resume - called when traffic can start flowing again.
7745 * @pdev: Pointer to PCI device
7747 * This callback is called when the error recovery driver tells us that
7748 * its OK to resume normal operation.
7750 static void ixgbe_io_resume(struct pci_dev
*pdev
)
7752 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
7753 struct net_device
*netdev
= adapter
->netdev
;
7755 if (netif_running(netdev
))
7758 netif_device_attach(netdev
);
7761 static struct pci_error_handlers ixgbe_err_handler
= {
7762 .error_detected
= ixgbe_io_error_detected
,
7763 .slot_reset
= ixgbe_io_slot_reset
,
7764 .resume
= ixgbe_io_resume
,
7767 static struct pci_driver ixgbe_driver
= {
7768 .name
= ixgbe_driver_name
,
7769 .id_table
= ixgbe_pci_tbl
,
7770 .probe
= ixgbe_probe
,
7771 .remove
= __devexit_p(ixgbe_remove
),
7773 .suspend
= ixgbe_suspend
,
7774 .resume
= ixgbe_resume
,
7776 .shutdown
= ixgbe_shutdown
,
7777 .err_handler
= &ixgbe_err_handler
7781 * ixgbe_init_module - Driver Registration Routine
7783 * ixgbe_init_module is the first routine called when the driver is
7784 * loaded. All it does is register with the PCI subsystem.
7786 static int __init
ixgbe_init_module(void)
7789 pr_info("%s - version %s\n", ixgbe_driver_string
, ixgbe_driver_version
);
7790 pr_info("%s\n", ixgbe_copyright
);
7792 #ifdef CONFIG_IXGBE_DCA
7793 dca_register_notify(&dca_notifier
);
7796 ret
= pci_register_driver(&ixgbe_driver
);
7800 module_init(ixgbe_init_module
);
7803 * ixgbe_exit_module - Driver Exit Cleanup Routine
7805 * ixgbe_exit_module is called just before the driver is removed
7808 static void __exit
ixgbe_exit_module(void)
7810 #ifdef CONFIG_IXGBE_DCA
7811 dca_unregister_notify(&dca_notifier
);
7813 pci_unregister_driver(&ixgbe_driver
);
7814 rcu_barrier(); /* Wait for completion of call_rcu()'s */
7817 #ifdef CONFIG_IXGBE_DCA
7818 static int ixgbe_notify_dca(struct notifier_block
*nb
, unsigned long event
,
7823 ret_val
= driver_for_each_device(&ixgbe_driver
.driver
, NULL
, &event
,
7824 __ixgbe_notify_dca
);
7826 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
7829 #endif /* CONFIG_IXGBE_DCA */
7831 module_exit(ixgbe_exit_module
);