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>
45 #include <linux/if_vlan.h>
46 #include <linux/prefetch.h>
47 #include <scsi/fc/fc_fcoe.h>
50 #include "ixgbe_common.h"
51 #include "ixgbe_dcb_82599.h"
52 #include "ixgbe_sriov.h"
54 char ixgbe_driver_name
[] = "ixgbe";
55 static const char ixgbe_driver_string
[] =
56 "Intel(R) 10 Gigabit PCI Express Network Driver";
60 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
61 __stringify(BUILD) "-k"
62 const char ixgbe_driver_version
[] = DRV_VERSION
;
63 static const char ixgbe_copyright
[] =
64 "Copyright (c) 1999-2011 Intel Corporation.";
66 static const struct ixgbe_info
*ixgbe_info_tbl
[] = {
67 [board_82598
] = &ixgbe_82598_info
,
68 [board_82599
] = &ixgbe_82599_info
,
69 [board_X540
] = &ixgbe_X540_info
,
72 /* ixgbe_pci_tbl - PCI Device ID Table
74 * Wildcard entries (PCI_ANY_ID) should come last
75 * Last entry must be all 0s
77 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
78 * Class, Class Mask, private data (not used) }
80 static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl
) = {
81 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598
),
83 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_DUAL_PORT
),
85 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_SINGLE_PORT
),
87 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT
),
89 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT2
),
91 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_CX4
),
93 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_CX4_DUAL_PORT
),
95 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_DA_DUAL_PORT
),
97 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM
),
99 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_XF_LR
),
101 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_SFP_LOM
),
103 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_BX
),
105 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4
),
107 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_XAUI_LOM
),
109 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KR
),
111 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP
),
113 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_EM
),
115 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4_MEZZ
),
117 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_CX4
),
119 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_BACKPLANE_FCOE
),
121 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_FCOE
),
123 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_T3_LOM
),
125 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_COMBO_BACKPLANE
),
127 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X540T
),
129 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_SF2
),
131 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_LS
),
134 /* required last entry */
137 MODULE_DEVICE_TABLE(pci
, ixgbe_pci_tbl
);
139 #ifdef CONFIG_IXGBE_DCA
140 static int ixgbe_notify_dca(struct notifier_block
*, unsigned long event
,
142 static struct notifier_block dca_notifier
= {
143 .notifier_call
= ixgbe_notify_dca
,
149 #ifdef CONFIG_PCI_IOV
150 static unsigned int max_vfs
;
151 module_param(max_vfs
, uint
, 0);
152 MODULE_PARM_DESC(max_vfs
,
153 "Maximum number of virtual functions to allocate per physical function");
154 #endif /* CONFIG_PCI_IOV */
156 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
157 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
158 MODULE_LICENSE("GPL");
159 MODULE_VERSION(DRV_VERSION
);
161 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
163 static inline void ixgbe_disable_sriov(struct ixgbe_adapter
*adapter
)
165 struct ixgbe_hw
*hw
= &adapter
->hw
;
170 #ifdef CONFIG_PCI_IOV
171 /* disable iov and allow time for transactions to clear */
172 pci_disable_sriov(adapter
->pdev
);
175 /* turn off device IOV mode */
176 gcr
= IXGBE_READ_REG(hw
, IXGBE_GCR_EXT
);
177 gcr
&= ~(IXGBE_GCR_EXT_SRIOV
);
178 IXGBE_WRITE_REG(hw
, IXGBE_GCR_EXT
, gcr
);
179 gpie
= IXGBE_READ_REG(hw
, IXGBE_GPIE
);
180 gpie
&= ~IXGBE_GPIE_VTMODE_MASK
;
181 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
183 /* set default pool back to 0 */
184 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VT_CTL
);
185 vmdctl
&= ~IXGBE_VT_CTL_POOL_MASK
;
186 IXGBE_WRITE_REG(hw
, IXGBE_VT_CTL
, vmdctl
);
187 IXGBE_WRITE_FLUSH(hw
);
189 /* take a breather then clean up driver data */
192 kfree(adapter
->vfinfo
);
193 adapter
->vfinfo
= NULL
;
195 adapter
->num_vfs
= 0;
196 adapter
->flags
&= ~IXGBE_FLAG_SRIOV_ENABLED
;
199 static void ixgbe_service_event_schedule(struct ixgbe_adapter
*adapter
)
201 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
) &&
202 !test_and_set_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
))
203 schedule_work(&adapter
->service_task
);
206 static void ixgbe_service_event_complete(struct ixgbe_adapter
*adapter
)
208 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
));
210 /* flush memory to make sure state is correct before next watchog */
211 smp_mb__before_clear_bit();
212 clear_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
);
215 struct ixgbe_reg_info
{
220 static const struct ixgbe_reg_info ixgbe_reg_info_tbl
[] = {
222 /* General Registers */
223 {IXGBE_CTRL
, "CTRL"},
224 {IXGBE_STATUS
, "STATUS"},
225 {IXGBE_CTRL_EXT
, "CTRL_EXT"},
227 /* Interrupt Registers */
228 {IXGBE_EICR
, "EICR"},
231 {IXGBE_SRRCTL(0), "SRRCTL"},
232 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
233 {IXGBE_RDLEN(0), "RDLEN"},
234 {IXGBE_RDH(0), "RDH"},
235 {IXGBE_RDT(0), "RDT"},
236 {IXGBE_RXDCTL(0), "RXDCTL"},
237 {IXGBE_RDBAL(0), "RDBAL"},
238 {IXGBE_RDBAH(0), "RDBAH"},
241 {IXGBE_TDBAL(0), "TDBAL"},
242 {IXGBE_TDBAH(0), "TDBAH"},
243 {IXGBE_TDLEN(0), "TDLEN"},
244 {IXGBE_TDH(0), "TDH"},
245 {IXGBE_TDT(0), "TDT"},
246 {IXGBE_TXDCTL(0), "TXDCTL"},
248 /* List Terminator */
254 * ixgbe_regdump - register printout routine
256 static void ixgbe_regdump(struct ixgbe_hw
*hw
, struct ixgbe_reg_info
*reginfo
)
262 switch (reginfo
->ofs
) {
263 case IXGBE_SRRCTL(0):
264 for (i
= 0; i
< 64; i
++)
265 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_SRRCTL(i
));
267 case IXGBE_DCA_RXCTRL(0):
268 for (i
= 0; i
< 64; i
++)
269 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_DCA_RXCTRL(i
));
272 for (i
= 0; i
< 64; i
++)
273 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDLEN(i
));
276 for (i
= 0; i
< 64; i
++)
277 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDH(i
));
280 for (i
= 0; i
< 64; i
++)
281 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDT(i
));
283 case IXGBE_RXDCTL(0):
284 for (i
= 0; i
< 64; i
++)
285 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RXDCTL(i
));
288 for (i
= 0; i
< 64; i
++)
289 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDBAL(i
));
292 for (i
= 0; i
< 64; i
++)
293 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDBAH(i
));
296 for (i
= 0; i
< 64; i
++)
297 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDBAL(i
));
300 for (i
= 0; i
< 64; i
++)
301 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDBAH(i
));
304 for (i
= 0; i
< 64; i
++)
305 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDLEN(i
));
308 for (i
= 0; i
< 64; i
++)
309 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDH(i
));
312 for (i
= 0; i
< 64; i
++)
313 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDT(i
));
315 case IXGBE_TXDCTL(0):
316 for (i
= 0; i
< 64; i
++)
317 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TXDCTL(i
));
320 pr_info("%-15s %08x\n", reginfo
->name
,
321 IXGBE_READ_REG(hw
, reginfo
->ofs
));
325 for (i
= 0; i
< 8; i
++) {
326 snprintf(rname
, 16, "%s[%d-%d]", reginfo
->name
, i
*8, i
*8+7);
327 pr_err("%-15s", rname
);
328 for (j
= 0; j
< 8; j
++)
329 pr_cont(" %08x", regs
[i
*8+j
]);
336 * ixgbe_dump - Print registers, tx-rings and rx-rings
338 static void ixgbe_dump(struct ixgbe_adapter
*adapter
)
340 struct net_device
*netdev
= adapter
->netdev
;
341 struct ixgbe_hw
*hw
= &adapter
->hw
;
342 struct ixgbe_reg_info
*reginfo
;
344 struct ixgbe_ring
*tx_ring
;
345 struct ixgbe_tx_buffer
*tx_buffer_info
;
346 union ixgbe_adv_tx_desc
*tx_desc
;
347 struct my_u0
{ u64 a
; u64 b
; } *u0
;
348 struct ixgbe_ring
*rx_ring
;
349 union ixgbe_adv_rx_desc
*rx_desc
;
350 struct ixgbe_rx_buffer
*rx_buffer_info
;
354 if (!netif_msg_hw(adapter
))
357 /* Print netdevice Info */
359 dev_info(&adapter
->pdev
->dev
, "Net device Info\n");
360 pr_info("Device Name state "
361 "trans_start last_rx\n");
362 pr_info("%-15s %016lX %016lX %016lX\n",
369 /* Print Registers */
370 dev_info(&adapter
->pdev
->dev
, "Register Dump\n");
371 pr_info(" Register Name Value\n");
372 for (reginfo
= (struct ixgbe_reg_info
*)ixgbe_reg_info_tbl
;
373 reginfo
->name
; reginfo
++) {
374 ixgbe_regdump(hw
, reginfo
);
377 /* Print TX Ring Summary */
378 if (!netdev
|| !netif_running(netdev
))
381 dev_info(&adapter
->pdev
->dev
, "TX Rings Summary\n");
382 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
383 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
384 tx_ring
= adapter
->tx_ring
[n
];
386 &tx_ring
->tx_buffer_info
[tx_ring
->next_to_clean
];
387 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
388 n
, tx_ring
->next_to_use
, tx_ring
->next_to_clean
,
389 (u64
)tx_buffer_info
->dma
,
390 tx_buffer_info
->length
,
391 tx_buffer_info
->next_to_watch
,
392 (u64
)tx_buffer_info
->time_stamp
);
396 if (!netif_msg_tx_done(adapter
))
397 goto rx_ring_summary
;
399 dev_info(&adapter
->pdev
->dev
, "TX Rings Dump\n");
401 /* Transmit Descriptor Formats
403 * Advanced Transmit Descriptor
404 * +--------------------------------------------------------------+
405 * 0 | Buffer Address [63:0] |
406 * +--------------------------------------------------------------+
407 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
408 * +--------------------------------------------------------------+
409 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
412 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
413 tx_ring
= adapter
->tx_ring
[n
];
414 pr_info("------------------------------------\n");
415 pr_info("TX QUEUE INDEX = %d\n", tx_ring
->queue_index
);
416 pr_info("------------------------------------\n");
417 pr_info("T [desc] [address 63:0 ] "
418 "[PlPOIdStDDt Ln] [bi->dma ] "
419 "leng ntw timestamp bi->skb\n");
421 for (i
= 0; tx_ring
->desc
&& (i
< tx_ring
->count
); i
++) {
422 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, i
);
423 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
424 u0
= (struct my_u0
*)tx_desc
;
425 pr_info("T [0x%03X] %016llX %016llX %016llX"
426 " %04X %3X %016llX %p", i
,
429 (u64
)tx_buffer_info
->dma
,
430 tx_buffer_info
->length
,
431 tx_buffer_info
->next_to_watch
,
432 (u64
)tx_buffer_info
->time_stamp
,
433 tx_buffer_info
->skb
);
434 if (i
== tx_ring
->next_to_use
&&
435 i
== tx_ring
->next_to_clean
)
437 else if (i
== tx_ring
->next_to_use
)
439 else if (i
== tx_ring
->next_to_clean
)
444 if (netif_msg_pktdata(adapter
) &&
445 tx_buffer_info
->dma
!= 0)
446 print_hex_dump(KERN_INFO
, "",
447 DUMP_PREFIX_ADDRESS
, 16, 1,
448 phys_to_virt(tx_buffer_info
->dma
),
449 tx_buffer_info
->length
, true);
453 /* Print RX Rings Summary */
455 dev_info(&adapter
->pdev
->dev
, "RX Rings Summary\n");
456 pr_info("Queue [NTU] [NTC]\n");
457 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
458 rx_ring
= adapter
->rx_ring
[n
];
459 pr_info("%5d %5X %5X\n",
460 n
, rx_ring
->next_to_use
, rx_ring
->next_to_clean
);
464 if (!netif_msg_rx_status(adapter
))
467 dev_info(&adapter
->pdev
->dev
, "RX Rings Dump\n");
469 /* Advanced Receive Descriptor (Read) Format
471 * +-----------------------------------------------------+
472 * 0 | Packet Buffer Address [63:1] |A0/NSE|
473 * +----------------------------------------------+------+
474 * 8 | Header Buffer Address [63:1] | DD |
475 * +-----------------------------------------------------+
478 * Advanced Receive Descriptor (Write-Back) Format
480 * 63 48 47 32 31 30 21 20 16 15 4 3 0
481 * +------------------------------------------------------+
482 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
483 * | Checksum Ident | | | | Type | Type |
484 * +------------------------------------------------------+
485 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
486 * +------------------------------------------------------+
487 * 63 48 47 32 31 20 19 0
489 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
490 rx_ring
= adapter
->rx_ring
[n
];
491 pr_info("------------------------------------\n");
492 pr_info("RX QUEUE INDEX = %d\n", rx_ring
->queue_index
);
493 pr_info("------------------------------------\n");
494 pr_info("R [desc] [ PktBuf A0] "
495 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
496 "<-- Adv Rx Read format\n");
497 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
498 "[vl er S cks ln] ---------------- [bi->skb] "
499 "<-- Adv Rx Write-Back format\n");
501 for (i
= 0; i
< rx_ring
->count
; i
++) {
502 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
503 rx_desc
= IXGBE_RX_DESC_ADV(rx_ring
, i
);
504 u0
= (struct my_u0
*)rx_desc
;
505 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
506 if (staterr
& IXGBE_RXD_STAT_DD
) {
507 /* Descriptor Done */
508 pr_info("RWB[0x%03X] %016llX "
509 "%016llX ---------------- %p", i
,
512 rx_buffer_info
->skb
);
514 pr_info("R [0x%03X] %016llX "
515 "%016llX %016llX %p", i
,
518 (u64
)rx_buffer_info
->dma
,
519 rx_buffer_info
->skb
);
521 if (netif_msg_pktdata(adapter
)) {
522 print_hex_dump(KERN_INFO
, "",
523 DUMP_PREFIX_ADDRESS
, 16, 1,
524 phys_to_virt(rx_buffer_info
->dma
),
525 rx_ring
->rx_buf_len
, true);
527 if (rx_ring
->rx_buf_len
528 < IXGBE_RXBUFFER_2048
)
529 print_hex_dump(KERN_INFO
, "",
530 DUMP_PREFIX_ADDRESS
, 16, 1,
532 rx_buffer_info
->page_dma
+
533 rx_buffer_info
->page_offset
539 if (i
== rx_ring
->next_to_use
)
541 else if (i
== rx_ring
->next_to_clean
)
553 static void ixgbe_release_hw_control(struct ixgbe_adapter
*adapter
)
557 /* Let firmware take over control of h/w */
558 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
559 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
560 ctrl_ext
& ~IXGBE_CTRL_EXT_DRV_LOAD
);
563 static void ixgbe_get_hw_control(struct ixgbe_adapter
*adapter
)
567 /* Let firmware know the driver has taken over */
568 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
569 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
570 ctrl_ext
| IXGBE_CTRL_EXT_DRV_LOAD
);
574 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
575 * @adapter: pointer to adapter struct
576 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
577 * @queue: queue to map the corresponding interrupt to
578 * @msix_vector: the vector to map to the corresponding queue
581 static void ixgbe_set_ivar(struct ixgbe_adapter
*adapter
, s8 direction
,
582 u8 queue
, u8 msix_vector
)
585 struct ixgbe_hw
*hw
= &adapter
->hw
;
586 switch (hw
->mac
.type
) {
587 case ixgbe_mac_82598EB
:
588 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
591 index
= (((direction
* 64) + queue
) >> 2) & 0x1F;
592 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(index
));
593 ivar
&= ~(0xFF << (8 * (queue
& 0x3)));
594 ivar
|= (msix_vector
<< (8 * (queue
& 0x3)));
595 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(index
), ivar
);
597 case ixgbe_mac_82599EB
:
599 if (direction
== -1) {
601 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
602 index
= ((queue
& 1) * 8);
603 ivar
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_IVAR_MISC
);
604 ivar
&= ~(0xFF << index
);
605 ivar
|= (msix_vector
<< index
);
606 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_IVAR_MISC
, ivar
);
609 /* tx or rx causes */
610 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
611 index
= ((16 * (queue
& 1)) + (8 * direction
));
612 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(queue
>> 1));
613 ivar
&= ~(0xFF << index
);
614 ivar
|= (msix_vector
<< index
);
615 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(queue
>> 1), ivar
);
623 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter
*adapter
,
628 switch (adapter
->hw
.mac
.type
) {
629 case ixgbe_mac_82598EB
:
630 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
631 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS
, mask
);
633 case ixgbe_mac_82599EB
:
635 mask
= (qmask
& 0xFFFFFFFF);
636 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(0), mask
);
637 mask
= (qmask
>> 32);
638 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(1), mask
);
645 void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring
*tx_ring
,
646 struct ixgbe_tx_buffer
*tx_buffer_info
)
648 if (tx_buffer_info
->dma
) {
649 if (tx_buffer_info
->mapped_as_page
)
650 dma_unmap_page(tx_ring
->dev
,
652 tx_buffer_info
->length
,
655 dma_unmap_single(tx_ring
->dev
,
657 tx_buffer_info
->length
,
659 tx_buffer_info
->dma
= 0;
661 if (tx_buffer_info
->skb
) {
662 dev_kfree_skb_any(tx_buffer_info
->skb
);
663 tx_buffer_info
->skb
= NULL
;
665 tx_buffer_info
->time_stamp
= 0;
666 /* tx_buffer_info must be completely set up in the transmit path */
669 static void ixgbe_update_xoff_received(struct ixgbe_adapter
*adapter
)
671 struct ixgbe_hw
*hw
= &adapter
->hw
;
672 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
677 if ((hw
->fc
.current_mode
== ixgbe_fc_full
) ||
678 (hw
->fc
.current_mode
== ixgbe_fc_rx_pause
)) {
679 switch (hw
->mac
.type
) {
680 case ixgbe_mac_82598EB
:
681 data
= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXC
);
684 data
= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXCNT
);
686 hwstats
->lxoffrxc
+= data
;
688 /* refill credits (no tx hang) if we received xoff */
692 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
693 clear_bit(__IXGBE_HANG_CHECK_ARMED
,
694 &adapter
->tx_ring
[i
]->state
);
696 } else if (!(adapter
->dcb_cfg
.pfc_mode_enable
))
699 /* update stats for each tc, only valid with PFC enabled */
700 for (i
= 0; i
< MAX_TX_PACKET_BUFFERS
; i
++) {
701 switch (hw
->mac
.type
) {
702 case ixgbe_mac_82598EB
:
703 xoff
[i
] = IXGBE_READ_REG(hw
, IXGBE_PXOFFRXC(i
));
706 xoff
[i
] = IXGBE_READ_REG(hw
, IXGBE_PXOFFRXCNT(i
));
708 hwstats
->pxoffrxc
[i
] += xoff
[i
];
711 /* disarm tx queues that have received xoff frames */
712 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
713 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
714 u8 tc
= tx_ring
->dcb_tc
;
717 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &tx_ring
->state
);
721 static u64
ixgbe_get_tx_completed(struct ixgbe_ring
*ring
)
723 return ring
->tx_stats
.completed
;
726 static u64
ixgbe_get_tx_pending(struct ixgbe_ring
*ring
)
728 struct ixgbe_adapter
*adapter
= netdev_priv(ring
->netdev
);
729 struct ixgbe_hw
*hw
= &adapter
->hw
;
731 u32 head
= IXGBE_READ_REG(hw
, IXGBE_TDH(ring
->reg_idx
));
732 u32 tail
= IXGBE_READ_REG(hw
, IXGBE_TDT(ring
->reg_idx
));
735 return (head
< tail
) ?
736 tail
- head
: (tail
+ ring
->count
- head
);
741 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring
*tx_ring
)
743 u32 tx_done
= ixgbe_get_tx_completed(tx_ring
);
744 u32 tx_done_old
= tx_ring
->tx_stats
.tx_done_old
;
745 u32 tx_pending
= ixgbe_get_tx_pending(tx_ring
);
748 clear_check_for_tx_hang(tx_ring
);
751 * Check for a hung queue, but be thorough. This verifies
752 * that a transmit has been completed since the previous
753 * check AND there is at least one packet pending. The
754 * ARMED bit is set to indicate a potential hang. The
755 * bit is cleared if a pause frame is received to remove
756 * false hang detection due to PFC or 802.3x frames. By
757 * requiring this to fail twice we avoid races with
758 * pfc clearing the ARMED bit and conditions where we
759 * run the check_tx_hang logic with a transmit completion
760 * pending but without time to complete it yet.
762 if ((tx_done_old
== tx_done
) && tx_pending
) {
763 /* make sure it is true for two checks in a row */
764 ret
= test_and_set_bit(__IXGBE_HANG_CHECK_ARMED
,
767 /* update completed stats and continue */
768 tx_ring
->tx_stats
.tx_done_old
= tx_done
;
769 /* reset the countdown */
770 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &tx_ring
->state
);
777 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
778 * @adapter: driver private struct
780 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter
*adapter
)
783 /* Do the reset outside of interrupt context */
784 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
785 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
786 ixgbe_service_event_schedule(adapter
);
791 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
792 * @q_vector: structure containing interrupt and ring information
793 * @tx_ring: tx ring to clean
795 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector
*q_vector
,
796 struct ixgbe_ring
*tx_ring
)
798 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
799 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
800 struct ixgbe_tx_buffer
*tx_buffer_info
;
801 unsigned int total_bytes
= 0, total_packets
= 0;
802 u16 i
, eop
, count
= 0;
804 i
= tx_ring
->next_to_clean
;
805 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
806 eop_desc
= IXGBE_TX_DESC_ADV(tx_ring
, eop
);
808 while ((eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) &&
809 (count
< q_vector
->tx
.work_limit
)) {
810 bool cleaned
= false;
811 rmb(); /* read buffer_info after eop_desc */
812 for ( ; !cleaned
; count
++) {
813 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, i
);
814 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
816 tx_desc
->wb
.status
= 0;
817 cleaned
= (i
== eop
);
820 if (i
== tx_ring
->count
)
823 if (cleaned
&& tx_buffer_info
->skb
) {
824 total_bytes
+= tx_buffer_info
->bytecount
;
825 total_packets
+= tx_buffer_info
->gso_segs
;
828 ixgbe_unmap_and_free_tx_resource(tx_ring
,
832 tx_ring
->tx_stats
.completed
++;
833 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
834 eop_desc
= IXGBE_TX_DESC_ADV(tx_ring
, eop
);
837 tx_ring
->next_to_clean
= i
;
838 tx_ring
->stats
.bytes
+= total_bytes
;
839 tx_ring
->stats
.packets
+= total_packets
;
840 u64_stats_update_begin(&tx_ring
->syncp
);
841 q_vector
->tx
.total_bytes
+= total_bytes
;
842 q_vector
->tx
.total_packets
+= total_packets
;
843 u64_stats_update_end(&tx_ring
->syncp
);
845 if (check_for_tx_hang(tx_ring
) && ixgbe_check_tx_hang(tx_ring
)) {
846 /* schedule immediate reset if we believe we hung */
847 struct ixgbe_hw
*hw
= &adapter
->hw
;
848 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, eop
);
849 e_err(drv
, "Detected Tx Unit Hang\n"
851 " TDH, TDT <%x>, <%x>\n"
852 " next_to_use <%x>\n"
853 " next_to_clean <%x>\n"
854 "tx_buffer_info[next_to_clean]\n"
855 " time_stamp <%lx>\n"
857 tx_ring
->queue_index
,
858 IXGBE_READ_REG(hw
, IXGBE_TDH(tx_ring
->reg_idx
)),
859 IXGBE_READ_REG(hw
, IXGBE_TDT(tx_ring
->reg_idx
)),
860 tx_ring
->next_to_use
, eop
,
861 tx_ring
->tx_buffer_info
[eop
].time_stamp
, jiffies
);
863 netif_stop_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
866 "tx hang %d detected on queue %d, resetting adapter\n",
867 adapter
->tx_timeout_count
+ 1, tx_ring
->queue_index
);
869 /* schedule immediate reset if we believe we hung */
870 ixgbe_tx_timeout_reset(adapter
);
872 /* the adapter is about to reset, no point in enabling stuff */
876 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
877 if (unlikely(count
&& netif_carrier_ok(tx_ring
->netdev
) &&
878 (ixgbe_desc_unused(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
879 /* Make sure that anybody stopping the queue after this
880 * sees the new next_to_clean.
883 if (__netif_subqueue_stopped(tx_ring
->netdev
, tx_ring
->queue_index
) &&
884 !test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
885 netif_wake_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
886 ++tx_ring
->tx_stats
.restart_queue
;
890 return count
< q_vector
->tx
.work_limit
;
893 #ifdef CONFIG_IXGBE_DCA
894 static void ixgbe_update_rx_dca(struct ixgbe_adapter
*adapter
,
895 struct ixgbe_ring
*rx_ring
,
898 struct ixgbe_hw
*hw
= &adapter
->hw
;
900 u8 reg_idx
= rx_ring
->reg_idx
;
902 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_RXCTRL(reg_idx
));
903 switch (hw
->mac
.type
) {
904 case ixgbe_mac_82598EB
:
905 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK
;
906 rxctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
908 case ixgbe_mac_82599EB
:
910 rxctrl
&= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599
;
911 rxctrl
|= (dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
912 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599
);
917 rxctrl
|= IXGBE_DCA_RXCTRL_DESC_DCA_EN
;
918 rxctrl
|= IXGBE_DCA_RXCTRL_HEAD_DCA_EN
;
919 rxctrl
&= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN
);
920 IXGBE_WRITE_REG(hw
, IXGBE_DCA_RXCTRL(reg_idx
), rxctrl
);
923 static void ixgbe_update_tx_dca(struct ixgbe_adapter
*adapter
,
924 struct ixgbe_ring
*tx_ring
,
927 struct ixgbe_hw
*hw
= &adapter
->hw
;
929 u8 reg_idx
= tx_ring
->reg_idx
;
931 switch (hw
->mac
.type
) {
932 case ixgbe_mac_82598EB
:
933 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL(reg_idx
));
934 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK
;
935 txctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
936 txctrl
|= IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
937 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL(reg_idx
), txctrl
);
939 case ixgbe_mac_82599EB
:
941 txctrl
= IXGBE_READ_REG(hw
, IXGBE_DCA_TXCTRL_82599(reg_idx
));
942 txctrl
&= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599
;
943 txctrl
|= (dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
944 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599
);
945 txctrl
|= IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
946 IXGBE_WRITE_REG(hw
, IXGBE_DCA_TXCTRL_82599(reg_idx
), txctrl
);
953 static void ixgbe_update_dca(struct ixgbe_q_vector
*q_vector
)
955 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
960 if (q_vector
->cpu
== cpu
)
963 r_idx
= find_first_bit(q_vector
->tx
.idx
, adapter
->num_tx_queues
);
964 for (i
= 0; i
< q_vector
->tx
.count
; i
++) {
965 ixgbe_update_tx_dca(adapter
, adapter
->tx_ring
[r_idx
], cpu
);
966 r_idx
= find_next_bit(q_vector
->tx
.idx
, adapter
->num_tx_queues
,
970 r_idx
= find_first_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
);
971 for (i
= 0; i
< q_vector
->rx
.count
; i
++) {
972 ixgbe_update_rx_dca(adapter
, adapter
->rx_ring
[r_idx
], cpu
);
973 r_idx
= find_next_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
,
982 static void ixgbe_setup_dca(struct ixgbe_adapter
*adapter
)
987 if (!(adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
))
990 /* always use CB2 mode, difference is masked in the CB driver */
991 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 2);
993 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
994 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
998 for (i
= 0; i
< num_q_vectors
; i
++) {
999 adapter
->q_vector
[i
]->cpu
= -1;
1000 ixgbe_update_dca(adapter
->q_vector
[i
]);
1004 static int __ixgbe_notify_dca(struct device
*dev
, void *data
)
1006 struct ixgbe_adapter
*adapter
= dev_get_drvdata(dev
);
1007 unsigned long event
= *(unsigned long *)data
;
1009 if (!(adapter
->flags
& IXGBE_FLAG_DCA_CAPABLE
))
1013 case DCA_PROVIDER_ADD
:
1014 /* if we're already enabled, don't do it again */
1015 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1017 if (dca_add_requester(dev
) == 0) {
1018 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
1019 ixgbe_setup_dca(adapter
);
1022 /* Fall Through since DCA is disabled. */
1023 case DCA_PROVIDER_REMOVE
:
1024 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
1025 dca_remove_requester(dev
);
1026 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
1027 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
1034 #endif /* CONFIG_IXGBE_DCA */
1036 static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc
*rx_desc
,
1037 struct sk_buff
*skb
)
1039 skb
->rxhash
= le32_to_cpu(rx_desc
->wb
.lower
.hi_dword
.rss
);
1043 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1044 * @adapter: address of board private structure
1045 * @rx_desc: advanced rx descriptor
1047 * Returns : true if it is FCoE pkt
1049 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter
*adapter
,
1050 union ixgbe_adv_rx_desc
*rx_desc
)
1052 __le16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1054 return (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
1055 ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK
)) ==
1056 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE
<<
1057 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT
)));
1061 * ixgbe_receive_skb - Send a completed packet up the stack
1062 * @adapter: board private structure
1063 * @skb: packet to send up
1064 * @status: hardware indication of status of receive
1065 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1066 * @rx_desc: rx descriptor
1068 static void ixgbe_receive_skb(struct ixgbe_q_vector
*q_vector
,
1069 struct sk_buff
*skb
, u8 status
,
1070 struct ixgbe_ring
*ring
,
1071 union ixgbe_adv_rx_desc
*rx_desc
)
1073 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1074 struct napi_struct
*napi
= &q_vector
->napi
;
1075 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
1076 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
1078 if (is_vlan
&& (tag
& VLAN_VID_MASK
))
1079 __vlan_hwaccel_put_tag(skb
, tag
);
1081 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
))
1082 napi_gro_receive(napi
, skb
);
1088 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1089 * @adapter: address of board private structure
1090 * @status_err: hardware indication of status of receive
1091 * @skb: skb currently being received and modified
1092 * @status_err: status error value of last descriptor in packet
1094 static inline void ixgbe_rx_checksum(struct ixgbe_adapter
*adapter
,
1095 union ixgbe_adv_rx_desc
*rx_desc
,
1096 struct sk_buff
*skb
,
1099 skb
->ip_summed
= CHECKSUM_NONE
;
1101 /* Rx csum disabled */
1102 if (!(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
1105 /* if IP and error */
1106 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
1107 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
1108 adapter
->hw_csum_rx_error
++;
1112 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
1115 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
1116 u16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1119 * 82599 errata, UDP frames with a 0 checksum can be marked as
1122 if ((pkt_info
& IXGBE_RXDADV_PKTTYPE_UDP
) &&
1123 (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
))
1126 adapter
->hw_csum_rx_error
++;
1130 /* It must be a TCP or UDP packet with a valid checksum */
1131 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1134 static inline void ixgbe_release_rx_desc(struct ixgbe_ring
*rx_ring
, u32 val
)
1137 * Force memory writes to complete before letting h/w
1138 * know there are new descriptors to fetch. (Only
1139 * applicable for weak-ordered memory model archs,
1143 writel(val
, rx_ring
->tail
);
1147 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
1148 * @rx_ring: ring to place buffers on
1149 * @cleaned_count: number of buffers to replace
1151 void ixgbe_alloc_rx_buffers(struct ixgbe_ring
*rx_ring
, u16 cleaned_count
)
1153 union ixgbe_adv_rx_desc
*rx_desc
;
1154 struct ixgbe_rx_buffer
*bi
;
1155 struct sk_buff
*skb
;
1156 u16 i
= rx_ring
->next_to_use
;
1158 /* do nothing if no valid netdev defined */
1159 if (!rx_ring
->netdev
)
1162 while (cleaned_count
--) {
1163 rx_desc
= IXGBE_RX_DESC_ADV(rx_ring
, i
);
1164 bi
= &rx_ring
->rx_buffer_info
[i
];
1168 skb
= netdev_alloc_skb_ip_align(rx_ring
->netdev
,
1169 rx_ring
->rx_buf_len
);
1171 rx_ring
->rx_stats
.alloc_rx_buff_failed
++;
1174 /* initialize queue mapping */
1175 skb_record_rx_queue(skb
, rx_ring
->queue_index
);
1180 bi
->dma
= dma_map_single(rx_ring
->dev
,
1182 rx_ring
->rx_buf_len
,
1184 if (dma_mapping_error(rx_ring
->dev
, bi
->dma
)) {
1185 rx_ring
->rx_stats
.alloc_rx_buff_failed
++;
1191 if (ring_is_ps_enabled(rx_ring
)) {
1193 bi
->page
= netdev_alloc_page(rx_ring
->netdev
);
1195 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1200 if (!bi
->page_dma
) {
1201 /* use a half page if we're re-using */
1202 bi
->page_offset
^= PAGE_SIZE
/ 2;
1203 bi
->page_dma
= dma_map_page(rx_ring
->dev
,
1208 if (dma_mapping_error(rx_ring
->dev
,
1210 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1216 /* Refresh the desc even if buffer_addrs didn't change
1217 * because each write-back erases this info. */
1218 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->page_dma
);
1219 rx_desc
->read
.hdr_addr
= cpu_to_le64(bi
->dma
);
1221 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
1222 rx_desc
->read
.hdr_addr
= 0;
1226 if (i
== rx_ring
->count
)
1231 if (rx_ring
->next_to_use
!= i
) {
1232 rx_ring
->next_to_use
= i
;
1233 ixgbe_release_rx_desc(rx_ring
, i
);
1237 static inline u16
ixgbe_get_hlen(union ixgbe_adv_rx_desc
*rx_desc
)
1239 /* HW will not DMA in data larger than the given buffer, even if it
1240 * parses the (NFS, of course) header to be larger. In that case, it
1241 * fills the header buffer and spills the rest into the page.
1243 u16 hdr_info
= le16_to_cpu(rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
);
1244 u16 hlen
= (hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
1245 IXGBE_RXDADV_HDRBUFLEN_SHIFT
;
1246 if (hlen
> IXGBE_RX_HDR_SIZE
)
1247 hlen
= IXGBE_RX_HDR_SIZE
;
1252 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1253 * @skb: pointer to the last skb in the rsc queue
1255 * This function changes a queue full of hw rsc buffers into a completed
1256 * packet. It uses the ->prev pointers to find the first packet and then
1257 * turns it into the frag list owner.
1259 static inline struct sk_buff
*ixgbe_transform_rsc_queue(struct sk_buff
*skb
)
1261 unsigned int frag_list_size
= 0;
1262 unsigned int skb_cnt
= 1;
1265 struct sk_buff
*prev
= skb
->prev
;
1266 frag_list_size
+= skb
->len
;
1272 skb_shinfo(skb
)->frag_list
= skb
->next
;
1274 skb
->len
+= frag_list_size
;
1275 skb
->data_len
+= frag_list_size
;
1276 skb
->truesize
+= frag_list_size
;
1277 IXGBE_RSC_CB(skb
)->skb_cnt
= skb_cnt
;
1282 static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc
*rx_desc
)
1284 return !!(le32_to_cpu(rx_desc
->wb
.lower
.lo_dword
.data
) &
1285 IXGBE_RXDADV_RSCCNT_MASK
);
1288 static void ixgbe_clean_rx_irq(struct ixgbe_q_vector
*q_vector
,
1289 struct ixgbe_ring
*rx_ring
,
1290 int *work_done
, int work_to_do
)
1292 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1293 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
1294 struct ixgbe_rx_buffer
*rx_buffer_info
, *next_buffer
;
1295 struct sk_buff
*skb
;
1296 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
1297 const int current_node
= numa_node_id();
1300 #endif /* IXGBE_FCOE */
1303 u16 cleaned_count
= 0;
1304 bool pkt_is_rsc
= false;
1306 i
= rx_ring
->next_to_clean
;
1307 rx_desc
= IXGBE_RX_DESC_ADV(rx_ring
, i
);
1308 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1310 while (staterr
& IXGBE_RXD_STAT_DD
) {
1313 rmb(); /* read descriptor and rx_buffer_info after status DD */
1315 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
1317 skb
= rx_buffer_info
->skb
;
1318 rx_buffer_info
->skb
= NULL
;
1319 prefetch(skb
->data
);
1321 if (ring_is_rsc_enabled(rx_ring
))
1322 pkt_is_rsc
= ixgbe_get_rsc_state(rx_desc
);
1324 /* if this is a skb from previous receive DMA will be 0 */
1325 if (rx_buffer_info
->dma
) {
1328 !(staterr
& IXGBE_RXD_STAT_EOP
) &&
1331 * When HWRSC is enabled, delay unmapping
1332 * of the first packet. It carries the
1333 * header information, HW may still
1334 * access the header after the writeback.
1335 * Only unmap it when EOP is reached
1337 IXGBE_RSC_CB(skb
)->delay_unmap
= true;
1338 IXGBE_RSC_CB(skb
)->dma
= rx_buffer_info
->dma
;
1340 dma_unmap_single(rx_ring
->dev
,
1341 rx_buffer_info
->dma
,
1342 rx_ring
->rx_buf_len
,
1345 rx_buffer_info
->dma
= 0;
1347 if (ring_is_ps_enabled(rx_ring
)) {
1348 hlen
= ixgbe_get_hlen(rx_desc
);
1349 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
1351 hlen
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
1356 /* assume packet split since header is unmapped */
1357 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
1361 dma_unmap_page(rx_ring
->dev
,
1362 rx_buffer_info
->page_dma
,
1365 rx_buffer_info
->page_dma
= 0;
1366 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
1367 rx_buffer_info
->page
,
1368 rx_buffer_info
->page_offset
,
1371 if ((page_count(rx_buffer_info
->page
) == 1) &&
1372 (page_to_nid(rx_buffer_info
->page
) == current_node
))
1373 get_page(rx_buffer_info
->page
);
1375 rx_buffer_info
->page
= NULL
;
1377 skb
->len
+= upper_len
;
1378 skb
->data_len
+= upper_len
;
1379 skb
->truesize
+= upper_len
;
1383 if (i
== rx_ring
->count
)
1386 next_rxd
= IXGBE_RX_DESC_ADV(rx_ring
, i
);
1391 u32 nextp
= (staterr
& IXGBE_RXDADV_NEXTP_MASK
) >>
1392 IXGBE_RXDADV_NEXTP_SHIFT
;
1393 next_buffer
= &rx_ring
->rx_buffer_info
[nextp
];
1395 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
1398 if (!(staterr
& IXGBE_RXD_STAT_EOP
)) {
1399 if (ring_is_ps_enabled(rx_ring
)) {
1400 rx_buffer_info
->skb
= next_buffer
->skb
;
1401 rx_buffer_info
->dma
= next_buffer
->dma
;
1402 next_buffer
->skb
= skb
;
1403 next_buffer
->dma
= 0;
1405 skb
->next
= next_buffer
->skb
;
1406 skb
->next
->prev
= skb
;
1408 rx_ring
->rx_stats
.non_eop_descs
++;
1413 skb
= ixgbe_transform_rsc_queue(skb
);
1414 /* if we got here without RSC the packet is invalid */
1416 __pskb_trim(skb
, 0);
1417 rx_buffer_info
->skb
= skb
;
1422 if (ring_is_rsc_enabled(rx_ring
)) {
1423 if (IXGBE_RSC_CB(skb
)->delay_unmap
) {
1424 dma_unmap_single(rx_ring
->dev
,
1425 IXGBE_RSC_CB(skb
)->dma
,
1426 rx_ring
->rx_buf_len
,
1428 IXGBE_RSC_CB(skb
)->dma
= 0;
1429 IXGBE_RSC_CB(skb
)->delay_unmap
= false;
1433 if (ring_is_ps_enabled(rx_ring
))
1434 rx_ring
->rx_stats
.rsc_count
+=
1435 skb_shinfo(skb
)->nr_frags
;
1437 rx_ring
->rx_stats
.rsc_count
+=
1438 IXGBE_RSC_CB(skb
)->skb_cnt
;
1439 rx_ring
->rx_stats
.rsc_flush
++;
1442 /* ERR_MASK will only have valid bits if EOP set */
1443 if (unlikely(staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
)) {
1444 dev_kfree_skb_any(skb
);
1448 ixgbe_rx_checksum(adapter
, rx_desc
, skb
, staterr
);
1449 if (adapter
->netdev
->features
& NETIF_F_RXHASH
)
1450 ixgbe_rx_hash(rx_desc
, skb
);
1452 /* probably a little skewed due to removing CRC */
1453 total_rx_bytes
+= skb
->len
;
1456 skb
->protocol
= eth_type_trans(skb
, rx_ring
->netdev
);
1458 /* if ddp, not passing to ULD unless for FCP_RSP or error */
1459 if (ixgbe_rx_is_fcoe(adapter
, rx_desc
)) {
1460 ddp_bytes
= ixgbe_fcoe_ddp(adapter
, rx_desc
, skb
,
1465 #endif /* IXGBE_FCOE */
1466 ixgbe_receive_skb(q_vector
, skb
, staterr
, rx_ring
, rx_desc
);
1469 rx_desc
->wb
.upper
.status_error
= 0;
1472 if (*work_done
>= work_to_do
)
1475 /* return some buffers to hardware, one at a time is too slow */
1476 if (cleaned_count
>= IXGBE_RX_BUFFER_WRITE
) {
1477 ixgbe_alloc_rx_buffers(rx_ring
, cleaned_count
);
1481 /* use prefetched values */
1483 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1486 rx_ring
->next_to_clean
= i
;
1487 cleaned_count
= ixgbe_desc_unused(rx_ring
);
1490 ixgbe_alloc_rx_buffers(rx_ring
, cleaned_count
);
1493 /* include DDPed FCoE data */
1494 if (ddp_bytes
> 0) {
1497 mss
= rx_ring
->netdev
->mtu
- sizeof(struct fcoe_hdr
) -
1498 sizeof(struct fc_frame_header
) -
1499 sizeof(struct fcoe_crc_eof
);
1502 total_rx_bytes
+= ddp_bytes
;
1503 total_rx_packets
+= DIV_ROUND_UP(ddp_bytes
, mss
);
1505 #endif /* IXGBE_FCOE */
1507 u64_stats_update_begin(&rx_ring
->syncp
);
1508 rx_ring
->stats
.packets
+= total_rx_packets
;
1509 rx_ring
->stats
.bytes
+= total_rx_bytes
;
1510 u64_stats_update_end(&rx_ring
->syncp
);
1511 q_vector
->rx
.total_packets
+= total_rx_packets
;
1512 q_vector
->rx
.total_bytes
+= total_rx_bytes
;
1515 static int ixgbe_clean_rxonly(struct napi_struct
*, int);
1517 * ixgbe_configure_msix - Configure MSI-X hardware
1518 * @adapter: board private structure
1520 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1523 static void ixgbe_configure_msix(struct ixgbe_adapter
*adapter
)
1525 struct ixgbe_q_vector
*q_vector
;
1526 int i
, q_vectors
, v_idx
, r_idx
;
1529 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1532 * Populate the IVAR table and set the ITR values to the
1533 * corresponding register.
1535 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
1536 q_vector
= adapter
->q_vector
[v_idx
];
1537 /* XXX for_each_set_bit(...) */
1538 r_idx
= find_first_bit(q_vector
->rx
.idx
,
1539 adapter
->num_rx_queues
);
1541 for (i
= 0; i
< q_vector
->rx
.count
; i
++) {
1542 u8 reg_idx
= adapter
->rx_ring
[r_idx
]->reg_idx
;
1543 ixgbe_set_ivar(adapter
, 0, reg_idx
, v_idx
);
1544 r_idx
= find_next_bit(q_vector
->rx
.idx
,
1545 adapter
->num_rx_queues
,
1548 r_idx
= find_first_bit(q_vector
->tx
.idx
,
1549 adapter
->num_tx_queues
);
1551 for (i
= 0; i
< q_vector
->tx
.count
; i
++) {
1552 u8 reg_idx
= adapter
->tx_ring
[r_idx
]->reg_idx
;
1553 ixgbe_set_ivar(adapter
, 1, reg_idx
, v_idx
);
1554 r_idx
= find_next_bit(q_vector
->tx
.idx
,
1555 adapter
->num_tx_queues
,
1559 if (q_vector
->tx
.count
&& !q_vector
->rx
.count
)
1561 q_vector
->eitr
= adapter
->tx_eitr_param
;
1562 else if (q_vector
->rx
.count
)
1564 q_vector
->eitr
= adapter
->rx_eitr_param
;
1566 ixgbe_write_eitr(q_vector
);
1567 /* If ATR is enabled, set interrupt affinity */
1568 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
1570 * Allocate the affinity_hint cpumask, assign the mask
1571 * for this vector, and set our affinity_hint for
1574 if (!alloc_cpumask_var(&q_vector
->affinity_mask
,
1577 cpumask_set_cpu(v_idx
, q_vector
->affinity_mask
);
1578 irq_set_affinity_hint(adapter
->msix_entries
[v_idx
].vector
,
1579 q_vector
->affinity_mask
);
1583 switch (adapter
->hw
.mac
.type
) {
1584 case ixgbe_mac_82598EB
:
1585 ixgbe_set_ivar(adapter
, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX
,
1588 case ixgbe_mac_82599EB
:
1589 case ixgbe_mac_X540
:
1590 ixgbe_set_ivar(adapter
, -1, 1, v_idx
);
1596 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITR(v_idx
), 1950);
1598 /* set up to autoclear timer, and the vectors */
1599 mask
= IXGBE_EIMS_ENABLE_MASK
;
1600 if (adapter
->num_vfs
)
1601 mask
&= ~(IXGBE_EIMS_OTHER
|
1602 IXGBE_EIMS_MAILBOX
|
1605 mask
&= ~(IXGBE_EIMS_OTHER
| IXGBE_EIMS_LSC
);
1606 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIAC
, mask
);
1609 enum latency_range
{
1613 latency_invalid
= 255
1617 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1618 * @q_vector: structure containing interrupt and ring information
1619 * @ring_container: structure containing ring performance data
1621 * Stores a new ITR value based on packets and byte
1622 * counts during the last interrupt. The advantage of per interrupt
1623 * computation is faster updates and more accurate ITR for the current
1624 * traffic pattern. Constants in this function were computed
1625 * based on theoretical maximum wire speed and thresholds were set based
1626 * on testing data as well as attempting to minimize response time
1627 * while increasing bulk throughput.
1628 * this functionality is controlled by the InterruptThrottleRate module
1629 * parameter (see ixgbe_param.c)
1631 static void ixgbe_update_itr(struct ixgbe_q_vector
*q_vector
,
1632 struct ixgbe_ring_container
*ring_container
)
1635 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1636 int bytes
= ring_container
->total_bytes
;
1637 int packets
= ring_container
->total_packets
;
1639 u8 itr_setting
= ring_container
->itr
;
1644 /* simple throttlerate management
1645 * 0-20MB/s lowest (100000 ints/s)
1646 * 20-100MB/s low (20000 ints/s)
1647 * 100-1249MB/s bulk (8000 ints/s)
1649 /* what was last interrupt timeslice? */
1650 timepassed_us
= 1000000/q_vector
->eitr
;
1651 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
1653 switch (itr_setting
) {
1654 case lowest_latency
:
1655 if (bytes_perint
> adapter
->eitr_low
)
1656 itr_setting
= low_latency
;
1659 if (bytes_perint
> adapter
->eitr_high
)
1660 itr_setting
= bulk_latency
;
1661 else if (bytes_perint
<= adapter
->eitr_low
)
1662 itr_setting
= lowest_latency
;
1665 if (bytes_perint
<= adapter
->eitr_high
)
1666 itr_setting
= low_latency
;
1670 /* clear work counters since we have the values we need */
1671 ring_container
->total_bytes
= 0;
1672 ring_container
->total_packets
= 0;
1674 /* write updated itr to ring container */
1675 ring_container
->itr
= itr_setting
;
1679 * ixgbe_write_eitr - write EITR register in hardware specific way
1680 * @q_vector: structure containing interrupt and ring information
1682 * This function is made to be called by ethtool and by the driver
1683 * when it needs to update EITR registers at runtime. Hardware
1684 * specific quirks/differences are taken care of here.
1686 void ixgbe_write_eitr(struct ixgbe_q_vector
*q_vector
)
1688 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1689 struct ixgbe_hw
*hw
= &adapter
->hw
;
1690 int v_idx
= q_vector
->v_idx
;
1691 u32 itr_reg
= EITR_INTS_PER_SEC_TO_REG(q_vector
->eitr
);
1693 switch (adapter
->hw
.mac
.type
) {
1694 case ixgbe_mac_82598EB
:
1695 /* must write high and low 16 bits to reset counter */
1696 itr_reg
|= (itr_reg
<< 16);
1698 case ixgbe_mac_82599EB
:
1699 case ixgbe_mac_X540
:
1701 * 82599 and X540 can support a value of zero, so allow it for
1702 * max interrupt rate, but there is an errata where it can
1703 * not be zero with RSC
1706 !(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
))
1710 * set the WDIS bit to not clear the timer bits and cause an
1711 * immediate assertion of the interrupt
1713 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
1718 IXGBE_WRITE_REG(hw
, IXGBE_EITR(v_idx
), itr_reg
);
1721 static void ixgbe_set_itr(struct ixgbe_q_vector
*q_vector
)
1723 u32 new_itr
= q_vector
->eitr
;
1726 ixgbe_update_itr(q_vector
, &q_vector
->tx
);
1727 ixgbe_update_itr(q_vector
, &q_vector
->rx
);
1729 current_itr
= max(q_vector
->rx
.itr
, q_vector
->tx
.itr
);
1731 switch (current_itr
) {
1732 /* counts and packets in update_itr are dependent on these numbers */
1733 case lowest_latency
:
1737 new_itr
= 20000; /* aka hwitr = ~200 */
1746 if (new_itr
!= q_vector
->eitr
) {
1747 /* do an exponential smoothing */
1748 new_itr
= ((q_vector
->eitr
* 9) + new_itr
)/10;
1750 /* save the algorithm value here */
1751 q_vector
->eitr
= new_itr
;
1753 ixgbe_write_eitr(q_vector
);
1758 * ixgbe_check_overtemp_subtask - check for over tempurature
1759 * @adapter: pointer to adapter
1761 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter
*adapter
)
1763 struct ixgbe_hw
*hw
= &adapter
->hw
;
1764 u32 eicr
= adapter
->interrupt_event
;
1766 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
1769 if (!(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) &&
1770 !(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_EVENT
))
1773 adapter
->flags2
&= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
1775 switch (hw
->device_id
) {
1776 case IXGBE_DEV_ID_82599_T3_LOM
:
1778 * Since the warning interrupt is for both ports
1779 * we don't have to check if:
1780 * - This interrupt wasn't for our port.
1781 * - We may have missed the interrupt so always have to
1782 * check if we got a LSC
1784 if (!(eicr
& IXGBE_EICR_GPI_SDP0
) &&
1785 !(eicr
& IXGBE_EICR_LSC
))
1788 if (!(eicr
& IXGBE_EICR_LSC
) && hw
->mac
.ops
.check_link
) {
1790 bool link_up
= false;
1792 hw
->mac
.ops
.check_link(hw
, &autoneg
, &link_up
, false);
1798 /* Check if this is not due to overtemp */
1799 if (hw
->phy
.ops
.check_overtemp(hw
) != IXGBE_ERR_OVERTEMP
)
1804 if (!(eicr
& IXGBE_EICR_GPI_SDP0
))
1809 "Network adapter has been stopped because it has over heated. "
1810 "Restart the computer. If the problem persists, "
1811 "power off the system and replace the adapter\n");
1813 adapter
->interrupt_event
= 0;
1816 static void ixgbe_check_fan_failure(struct ixgbe_adapter
*adapter
, u32 eicr
)
1818 struct ixgbe_hw
*hw
= &adapter
->hw
;
1820 if ((adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) &&
1821 (eicr
& IXGBE_EICR_GPI_SDP1
)) {
1822 e_crit(probe
, "Fan has stopped, replace the adapter\n");
1823 /* write to clear the interrupt */
1824 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1828 static void ixgbe_check_sfp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
1830 struct ixgbe_hw
*hw
= &adapter
->hw
;
1832 if (eicr
& IXGBE_EICR_GPI_SDP2
) {
1833 /* Clear the interrupt */
1834 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP2
);
1835 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1836 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
1837 ixgbe_service_event_schedule(adapter
);
1841 if (eicr
& IXGBE_EICR_GPI_SDP1
) {
1842 /* Clear the interrupt */
1843 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1
);
1844 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1845 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
1846 ixgbe_service_event_schedule(adapter
);
1851 static void ixgbe_check_lsc(struct ixgbe_adapter
*adapter
)
1853 struct ixgbe_hw
*hw
= &adapter
->hw
;
1856 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
1857 adapter
->link_check_timeout
= jiffies
;
1858 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1859 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_LSC
);
1860 IXGBE_WRITE_FLUSH(hw
);
1861 ixgbe_service_event_schedule(adapter
);
1865 static irqreturn_t
ixgbe_msix_lsc(int irq
, void *data
)
1867 struct ixgbe_adapter
*adapter
= data
;
1868 struct ixgbe_hw
*hw
= &adapter
->hw
;
1872 * Workaround for Silicon errata. Use clear-by-write instead
1873 * of clear-by-read. Reading with EICS will return the
1874 * interrupt causes without clearing, which later be done
1875 * with the write to EICR.
1877 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICS
);
1878 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr
);
1880 if (eicr
& IXGBE_EICR_LSC
)
1881 ixgbe_check_lsc(adapter
);
1883 if (eicr
& IXGBE_EICR_MAILBOX
)
1884 ixgbe_msg_task(adapter
);
1886 switch (hw
->mac
.type
) {
1887 case ixgbe_mac_82599EB
:
1888 case ixgbe_mac_X540
:
1889 /* Handle Flow Director Full threshold interrupt */
1890 if (eicr
& IXGBE_EICR_FLOW_DIR
) {
1891 int reinit_count
= 0;
1893 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1894 struct ixgbe_ring
*ring
= adapter
->tx_ring
[i
];
1895 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE
,
1900 /* no more flow director interrupts until after init */
1901 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_FLOW_DIR
);
1902 eicr
&= ~IXGBE_EICR_FLOW_DIR
;
1903 adapter
->flags2
|= IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
1904 ixgbe_service_event_schedule(adapter
);
1907 ixgbe_check_sfp_event(adapter
, eicr
);
1908 if ((adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) &&
1909 ((eicr
& IXGBE_EICR_GPI_SDP0
) || (eicr
& IXGBE_EICR_LSC
))) {
1910 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1911 adapter
->interrupt_event
= eicr
;
1912 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
1913 ixgbe_service_event_schedule(adapter
);
1921 ixgbe_check_fan_failure(adapter
, eicr
);
1923 /* re-enable the original interrupt state, no lsc, no queues */
1924 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
1925 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, eicr
&
1926 ~(IXGBE_EIMS_LSC
| IXGBE_EIMS_RTX_QUEUE
));
1931 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter
*adapter
,
1935 struct ixgbe_hw
*hw
= &adapter
->hw
;
1937 switch (hw
->mac
.type
) {
1938 case ixgbe_mac_82598EB
:
1939 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1940 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, mask
);
1942 case ixgbe_mac_82599EB
:
1943 case ixgbe_mac_X540
:
1944 mask
= (qmask
& 0xFFFFFFFF);
1946 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(0), mask
);
1947 mask
= (qmask
>> 32);
1949 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(1), mask
);
1954 /* skip the flush */
1957 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter
*adapter
,
1961 struct ixgbe_hw
*hw
= &adapter
->hw
;
1963 switch (hw
->mac
.type
) {
1964 case ixgbe_mac_82598EB
:
1965 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
1966 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, mask
);
1968 case ixgbe_mac_82599EB
:
1969 case ixgbe_mac_X540
:
1970 mask
= (qmask
& 0xFFFFFFFF);
1972 IXGBE_WRITE_REG(hw
, IXGBE_EIMC_EX(0), mask
);
1973 mask
= (qmask
>> 32);
1975 IXGBE_WRITE_REG(hw
, IXGBE_EIMC_EX(1), mask
);
1980 /* skip the flush */
1983 static irqreturn_t
ixgbe_msix_clean_tx(int irq
, void *data
)
1985 struct ixgbe_q_vector
*q_vector
= data
;
1986 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1987 struct ixgbe_ring
*tx_ring
;
1990 if (!q_vector
->tx
.count
)
1993 r_idx
= find_first_bit(q_vector
->tx
.idx
, adapter
->num_tx_queues
);
1994 for (i
= 0; i
< q_vector
->tx
.count
; i
++) {
1995 tx_ring
= adapter
->tx_ring
[r_idx
];
1996 r_idx
= find_next_bit(q_vector
->tx
.idx
, adapter
->num_tx_queues
,
2000 /* EIAM disabled interrupts (on this vector) for us */
2001 napi_schedule(&q_vector
->napi
);
2007 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2009 * @data: pointer to our q_vector struct for this interrupt vector
2011 static irqreturn_t
ixgbe_msix_clean_rx(int irq
, void *data
)
2013 struct ixgbe_q_vector
*q_vector
= data
;
2014 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2015 struct ixgbe_ring
*rx_ring
;
2019 #ifdef CONFIG_IXGBE_DCA
2020 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
2021 ixgbe_update_dca(q_vector
);
2024 r_idx
= find_first_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
);
2025 for (i
= 0; i
< q_vector
->rx
.count
; i
++) {
2026 rx_ring
= adapter
->rx_ring
[r_idx
];
2027 r_idx
= find_next_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
,
2031 if (!q_vector
->rx
.count
)
2034 /* EIAM disabled interrupts (on this vector) for us */
2035 napi_schedule(&q_vector
->napi
);
2040 static irqreturn_t
ixgbe_msix_clean_many(int irq
, void *data
)
2042 struct ixgbe_q_vector
*q_vector
= data
;
2043 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2044 struct ixgbe_ring
*ring
;
2048 if (!q_vector
->tx
.count
&& !q_vector
->rx
.count
)
2051 r_idx
= find_first_bit(q_vector
->tx
.idx
, adapter
->num_tx_queues
);
2052 for (i
= 0; i
< q_vector
->tx
.count
; i
++) {
2053 ring
= adapter
->tx_ring
[r_idx
];
2054 r_idx
= find_next_bit(q_vector
->tx
.idx
, adapter
->num_tx_queues
,
2058 r_idx
= find_first_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
);
2059 for (i
= 0; i
< q_vector
->rx
.count
; i
++) {
2060 ring
= adapter
->rx_ring
[r_idx
];
2061 r_idx
= find_next_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
,
2065 /* EIAM disabled interrupts (on this vector) for us */
2066 napi_schedule(&q_vector
->napi
);
2072 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2073 * @napi: napi struct with our devices info in it
2074 * @budget: amount of work driver is allowed to do this pass, in packets
2076 * This function is optimized for cleaning one queue only on a single
2079 static int ixgbe_clean_rxonly(struct napi_struct
*napi
, int budget
)
2081 struct ixgbe_q_vector
*q_vector
=
2082 container_of(napi
, struct ixgbe_q_vector
, napi
);
2083 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2084 struct ixgbe_ring
*rx_ring
= NULL
;
2088 #ifdef CONFIG_IXGBE_DCA
2089 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
2090 ixgbe_update_dca(q_vector
);
2093 r_idx
= find_first_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
);
2094 rx_ring
= adapter
->rx_ring
[r_idx
];
2096 ixgbe_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
2098 /* If all Rx work done, exit the polling mode */
2099 if (work_done
< budget
) {
2100 napi_complete(napi
);
2101 if (adapter
->rx_itr_setting
& 1)
2102 ixgbe_set_itr(q_vector
);
2103 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2104 ixgbe_irq_enable_queues(adapter
,
2105 ((u64
)1 << q_vector
->v_idx
));
2112 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
2113 * @napi: napi struct with our devices info in it
2114 * @budget: amount of work driver is allowed to do this pass, in packets
2116 * This function will clean more than one rx queue associated with a
2119 static int ixgbe_clean_rxtx_many(struct napi_struct
*napi
, int budget
)
2121 struct ixgbe_q_vector
*q_vector
=
2122 container_of(napi
, struct ixgbe_q_vector
, napi
);
2123 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2124 struct ixgbe_ring
*ring
= NULL
;
2125 int work_done
= 0, i
;
2127 bool tx_clean_complete
= true;
2129 #ifdef CONFIG_IXGBE_DCA
2130 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
2131 ixgbe_update_dca(q_vector
);
2134 r_idx
= find_first_bit(q_vector
->tx
.idx
, adapter
->num_tx_queues
);
2135 for (i
= 0; i
< q_vector
->tx
.count
; i
++) {
2136 ring
= adapter
->tx_ring
[r_idx
];
2137 tx_clean_complete
&= ixgbe_clean_tx_irq(q_vector
, ring
);
2138 r_idx
= find_next_bit(q_vector
->tx
.idx
, adapter
->num_tx_queues
,
2142 /* attempt to distribute budget to each queue fairly, but don't allow
2143 * the budget to go below 1 because we'll exit polling */
2144 budget
/= (q_vector
->rx
.count
?: 1);
2145 budget
= max(budget
, 1);
2146 r_idx
= find_first_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
);
2147 for (i
= 0; i
< q_vector
->rx
.count
; i
++) {
2148 ring
= adapter
->rx_ring
[r_idx
];
2149 ixgbe_clean_rx_irq(q_vector
, ring
, &work_done
, budget
);
2150 r_idx
= find_next_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
,
2154 r_idx
= find_first_bit(q_vector
->rx
.idx
, adapter
->num_rx_queues
);
2155 ring
= adapter
->rx_ring
[r_idx
];
2156 /* If all Rx work done, exit the polling mode */
2157 if (work_done
< budget
) {
2158 napi_complete(napi
);
2159 if (adapter
->rx_itr_setting
& 1)
2160 ixgbe_set_itr(q_vector
);
2161 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2162 ixgbe_irq_enable_queues(adapter
,
2163 ((u64
)1 << q_vector
->v_idx
));
2171 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2172 * @napi: napi struct with our devices info in it
2173 * @budget: amount of work driver is allowed to do this pass, in packets
2175 * This function is optimized for cleaning one queue only on a single
2178 static int ixgbe_clean_txonly(struct napi_struct
*napi
, int budget
)
2180 struct ixgbe_q_vector
*q_vector
=
2181 container_of(napi
, struct ixgbe_q_vector
, napi
);
2182 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2183 struct ixgbe_ring
*tx_ring
= NULL
;
2187 #ifdef CONFIG_IXGBE_DCA
2188 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
2189 ixgbe_update_dca(q_vector
);
2192 r_idx
= find_first_bit(q_vector
->tx
.idx
, adapter
->num_tx_queues
);
2193 tx_ring
= adapter
->tx_ring
[r_idx
];
2195 if (!ixgbe_clean_tx_irq(q_vector
, tx_ring
))
2198 /* If all Tx work done, exit the polling mode */
2199 if (work_done
< budget
) {
2200 napi_complete(napi
);
2201 if (adapter
->tx_itr_setting
& 1)
2202 ixgbe_set_itr(q_vector
);
2203 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2204 ixgbe_irq_enable_queues(adapter
,
2205 ((u64
)1 << q_vector
->v_idx
));
2211 static inline void map_vector_to_rxq(struct ixgbe_adapter
*a
, int v_idx
,
2214 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
2215 struct ixgbe_ring
*rx_ring
= a
->rx_ring
[r_idx
];
2217 set_bit(r_idx
, q_vector
->rx
.idx
);
2218 q_vector
->rx
.count
++;
2219 rx_ring
->q_vector
= q_vector
;
2222 static inline void map_vector_to_txq(struct ixgbe_adapter
*a
, int v_idx
,
2225 struct ixgbe_q_vector
*q_vector
= a
->q_vector
[v_idx
];
2226 struct ixgbe_ring
*tx_ring
= a
->tx_ring
[t_idx
];
2228 set_bit(t_idx
, q_vector
->tx
.idx
);
2229 q_vector
->tx
.count
++;
2230 tx_ring
->q_vector
= q_vector
;
2231 q_vector
->tx
.work_limit
= a
->tx_work_limit
;
2235 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2236 * @adapter: board private structure to initialize
2238 * This function maps descriptor rings to the queue-specific vectors
2239 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2240 * one vector per ring/queue, but on a constrained vector budget, we
2241 * group the rings as "efficiently" as possible. You would add new
2242 * mapping configurations in here.
2244 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter
*adapter
)
2248 int rxr_idx
= 0, txr_idx
= 0;
2249 int rxr_remaining
= adapter
->num_rx_queues
;
2250 int txr_remaining
= adapter
->num_tx_queues
;
2255 /* No mapping required if MSI-X is disabled. */
2256 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
2259 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2262 * The ideal configuration...
2263 * We have enough vectors to map one per queue.
2265 if (q_vectors
== adapter
->num_rx_queues
+ adapter
->num_tx_queues
) {
2266 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
2267 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
2269 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
2270 map_vector_to_txq(adapter
, v_start
, txr_idx
);
2276 * If we don't have enough vectors for a 1-to-1
2277 * mapping, we'll have to group them so there are
2278 * multiple queues per vector.
2280 /* Re-adjusting *qpv takes care of the remainder. */
2281 for (i
= v_start
; i
< q_vectors
; i
++) {
2282 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
2283 for (j
= 0; j
< rqpv
; j
++) {
2284 map_vector_to_rxq(adapter
, i
, rxr_idx
);
2288 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
2289 for (j
= 0; j
< tqpv
; j
++) {
2290 map_vector_to_txq(adapter
, i
, txr_idx
);
2300 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2301 * @adapter: board private structure
2303 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2304 * interrupts from the kernel.
2306 static int ixgbe_request_msix_irqs(struct ixgbe_adapter
*adapter
)
2308 struct net_device
*netdev
= adapter
->netdev
;
2309 irqreturn_t (*handler
)(int, void *);
2310 int i
, vector
, q_vectors
, err
;
2313 /* Decrement for Other and TCP Timer vectors */
2314 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2316 err
= ixgbe_map_rings_to_vectors(adapter
);
2320 #define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \
2321 ? &ixgbe_msix_clean_many : \
2322 (_v)->rx.count ? &ixgbe_msix_clean_rx : \
2323 (_v)->tx.count ? &ixgbe_msix_clean_tx : \
2325 for (vector
= 0; vector
< q_vectors
; vector
++) {
2326 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[vector
];
2327 handler
= SET_HANDLER(q_vector
);
2329 if (handler
== &ixgbe_msix_clean_rx
) {
2330 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2331 "%s-%s-%d", netdev
->name
, "rx", ri
++);
2332 } else if (handler
== &ixgbe_msix_clean_tx
) {
2333 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2334 "%s-%s-%d", netdev
->name
, "tx", ti
++);
2335 } else if (handler
== &ixgbe_msix_clean_many
) {
2336 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2337 "%s-%s-%d", netdev
->name
, "TxRx", ri
++);
2340 /* skip this unused q_vector */
2343 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
2344 handler
, 0, q_vector
->name
,
2347 e_err(probe
, "request_irq failed for MSIX interrupt "
2348 "Error: %d\n", err
);
2349 goto free_queue_irqs
;
2353 sprintf(adapter
->lsc_int_name
, "%s:lsc", netdev
->name
);
2354 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
2355 ixgbe_msix_lsc
, 0, adapter
->lsc_int_name
, adapter
);
2357 e_err(probe
, "request_irq for msix_lsc failed: %d\n", err
);
2358 goto free_queue_irqs
;
2364 for (i
= vector
- 1; i
>= 0; i
--)
2365 free_irq(adapter
->msix_entries
[--vector
].vector
,
2366 adapter
->q_vector
[i
]);
2367 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
2368 pci_disable_msix(adapter
->pdev
);
2369 kfree(adapter
->msix_entries
);
2370 adapter
->msix_entries
= NULL
;
2375 * ixgbe_irq_enable - Enable default interrupt generation settings
2376 * @adapter: board private structure
2378 static inline void ixgbe_irq_enable(struct ixgbe_adapter
*adapter
, bool queues
,
2383 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
2384 if (adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
)
2385 mask
|= IXGBE_EIMS_GPI_SDP0
;
2386 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
2387 mask
|= IXGBE_EIMS_GPI_SDP1
;
2388 switch (adapter
->hw
.mac
.type
) {
2389 case ixgbe_mac_82599EB
:
2390 case ixgbe_mac_X540
:
2391 mask
|= IXGBE_EIMS_ECC
;
2392 mask
|= IXGBE_EIMS_GPI_SDP1
;
2393 mask
|= IXGBE_EIMS_GPI_SDP2
;
2394 if (adapter
->num_vfs
)
2395 mask
|= IXGBE_EIMS_MAILBOX
;
2400 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)
2401 mask
|= IXGBE_EIMS_FLOW_DIR
;
2403 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
2405 ixgbe_irq_enable_queues(adapter
, ~0);
2407 IXGBE_WRITE_FLUSH(&adapter
->hw
);
2409 if (adapter
->num_vfs
> 32) {
2410 u32 eitrsel
= (1 << (adapter
->num_vfs
- 32)) - 1;
2411 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, eitrsel
);
2416 * ixgbe_intr - legacy mode Interrupt Handler
2417 * @irq: interrupt number
2418 * @data: pointer to a network interface device structure
2420 static irqreturn_t
ixgbe_intr(int irq
, void *data
)
2422 struct ixgbe_adapter
*adapter
= data
;
2423 struct ixgbe_hw
*hw
= &adapter
->hw
;
2424 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
2428 * Workaround for silicon errata on 82598. Mask the interrupts
2429 * before the read of EICR.
2431 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_IRQ_CLEAR_MASK
);
2433 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2434 * therefore no explict interrupt disable is necessary */
2435 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
2438 * shared interrupt alert!
2439 * make sure interrupts are enabled because the read will
2440 * have disabled interrupts due to EIAM
2441 * finish the workaround of silicon errata on 82598. Unmask
2442 * the interrupt that we masked before the EICR read.
2444 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2445 ixgbe_irq_enable(adapter
, true, true);
2446 return IRQ_NONE
; /* Not our interrupt */
2449 if (eicr
& IXGBE_EICR_LSC
)
2450 ixgbe_check_lsc(adapter
);
2452 switch (hw
->mac
.type
) {
2453 case ixgbe_mac_82599EB
:
2454 ixgbe_check_sfp_event(adapter
, eicr
);
2455 if ((adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) &&
2456 ((eicr
& IXGBE_EICR_GPI_SDP0
) || (eicr
& IXGBE_EICR_LSC
))) {
2457 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2458 adapter
->interrupt_event
= eicr
;
2459 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
2460 ixgbe_service_event_schedule(adapter
);
2468 ixgbe_check_fan_failure(adapter
, eicr
);
2470 if (napi_schedule_prep(&(q_vector
->napi
))) {
2471 /* would disable interrupts here but EIAM disabled it */
2472 __napi_schedule(&(q_vector
->napi
));
2476 * re-enable link(maybe) and non-queue interrupts, no flush.
2477 * ixgbe_poll will re-enable the queue interrupts
2480 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2481 ixgbe_irq_enable(adapter
, false, false);
2486 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter
*adapter
)
2488 int i
, q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2490 for (i
= 0; i
< q_vectors
; i
++) {
2491 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
2492 bitmap_zero(q_vector
->rx
.idx
, MAX_RX_QUEUES
);
2493 bitmap_zero(q_vector
->tx
.idx
, MAX_TX_QUEUES
);
2494 q_vector
->rx
.count
= 0;
2495 q_vector
->tx
.count
= 0;
2500 * ixgbe_request_irq - initialize interrupts
2501 * @adapter: board private structure
2503 * Attempts to configure interrupts using the best available
2504 * capabilities of the hardware and kernel.
2506 static int ixgbe_request_irq(struct ixgbe_adapter
*adapter
)
2508 struct net_device
*netdev
= adapter
->netdev
;
2511 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2512 err
= ixgbe_request_msix_irqs(adapter
);
2513 } else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
2514 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, 0,
2515 netdev
->name
, adapter
);
2517 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, IRQF_SHARED
,
2518 netdev
->name
, adapter
);
2522 e_err(probe
, "request_irq failed, Error %d\n", err
);
2527 static void ixgbe_free_irq(struct ixgbe_adapter
*adapter
)
2529 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2532 q_vectors
= adapter
->num_msix_vectors
;
2535 free_irq(adapter
->msix_entries
[i
].vector
, adapter
);
2538 for (; i
>= 0; i
--) {
2539 /* free only the irqs that were actually requested */
2540 if (!adapter
->q_vector
[i
]->rx
.count
&&
2541 !adapter
->q_vector
[i
]->tx
.count
)
2544 free_irq(adapter
->msix_entries
[i
].vector
,
2545 adapter
->q_vector
[i
]);
2548 ixgbe_reset_q_vectors(adapter
);
2550 free_irq(adapter
->pdev
->irq
, adapter
);
2555 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2556 * @adapter: board private structure
2558 static inline void ixgbe_irq_disable(struct ixgbe_adapter
*adapter
)
2560 switch (adapter
->hw
.mac
.type
) {
2561 case ixgbe_mac_82598EB
:
2562 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
2564 case ixgbe_mac_82599EB
:
2565 case ixgbe_mac_X540
:
2566 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, 0xFFFF0000);
2567 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), ~0);
2568 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), ~0);
2569 if (adapter
->num_vfs
> 32)
2570 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, 0);
2575 IXGBE_WRITE_FLUSH(&adapter
->hw
);
2576 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
2578 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
2579 synchronize_irq(adapter
->msix_entries
[i
].vector
);
2581 synchronize_irq(adapter
->pdev
->irq
);
2586 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2589 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter
*adapter
)
2591 struct ixgbe_hw
*hw
= &adapter
->hw
;
2593 IXGBE_WRITE_REG(hw
, IXGBE_EITR(0),
2594 EITR_INTS_PER_SEC_TO_REG(adapter
->rx_eitr_param
));
2596 ixgbe_set_ivar(adapter
, 0, 0, 0);
2597 ixgbe_set_ivar(adapter
, 1, 0, 0);
2599 map_vector_to_rxq(adapter
, 0, 0);
2600 map_vector_to_txq(adapter
, 0, 0);
2602 e_info(hw
, "Legacy interrupt IVAR setup done\n");
2606 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2607 * @adapter: board private structure
2608 * @ring: structure containing ring specific data
2610 * Configure the Tx descriptor ring after a reset.
2612 void ixgbe_configure_tx_ring(struct ixgbe_adapter
*adapter
,
2613 struct ixgbe_ring
*ring
)
2615 struct ixgbe_hw
*hw
= &adapter
->hw
;
2616 u64 tdba
= ring
->dma
;
2619 u8 reg_idx
= ring
->reg_idx
;
2621 /* disable queue to avoid issues while updating state */
2622 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(reg_idx
));
2623 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
),
2624 txdctl
& ~IXGBE_TXDCTL_ENABLE
);
2625 IXGBE_WRITE_FLUSH(hw
);
2627 IXGBE_WRITE_REG(hw
, IXGBE_TDBAL(reg_idx
),
2628 (tdba
& DMA_BIT_MASK(32)));
2629 IXGBE_WRITE_REG(hw
, IXGBE_TDBAH(reg_idx
), (tdba
>> 32));
2630 IXGBE_WRITE_REG(hw
, IXGBE_TDLEN(reg_idx
),
2631 ring
->count
* sizeof(union ixgbe_adv_tx_desc
));
2632 IXGBE_WRITE_REG(hw
, IXGBE_TDH(reg_idx
), 0);
2633 IXGBE_WRITE_REG(hw
, IXGBE_TDT(reg_idx
), 0);
2634 ring
->tail
= hw
->hw_addr
+ IXGBE_TDT(reg_idx
);
2636 /* configure fetching thresholds */
2637 if (adapter
->rx_itr_setting
== 0) {
2638 /* cannot set wthresh when itr==0 */
2639 txdctl
&= ~0x007F0000;
2641 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2642 txdctl
|= (8 << 16);
2644 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
2645 /* PThresh workaround for Tx hang with DFP enabled. */
2649 /* reinitialize flowdirector state */
2650 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) &&
2651 adapter
->atr_sample_rate
) {
2652 ring
->atr_sample_rate
= adapter
->atr_sample_rate
;
2653 ring
->atr_count
= 0;
2654 set_bit(__IXGBE_TX_FDIR_INIT_DONE
, &ring
->state
);
2656 ring
->atr_sample_rate
= 0;
2659 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &ring
->state
);
2662 txdctl
|= IXGBE_TXDCTL_ENABLE
;
2663 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), txdctl
);
2665 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2666 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
2667 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
2670 /* poll to verify queue is enabled */
2672 usleep_range(1000, 2000);
2673 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(reg_idx
));
2674 } while (--wait_loop
&& !(txdctl
& IXGBE_TXDCTL_ENABLE
));
2676 e_err(drv
, "Could not enable Tx Queue %d\n", reg_idx
);
2679 static void ixgbe_setup_mtqc(struct ixgbe_adapter
*adapter
)
2681 struct ixgbe_hw
*hw
= &adapter
->hw
;
2684 u8 tcs
= netdev_get_num_tc(adapter
->netdev
);
2686 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
2689 /* disable the arbiter while setting MTQC */
2690 rttdcs
= IXGBE_READ_REG(hw
, IXGBE_RTTDCS
);
2691 rttdcs
|= IXGBE_RTTDCS_ARBDIS
;
2692 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
2694 /* set transmit pool layout */
2695 switch (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
2696 case (IXGBE_FLAG_SRIOV_ENABLED
):
2697 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
,
2698 (IXGBE_MTQC_VT_ENA
| IXGBE_MTQC_64VF
));
2702 reg
= IXGBE_MTQC_64Q_1PB
;
2704 reg
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
2706 reg
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
;
2708 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
, reg
);
2710 /* Enable Security TX Buffer IFG for multiple pb */
2712 reg
= IXGBE_READ_REG(hw
, IXGBE_SECTXMINIFG
);
2713 reg
|= IXGBE_SECTX_DCB
;
2714 IXGBE_WRITE_REG(hw
, IXGBE_SECTXMINIFG
, reg
);
2719 /* re-enable the arbiter */
2720 rttdcs
&= ~IXGBE_RTTDCS_ARBDIS
;
2721 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
2725 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
2726 * @adapter: board private structure
2728 * Configure the Tx unit of the MAC after a reset.
2730 static void ixgbe_configure_tx(struct ixgbe_adapter
*adapter
)
2732 struct ixgbe_hw
*hw
= &adapter
->hw
;
2736 ixgbe_setup_mtqc(adapter
);
2738 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
2739 /* DMATXCTL.EN must be before Tx queues are enabled */
2740 dmatxctl
= IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
);
2741 dmatxctl
|= IXGBE_DMATXCTL_TE
;
2742 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
, dmatxctl
);
2745 /* Setup the HW Tx Head and Tail descriptor pointers */
2746 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2747 ixgbe_configure_tx_ring(adapter
, adapter
->tx_ring
[i
]);
2750 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
2752 static void ixgbe_configure_srrctl(struct ixgbe_adapter
*adapter
,
2753 struct ixgbe_ring
*rx_ring
)
2756 u8 reg_idx
= rx_ring
->reg_idx
;
2758 switch (adapter
->hw
.mac
.type
) {
2759 case ixgbe_mac_82598EB
: {
2760 struct ixgbe_ring_feature
*feature
= adapter
->ring_feature
;
2761 const int mask
= feature
[RING_F_RSS
].mask
;
2762 reg_idx
= reg_idx
& mask
;
2765 case ixgbe_mac_82599EB
:
2766 case ixgbe_mac_X540
:
2771 srrctl
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SRRCTL(reg_idx
));
2773 srrctl
&= ~IXGBE_SRRCTL_BSIZEHDR_MASK
;
2774 srrctl
&= ~IXGBE_SRRCTL_BSIZEPKT_MASK
;
2775 if (adapter
->num_vfs
)
2776 srrctl
|= IXGBE_SRRCTL_DROP_EN
;
2778 srrctl
|= (IXGBE_RX_HDR_SIZE
<< IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
2779 IXGBE_SRRCTL_BSIZEHDR_MASK
;
2781 if (ring_is_ps_enabled(rx_ring
)) {
2782 #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2783 srrctl
|= IXGBE_MAX_RXBUFFER
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
2785 srrctl
|= (PAGE_SIZE
/ 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
2787 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
2789 srrctl
|= ALIGN(rx_ring
->rx_buf_len
, 1024) >>
2790 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
2791 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
2794 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
2797 static void ixgbe_setup_mrqc(struct ixgbe_adapter
*adapter
)
2799 struct ixgbe_hw
*hw
= &adapter
->hw
;
2800 static const u32 seed
[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2801 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2802 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2803 u32 mrqc
= 0, reta
= 0;
2806 u8 tcs
= netdev_get_num_tc(adapter
->netdev
);
2807 int maxq
= adapter
->ring_feature
[RING_F_RSS
].indices
;
2810 maxq
= min(maxq
, adapter
->num_tx_queues
/ tcs
);
2812 /* Fill out hash function seeds */
2813 for (i
= 0; i
< 10; i
++)
2814 IXGBE_WRITE_REG(hw
, IXGBE_RSSRK(i
), seed
[i
]);
2816 /* Fill out redirection table */
2817 for (i
= 0, j
= 0; i
< 128; i
++, j
++) {
2820 /* reta = 4-byte sliding window of
2821 * 0x00..(indices-1)(indices-1)00..etc. */
2822 reta
= (reta
<< 8) | (j
* 0x11);
2824 IXGBE_WRITE_REG(hw
, IXGBE_RETA(i
>> 2), reta
);
2827 /* Disable indicating checksum in descriptor, enables RSS hash */
2828 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
2829 rxcsum
|= IXGBE_RXCSUM_PCSD
;
2830 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
2832 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
&&
2833 (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
)) {
2834 mrqc
= IXGBE_MRQC_RSSEN
;
2836 int mask
= adapter
->flags
& (IXGBE_FLAG_RSS_ENABLED
2837 | IXGBE_FLAG_SRIOV_ENABLED
);
2840 case (IXGBE_FLAG_RSS_ENABLED
):
2842 mrqc
= IXGBE_MRQC_RSSEN
;
2844 mrqc
= IXGBE_MRQC_RTRSS4TCEN
;
2846 mrqc
= IXGBE_MRQC_RTRSS8TCEN
;
2848 case (IXGBE_FLAG_SRIOV_ENABLED
):
2849 mrqc
= IXGBE_MRQC_VMDQEN
;
2856 /* Perform hash on these packet types */
2857 mrqc
|= IXGBE_MRQC_RSS_FIELD_IPV4
2858 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2859 | IXGBE_MRQC_RSS_FIELD_IPV6
2860 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
;
2862 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
2866 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2867 * @adapter: address of board private structure
2868 * @index: index of ring to set
2870 static void ixgbe_configure_rscctl(struct ixgbe_adapter
*adapter
,
2871 struct ixgbe_ring
*ring
)
2873 struct ixgbe_hw
*hw
= &adapter
->hw
;
2876 u8 reg_idx
= ring
->reg_idx
;
2878 if (!ring_is_rsc_enabled(ring
))
2881 rx_buf_len
= ring
->rx_buf_len
;
2882 rscctrl
= IXGBE_READ_REG(hw
, IXGBE_RSCCTL(reg_idx
));
2883 rscctrl
|= IXGBE_RSCCTL_RSCEN
;
2885 * we must limit the number of descriptors so that the
2886 * total size of max desc * buf_len is not greater
2889 if (ring_is_ps_enabled(ring
)) {
2890 #if (MAX_SKB_FRAGS > 16)
2891 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2892 #elif (MAX_SKB_FRAGS > 8)
2893 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2894 #elif (MAX_SKB_FRAGS > 4)
2895 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2897 rscctrl
|= IXGBE_RSCCTL_MAXDESC_1
;
2900 if (rx_buf_len
< IXGBE_RXBUFFER_4096
)
2901 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
2902 else if (rx_buf_len
< IXGBE_RXBUFFER_8192
)
2903 rscctrl
|= IXGBE_RSCCTL_MAXDESC_8
;
2905 rscctrl
|= IXGBE_RSCCTL_MAXDESC_4
;
2907 IXGBE_WRITE_REG(hw
, IXGBE_RSCCTL(reg_idx
), rscctrl
);
2911 * ixgbe_set_uta - Set unicast filter table address
2912 * @adapter: board private structure
2914 * The unicast table address is a register array of 32-bit registers.
2915 * The table is meant to be used in a way similar to how the MTA is used
2916 * however due to certain limitations in the hardware it is necessary to
2917 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2918 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2920 static void ixgbe_set_uta(struct ixgbe_adapter
*adapter
)
2922 struct ixgbe_hw
*hw
= &adapter
->hw
;
2925 /* The UTA table only exists on 82599 hardware and newer */
2926 if (hw
->mac
.type
< ixgbe_mac_82599EB
)
2929 /* we only need to do this if VMDq is enabled */
2930 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
2933 for (i
= 0; i
< 128; i
++)
2934 IXGBE_WRITE_REG(hw
, IXGBE_UTA(i
), ~0);
2937 #define IXGBE_MAX_RX_DESC_POLL 10
2938 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter
*adapter
,
2939 struct ixgbe_ring
*ring
)
2941 struct ixgbe_hw
*hw
= &adapter
->hw
;
2942 int wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
2944 u8 reg_idx
= ring
->reg_idx
;
2946 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2947 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
2948 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
2952 usleep_range(1000, 2000);
2953 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
2954 } while (--wait_loop
&& !(rxdctl
& IXGBE_RXDCTL_ENABLE
));
2957 e_err(drv
, "RXDCTL.ENABLE on Rx queue %d not set within "
2958 "the polling period\n", reg_idx
);
2962 void ixgbe_disable_rx_queue(struct ixgbe_adapter
*adapter
,
2963 struct ixgbe_ring
*ring
)
2965 struct ixgbe_hw
*hw
= &adapter
->hw
;
2966 int wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
2968 u8 reg_idx
= ring
->reg_idx
;
2970 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
2971 rxdctl
&= ~IXGBE_RXDCTL_ENABLE
;
2973 /* write value back with RXDCTL.ENABLE bit cleared */
2974 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
2976 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
2977 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
2980 /* the hardware may take up to 100us to really disable the rx queue */
2983 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
2984 } while (--wait_loop
&& (rxdctl
& IXGBE_RXDCTL_ENABLE
));
2987 e_err(drv
, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2988 "the polling period\n", reg_idx
);
2992 void ixgbe_configure_rx_ring(struct ixgbe_adapter
*adapter
,
2993 struct ixgbe_ring
*ring
)
2995 struct ixgbe_hw
*hw
= &adapter
->hw
;
2996 u64 rdba
= ring
->dma
;
2998 u8 reg_idx
= ring
->reg_idx
;
3000 /* disable queue to avoid issues while updating state */
3001 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
3002 ixgbe_disable_rx_queue(adapter
, ring
);
3004 IXGBE_WRITE_REG(hw
, IXGBE_RDBAL(reg_idx
), (rdba
& DMA_BIT_MASK(32)));
3005 IXGBE_WRITE_REG(hw
, IXGBE_RDBAH(reg_idx
), (rdba
>> 32));
3006 IXGBE_WRITE_REG(hw
, IXGBE_RDLEN(reg_idx
),
3007 ring
->count
* sizeof(union ixgbe_adv_rx_desc
));
3008 IXGBE_WRITE_REG(hw
, IXGBE_RDH(reg_idx
), 0);
3009 IXGBE_WRITE_REG(hw
, IXGBE_RDT(reg_idx
), 0);
3010 ring
->tail
= hw
->hw_addr
+ IXGBE_RDT(reg_idx
);
3012 ixgbe_configure_srrctl(adapter
, ring
);
3013 ixgbe_configure_rscctl(adapter
, ring
);
3015 /* If operating in IOV mode set RLPML for X540 */
3016 if ((adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) &&
3017 hw
->mac
.type
== ixgbe_mac_X540
) {
3018 rxdctl
&= ~IXGBE_RXDCTL_RLPMLMASK
;
3019 rxdctl
|= ((ring
->netdev
->mtu
+ ETH_HLEN
+
3020 ETH_FCS_LEN
+ VLAN_HLEN
) | IXGBE_RXDCTL_RLPML_EN
);
3023 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
3025 * enable cache line friendly hardware writes:
3026 * PTHRESH=32 descriptors (half the internal cache),
3027 * this also removes ugly rx_no_buffer_count increment
3028 * HTHRESH=4 descriptors (to minimize latency on fetch)
3029 * WTHRESH=8 burst writeback up to two cache lines
3031 rxdctl
&= ~0x3FFFFF;
3035 /* enable receive descriptor ring */
3036 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
3037 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
3039 ixgbe_rx_desc_queue_enable(adapter
, ring
);
3040 ixgbe_alloc_rx_buffers(ring
, ixgbe_desc_unused(ring
));
3043 static void ixgbe_setup_psrtype(struct ixgbe_adapter
*adapter
)
3045 struct ixgbe_hw
*hw
= &adapter
->hw
;
3048 /* PSRTYPE must be initialized in non 82598 adapters */
3049 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
3050 IXGBE_PSRTYPE_UDPHDR
|
3051 IXGBE_PSRTYPE_IPV4HDR
|
3052 IXGBE_PSRTYPE_L2HDR
|
3053 IXGBE_PSRTYPE_IPV6HDR
;
3055 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3058 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
)
3059 psrtype
|= (adapter
->num_rx_queues_per_pool
<< 29);
3061 for (p
= 0; p
< adapter
->num_rx_pools
; p
++)
3062 IXGBE_WRITE_REG(hw
, IXGBE_PSRTYPE(adapter
->num_vfs
+ p
),
3066 static void ixgbe_configure_virtualization(struct ixgbe_adapter
*adapter
)
3068 struct ixgbe_hw
*hw
= &adapter
->hw
;
3071 u32 reg_offset
, vf_shift
;
3074 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
3077 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VT_CTL
);
3078 vt_reg_bits
= IXGBE_VMD_CTL_VMDQ_EN
| IXGBE_VT_CTL_REPLEN
;
3079 vt_reg_bits
|= (adapter
->num_vfs
<< IXGBE_VT_CTL_POOL_SHIFT
);
3080 IXGBE_WRITE_REG(hw
, IXGBE_VT_CTL
, vmdctl
| vt_reg_bits
);
3082 vf_shift
= adapter
->num_vfs
% 32;
3083 reg_offset
= (adapter
->num_vfs
> 32) ? 1 : 0;
3085 /* Enable only the PF's pool for Tx/Rx */
3086 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
), (1 << vf_shift
));
3087 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
^ 1), 0);
3088 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
), (1 << vf_shift
));
3089 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
^ 1), 0);
3090 IXGBE_WRITE_REG(hw
, IXGBE_PFDTXGSWC
, IXGBE_PFDTXGSWC_VT_LBEN
);
3092 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3093 hw
->mac
.ops
.set_vmdq(hw
, 0, adapter
->num_vfs
);
3096 * Set up VF register offsets for selected VT Mode,
3097 * i.e. 32 or 64 VFs for SR-IOV
3099 gcr_ext
= IXGBE_READ_REG(hw
, IXGBE_GCR_EXT
);
3100 gcr_ext
|= IXGBE_GCR_EXT_MSIX_EN
;
3101 gcr_ext
|= IXGBE_GCR_EXT_VT_MODE_64
;
3102 IXGBE_WRITE_REG(hw
, IXGBE_GCR_EXT
, gcr_ext
);
3104 /* enable Tx loopback for VF/PF communication */
3105 IXGBE_WRITE_REG(hw
, IXGBE_PFDTXGSWC
, IXGBE_PFDTXGSWC_VT_LBEN
);
3106 /* Enable MAC Anti-Spoofing */
3107 hw
->mac
.ops
.set_mac_anti_spoofing(hw
,
3108 (adapter
->antispoofing_enabled
=
3109 (adapter
->num_vfs
!= 0)),
3113 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter
*adapter
)
3115 struct ixgbe_hw
*hw
= &adapter
->hw
;
3116 struct net_device
*netdev
= adapter
->netdev
;
3117 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3119 struct ixgbe_ring
*rx_ring
;
3123 /* Decide whether to use packet split mode or not */
3125 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
3127 /* Do not use packet split if we're in SR-IOV Mode */
3128 if (adapter
->num_vfs
)
3129 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
3131 /* Disable packet split due to 82599 erratum #45 */
3132 if (hw
->mac
.type
== ixgbe_mac_82599EB
)
3133 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
3135 /* Set the RX buffer length according to the mode */
3136 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
3137 rx_buf_len
= IXGBE_RX_HDR_SIZE
;
3139 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) &&
3140 (netdev
->mtu
<= ETH_DATA_LEN
))
3141 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3143 rx_buf_len
= ALIGN(max_frame
+ VLAN_HLEN
, 1024);
3147 /* adjust max frame to be able to do baby jumbo for FCoE */
3148 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
3149 (max_frame
< IXGBE_FCOE_JUMBO_FRAME_SIZE
))
3150 max_frame
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
3152 #endif /* IXGBE_FCOE */
3153 mhadd
= IXGBE_READ_REG(hw
, IXGBE_MHADD
);
3154 if (max_frame
!= (mhadd
>> IXGBE_MHADD_MFS_SHIFT
)) {
3155 mhadd
&= ~IXGBE_MHADD_MFS_MASK
;
3156 mhadd
|= max_frame
<< IXGBE_MHADD_MFS_SHIFT
;
3158 IXGBE_WRITE_REG(hw
, IXGBE_MHADD
, mhadd
);
3161 hlreg0
= IXGBE_READ_REG(hw
, IXGBE_HLREG0
);
3162 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3163 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
3164 IXGBE_WRITE_REG(hw
, IXGBE_HLREG0
, hlreg0
);
3167 * Setup the HW Rx Head and Tail Descriptor Pointers and
3168 * the Base and Length of the Rx Descriptor Ring
3170 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3171 rx_ring
= adapter
->rx_ring
[i
];
3172 rx_ring
->rx_buf_len
= rx_buf_len
;
3174 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)
3175 set_ring_ps_enabled(rx_ring
);
3177 clear_ring_ps_enabled(rx_ring
);
3179 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
3180 set_ring_rsc_enabled(rx_ring
);
3182 clear_ring_rsc_enabled(rx_ring
);
3185 if (netdev
->features
& NETIF_F_FCOE_MTU
) {
3186 struct ixgbe_ring_feature
*f
;
3187 f
= &adapter
->ring_feature
[RING_F_FCOE
];
3188 if ((i
>= f
->mask
) && (i
< f
->mask
+ f
->indices
)) {
3189 clear_ring_ps_enabled(rx_ring
);
3190 if (rx_buf_len
< IXGBE_FCOE_JUMBO_FRAME_SIZE
)
3191 rx_ring
->rx_buf_len
=
3192 IXGBE_FCOE_JUMBO_FRAME_SIZE
;
3193 } else if (!ring_is_rsc_enabled(rx_ring
) &&
3194 !ring_is_ps_enabled(rx_ring
)) {
3195 rx_ring
->rx_buf_len
=
3196 IXGBE_FCOE_JUMBO_FRAME_SIZE
;
3199 #endif /* IXGBE_FCOE */
3203 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter
*adapter
)
3205 struct ixgbe_hw
*hw
= &adapter
->hw
;
3206 u32 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
3208 switch (hw
->mac
.type
) {
3209 case ixgbe_mac_82598EB
:
3211 * For VMDq support of different descriptor types or
3212 * buffer sizes through the use of multiple SRRCTL
3213 * registers, RDRXCTL.MVMEN must be set to 1
3215 * also, the manual doesn't mention it clearly but DCA hints
3216 * will only use queue 0's tags unless this bit is set. Side
3217 * effects of setting this bit are only that SRRCTL must be
3218 * fully programmed [0..15]
3220 rdrxctl
|= IXGBE_RDRXCTL_MVMEN
;
3222 case ixgbe_mac_82599EB
:
3223 case ixgbe_mac_X540
:
3224 /* Disable RSC for ACK packets */
3225 IXGBE_WRITE_REG(hw
, IXGBE_RSCDBU
,
3226 (IXGBE_RSCDBU_RSCACKDIS
| IXGBE_READ_REG(hw
, IXGBE_RSCDBU
)));
3227 rdrxctl
&= ~IXGBE_RDRXCTL_RSCFRSTSIZE
;
3228 /* hardware requires some bits to be set by default */
3229 rdrxctl
|= (IXGBE_RDRXCTL_RSCACKC
| IXGBE_RDRXCTL_FCOE_WRFIX
);
3230 rdrxctl
|= IXGBE_RDRXCTL_CRCSTRIP
;
3233 /* We should do nothing since we don't know this hardware */
3237 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
3241 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3242 * @adapter: board private structure
3244 * Configure the Rx unit of the MAC after a reset.
3246 static void ixgbe_configure_rx(struct ixgbe_adapter
*adapter
)
3248 struct ixgbe_hw
*hw
= &adapter
->hw
;
3252 /* disable receives while setting up the descriptors */
3253 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
3254 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
3256 ixgbe_setup_psrtype(adapter
);
3257 ixgbe_setup_rdrxctl(adapter
);
3259 /* Program registers for the distribution of queues */
3260 ixgbe_setup_mrqc(adapter
);
3262 ixgbe_set_uta(adapter
);
3264 /* set_rx_buffer_len must be called before ring initialization */
3265 ixgbe_set_rx_buffer_len(adapter
);
3268 * Setup the HW Rx Head and Tail Descriptor Pointers and
3269 * the Base and Length of the Rx Descriptor Ring
3271 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3272 ixgbe_configure_rx_ring(adapter
, adapter
->rx_ring
[i
]);
3274 /* disable drop enable for 82598 parts */
3275 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3276 rxctrl
|= IXGBE_RXCTRL_DMBYPS
;
3278 /* enable all receives */
3279 rxctrl
|= IXGBE_RXCTRL_RXEN
;
3280 hw
->mac
.ops
.enable_rx_dma(hw
, rxctrl
);
3283 static void ixgbe_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
3285 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3286 struct ixgbe_hw
*hw
= &adapter
->hw
;
3287 int pool_ndx
= adapter
->num_vfs
;
3289 /* add VID to filter table */
3290 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, pool_ndx
, true);
3291 set_bit(vid
, adapter
->active_vlans
);
3294 static void ixgbe_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
3296 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3297 struct ixgbe_hw
*hw
= &adapter
->hw
;
3298 int pool_ndx
= adapter
->num_vfs
;
3300 /* remove VID from filter table */
3301 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, pool_ndx
, false);
3302 clear_bit(vid
, adapter
->active_vlans
);
3306 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3307 * @adapter: driver data
3309 static void ixgbe_vlan_filter_disable(struct ixgbe_adapter
*adapter
)
3311 struct ixgbe_hw
*hw
= &adapter
->hw
;
3314 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
3315 vlnctrl
&= ~(IXGBE_VLNCTRL_VFE
| IXGBE_VLNCTRL_CFIEN
);
3316 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
3320 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3321 * @adapter: driver data
3323 static void ixgbe_vlan_filter_enable(struct ixgbe_adapter
*adapter
)
3325 struct ixgbe_hw
*hw
= &adapter
->hw
;
3328 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
3329 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
3330 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
3331 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
3335 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3336 * @adapter: driver data
3338 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter
*adapter
)
3340 struct ixgbe_hw
*hw
= &adapter
->hw
;
3344 switch (hw
->mac
.type
) {
3345 case ixgbe_mac_82598EB
:
3346 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
3347 vlnctrl
&= ~IXGBE_VLNCTRL_VME
;
3348 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
3350 case ixgbe_mac_82599EB
:
3351 case ixgbe_mac_X540
:
3352 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3353 j
= adapter
->rx_ring
[i
]->reg_idx
;
3354 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
3355 vlnctrl
&= ~IXGBE_RXDCTL_VME
;
3356 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
3365 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
3366 * @adapter: driver data
3368 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter
*adapter
)
3370 struct ixgbe_hw
*hw
= &adapter
->hw
;
3374 switch (hw
->mac
.type
) {
3375 case ixgbe_mac_82598EB
:
3376 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
3377 vlnctrl
|= IXGBE_VLNCTRL_VME
;
3378 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
3380 case ixgbe_mac_82599EB
:
3381 case ixgbe_mac_X540
:
3382 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3383 j
= adapter
->rx_ring
[i
]->reg_idx
;
3384 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
3385 vlnctrl
|= IXGBE_RXDCTL_VME
;
3386 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
3394 static void ixgbe_restore_vlan(struct ixgbe_adapter
*adapter
)
3398 ixgbe_vlan_rx_add_vid(adapter
->netdev
, 0);
3400 for_each_set_bit(vid
, adapter
->active_vlans
, VLAN_N_VID
)
3401 ixgbe_vlan_rx_add_vid(adapter
->netdev
, vid
);
3405 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3406 * @netdev: network interface device structure
3408 * Writes unicast address list to the RAR table.
3409 * Returns: -ENOMEM on failure/insufficient address space
3410 * 0 on no addresses written
3411 * X on writing X addresses to the RAR table
3413 static int ixgbe_write_uc_addr_list(struct net_device
*netdev
)
3415 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3416 struct ixgbe_hw
*hw
= &adapter
->hw
;
3417 unsigned int vfn
= adapter
->num_vfs
;
3418 unsigned int rar_entries
= IXGBE_MAX_PF_MACVLANS
;
3421 /* return ENOMEM indicating insufficient memory for addresses */
3422 if (netdev_uc_count(netdev
) > rar_entries
)
3425 if (!netdev_uc_empty(netdev
) && rar_entries
) {
3426 struct netdev_hw_addr
*ha
;
3427 /* return error if we do not support writing to RAR table */
3428 if (!hw
->mac
.ops
.set_rar
)
3431 netdev_for_each_uc_addr(ha
, netdev
) {
3434 hw
->mac
.ops
.set_rar(hw
, rar_entries
--, ha
->addr
,
3439 /* write the addresses in reverse order to avoid write combining */
3440 for (; rar_entries
> 0 ; rar_entries
--)
3441 hw
->mac
.ops
.clear_rar(hw
, rar_entries
);
3447 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
3448 * @netdev: network interface device structure
3450 * The set_rx_method entry point is called whenever the unicast/multicast
3451 * address list or the network interface flags are updated. This routine is
3452 * responsible for configuring the hardware for proper unicast, multicast and
3455 void ixgbe_set_rx_mode(struct net_device
*netdev
)
3457 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3458 struct ixgbe_hw
*hw
= &adapter
->hw
;
3459 u32 fctrl
, vmolr
= IXGBE_VMOLR_BAM
| IXGBE_VMOLR_AUPE
;
3462 /* Check for Promiscuous and All Multicast modes */
3464 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
3466 /* set all bits that we expect to always be set */
3467 fctrl
|= IXGBE_FCTRL_BAM
;
3468 fctrl
|= IXGBE_FCTRL_DPF
; /* discard pause frames when FC enabled */
3469 fctrl
|= IXGBE_FCTRL_PMCF
;
3471 /* clear the bits we are changing the status of */
3472 fctrl
&= ~(IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
3474 if (netdev
->flags
& IFF_PROMISC
) {
3475 hw
->addr_ctrl
.user_set_promisc
= true;
3476 fctrl
|= (IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
3477 vmolr
|= (IXGBE_VMOLR_ROPE
| IXGBE_VMOLR_MPE
);
3478 /* don't hardware filter vlans in promisc mode */
3479 ixgbe_vlan_filter_disable(adapter
);
3481 if (netdev
->flags
& IFF_ALLMULTI
) {
3482 fctrl
|= IXGBE_FCTRL_MPE
;
3483 vmolr
|= IXGBE_VMOLR_MPE
;
3486 * Write addresses to the MTA, if the attempt fails
3487 * then we should just turn on promiscuous mode so
3488 * that we can at least receive multicast traffic
3490 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
3491 vmolr
|= IXGBE_VMOLR_ROMPE
;
3493 ixgbe_vlan_filter_enable(adapter
);
3494 hw
->addr_ctrl
.user_set_promisc
= false;
3496 * Write addresses to available RAR registers, if there is not
3497 * sufficient space to store all the addresses then enable
3498 * unicast promiscuous mode
3500 count
= ixgbe_write_uc_addr_list(netdev
);
3502 fctrl
|= IXGBE_FCTRL_UPE
;
3503 vmolr
|= IXGBE_VMOLR_ROPE
;
3507 if (adapter
->num_vfs
) {
3508 ixgbe_restore_vf_multicasts(adapter
);
3509 vmolr
|= IXGBE_READ_REG(hw
, IXGBE_VMOLR(adapter
->num_vfs
)) &
3510 ~(IXGBE_VMOLR_MPE
| IXGBE_VMOLR_ROMPE
|
3512 IXGBE_WRITE_REG(hw
, IXGBE_VMOLR(adapter
->num_vfs
), vmolr
);
3515 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
3517 if (netdev
->features
& NETIF_F_HW_VLAN_RX
)
3518 ixgbe_vlan_strip_enable(adapter
);
3520 ixgbe_vlan_strip_disable(adapter
);
3523 static void ixgbe_napi_enable_all(struct ixgbe_adapter
*adapter
)
3526 struct ixgbe_q_vector
*q_vector
;
3527 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
3529 /* legacy and MSI only use one vector */
3530 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
3533 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
3534 struct napi_struct
*napi
;
3535 q_vector
= adapter
->q_vector
[q_idx
];
3536 napi
= &q_vector
->napi
;
3537 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3538 if (!q_vector
->rx
.count
|| !q_vector
->tx
.count
) {
3539 if (q_vector
->tx
.count
== 1)
3540 napi
->poll
= &ixgbe_clean_txonly
;
3541 else if (q_vector
->rx
.count
== 1)
3542 napi
->poll
= &ixgbe_clean_rxonly
;
3550 static void ixgbe_napi_disable_all(struct ixgbe_adapter
*adapter
)
3553 struct ixgbe_q_vector
*q_vector
;
3554 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
3556 /* legacy and MSI only use one vector */
3557 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
))
3560 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
3561 q_vector
= adapter
->q_vector
[q_idx
];
3562 napi_disable(&q_vector
->napi
);
3566 #ifdef CONFIG_IXGBE_DCB
3568 * ixgbe_configure_dcb - Configure DCB hardware
3569 * @adapter: ixgbe adapter struct
3571 * This is called by the driver on open to configure the DCB hardware.
3572 * This is also called by the gennetlink interface when reconfiguring
3575 static void ixgbe_configure_dcb(struct ixgbe_adapter
*adapter
)
3577 struct ixgbe_hw
*hw
= &adapter
->hw
;
3578 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3580 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)) {
3581 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3582 netif_set_gso_max_size(adapter
->netdev
, 65536);
3586 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3587 netif_set_gso_max_size(adapter
->netdev
, 32768);
3590 /* Enable VLAN tag insert/strip */
3591 adapter
->netdev
->features
|= NETIF_F_HW_VLAN_RX
;
3593 hw
->mac
.ops
.set_vfta(&adapter
->hw
, 0, 0, true);
3595 /* reconfigure the hardware */
3596 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
) {
3598 if (adapter
->netdev
->features
& NETIF_F_FCOE_MTU
)
3599 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
3601 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
3603 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
3605 ixgbe_dcb_hw_config(hw
, &adapter
->dcb_cfg
);
3607 struct net_device
*dev
= adapter
->netdev
;
3609 if (adapter
->ixgbe_ieee_ets
)
3610 dev
->dcbnl_ops
->ieee_setets(dev
,
3611 adapter
->ixgbe_ieee_ets
);
3612 if (adapter
->ixgbe_ieee_pfc
)
3613 dev
->dcbnl_ops
->ieee_setpfc(dev
,
3614 adapter
->ixgbe_ieee_pfc
);
3617 /* Enable RSS Hash per TC */
3618 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
3622 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
3624 u8 cnt
= adapter
->netdev
->tc_to_txq
[i
].count
;
3629 reg
|= msb
<< IXGBE_RQTC_SHIFT_TC(i
);
3631 IXGBE_WRITE_REG(hw
, IXGBE_RQTC
, reg
);
3637 static void ixgbe_configure_pb(struct ixgbe_adapter
*adapter
)
3640 int num_tc
= netdev_get_num_tc(adapter
->netdev
);
3641 struct ixgbe_hw
*hw
= &adapter
->hw
;
3643 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
3644 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
3645 hdrm
= 64 << adapter
->fdir_pballoc
;
3647 hw
->mac
.ops
.set_rxpba(&adapter
->hw
, num_tc
, hdrm
, PBA_STRATEGY_EQUAL
);
3650 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter
*adapter
)
3652 struct ixgbe_hw
*hw
= &adapter
->hw
;
3653 struct hlist_node
*node
, *node2
;
3654 struct ixgbe_fdir_filter
*filter
;
3656 spin_lock(&adapter
->fdir_perfect_lock
);
3658 if (!hlist_empty(&adapter
->fdir_filter_list
))
3659 ixgbe_fdir_set_input_mask_82599(hw
, &adapter
->fdir_mask
);
3661 hlist_for_each_entry_safe(filter
, node
, node2
,
3662 &adapter
->fdir_filter_list
, fdir_node
) {
3663 ixgbe_fdir_write_perfect_filter_82599(hw
,
3666 (filter
->action
== IXGBE_FDIR_DROP_QUEUE
) ?
3667 IXGBE_FDIR_DROP_QUEUE
:
3668 adapter
->rx_ring
[filter
->action
]->reg_idx
);
3671 spin_unlock(&adapter
->fdir_perfect_lock
);
3674 static void ixgbe_configure(struct ixgbe_adapter
*adapter
)
3676 struct net_device
*netdev
= adapter
->netdev
;
3677 struct ixgbe_hw
*hw
= &adapter
->hw
;
3680 ixgbe_configure_pb(adapter
);
3681 #ifdef CONFIG_IXGBE_DCB
3682 ixgbe_configure_dcb(adapter
);
3685 ixgbe_set_rx_mode(netdev
);
3686 ixgbe_restore_vlan(adapter
);
3689 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
3690 ixgbe_configure_fcoe(adapter
);
3692 #endif /* IXGBE_FCOE */
3693 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
3694 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3695 adapter
->tx_ring
[i
]->atr_sample_rate
=
3696 adapter
->atr_sample_rate
;
3697 ixgbe_init_fdir_signature_82599(hw
, adapter
->fdir_pballoc
);
3698 } else if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
) {
3699 ixgbe_init_fdir_perfect_82599(&adapter
->hw
,
3700 adapter
->fdir_pballoc
);
3701 ixgbe_fdir_filter_restore(adapter
);
3703 ixgbe_configure_virtualization(adapter
);
3705 ixgbe_configure_tx(adapter
);
3706 ixgbe_configure_rx(adapter
);
3709 static inline bool ixgbe_is_sfp(struct ixgbe_hw
*hw
)
3711 switch (hw
->phy
.type
) {
3712 case ixgbe_phy_sfp_avago
:
3713 case ixgbe_phy_sfp_ftl
:
3714 case ixgbe_phy_sfp_intel
:
3715 case ixgbe_phy_sfp_unknown
:
3716 case ixgbe_phy_sfp_passive_tyco
:
3717 case ixgbe_phy_sfp_passive_unknown
:
3718 case ixgbe_phy_sfp_active_unknown
:
3719 case ixgbe_phy_sfp_ftl_active
:
3727 * ixgbe_sfp_link_config - set up SFP+ link
3728 * @adapter: pointer to private adapter struct
3730 static void ixgbe_sfp_link_config(struct ixgbe_adapter
*adapter
)
3733 * We are assuming the worst case scenerio here, and that
3734 * is that an SFP was inserted/removed after the reset
3735 * but before SFP detection was enabled. As such the best
3736 * solution is to just start searching as soon as we start
3738 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
3739 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
3741 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
3745 * ixgbe_non_sfp_link_config - set up non-SFP+ link
3746 * @hw: pointer to private hardware struct
3748 * Returns 0 on success, negative on failure
3750 static int ixgbe_non_sfp_link_config(struct ixgbe_hw
*hw
)
3753 bool negotiation
, link_up
= false;
3754 u32 ret
= IXGBE_ERR_LINK_SETUP
;
3756 if (hw
->mac
.ops
.check_link
)
3757 ret
= hw
->mac
.ops
.check_link(hw
, &autoneg
, &link_up
, false);
3762 autoneg
= hw
->phy
.autoneg_advertised
;
3763 if ((!autoneg
) && (hw
->mac
.ops
.get_link_capabilities
))
3764 ret
= hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
,
3769 if (hw
->mac
.ops
.setup_link
)
3770 ret
= hw
->mac
.ops
.setup_link(hw
, autoneg
, negotiation
, link_up
);
3775 static void ixgbe_setup_gpie(struct ixgbe_adapter
*adapter
)
3777 struct ixgbe_hw
*hw
= &adapter
->hw
;
3780 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3781 gpie
= IXGBE_GPIE_MSIX_MODE
| IXGBE_GPIE_PBA_SUPPORT
|
3783 gpie
|= IXGBE_GPIE_EIAME
;
3785 * use EIAM to auto-mask when MSI-X interrupt is asserted
3786 * this saves a register write for every interrupt
3788 switch (hw
->mac
.type
) {
3789 case ixgbe_mac_82598EB
:
3790 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
3792 case ixgbe_mac_82599EB
:
3793 case ixgbe_mac_X540
:
3795 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3796 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3800 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3801 * specifically only auto mask tx and rx interrupts */
3802 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
3805 /* XXX: to interrupt immediately for EICS writes, enable this */
3806 /* gpie |= IXGBE_GPIE_EIMEN; */
3808 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
3809 gpie
&= ~IXGBE_GPIE_VTMODE_MASK
;
3810 gpie
|= IXGBE_GPIE_VTMODE_64
;
3813 /* Enable fan failure interrupt */
3814 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
3815 gpie
|= IXGBE_SDP1_GPIEN
;
3817 if (hw
->mac
.type
== ixgbe_mac_82599EB
) {
3818 gpie
|= IXGBE_SDP1_GPIEN
;
3819 gpie
|= IXGBE_SDP2_GPIEN
;
3822 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
3825 static int ixgbe_up_complete(struct ixgbe_adapter
*adapter
)
3827 struct ixgbe_hw
*hw
= &adapter
->hw
;
3831 ixgbe_get_hw_control(adapter
);
3832 ixgbe_setup_gpie(adapter
);
3834 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3835 ixgbe_configure_msix(adapter
);
3837 ixgbe_configure_msi_and_legacy(adapter
);
3839 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3840 if (hw
->mac
.ops
.enable_tx_laser
&&
3841 ((hw
->phy
.multispeed_fiber
) ||
3842 ((hw
->mac
.ops
.get_media_type(hw
) == ixgbe_media_type_fiber
) &&
3843 (hw
->mac
.type
== ixgbe_mac_82599EB
))))
3844 hw
->mac
.ops
.enable_tx_laser(hw
);
3846 clear_bit(__IXGBE_DOWN
, &adapter
->state
);
3847 ixgbe_napi_enable_all(adapter
);
3849 if (ixgbe_is_sfp(hw
)) {
3850 ixgbe_sfp_link_config(adapter
);
3852 err
= ixgbe_non_sfp_link_config(hw
);
3854 e_err(probe
, "link_config FAILED %d\n", err
);
3857 /* clear any pending interrupts, may auto mask */
3858 IXGBE_READ_REG(hw
, IXGBE_EICR
);
3859 ixgbe_irq_enable(adapter
, true, true);
3862 * If this adapter has a fan, check to see if we had a failure
3863 * before we enabled the interrupt.
3865 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
3866 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
3867 if (esdp
& IXGBE_ESDP_SDP1
)
3868 e_crit(drv
, "Fan has stopped, replace the adapter\n");
3871 /* enable transmits */
3872 netif_tx_start_all_queues(adapter
->netdev
);
3874 /* bring the link up in the watchdog, this could race with our first
3875 * link up interrupt but shouldn't be a problem */
3876 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
3877 adapter
->link_check_timeout
= jiffies
;
3878 mod_timer(&adapter
->service_timer
, jiffies
);
3880 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3881 ctrl_ext
= IXGBE_READ_REG(hw
, IXGBE_CTRL_EXT
);
3882 ctrl_ext
|= IXGBE_CTRL_EXT_PFRSTD
;
3883 IXGBE_WRITE_REG(hw
, IXGBE_CTRL_EXT
, ctrl_ext
);
3888 void ixgbe_reinit_locked(struct ixgbe_adapter
*adapter
)
3890 WARN_ON(in_interrupt());
3891 /* put off any impending NetWatchDogTimeout */
3892 adapter
->netdev
->trans_start
= jiffies
;
3894 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
3895 usleep_range(1000, 2000);
3896 ixgbe_down(adapter
);
3898 * If SR-IOV enabled then wait a bit before bringing the adapter
3899 * back up to give the VFs time to respond to the reset. The
3900 * two second wait is based upon the watchdog timer cycle in
3903 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
3906 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
3909 int ixgbe_up(struct ixgbe_adapter
*adapter
)
3911 /* hardware has been reset, we need to reload some things */
3912 ixgbe_configure(adapter
);
3914 return ixgbe_up_complete(adapter
);
3917 void ixgbe_reset(struct ixgbe_adapter
*adapter
)
3919 struct ixgbe_hw
*hw
= &adapter
->hw
;
3922 /* lock SFP init bit to prevent race conditions with the watchdog */
3923 while (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
3924 usleep_range(1000, 2000);
3926 /* clear all SFP and link config related flags while holding SFP_INIT */
3927 adapter
->flags2
&= ~(IXGBE_FLAG2_SEARCH_FOR_SFP
|
3928 IXGBE_FLAG2_SFP_NEEDS_RESET
);
3929 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
3931 err
= hw
->mac
.ops
.init_hw(hw
);
3934 case IXGBE_ERR_SFP_NOT_PRESENT
:
3935 case IXGBE_ERR_SFP_NOT_SUPPORTED
:
3937 case IXGBE_ERR_MASTER_REQUESTS_PENDING
:
3938 e_dev_err("master disable timed out\n");
3940 case IXGBE_ERR_EEPROM_VERSION
:
3941 /* We are running on a pre-production device, log a warning */
3942 e_dev_warn("This device is a pre-production adapter/LOM. "
3943 "Please be aware there may be issuesassociated with "
3944 "your hardware. If you are experiencing problems "
3945 "please contact your Intel or hardware "
3946 "representative who provided you with this "
3950 e_dev_err("Hardware Error: %d\n", err
);
3953 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
3955 /* reprogram the RAR[0] in case user changed it. */
3956 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, adapter
->num_vfs
,
3961 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
3962 * @rx_ring: ring to free buffers from
3964 static void ixgbe_clean_rx_ring(struct ixgbe_ring
*rx_ring
)
3966 struct device
*dev
= rx_ring
->dev
;
3970 /* ring already cleared, nothing to do */
3971 if (!rx_ring
->rx_buffer_info
)
3974 /* Free all the Rx ring sk_buffs */
3975 for (i
= 0; i
< rx_ring
->count
; i
++) {
3976 struct ixgbe_rx_buffer
*rx_buffer_info
;
3978 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
3979 if (rx_buffer_info
->dma
) {
3980 dma_unmap_single(rx_ring
->dev
, rx_buffer_info
->dma
,
3981 rx_ring
->rx_buf_len
,
3983 rx_buffer_info
->dma
= 0;
3985 if (rx_buffer_info
->skb
) {
3986 struct sk_buff
*skb
= rx_buffer_info
->skb
;
3987 rx_buffer_info
->skb
= NULL
;
3989 struct sk_buff
*this = skb
;
3990 if (IXGBE_RSC_CB(this)->delay_unmap
) {
3991 dma_unmap_single(dev
,
3992 IXGBE_RSC_CB(this)->dma
,
3993 rx_ring
->rx_buf_len
,
3995 IXGBE_RSC_CB(this)->dma
= 0;
3996 IXGBE_RSC_CB(skb
)->delay_unmap
= false;
3999 dev_kfree_skb(this);
4002 if (!rx_buffer_info
->page
)
4004 if (rx_buffer_info
->page_dma
) {
4005 dma_unmap_page(dev
, rx_buffer_info
->page_dma
,
4006 PAGE_SIZE
/ 2, DMA_FROM_DEVICE
);
4007 rx_buffer_info
->page_dma
= 0;
4009 put_page(rx_buffer_info
->page
);
4010 rx_buffer_info
->page
= NULL
;
4011 rx_buffer_info
->page_offset
= 0;
4014 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
4015 memset(rx_ring
->rx_buffer_info
, 0, size
);
4017 /* Zero out the descriptor ring */
4018 memset(rx_ring
->desc
, 0, rx_ring
->size
);
4020 rx_ring
->next_to_clean
= 0;
4021 rx_ring
->next_to_use
= 0;
4025 * ixgbe_clean_tx_ring - Free Tx Buffers
4026 * @tx_ring: ring to be cleaned
4028 static void ixgbe_clean_tx_ring(struct ixgbe_ring
*tx_ring
)
4030 struct ixgbe_tx_buffer
*tx_buffer_info
;
4034 /* ring already cleared, nothing to do */
4035 if (!tx_ring
->tx_buffer_info
)
4038 /* Free all the Tx ring sk_buffs */
4039 for (i
= 0; i
< tx_ring
->count
; i
++) {
4040 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
4041 ixgbe_unmap_and_free_tx_resource(tx_ring
, tx_buffer_info
);
4044 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
4045 memset(tx_ring
->tx_buffer_info
, 0, size
);
4047 /* Zero out the descriptor ring */
4048 memset(tx_ring
->desc
, 0, tx_ring
->size
);
4050 tx_ring
->next_to_use
= 0;
4051 tx_ring
->next_to_clean
= 0;
4055 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4056 * @adapter: board private structure
4058 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter
*adapter
)
4062 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4063 ixgbe_clean_rx_ring(adapter
->rx_ring
[i
]);
4067 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4068 * @adapter: board private structure
4070 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter
*adapter
)
4074 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4075 ixgbe_clean_tx_ring(adapter
->tx_ring
[i
]);
4078 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter
*adapter
)
4080 struct hlist_node
*node
, *node2
;
4081 struct ixgbe_fdir_filter
*filter
;
4083 spin_lock(&adapter
->fdir_perfect_lock
);
4085 hlist_for_each_entry_safe(filter
, node
, node2
,
4086 &adapter
->fdir_filter_list
, fdir_node
) {
4087 hlist_del(&filter
->fdir_node
);
4090 adapter
->fdir_filter_count
= 0;
4092 spin_unlock(&adapter
->fdir_perfect_lock
);
4095 void ixgbe_down(struct ixgbe_adapter
*adapter
)
4097 struct net_device
*netdev
= adapter
->netdev
;
4098 struct ixgbe_hw
*hw
= &adapter
->hw
;
4101 int num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
4103 /* signal that we are down to the interrupt handler */
4104 set_bit(__IXGBE_DOWN
, &adapter
->state
);
4106 /* disable receives */
4107 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
4108 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, rxctrl
& ~IXGBE_RXCTRL_RXEN
);
4110 /* disable all enabled rx queues */
4111 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4112 /* this call also flushes the previous write */
4113 ixgbe_disable_rx_queue(adapter
, adapter
->rx_ring
[i
]);
4115 usleep_range(10000, 20000);
4117 netif_tx_stop_all_queues(netdev
);
4119 /* call carrier off first to avoid false dev_watchdog timeouts */
4120 netif_carrier_off(netdev
);
4121 netif_tx_disable(netdev
);
4123 ixgbe_irq_disable(adapter
);
4125 ixgbe_napi_disable_all(adapter
);
4127 adapter
->flags2
&= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT
|
4128 IXGBE_FLAG2_RESET_REQUESTED
);
4129 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
4131 del_timer_sync(&adapter
->service_timer
);
4133 /* disable receive for all VFs and wait one second */
4134 if (adapter
->num_vfs
) {
4135 /* ping all the active vfs to let them know we are going down */
4136 ixgbe_ping_all_vfs(adapter
);
4138 /* Disable all VFTE/VFRE TX/RX */
4139 ixgbe_disable_tx_rx(adapter
);
4141 /* Mark all the VFs as inactive */
4142 for (i
= 0 ; i
< adapter
->num_vfs
; i
++)
4143 adapter
->vfinfo
[i
].clear_to_send
= 0;
4146 /* Cleanup the affinity_hint CPU mask memory and callback */
4147 for (i
= 0; i
< num_q_vectors
; i
++) {
4148 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
4149 /* clear the affinity_mask in the IRQ descriptor */
4150 irq_set_affinity_hint(adapter
->msix_entries
[i
]. vector
, NULL
);
4151 /* release the CPU mask memory */
4152 free_cpumask_var(q_vector
->affinity_mask
);
4155 /* disable transmits in the hardware now that interrupts are off */
4156 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
4157 u8 reg_idx
= adapter
->tx_ring
[i
]->reg_idx
;
4158 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), IXGBE_TXDCTL_SWFLSH
);
4161 /* Disable the Tx DMA engine on 82599 and X540 */
4162 switch (hw
->mac
.type
) {
4163 case ixgbe_mac_82599EB
:
4164 case ixgbe_mac_X540
:
4165 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
,
4166 (IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
) &
4167 ~IXGBE_DMATXCTL_TE
));
4173 if (!pci_channel_offline(adapter
->pdev
))
4174 ixgbe_reset(adapter
);
4176 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4177 if (hw
->mac
.ops
.disable_tx_laser
&&
4178 ((hw
->phy
.multispeed_fiber
) ||
4179 ((hw
->mac
.ops
.get_media_type(hw
) == ixgbe_media_type_fiber
) &&
4180 (hw
->mac
.type
== ixgbe_mac_82599EB
))))
4181 hw
->mac
.ops
.disable_tx_laser(hw
);
4183 ixgbe_clean_all_tx_rings(adapter
);
4184 ixgbe_clean_all_rx_rings(adapter
);
4186 #ifdef CONFIG_IXGBE_DCA
4187 /* since we reset the hardware DCA settings were cleared */
4188 ixgbe_setup_dca(adapter
);
4193 * ixgbe_poll - NAPI Rx polling callback
4194 * @napi: structure for representing this polling device
4195 * @budget: how many packets driver is allowed to clean
4197 * This function is used for legacy and MSI, NAPI mode
4199 static int ixgbe_poll(struct napi_struct
*napi
, int budget
)
4201 struct ixgbe_q_vector
*q_vector
=
4202 container_of(napi
, struct ixgbe_q_vector
, napi
);
4203 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
4204 int tx_clean_complete
, work_done
= 0;
4206 #ifdef CONFIG_IXGBE_DCA
4207 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
4208 ixgbe_update_dca(q_vector
);
4211 tx_clean_complete
= ixgbe_clean_tx_irq(q_vector
, adapter
->tx_ring
[0]);
4212 ixgbe_clean_rx_irq(q_vector
, adapter
->rx_ring
[0], &work_done
, budget
);
4214 if (!tx_clean_complete
)
4217 /* If budget not fully consumed, exit the polling mode */
4218 if (work_done
< budget
) {
4219 napi_complete(napi
);
4220 if (adapter
->rx_itr_setting
& 1)
4221 ixgbe_set_itr(q_vector
);
4222 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
4223 ixgbe_irq_enable_queues(adapter
, IXGBE_EIMS_RTX_QUEUE
);
4229 * ixgbe_tx_timeout - Respond to a Tx Hang
4230 * @netdev: network interface device structure
4232 static void ixgbe_tx_timeout(struct net_device
*netdev
)
4234 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4236 /* Do the reset outside of interrupt context */
4237 ixgbe_tx_timeout_reset(adapter
);
4241 * ixgbe_set_rss_queues: Allocate queues for RSS
4242 * @adapter: board private structure to initialize
4244 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4245 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4248 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter
*adapter
)
4251 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_RSS
];
4253 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
4255 adapter
->num_rx_queues
= f
->indices
;
4256 adapter
->num_tx_queues
= f
->indices
;
4266 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4267 * @adapter: board private structure to initialize
4269 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4270 * to the original CPU that initiated the Tx session. This runs in addition
4271 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4272 * Rx load across CPUs using RSS.
4275 static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter
*adapter
)
4278 struct ixgbe_ring_feature
*f_fdir
= &adapter
->ring_feature
[RING_F_FDIR
];
4280 f_fdir
->indices
= min((int)num_online_cpus(), f_fdir
->indices
);
4283 /* Flow Director must have RSS enabled */
4284 if ((adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) &&
4285 (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)) {
4286 adapter
->num_tx_queues
= f_fdir
->indices
;
4287 adapter
->num_rx_queues
= f_fdir
->indices
;
4290 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
4297 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4298 * @adapter: board private structure to initialize
4300 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4301 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4302 * rx queues out of the max number of rx queues, instead, it is used as the
4303 * index of the first rx queue used by FCoE.
4306 static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter
*adapter
)
4308 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
4310 if (!(adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
))
4313 f
->indices
= min((int)num_online_cpus(), f
->indices
);
4315 adapter
->num_rx_queues
= 1;
4316 adapter
->num_tx_queues
= 1;
4318 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
4319 e_info(probe
, "FCoE enabled with RSS\n");
4320 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)
4321 ixgbe_set_fdir_queues(adapter
);
4323 ixgbe_set_rss_queues(adapter
);
4326 /* adding FCoE rx rings to the end */
4327 f
->mask
= adapter
->num_rx_queues
;
4328 adapter
->num_rx_queues
+= f
->indices
;
4329 adapter
->num_tx_queues
+= f
->indices
;
4333 #endif /* IXGBE_FCOE */
4335 /* Artificial max queue cap per traffic class in DCB mode */
4336 #define DCB_QUEUE_CAP 8
4338 #ifdef CONFIG_IXGBE_DCB
4339 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter
*adapter
)
4341 int per_tc_q
, q
, i
, offset
= 0;
4342 struct net_device
*dev
= adapter
->netdev
;
4343 int tcs
= netdev_get_num_tc(dev
);
4348 /* Map queue offset and counts onto allocated tx queues */
4349 per_tc_q
= min(dev
->num_tx_queues
/ tcs
, (unsigned int)DCB_QUEUE_CAP
);
4350 q
= min((int)num_online_cpus(), per_tc_q
);
4352 for (i
= 0; i
< tcs
; i
++) {
4353 netdev_set_prio_tc_map(dev
, i
, i
);
4354 netdev_set_tc_queue(dev
, i
, q
, offset
);
4358 adapter
->num_tx_queues
= q
* tcs
;
4359 adapter
->num_rx_queues
= q
* tcs
;
4362 /* FCoE enabled queues require special configuration indexed
4363 * by feature specific indices and mask. Here we map FCoE
4364 * indices onto the DCB queue pairs allowing FCoE to own
4365 * configuration later.
4367 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) {
4369 struct ixgbe_ring_feature
*f
=
4370 &adapter
->ring_feature
[RING_F_FCOE
];
4372 tc
= netdev_get_prio_tc_map(dev
, adapter
->fcoe
.up
);
4373 f
->indices
= dev
->tc_to_txq
[tc
].count
;
4374 f
->mask
= dev
->tc_to_txq
[tc
].offset
;
4383 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4384 * @adapter: board private structure to initialize
4386 * IOV doesn't actually use anything, so just NAK the
4387 * request for now and let the other queue routines
4388 * figure out what to do.
4390 static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter
*adapter
)
4396 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
4397 * @adapter: board private structure to initialize
4399 * This is the top level queue allocation routine. The order here is very
4400 * important, starting with the "most" number of features turned on at once,
4401 * and ending with the smallest set of features. This way large combinations
4402 * can be allocated if they're turned on, and smaller combinations are the
4403 * fallthrough conditions.
4406 static int ixgbe_set_num_queues(struct ixgbe_adapter
*adapter
)
4408 /* Start with base case */
4409 adapter
->num_rx_queues
= 1;
4410 adapter
->num_tx_queues
= 1;
4411 adapter
->num_rx_pools
= adapter
->num_rx_queues
;
4412 adapter
->num_rx_queues_per_pool
= 1;
4414 if (ixgbe_set_sriov_queues(adapter
))
4417 #ifdef CONFIG_IXGBE_DCB
4418 if (ixgbe_set_dcb_queues(adapter
))
4423 if (ixgbe_set_fcoe_queues(adapter
))
4426 #endif /* IXGBE_FCOE */
4427 if (ixgbe_set_fdir_queues(adapter
))
4430 if (ixgbe_set_rss_queues(adapter
))
4433 /* fallback to base case */
4434 adapter
->num_rx_queues
= 1;
4435 adapter
->num_tx_queues
= 1;
4438 /* Notify the stack of the (possibly) reduced queue counts. */
4439 netif_set_real_num_tx_queues(adapter
->netdev
, adapter
->num_tx_queues
);
4440 return netif_set_real_num_rx_queues(adapter
->netdev
,
4441 adapter
->num_rx_queues
);
4444 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter
*adapter
,
4447 int err
, vector_threshold
;
4449 /* We'll want at least 3 (vector_threshold):
4452 * 3) Other (Link Status Change, etc.)
4453 * 4) TCP Timer (optional)
4455 vector_threshold
= MIN_MSIX_COUNT
;
4457 /* The more we get, the more we will assign to Tx/Rx Cleanup
4458 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4459 * Right now, we simply care about how many we'll get; we'll
4460 * set them up later while requesting irq's.
4462 while (vectors
>= vector_threshold
) {
4463 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
4465 if (!err
) /* Success in acquiring all requested vectors. */
4468 vectors
= 0; /* Nasty failure, quit now */
4469 else /* err == number of vectors we should try again with */
4473 if (vectors
< vector_threshold
) {
4474 /* Can't allocate enough MSI-X interrupts? Oh well.
4475 * This just means we'll go with either a single MSI
4476 * vector or fall back to legacy interrupts.
4478 netif_printk(adapter
, hw
, KERN_DEBUG
, adapter
->netdev
,
4479 "Unable to allocate MSI-X interrupts\n");
4480 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
4481 kfree(adapter
->msix_entries
);
4482 adapter
->msix_entries
= NULL
;
4484 adapter
->flags
|= IXGBE_FLAG_MSIX_ENABLED
; /* Woot! */
4486 * Adjust for only the vectors we'll use, which is minimum
4487 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4488 * vectors we were allocated.
4490 adapter
->num_msix_vectors
= min(vectors
,
4491 adapter
->max_msix_q_vectors
+ NON_Q_VECTORS
);
4496 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
4497 * @adapter: board private structure to initialize
4499 * Cache the descriptor ring offsets for RSS to the assigned rings.
4502 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter
*adapter
)
4506 if (!(adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
))
4509 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4510 adapter
->rx_ring
[i
]->reg_idx
= i
;
4511 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4512 adapter
->tx_ring
[i
]->reg_idx
= i
;
4517 #ifdef CONFIG_IXGBE_DCB
4519 /* ixgbe_get_first_reg_idx - Return first register index associated with ring */
4520 static void ixgbe_get_first_reg_idx(struct ixgbe_adapter
*adapter
, u8 tc
,
4521 unsigned int *tx
, unsigned int *rx
)
4523 struct net_device
*dev
= adapter
->netdev
;
4524 struct ixgbe_hw
*hw
= &adapter
->hw
;
4525 u8 num_tcs
= netdev_get_num_tc(dev
);
4530 switch (hw
->mac
.type
) {
4531 case ixgbe_mac_82598EB
:
4535 case ixgbe_mac_82599EB
:
4536 case ixgbe_mac_X540
:
4541 } else if (tc
< 5) {
4542 *tx
= ((tc
+ 2) << 4);
4544 } else if (tc
< num_tcs
) {
4545 *tx
= ((tc
+ 8) << 3);
4548 } else if (num_tcs
== 4) {
4574 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4575 * @adapter: board private structure to initialize
4577 * Cache the descriptor ring offsets for DCB to the assigned rings.
4580 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter
*adapter
)
4582 struct net_device
*dev
= adapter
->netdev
;
4584 u8 num_tcs
= netdev_get_num_tc(dev
);
4589 for (i
= 0, k
= 0; i
< num_tcs
; i
++) {
4590 unsigned int tx_s
, rx_s
;
4591 u16 count
= dev
->tc_to_txq
[i
].count
;
4593 ixgbe_get_first_reg_idx(adapter
, i
, &tx_s
, &rx_s
);
4594 for (j
= 0; j
< count
; j
++, k
++) {
4595 adapter
->tx_ring
[k
]->reg_idx
= tx_s
+ j
;
4596 adapter
->rx_ring
[k
]->reg_idx
= rx_s
+ j
;
4597 adapter
->tx_ring
[k
]->dcb_tc
= i
;
4598 adapter
->rx_ring
[k
]->dcb_tc
= i
;
4607 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4608 * @adapter: board private structure to initialize
4610 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4613 static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter
*adapter
)
4618 if ((adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) &&
4619 (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)) {
4620 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4621 adapter
->rx_ring
[i
]->reg_idx
= i
;
4622 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4623 adapter
->tx_ring
[i
]->reg_idx
= i
;
4632 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4633 * @adapter: board private structure to initialize
4635 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4638 static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter
*adapter
)
4640 struct ixgbe_ring_feature
*f
= &adapter
->ring_feature
[RING_F_FCOE
];
4642 u8 fcoe_rx_i
= 0, fcoe_tx_i
= 0;
4644 if (!(adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
))
4647 if (adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) {
4648 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
)
4649 ixgbe_cache_ring_fdir(adapter
);
4651 ixgbe_cache_ring_rss(adapter
);
4653 fcoe_rx_i
= f
->mask
;
4654 fcoe_tx_i
= f
->mask
;
4656 for (i
= 0; i
< f
->indices
; i
++, fcoe_rx_i
++, fcoe_tx_i
++) {
4657 adapter
->rx_ring
[f
->mask
+ i
]->reg_idx
= fcoe_rx_i
;
4658 adapter
->tx_ring
[f
->mask
+ i
]->reg_idx
= fcoe_tx_i
;
4663 #endif /* IXGBE_FCOE */
4665 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4666 * @adapter: board private structure to initialize
4668 * SR-IOV doesn't use any descriptor rings but changes the default if
4669 * no other mapping is used.
4672 static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter
*adapter
)
4674 adapter
->rx_ring
[0]->reg_idx
= adapter
->num_vfs
* 2;
4675 adapter
->tx_ring
[0]->reg_idx
= adapter
->num_vfs
* 2;
4676 if (adapter
->num_vfs
)
4683 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4684 * @adapter: board private structure to initialize
4686 * Once we know the feature-set enabled for the device, we'll cache
4687 * the register offset the descriptor ring is assigned to.
4689 * Note, the order the various feature calls is important. It must start with
4690 * the "most" features enabled at the same time, then trickle down to the
4691 * least amount of features turned on at once.
4693 static void ixgbe_cache_ring_register(struct ixgbe_adapter
*adapter
)
4695 /* start with default case */
4696 adapter
->rx_ring
[0]->reg_idx
= 0;
4697 adapter
->tx_ring
[0]->reg_idx
= 0;
4699 if (ixgbe_cache_ring_sriov(adapter
))
4702 #ifdef CONFIG_IXGBE_DCB
4703 if (ixgbe_cache_ring_dcb(adapter
))
4708 if (ixgbe_cache_ring_fcoe(adapter
))
4710 #endif /* IXGBE_FCOE */
4712 if (ixgbe_cache_ring_fdir(adapter
))
4715 if (ixgbe_cache_ring_rss(adapter
))
4720 * ixgbe_alloc_queues - Allocate memory for all rings
4721 * @adapter: board private structure to initialize
4723 * We allocate one ring per queue at run-time since we don't know the
4724 * number of queues at compile-time. The polling_netdev array is
4725 * intended for Multiqueue, but should work fine with a single queue.
4727 static int ixgbe_alloc_queues(struct ixgbe_adapter
*adapter
)
4729 int rx
= 0, tx
= 0, nid
= adapter
->node
;
4731 if (nid
< 0 || !node_online(nid
))
4732 nid
= first_online_node
;
4734 for (; tx
< adapter
->num_tx_queues
; tx
++) {
4735 struct ixgbe_ring
*ring
;
4737 ring
= kzalloc_node(sizeof(*ring
), GFP_KERNEL
, nid
);
4739 ring
= kzalloc(sizeof(*ring
), GFP_KERNEL
);
4741 goto err_allocation
;
4742 ring
->count
= adapter
->tx_ring_count
;
4743 ring
->queue_index
= tx
;
4744 ring
->numa_node
= nid
;
4745 ring
->dev
= &adapter
->pdev
->dev
;
4746 ring
->netdev
= adapter
->netdev
;
4748 adapter
->tx_ring
[tx
] = ring
;
4751 for (; rx
< adapter
->num_rx_queues
; rx
++) {
4752 struct ixgbe_ring
*ring
;
4754 ring
= kzalloc_node(sizeof(*ring
), GFP_KERNEL
, nid
);
4756 ring
= kzalloc(sizeof(*ring
), GFP_KERNEL
);
4758 goto err_allocation
;
4759 ring
->count
= adapter
->rx_ring_count
;
4760 ring
->queue_index
= rx
;
4761 ring
->numa_node
= nid
;
4762 ring
->dev
= &adapter
->pdev
->dev
;
4763 ring
->netdev
= adapter
->netdev
;
4765 adapter
->rx_ring
[rx
] = ring
;
4768 ixgbe_cache_ring_register(adapter
);
4774 kfree(adapter
->tx_ring
[--tx
]);
4777 kfree(adapter
->rx_ring
[--rx
]);
4782 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4783 * @adapter: board private structure to initialize
4785 * Attempt to configure the interrupts using the best available
4786 * capabilities of the hardware and the kernel.
4788 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter
*adapter
)
4790 struct ixgbe_hw
*hw
= &adapter
->hw
;
4792 int vector
, v_budget
;
4795 * It's easy to be greedy for MSI-X vectors, but it really
4796 * doesn't do us much good if we have a lot more vectors
4797 * than CPU's. So let's be conservative and only ask for
4798 * (roughly) the same number of vectors as there are CPU's.
4800 v_budget
= min(adapter
->num_rx_queues
+ adapter
->num_tx_queues
,
4801 (int)num_online_cpus()) + NON_Q_VECTORS
;
4804 * At the same time, hardware can only support a maximum of
4805 * hw.mac->max_msix_vectors vectors. With features
4806 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4807 * descriptor queues supported by our device. Thus, we cap it off in
4808 * those rare cases where the cpu count also exceeds our vector limit.
4810 v_budget
= min(v_budget
, (int)hw
->mac
.max_msix_vectors
);
4812 /* A failure in MSI-X entry allocation isn't fatal, but it does
4813 * mean we disable MSI-X capabilities of the adapter. */
4814 adapter
->msix_entries
= kcalloc(v_budget
,
4815 sizeof(struct msix_entry
), GFP_KERNEL
);
4816 if (adapter
->msix_entries
) {
4817 for (vector
= 0; vector
< v_budget
; vector
++)
4818 adapter
->msix_entries
[vector
].entry
= vector
;
4820 ixgbe_acquire_msix_vectors(adapter
, v_budget
);
4822 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
4826 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
4827 adapter
->flags
&= ~IXGBE_FLAG_RSS_ENABLED
;
4828 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
4830 "ATR is not supported while multiple "
4831 "queues are disabled. Disabling Flow Director\n");
4833 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
4834 adapter
->atr_sample_rate
= 0;
4835 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
4836 ixgbe_disable_sriov(adapter
);
4838 err
= ixgbe_set_num_queues(adapter
);
4842 err
= pci_enable_msi(adapter
->pdev
);
4844 adapter
->flags
|= IXGBE_FLAG_MSI_ENABLED
;
4846 netif_printk(adapter
, hw
, KERN_DEBUG
, adapter
->netdev
,
4847 "Unable to allocate MSI interrupt, "
4848 "falling back to legacy. Error: %d\n", err
);
4858 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4859 * @adapter: board private structure to initialize
4861 * We allocate one q_vector per queue interrupt. If allocation fails we
4864 static int ixgbe_alloc_q_vectors(struct ixgbe_adapter
*adapter
)
4866 int q_idx
, num_q_vectors
;
4867 struct ixgbe_q_vector
*q_vector
;
4868 int (*poll
)(struct napi_struct
*, int);
4870 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
4871 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
4872 poll
= &ixgbe_clean_rxtx_many
;
4878 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
4879 q_vector
= kzalloc_node(sizeof(struct ixgbe_q_vector
),
4880 GFP_KERNEL
, adapter
->node
);
4882 q_vector
= kzalloc(sizeof(struct ixgbe_q_vector
),
4886 q_vector
->adapter
= adapter
;
4887 if (q_vector
->tx
.count
&& !q_vector
->rx
.count
)
4888 q_vector
->eitr
= adapter
->tx_eitr_param
;
4890 q_vector
->eitr
= adapter
->rx_eitr_param
;
4891 q_vector
->v_idx
= q_idx
;
4892 netif_napi_add(adapter
->netdev
, &q_vector
->napi
, (*poll
), 64);
4893 adapter
->q_vector
[q_idx
] = q_vector
;
4901 q_vector
= adapter
->q_vector
[q_idx
];
4902 netif_napi_del(&q_vector
->napi
);
4904 adapter
->q_vector
[q_idx
] = NULL
;
4910 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4911 * @adapter: board private structure to initialize
4913 * This function frees the memory allocated to the q_vectors. In addition if
4914 * NAPI is enabled it will delete any references to the NAPI struct prior
4915 * to freeing the q_vector.
4917 static void ixgbe_free_q_vectors(struct ixgbe_adapter
*adapter
)
4919 int q_idx
, num_q_vectors
;
4921 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
4922 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
4926 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
4927 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
4928 adapter
->q_vector
[q_idx
] = NULL
;
4929 netif_napi_del(&q_vector
->napi
);
4934 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter
*adapter
)
4936 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
4937 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
4938 pci_disable_msix(adapter
->pdev
);
4939 kfree(adapter
->msix_entries
);
4940 adapter
->msix_entries
= NULL
;
4941 } else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
) {
4942 adapter
->flags
&= ~IXGBE_FLAG_MSI_ENABLED
;
4943 pci_disable_msi(adapter
->pdev
);
4948 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4949 * @adapter: board private structure to initialize
4951 * We determine which interrupt scheme to use based on...
4952 * - Kernel support (MSI, MSI-X)
4953 * - which can be user-defined (via MODULE_PARAM)
4954 * - Hardware queue count (num_*_queues)
4955 * - defined by miscellaneous hardware support/features (RSS, etc.)
4957 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter
*adapter
)
4961 /* Number of supported queues */
4962 err
= ixgbe_set_num_queues(adapter
);
4966 err
= ixgbe_set_interrupt_capability(adapter
);
4968 e_dev_err("Unable to setup interrupt capabilities\n");
4969 goto err_set_interrupt
;
4972 err
= ixgbe_alloc_q_vectors(adapter
);
4974 e_dev_err("Unable to allocate memory for queue vectors\n");
4975 goto err_alloc_q_vectors
;
4978 err
= ixgbe_alloc_queues(adapter
);
4980 e_dev_err("Unable to allocate memory for queues\n");
4981 goto err_alloc_queues
;
4984 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
4985 (adapter
->num_rx_queues
> 1) ? "Enabled" : "Disabled",
4986 adapter
->num_rx_queues
, adapter
->num_tx_queues
);
4988 set_bit(__IXGBE_DOWN
, &adapter
->state
);
4993 ixgbe_free_q_vectors(adapter
);
4994 err_alloc_q_vectors
:
4995 ixgbe_reset_interrupt_capability(adapter
);
5001 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5002 * @adapter: board private structure to clear interrupt scheme on
5004 * We go through and clear interrupt specific resources and reset the structure
5005 * to pre-load conditions
5007 void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter
*adapter
)
5011 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5012 kfree(adapter
->tx_ring
[i
]);
5013 adapter
->tx_ring
[i
] = NULL
;
5015 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5016 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
5018 /* ixgbe_get_stats64() might access this ring, we must wait
5019 * a grace period before freeing it.
5021 kfree_rcu(ring
, rcu
);
5022 adapter
->rx_ring
[i
] = NULL
;
5025 adapter
->num_tx_queues
= 0;
5026 adapter
->num_rx_queues
= 0;
5028 ixgbe_free_q_vectors(adapter
);
5029 ixgbe_reset_interrupt_capability(adapter
);
5033 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5034 * @adapter: board private structure to initialize
5036 * ixgbe_sw_init initializes the Adapter private data structure.
5037 * Fields are initialized based on PCI device information and
5038 * OS network device settings (MTU size).
5040 static int __devinit
ixgbe_sw_init(struct ixgbe_adapter
*adapter
)
5042 struct ixgbe_hw
*hw
= &adapter
->hw
;
5043 struct pci_dev
*pdev
= adapter
->pdev
;
5044 struct net_device
*dev
= adapter
->netdev
;
5046 #ifdef CONFIG_IXGBE_DCB
5048 struct tc_configuration
*tc
;
5050 int max_frame
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5052 /* PCI config space info */
5054 hw
->vendor_id
= pdev
->vendor
;
5055 hw
->device_id
= pdev
->device
;
5056 hw
->revision_id
= pdev
->revision
;
5057 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
5058 hw
->subsystem_device_id
= pdev
->subsystem_device
;
5060 /* Set capability flags */
5061 rss
= min(IXGBE_MAX_RSS_INDICES
, (int)num_online_cpus());
5062 adapter
->ring_feature
[RING_F_RSS
].indices
= rss
;
5063 adapter
->flags
|= IXGBE_FLAG_RSS_ENABLED
;
5064 switch (hw
->mac
.type
) {
5065 case ixgbe_mac_82598EB
:
5066 if (hw
->device_id
== IXGBE_DEV_ID_82598AT
)
5067 adapter
->flags
|= IXGBE_FLAG_FAN_FAIL_CAPABLE
;
5068 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82598
;
5070 case ixgbe_mac_82599EB
:
5071 case ixgbe_mac_X540
:
5072 adapter
->max_msix_q_vectors
= MAX_MSIX_Q_VECTORS_82599
;
5073 adapter
->flags2
|= IXGBE_FLAG2_RSC_CAPABLE
;
5074 adapter
->flags2
|= IXGBE_FLAG2_RSC_ENABLED
;
5075 if (hw
->device_id
== IXGBE_DEV_ID_82599_T3_LOM
)
5076 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
5077 /* Flow Director hash filters enabled */
5078 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
5079 adapter
->atr_sample_rate
= 20;
5080 adapter
->ring_feature
[RING_F_FDIR
].indices
=
5081 IXGBE_MAX_FDIR_INDICES
;
5082 adapter
->fdir_pballoc
= IXGBE_FDIR_PBALLOC_64K
;
5084 adapter
->flags
|= IXGBE_FLAG_FCOE_CAPABLE
;
5085 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
5086 adapter
->ring_feature
[RING_F_FCOE
].indices
= 0;
5087 #ifdef CONFIG_IXGBE_DCB
5088 /* Default traffic class to use for FCoE */
5089 adapter
->fcoe
.up
= IXGBE_FCOE_DEFTC
;
5091 #endif /* IXGBE_FCOE */
5097 /* n-tuple support exists, always init our spinlock */
5098 spin_lock_init(&adapter
->fdir_perfect_lock
);
5100 #ifdef CONFIG_IXGBE_DCB
5101 /* Configure DCB traffic classes */
5102 for (j
= 0; j
< MAX_TRAFFIC_CLASS
; j
++) {
5103 tc
= &adapter
->dcb_cfg
.tc_config
[j
];
5104 tc
->path
[DCB_TX_CONFIG
].bwg_id
= 0;
5105 tc
->path
[DCB_TX_CONFIG
].bwg_percent
= 12 + (j
& 1);
5106 tc
->path
[DCB_RX_CONFIG
].bwg_id
= 0;
5107 tc
->path
[DCB_RX_CONFIG
].bwg_percent
= 12 + (j
& 1);
5108 tc
->dcb_pfc
= pfc_disabled
;
5110 adapter
->dcb_cfg
.bw_percentage
[DCB_TX_CONFIG
][0] = 100;
5111 adapter
->dcb_cfg
.bw_percentage
[DCB_RX_CONFIG
][0] = 100;
5112 adapter
->dcb_cfg
.pfc_mode_enable
= false;
5113 adapter
->dcb_set_bitmap
= 0x00;
5114 adapter
->dcbx_cap
= DCB_CAP_DCBX_HOST
| DCB_CAP_DCBX_VER_CEE
;
5115 ixgbe_copy_dcb_cfg(&adapter
->dcb_cfg
, &adapter
->temp_dcb_cfg
,
5120 /* default flow control settings */
5121 hw
->fc
.requested_mode
= ixgbe_fc_full
;
5122 hw
->fc
.current_mode
= ixgbe_fc_full
; /* init for ethtool output */
5124 adapter
->last_lfc_mode
= hw
->fc
.current_mode
;
5126 hw
->fc
.high_water
= FC_HIGH_WATER(max_frame
);
5127 hw
->fc
.low_water
= FC_LOW_WATER(max_frame
);
5128 hw
->fc
.pause_time
= IXGBE_DEFAULT_FCPAUSE
;
5129 hw
->fc
.send_xon
= true;
5130 hw
->fc
.disable_fc_autoneg
= false;
5132 /* enable itr by default in dynamic mode */
5133 adapter
->rx_itr_setting
= 1;
5134 adapter
->rx_eitr_param
= 20000;
5135 adapter
->tx_itr_setting
= 1;
5136 adapter
->tx_eitr_param
= 10000;
5138 /* set defaults for eitr in MegaBytes */
5139 adapter
->eitr_low
= 10;
5140 adapter
->eitr_high
= 20;
5142 /* set default ring sizes */
5143 adapter
->tx_ring_count
= IXGBE_DEFAULT_TXD
;
5144 adapter
->rx_ring_count
= IXGBE_DEFAULT_RXD
;
5146 /* set default work limits */
5147 adapter
->tx_work_limit
= adapter
->tx_ring_count
;
5149 /* initialize eeprom parameters */
5150 if (ixgbe_init_eeprom_params_generic(hw
)) {
5151 e_dev_err("EEPROM initialization failed\n");
5155 /* enable rx csum by default */
5156 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
5158 /* get assigned NUMA node */
5159 adapter
->node
= dev_to_node(&pdev
->dev
);
5161 set_bit(__IXGBE_DOWN
, &adapter
->state
);
5167 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
5168 * @tx_ring: tx descriptor ring (for a specific queue) to setup
5170 * Return 0 on success, negative on failure
5172 int ixgbe_setup_tx_resources(struct ixgbe_ring
*tx_ring
)
5174 struct device
*dev
= tx_ring
->dev
;
5177 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
5178 tx_ring
->tx_buffer_info
= vzalloc_node(size
, tx_ring
->numa_node
);
5179 if (!tx_ring
->tx_buffer_info
)
5180 tx_ring
->tx_buffer_info
= vzalloc(size
);
5181 if (!tx_ring
->tx_buffer_info
)
5184 /* round up to nearest 4K */
5185 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
5186 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
5188 tx_ring
->desc
= dma_alloc_coherent(dev
, tx_ring
->size
,
5189 &tx_ring
->dma
, GFP_KERNEL
);
5193 tx_ring
->next_to_use
= 0;
5194 tx_ring
->next_to_clean
= 0;
5198 vfree(tx_ring
->tx_buffer_info
);
5199 tx_ring
->tx_buffer_info
= NULL
;
5200 dev_err(dev
, "Unable to allocate memory for the Tx descriptor ring\n");
5205 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5206 * @adapter: board private structure
5208 * If this function returns with an error, then it's possible one or
5209 * more of the rings is populated (while the rest are not). It is the
5210 * callers duty to clean those orphaned rings.
5212 * Return 0 on success, negative on failure
5214 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter
*adapter
)
5218 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5219 err
= ixgbe_setup_tx_resources(adapter
->tx_ring
[i
]);
5222 e_err(probe
, "Allocation for Tx Queue %u failed\n", i
);
5230 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
5231 * @rx_ring: rx descriptor ring (for a specific queue) to setup
5233 * Returns 0 on success, negative on failure
5235 int ixgbe_setup_rx_resources(struct ixgbe_ring
*rx_ring
)
5237 struct device
*dev
= rx_ring
->dev
;
5240 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
5241 rx_ring
->rx_buffer_info
= vzalloc_node(size
, rx_ring
->numa_node
);
5242 if (!rx_ring
->rx_buffer_info
)
5243 rx_ring
->rx_buffer_info
= vzalloc(size
);
5244 if (!rx_ring
->rx_buffer_info
)
5247 /* Round up to nearest 4K */
5248 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
5249 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
5251 rx_ring
->desc
= dma_alloc_coherent(dev
, rx_ring
->size
,
5252 &rx_ring
->dma
, GFP_KERNEL
);
5257 rx_ring
->next_to_clean
= 0;
5258 rx_ring
->next_to_use
= 0;
5262 vfree(rx_ring
->rx_buffer_info
);
5263 rx_ring
->rx_buffer_info
= NULL
;
5264 dev_err(dev
, "Unable to allocate memory for the Rx descriptor ring\n");
5269 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5270 * @adapter: board private structure
5272 * If this function returns with an error, then it's possible one or
5273 * more of the rings is populated (while the rest are not). It is the
5274 * callers duty to clean those orphaned rings.
5276 * Return 0 on success, negative on failure
5278 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter
*adapter
)
5282 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5283 err
= ixgbe_setup_rx_resources(adapter
->rx_ring
[i
]);
5286 e_err(probe
, "Allocation for Rx Queue %u failed\n", i
);
5294 * ixgbe_free_tx_resources - Free Tx Resources per Queue
5295 * @tx_ring: Tx descriptor ring for a specific queue
5297 * Free all transmit software resources
5299 void ixgbe_free_tx_resources(struct ixgbe_ring
*tx_ring
)
5301 ixgbe_clean_tx_ring(tx_ring
);
5303 vfree(tx_ring
->tx_buffer_info
);
5304 tx_ring
->tx_buffer_info
= NULL
;
5306 /* if not set, then don't free */
5310 dma_free_coherent(tx_ring
->dev
, tx_ring
->size
,
5311 tx_ring
->desc
, tx_ring
->dma
);
5313 tx_ring
->desc
= NULL
;
5317 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5318 * @adapter: board private structure
5320 * Free all transmit software resources
5322 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter
*adapter
)
5326 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5327 if (adapter
->tx_ring
[i
]->desc
)
5328 ixgbe_free_tx_resources(adapter
->tx_ring
[i
]);
5332 * ixgbe_free_rx_resources - Free Rx Resources
5333 * @rx_ring: ring to clean the resources from
5335 * Free all receive software resources
5337 void ixgbe_free_rx_resources(struct ixgbe_ring
*rx_ring
)
5339 ixgbe_clean_rx_ring(rx_ring
);
5341 vfree(rx_ring
->rx_buffer_info
);
5342 rx_ring
->rx_buffer_info
= NULL
;
5344 /* if not set, then don't free */
5348 dma_free_coherent(rx_ring
->dev
, rx_ring
->size
,
5349 rx_ring
->desc
, rx_ring
->dma
);
5351 rx_ring
->desc
= NULL
;
5355 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5356 * @adapter: board private structure
5358 * Free all receive software resources
5360 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter
*adapter
)
5364 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
5365 if (adapter
->rx_ring
[i
]->desc
)
5366 ixgbe_free_rx_resources(adapter
->rx_ring
[i
]);
5370 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5371 * @netdev: network interface device structure
5372 * @new_mtu: new value for maximum frame size
5374 * Returns 0 on success, negative on failure
5376 static int ixgbe_change_mtu(struct net_device
*netdev
, int new_mtu
)
5378 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5379 struct ixgbe_hw
*hw
= &adapter
->hw
;
5380 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5382 /* MTU < 68 is an error and causes problems on some kernels */
5383 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
&&
5384 hw
->mac
.type
!= ixgbe_mac_X540
) {
5385 if ((new_mtu
< 68) || (max_frame
> MAXIMUM_ETHERNET_VLAN_SIZE
))
5388 if ((new_mtu
< 68) || (max_frame
> IXGBE_MAX_JUMBO_FRAME_SIZE
))
5392 e_info(probe
, "changing MTU from %d to %d\n", netdev
->mtu
, new_mtu
);
5393 /* must set new MTU before calling down or up */
5394 netdev
->mtu
= new_mtu
;
5396 hw
->fc
.high_water
= FC_HIGH_WATER(max_frame
);
5397 hw
->fc
.low_water
= FC_LOW_WATER(max_frame
);
5399 if (netif_running(netdev
))
5400 ixgbe_reinit_locked(adapter
);
5406 * ixgbe_open - Called when a network interface is made active
5407 * @netdev: network interface device structure
5409 * Returns 0 on success, negative value on failure
5411 * The open entry point is called when a network interface is made
5412 * active by the system (IFF_UP). At this point all resources needed
5413 * for transmit and receive operations are allocated, the interrupt
5414 * handler is registered with the OS, the watchdog timer is started,
5415 * and the stack is notified that the interface is ready.
5417 static int ixgbe_open(struct net_device
*netdev
)
5419 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5422 /* disallow open during test */
5423 if (test_bit(__IXGBE_TESTING
, &adapter
->state
))
5426 netif_carrier_off(netdev
);
5428 /* allocate transmit descriptors */
5429 err
= ixgbe_setup_all_tx_resources(adapter
);
5433 /* allocate receive descriptors */
5434 err
= ixgbe_setup_all_rx_resources(adapter
);
5438 ixgbe_configure(adapter
);
5440 err
= ixgbe_request_irq(adapter
);
5444 err
= ixgbe_up_complete(adapter
);
5448 netif_tx_start_all_queues(netdev
);
5453 ixgbe_release_hw_control(adapter
);
5454 ixgbe_free_irq(adapter
);
5457 ixgbe_free_all_rx_resources(adapter
);
5459 ixgbe_free_all_tx_resources(adapter
);
5460 ixgbe_reset(adapter
);
5466 * ixgbe_close - Disables a network interface
5467 * @netdev: network interface device structure
5469 * Returns 0, this is not allowed to fail
5471 * The close entry point is called when an interface is de-activated
5472 * by the OS. The hardware is still under the drivers control, but
5473 * needs to be disabled. A global MAC reset is issued to stop the
5474 * hardware, and all transmit and receive resources are freed.
5476 static int ixgbe_close(struct net_device
*netdev
)
5478 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5480 ixgbe_down(adapter
);
5481 ixgbe_free_irq(adapter
);
5483 ixgbe_fdir_filter_exit(adapter
);
5485 ixgbe_free_all_tx_resources(adapter
);
5486 ixgbe_free_all_rx_resources(adapter
);
5488 ixgbe_release_hw_control(adapter
);
5494 static int ixgbe_resume(struct pci_dev
*pdev
)
5496 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
5497 struct net_device
*netdev
= adapter
->netdev
;
5500 pci_set_power_state(pdev
, PCI_D0
);
5501 pci_restore_state(pdev
);
5503 * pci_restore_state clears dev->state_saved so call
5504 * pci_save_state to restore it.
5506 pci_save_state(pdev
);
5508 err
= pci_enable_device_mem(pdev
);
5510 e_dev_err("Cannot enable PCI device from suspend\n");
5513 pci_set_master(pdev
);
5515 pci_wake_from_d3(pdev
, false);
5517 err
= ixgbe_init_interrupt_scheme(adapter
);
5519 e_dev_err("Cannot initialize interrupts for device\n");
5523 ixgbe_reset(adapter
);
5525 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
5527 if (netif_running(netdev
)) {
5528 err
= ixgbe_open(netdev
);
5533 netif_device_attach(netdev
);
5537 #endif /* CONFIG_PM */
5539 static int __ixgbe_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
5541 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
5542 struct net_device
*netdev
= adapter
->netdev
;
5543 struct ixgbe_hw
*hw
= &adapter
->hw
;
5545 u32 wufc
= adapter
->wol
;
5550 netif_device_detach(netdev
);
5552 if (netif_running(netdev
)) {
5553 ixgbe_down(adapter
);
5554 ixgbe_free_irq(adapter
);
5555 ixgbe_free_all_tx_resources(adapter
);
5556 ixgbe_free_all_rx_resources(adapter
);
5559 ixgbe_clear_interrupt_scheme(adapter
);
5561 kfree(adapter
->ixgbe_ieee_pfc
);
5562 kfree(adapter
->ixgbe_ieee_ets
);
5566 retval
= pci_save_state(pdev
);
5572 ixgbe_set_rx_mode(netdev
);
5574 /* turn on all-multi mode if wake on multicast is enabled */
5575 if (wufc
& IXGBE_WUFC_MC
) {
5576 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
5577 fctrl
|= IXGBE_FCTRL_MPE
;
5578 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
5581 ctrl
= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
5582 ctrl
|= IXGBE_CTRL_GIO_DIS
;
5583 IXGBE_WRITE_REG(hw
, IXGBE_CTRL
, ctrl
);
5585 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, wufc
);
5587 IXGBE_WRITE_REG(hw
, IXGBE_WUC
, 0);
5588 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, 0);
5591 switch (hw
->mac
.type
) {
5592 case ixgbe_mac_82598EB
:
5593 pci_wake_from_d3(pdev
, false);
5595 case ixgbe_mac_82599EB
:
5596 case ixgbe_mac_X540
:
5597 pci_wake_from_d3(pdev
, !!wufc
);
5603 *enable_wake
= !!wufc
;
5605 ixgbe_release_hw_control(adapter
);
5607 pci_disable_device(pdev
);
5613 static int ixgbe_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5618 retval
= __ixgbe_shutdown(pdev
, &wake
);
5623 pci_prepare_to_sleep(pdev
);
5625 pci_wake_from_d3(pdev
, false);
5626 pci_set_power_state(pdev
, PCI_D3hot
);
5631 #endif /* CONFIG_PM */
5633 static void ixgbe_shutdown(struct pci_dev
*pdev
)
5637 __ixgbe_shutdown(pdev
, &wake
);
5639 if (system_state
== SYSTEM_POWER_OFF
) {
5640 pci_wake_from_d3(pdev
, wake
);
5641 pci_set_power_state(pdev
, PCI_D3hot
);
5646 * ixgbe_update_stats - Update the board statistics counters.
5647 * @adapter: board private structure
5649 void ixgbe_update_stats(struct ixgbe_adapter
*adapter
)
5651 struct net_device
*netdev
= adapter
->netdev
;
5652 struct ixgbe_hw
*hw
= &adapter
->hw
;
5653 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
5655 u32 i
, missed_rx
= 0, mpc
, bprc
, lxon
, lxoff
, xon_off_tot
;
5656 u64 non_eop_descs
= 0, restart_queue
= 0, tx_busy
= 0;
5657 u64 alloc_rx_page_failed
= 0, alloc_rx_buff_failed
= 0;
5658 u64 bytes
= 0, packets
= 0;
5660 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
5661 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
5664 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) {
5667 for (i
= 0; i
< 16; i
++)
5668 adapter
->hw_rx_no_dma_resources
+=
5669 IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
5670 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5671 rsc_count
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_count
;
5672 rsc_flush
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_flush
;
5674 adapter
->rsc_total_count
= rsc_count
;
5675 adapter
->rsc_total_flush
= rsc_flush
;
5678 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5679 struct ixgbe_ring
*rx_ring
= adapter
->rx_ring
[i
];
5680 non_eop_descs
+= rx_ring
->rx_stats
.non_eop_descs
;
5681 alloc_rx_page_failed
+= rx_ring
->rx_stats
.alloc_rx_page_failed
;
5682 alloc_rx_buff_failed
+= rx_ring
->rx_stats
.alloc_rx_buff_failed
;
5683 bytes
+= rx_ring
->stats
.bytes
;
5684 packets
+= rx_ring
->stats
.packets
;
5686 adapter
->non_eop_descs
= non_eop_descs
;
5687 adapter
->alloc_rx_page_failed
= alloc_rx_page_failed
;
5688 adapter
->alloc_rx_buff_failed
= alloc_rx_buff_failed
;
5689 netdev
->stats
.rx_bytes
= bytes
;
5690 netdev
->stats
.rx_packets
= packets
;
5694 /* gather some stats to the adapter struct that are per queue */
5695 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5696 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
5697 restart_queue
+= tx_ring
->tx_stats
.restart_queue
;
5698 tx_busy
+= tx_ring
->tx_stats
.tx_busy
;
5699 bytes
+= tx_ring
->stats
.bytes
;
5700 packets
+= tx_ring
->stats
.packets
;
5702 adapter
->restart_queue
= restart_queue
;
5703 adapter
->tx_busy
= tx_busy
;
5704 netdev
->stats
.tx_bytes
= bytes
;
5705 netdev
->stats
.tx_packets
= packets
;
5707 hwstats
->crcerrs
+= IXGBE_READ_REG(hw
, IXGBE_CRCERRS
);
5708 for (i
= 0; i
< 8; i
++) {
5709 /* for packet buffers not used, the register should read 0 */
5710 mpc
= IXGBE_READ_REG(hw
, IXGBE_MPC(i
));
5712 hwstats
->mpc
[i
] += mpc
;
5713 total_mpc
+= hwstats
->mpc
[i
];
5714 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
5715 hwstats
->rnbc
[i
] += IXGBE_READ_REG(hw
, IXGBE_RNBC(i
));
5716 hwstats
->qptc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPTC(i
));
5717 hwstats
->qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC(i
));
5718 hwstats
->qprc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRC(i
));
5719 hwstats
->qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC(i
));
5720 switch (hw
->mac
.type
) {
5721 case ixgbe_mac_82598EB
:
5722 hwstats
->pxonrxc
[i
] +=
5723 IXGBE_READ_REG(hw
, IXGBE_PXONRXC(i
));
5725 case ixgbe_mac_82599EB
:
5726 case ixgbe_mac_X540
:
5727 hwstats
->pxonrxc
[i
] +=
5728 IXGBE_READ_REG(hw
, IXGBE_PXONRXCNT(i
));
5733 hwstats
->pxontxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXONTXC(i
));
5734 hwstats
->pxofftxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXOFFTXC(i
));
5736 hwstats
->gprc
+= IXGBE_READ_REG(hw
, IXGBE_GPRC
);
5737 /* work around hardware counting issue */
5738 hwstats
->gprc
-= missed_rx
;
5740 ixgbe_update_xoff_received(adapter
);
5742 /* 82598 hardware only has a 32 bit counter in the high register */
5743 switch (hw
->mac
.type
) {
5744 case ixgbe_mac_82598EB
:
5745 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXC
);
5746 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCH
);
5747 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCH
);
5748 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORH
);
5750 case ixgbe_mac_X540
:
5751 /* OS2BMC stats are X540 only*/
5752 hwstats
->o2bgptc
+= IXGBE_READ_REG(hw
, IXGBE_O2BGPTC
);
5753 hwstats
->o2bspc
+= IXGBE_READ_REG(hw
, IXGBE_O2BSPC
);
5754 hwstats
->b2ospc
+= IXGBE_READ_REG(hw
, IXGBE_B2OSPC
);
5755 hwstats
->b2ogprc
+= IXGBE_READ_REG(hw
, IXGBE_B2OGPRC
);
5756 case ixgbe_mac_82599EB
:
5757 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCL
);
5758 IXGBE_READ_REG(hw
, IXGBE_GORCH
); /* to clear */
5759 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCL
);
5760 IXGBE_READ_REG(hw
, IXGBE_GOTCH
); /* to clear */
5761 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORL
);
5762 IXGBE_READ_REG(hw
, IXGBE_TORH
); /* to clear */
5763 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXCNT
);
5764 hwstats
->fdirmatch
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMATCH
);
5765 hwstats
->fdirmiss
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMISS
);
5767 hwstats
->fccrc
+= IXGBE_READ_REG(hw
, IXGBE_FCCRC
);
5768 hwstats
->fcoerpdc
+= IXGBE_READ_REG(hw
, IXGBE_FCOERPDC
);
5769 hwstats
->fcoeprc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPRC
);
5770 hwstats
->fcoeptc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPTC
);
5771 hwstats
->fcoedwrc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWRC
);
5772 hwstats
->fcoedwtc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWTC
);
5773 #endif /* IXGBE_FCOE */
5778 bprc
= IXGBE_READ_REG(hw
, IXGBE_BPRC
);
5779 hwstats
->bprc
+= bprc
;
5780 hwstats
->mprc
+= IXGBE_READ_REG(hw
, IXGBE_MPRC
);
5781 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
5782 hwstats
->mprc
-= bprc
;
5783 hwstats
->roc
+= IXGBE_READ_REG(hw
, IXGBE_ROC
);
5784 hwstats
->prc64
+= IXGBE_READ_REG(hw
, IXGBE_PRC64
);
5785 hwstats
->prc127
+= IXGBE_READ_REG(hw
, IXGBE_PRC127
);
5786 hwstats
->prc255
+= IXGBE_READ_REG(hw
, IXGBE_PRC255
);
5787 hwstats
->prc511
+= IXGBE_READ_REG(hw
, IXGBE_PRC511
);
5788 hwstats
->prc1023
+= IXGBE_READ_REG(hw
, IXGBE_PRC1023
);
5789 hwstats
->prc1522
+= IXGBE_READ_REG(hw
, IXGBE_PRC1522
);
5790 hwstats
->rlec
+= IXGBE_READ_REG(hw
, IXGBE_RLEC
);
5791 lxon
= IXGBE_READ_REG(hw
, IXGBE_LXONTXC
);
5792 hwstats
->lxontxc
+= lxon
;
5793 lxoff
= IXGBE_READ_REG(hw
, IXGBE_LXOFFTXC
);
5794 hwstats
->lxofftxc
+= lxoff
;
5795 hwstats
->ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
5796 hwstats
->gptc
+= IXGBE_READ_REG(hw
, IXGBE_GPTC
);
5797 hwstats
->mptc
+= IXGBE_READ_REG(hw
, IXGBE_MPTC
);
5799 * 82598 errata - tx of flow control packets is included in tx counters
5801 xon_off_tot
= lxon
+ lxoff
;
5802 hwstats
->gptc
-= xon_off_tot
;
5803 hwstats
->mptc
-= xon_off_tot
;
5804 hwstats
->gotc
-= (xon_off_tot
* (ETH_ZLEN
+ ETH_FCS_LEN
));
5805 hwstats
->ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
5806 hwstats
->rfc
+= IXGBE_READ_REG(hw
, IXGBE_RFC
);
5807 hwstats
->rjc
+= IXGBE_READ_REG(hw
, IXGBE_RJC
);
5808 hwstats
->tpr
+= IXGBE_READ_REG(hw
, IXGBE_TPR
);
5809 hwstats
->ptc64
+= IXGBE_READ_REG(hw
, IXGBE_PTC64
);
5810 hwstats
->ptc64
-= xon_off_tot
;
5811 hwstats
->ptc127
+= IXGBE_READ_REG(hw
, IXGBE_PTC127
);
5812 hwstats
->ptc255
+= IXGBE_READ_REG(hw
, IXGBE_PTC255
);
5813 hwstats
->ptc511
+= IXGBE_READ_REG(hw
, IXGBE_PTC511
);
5814 hwstats
->ptc1023
+= IXGBE_READ_REG(hw
, IXGBE_PTC1023
);
5815 hwstats
->ptc1522
+= IXGBE_READ_REG(hw
, IXGBE_PTC1522
);
5816 hwstats
->bptc
+= IXGBE_READ_REG(hw
, IXGBE_BPTC
);
5818 /* Fill out the OS statistics structure */
5819 netdev
->stats
.multicast
= hwstats
->mprc
;
5822 netdev
->stats
.rx_errors
= hwstats
->crcerrs
+ hwstats
->rlec
;
5823 netdev
->stats
.rx_dropped
= 0;
5824 netdev
->stats
.rx_length_errors
= hwstats
->rlec
;
5825 netdev
->stats
.rx_crc_errors
= hwstats
->crcerrs
;
5826 netdev
->stats
.rx_missed_errors
= total_mpc
;
5830 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5831 * @adapter - pointer to the device adapter structure
5833 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter
*adapter
)
5835 struct ixgbe_hw
*hw
= &adapter
->hw
;
5838 if (!(adapter
->flags2
& IXGBE_FLAG2_FDIR_REQUIRES_REINIT
))
5841 adapter
->flags2
&= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
5843 /* if interface is down do nothing */
5844 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
5847 /* do nothing if we are not using signature filters */
5848 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
))
5851 adapter
->fdir_overflow
++;
5853 if (ixgbe_reinit_fdir_tables_82599(hw
) == 0) {
5854 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5855 set_bit(__IXGBE_TX_FDIR_INIT_DONE
,
5856 &(adapter
->tx_ring
[i
]->state
));
5857 /* re-enable flow director interrupts */
5858 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMS_FLOW_DIR
);
5860 e_err(probe
, "failed to finish FDIR re-initialization, "
5861 "ignored adding FDIR ATR filters\n");
5866 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5867 * @adapter - pointer to the device adapter structure
5869 * This function serves two purposes. First it strobes the interrupt lines
5870 * in order to make certain interrupts are occuring. Secondly it sets the
5871 * bits needed to check for TX hangs. As a result we should immediately
5872 * determine if a hang has occured.
5874 static void ixgbe_check_hang_subtask(struct ixgbe_adapter
*adapter
)
5876 struct ixgbe_hw
*hw
= &adapter
->hw
;
5880 /* If we're down or resetting, just bail */
5881 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
5882 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
5885 /* Force detection of hung controller */
5886 if (netif_carrier_ok(adapter
->netdev
)) {
5887 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5888 set_check_for_tx_hang(adapter
->tx_ring
[i
]);
5891 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
5893 * for legacy and MSI interrupts don't set any bits
5894 * that are enabled for EIAM, because this operation
5895 * would set *both* EIMS and EICS for any bit in EIAM
5897 IXGBE_WRITE_REG(hw
, IXGBE_EICS
,
5898 (IXGBE_EICS_TCP_TIMER
| IXGBE_EICS_OTHER
));
5900 /* get one bit for every active tx/rx interrupt vector */
5901 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
5902 struct ixgbe_q_vector
*qv
= adapter
->q_vector
[i
];
5903 if (qv
->rx
.count
|| qv
->tx
.count
)
5904 eics
|= ((u64
)1 << i
);
5908 /* Cause software interrupt to ensure rings are cleaned */
5909 ixgbe_irq_rearm_queues(adapter
, eics
);
5914 * ixgbe_watchdog_update_link - update the link status
5915 * @adapter - pointer to the device adapter structure
5916 * @link_speed - pointer to a u32 to store the link_speed
5918 static void ixgbe_watchdog_update_link(struct ixgbe_adapter
*adapter
)
5920 struct ixgbe_hw
*hw
= &adapter
->hw
;
5921 u32 link_speed
= adapter
->link_speed
;
5922 bool link_up
= adapter
->link_up
;
5925 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
))
5928 if (hw
->mac
.ops
.check_link
) {
5929 hw
->mac
.ops
.check_link(hw
, &link_speed
, &link_up
, false);
5931 /* always assume link is up, if no check link function */
5932 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
5936 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
5937 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++)
5938 hw
->mac
.ops
.fc_enable(hw
, i
);
5940 hw
->mac
.ops
.fc_enable(hw
, 0);
5945 time_after(jiffies
, (adapter
->link_check_timeout
+
5946 IXGBE_TRY_LINK_TIMEOUT
))) {
5947 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
5948 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMC_LSC
);
5949 IXGBE_WRITE_FLUSH(hw
);
5952 adapter
->link_up
= link_up
;
5953 adapter
->link_speed
= link_speed
;
5957 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5958 * print link up message
5959 * @adapter - pointer to the device adapter structure
5961 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter
*adapter
)
5963 struct net_device
*netdev
= adapter
->netdev
;
5964 struct ixgbe_hw
*hw
= &adapter
->hw
;
5965 u32 link_speed
= adapter
->link_speed
;
5966 bool flow_rx
, flow_tx
;
5968 /* only continue if link was previously down */
5969 if (netif_carrier_ok(netdev
))
5972 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
5974 switch (hw
->mac
.type
) {
5975 case ixgbe_mac_82598EB
: {
5976 u32 frctl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
5977 u32 rmcs
= IXGBE_READ_REG(hw
, IXGBE_RMCS
);
5978 flow_rx
= !!(frctl
& IXGBE_FCTRL_RFCE
);
5979 flow_tx
= !!(rmcs
& IXGBE_RMCS_TFCE_802_3X
);
5982 case ixgbe_mac_X540
:
5983 case ixgbe_mac_82599EB
: {
5984 u32 mflcn
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
5985 u32 fccfg
= IXGBE_READ_REG(hw
, IXGBE_FCCFG
);
5986 flow_rx
= !!(mflcn
& IXGBE_MFLCN_RFCE
);
5987 flow_tx
= !!(fccfg
& IXGBE_FCCFG_TFCE_802_3X
);
5995 e_info(drv
, "NIC Link is Up %s, Flow Control: %s\n",
5996 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
?
5998 (link_speed
== IXGBE_LINK_SPEED_1GB_FULL
?
6000 (link_speed
== IXGBE_LINK_SPEED_100_FULL
?
6003 ((flow_rx
&& flow_tx
) ? "RX/TX" :
6005 (flow_tx
? "TX" : "None"))));
6007 netif_carrier_on(netdev
);
6008 ixgbe_check_vf_rate_limit(adapter
);
6012 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6013 * print link down message
6014 * @adapter - pointer to the adapter structure
6016 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter
* adapter
)
6018 struct net_device
*netdev
= adapter
->netdev
;
6019 struct ixgbe_hw
*hw
= &adapter
->hw
;
6021 adapter
->link_up
= false;
6022 adapter
->link_speed
= 0;
6024 /* only continue if link was up previously */
6025 if (!netif_carrier_ok(netdev
))
6028 /* poll for SFP+ cable when link is down */
6029 if (ixgbe_is_sfp(hw
) && hw
->mac
.type
== ixgbe_mac_82598EB
)
6030 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
6032 e_info(drv
, "NIC Link is Down\n");
6033 netif_carrier_off(netdev
);
6037 * ixgbe_watchdog_flush_tx - flush queues on link down
6038 * @adapter - pointer to the device adapter structure
6040 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter
*adapter
)
6043 int some_tx_pending
= 0;
6045 if (!netif_carrier_ok(adapter
->netdev
)) {
6046 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
6047 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
6048 if (tx_ring
->next_to_use
!= tx_ring
->next_to_clean
) {
6049 some_tx_pending
= 1;
6054 if (some_tx_pending
) {
6055 /* We've lost link, so the controller stops DMA,
6056 * but we've got queued Tx work that's never going
6057 * to get done, so reset controller to flush Tx.
6058 * (Do the reset outside of interrupt context).
6060 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
6065 static void ixgbe_spoof_check(struct ixgbe_adapter
*adapter
)
6069 /* Do not perform spoof check for 82598 */
6070 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
6073 ssvpc
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SSVPC
);
6076 * ssvpc register is cleared on read, if zero then no
6077 * spoofed packets in the last interval.
6082 e_warn(drv
, "%d Spoofed packets detected\n", ssvpc
);
6086 * ixgbe_watchdog_subtask - check and bring link up
6087 * @adapter - pointer to the device adapter structure
6089 static void ixgbe_watchdog_subtask(struct ixgbe_adapter
*adapter
)
6091 /* if interface is down do nothing */
6092 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
6095 ixgbe_watchdog_update_link(adapter
);
6097 if (adapter
->link_up
)
6098 ixgbe_watchdog_link_is_up(adapter
);
6100 ixgbe_watchdog_link_is_down(adapter
);
6102 ixgbe_spoof_check(adapter
);
6103 ixgbe_update_stats(adapter
);
6105 ixgbe_watchdog_flush_tx(adapter
);
6109 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6110 * @adapter - the ixgbe adapter structure
6112 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter
*adapter
)
6114 struct ixgbe_hw
*hw
= &adapter
->hw
;
6117 /* not searching for SFP so there is nothing to do here */
6118 if (!(adapter
->flags2
& IXGBE_FLAG2_SEARCH_FOR_SFP
) &&
6119 !(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
6122 /* someone else is in init, wait until next service event */
6123 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
6126 err
= hw
->phy
.ops
.identify_sfp(hw
);
6127 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
6130 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
) {
6131 /* If no cable is present, then we need to reset
6132 * the next time we find a good cable. */
6133 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
6140 /* exit if reset not needed */
6141 if (!(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
6144 adapter
->flags2
&= ~IXGBE_FLAG2_SFP_NEEDS_RESET
;
6147 * A module may be identified correctly, but the EEPROM may not have
6148 * support for that module. setup_sfp() will fail in that case, so
6149 * we should not allow that module to load.
6151 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
6152 err
= hw
->phy
.ops
.reset(hw
);
6154 err
= hw
->mac
.ops
.setup_sfp(hw
);
6156 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
6159 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
6160 e_info(probe
, "detected SFP+: %d\n", hw
->phy
.sfp_type
);
6163 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
6165 if ((err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) &&
6166 (adapter
->netdev
->reg_state
== NETREG_REGISTERED
)) {
6167 e_dev_err("failed to initialize because an unsupported "
6168 "SFP+ module type was detected.\n");
6169 e_dev_err("Reload the driver after installing a "
6170 "supported module.\n");
6171 unregister_netdev(adapter
->netdev
);
6176 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6177 * @adapter - the ixgbe adapter structure
6179 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter
*adapter
)
6181 struct ixgbe_hw
*hw
= &adapter
->hw
;
6185 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_CONFIG
))
6188 /* someone else is in init, wait until next service event */
6189 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
6192 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
6194 autoneg
= hw
->phy
.autoneg_advertised
;
6195 if ((!autoneg
) && (hw
->mac
.ops
.get_link_capabilities
))
6196 hw
->mac
.ops
.get_link_capabilities(hw
, &autoneg
, &negotiation
);
6197 hw
->mac
.autotry_restart
= false;
6198 if (hw
->mac
.ops
.setup_link
)
6199 hw
->mac
.ops
.setup_link(hw
, autoneg
, negotiation
, true);
6201 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
6202 adapter
->link_check_timeout
= jiffies
;
6203 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
6207 * ixgbe_service_timer - Timer Call-back
6208 * @data: pointer to adapter cast into an unsigned long
6210 static void ixgbe_service_timer(unsigned long data
)
6212 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
6213 unsigned long next_event_offset
;
6215 /* poll faster when waiting for link */
6216 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
)
6217 next_event_offset
= HZ
/ 10;
6219 next_event_offset
= HZ
* 2;
6221 /* Reset the timer */
6222 mod_timer(&adapter
->service_timer
, next_event_offset
+ jiffies
);
6224 ixgbe_service_event_schedule(adapter
);
6227 static void ixgbe_reset_subtask(struct ixgbe_adapter
*adapter
)
6229 if (!(adapter
->flags2
& IXGBE_FLAG2_RESET_REQUESTED
))
6232 adapter
->flags2
&= ~IXGBE_FLAG2_RESET_REQUESTED
;
6234 /* If we're already down or resetting, just bail */
6235 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
6236 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
6239 ixgbe_dump(adapter
);
6240 netdev_err(adapter
->netdev
, "Reset adapter\n");
6241 adapter
->tx_timeout_count
++;
6243 ixgbe_reinit_locked(adapter
);
6247 * ixgbe_service_task - manages and runs subtasks
6248 * @work: pointer to work_struct containing our data
6250 static void ixgbe_service_task(struct work_struct
*work
)
6252 struct ixgbe_adapter
*adapter
= container_of(work
,
6253 struct ixgbe_adapter
,
6256 ixgbe_reset_subtask(adapter
);
6257 ixgbe_sfp_detection_subtask(adapter
);
6258 ixgbe_sfp_link_config_subtask(adapter
);
6259 ixgbe_check_overtemp_subtask(adapter
);
6260 ixgbe_watchdog_subtask(adapter
);
6261 ixgbe_fdir_reinit_subtask(adapter
);
6262 ixgbe_check_hang_subtask(adapter
);
6264 ixgbe_service_event_complete(adapter
);
6267 void ixgbe_tx_ctxtdesc(struct ixgbe_ring
*tx_ring
, u32 vlan_macip_lens
,
6268 u32 fcoe_sof_eof
, u32 type_tucmd
, u32 mss_l4len_idx
)
6270 struct ixgbe_adv_tx_context_desc
*context_desc
;
6271 u16 i
= tx_ring
->next_to_use
;
6273 context_desc
= IXGBE_TX_CTXTDESC_ADV(tx_ring
, i
);
6276 tx_ring
->next_to_use
= (i
< tx_ring
->count
) ? i
: 0;
6278 /* set bits to identify this as an advanced context descriptor */
6279 type_tucmd
|= IXGBE_TXD_CMD_DEXT
| IXGBE_ADVTXD_DTYP_CTXT
;
6281 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
6282 context_desc
->seqnum_seed
= cpu_to_le32(fcoe_sof_eof
);
6283 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd
);
6284 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
6287 static int ixgbe_tso(struct ixgbe_ring
*tx_ring
, struct sk_buff
*skb
,
6288 u32 tx_flags
, __be16 protocol
, u8
*hdr_len
)
6291 u32 vlan_macip_lens
, type_tucmd
;
6292 u32 mss_l4len_idx
, l4len
;
6294 if (!skb_is_gso(skb
))
6297 if (skb_header_cloned(skb
)) {
6298 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
6303 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6304 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
6306 if (protocol
== __constant_htons(ETH_P_IP
)) {
6307 struct iphdr
*iph
= ip_hdr(skb
);
6310 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
6314 type_tucmd
|= IXGBE_ADVTXD_TUCMD_IPV4
;
6315 } else if (skb_is_gso_v6(skb
)) {
6316 ipv6_hdr(skb
)->payload_len
= 0;
6317 tcp_hdr(skb
)->check
=
6318 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
6319 &ipv6_hdr(skb
)->daddr
,
6323 l4len
= tcp_hdrlen(skb
);
6324 *hdr_len
= skb_transport_offset(skb
) + l4len
;
6326 /* mss_l4len_id: use 1 as index for TSO */
6327 mss_l4len_idx
= l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
;
6328 mss_l4len_idx
|= skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
;
6329 mss_l4len_idx
|= 1 << IXGBE_ADVTXD_IDX_SHIFT
;
6331 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6332 vlan_macip_lens
= skb_network_header_len(skb
);
6333 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
6334 vlan_macip_lens
|= tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
6336 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, 0, type_tucmd
,
6342 static bool ixgbe_tx_csum(struct ixgbe_ring
*tx_ring
,
6343 struct sk_buff
*skb
, u32 tx_flags
,
6346 u32 vlan_macip_lens
= 0;
6347 u32 mss_l4len_idx
= 0;
6350 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
) {
6351 if (!(tx_flags
& IXGBE_TX_FLAGS_VLAN
))
6356 case __constant_htons(ETH_P_IP
):
6357 vlan_macip_lens
|= skb_network_header_len(skb
);
6358 type_tucmd
|= IXGBE_ADVTXD_TUCMD_IPV4
;
6359 l4_hdr
= ip_hdr(skb
)->protocol
;
6361 case __constant_htons(ETH_P_IPV6
):
6362 vlan_macip_lens
|= skb_network_header_len(skb
);
6363 l4_hdr
= ipv6_hdr(skb
)->nexthdr
;
6366 if (unlikely(net_ratelimit())) {
6367 dev_warn(tx_ring
->dev
,
6368 "partial checksum but proto=%x!\n",
6376 type_tucmd
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
6377 mss_l4len_idx
= tcp_hdrlen(skb
) <<
6378 IXGBE_ADVTXD_L4LEN_SHIFT
;
6381 type_tucmd
|= IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
6382 mss_l4len_idx
= sizeof(struct sctphdr
) <<
6383 IXGBE_ADVTXD_L4LEN_SHIFT
;
6386 mss_l4len_idx
= sizeof(struct udphdr
) <<
6387 IXGBE_ADVTXD_L4LEN_SHIFT
;
6390 if (unlikely(net_ratelimit())) {
6391 dev_warn(tx_ring
->dev
,
6392 "partial checksum but l4 proto=%x!\n",
6399 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
6400 vlan_macip_lens
|= tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
6402 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, 0,
6403 type_tucmd
, mss_l4len_idx
);
6405 return (skb
->ip_summed
== CHECKSUM_PARTIAL
);
6408 static int ixgbe_tx_map(struct ixgbe_adapter
*adapter
,
6409 struct ixgbe_ring
*tx_ring
,
6410 struct sk_buff
*skb
, u32 tx_flags
,
6411 unsigned int first
, const u8 hdr_len
)
6413 struct device
*dev
= tx_ring
->dev
;
6414 struct ixgbe_tx_buffer
*tx_buffer_info
;
6416 unsigned int total
= skb
->len
;
6417 unsigned int offset
= 0, size
, count
= 0;
6418 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
6420 unsigned int bytecount
= skb
->len
;
6424 i
= tx_ring
->next_to_use
;
6426 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
)
6427 /* excluding fcoe_crc_eof for FCoE */
6428 total
-= sizeof(struct fcoe_crc_eof
);
6430 len
= min(skb_headlen(skb
), total
);
6432 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
6433 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
6435 tx_buffer_info
->length
= size
;
6436 tx_buffer_info
->mapped_as_page
= false;
6437 tx_buffer_info
->dma
= dma_map_single(dev
,
6439 size
, DMA_TO_DEVICE
);
6440 if (dma_mapping_error(dev
, tx_buffer_info
->dma
))
6442 tx_buffer_info
->time_stamp
= jiffies
;
6443 tx_buffer_info
->next_to_watch
= i
;
6452 if (i
== tx_ring
->count
)
6457 for (f
= 0; f
< nr_frags
; f
++) {
6458 struct skb_frag_struct
*frag
;
6460 frag
= &skb_shinfo(skb
)->frags
[f
];
6461 len
= min((unsigned int)frag
->size
, total
);
6462 offset
= frag
->page_offset
;
6466 if (i
== tx_ring
->count
)
6469 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
6470 size
= min(len
, (uint
)IXGBE_MAX_DATA_PER_TXD
);
6472 tx_buffer_info
->length
= size
;
6473 tx_buffer_info
->dma
= dma_map_page(dev
,
6477 tx_buffer_info
->mapped_as_page
= true;
6478 if (dma_mapping_error(dev
, tx_buffer_info
->dma
))
6480 tx_buffer_info
->time_stamp
= jiffies
;
6481 tx_buffer_info
->next_to_watch
= i
;
6492 if (tx_flags
& IXGBE_TX_FLAGS_TSO
)
6493 gso_segs
= skb_shinfo(skb
)->gso_segs
;
6495 /* adjust for FCoE Sequence Offload */
6496 else if (tx_flags
& IXGBE_TX_FLAGS_FSO
)
6497 gso_segs
= DIV_ROUND_UP(skb
->len
- hdr_len
,
6498 skb_shinfo(skb
)->gso_size
);
6499 #endif /* IXGBE_FCOE */
6500 bytecount
+= (gso_segs
- 1) * hdr_len
;
6502 /* multiply data chunks by size of headers */
6503 tx_ring
->tx_buffer_info
[i
].bytecount
= bytecount
;
6504 tx_ring
->tx_buffer_info
[i
].gso_segs
= gso_segs
;
6505 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
6506 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
6511 e_dev_err("TX DMA map failed\n");
6513 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6514 tx_buffer_info
->dma
= 0;
6515 tx_buffer_info
->time_stamp
= 0;
6516 tx_buffer_info
->next_to_watch
= 0;
6520 /* clear timestamp and dma mappings for remaining portion of packet */
6523 i
+= tx_ring
->count
;
6525 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
6526 ixgbe_unmap_and_free_tx_resource(tx_ring
, tx_buffer_info
);
6532 static void ixgbe_tx_queue(struct ixgbe_ring
*tx_ring
,
6533 int tx_flags
, int count
, u32 paylen
, u8 hdr_len
)
6535 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
6536 struct ixgbe_tx_buffer
*tx_buffer_info
;
6537 u32 olinfo_status
= 0, cmd_type_len
= 0;
6539 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
6541 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
6543 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
6545 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
6546 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
6548 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
6549 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
6551 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
6552 IXGBE_ADVTXD_POPTS_SHIFT
;
6554 /* use index 1 context for tso */
6555 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
6556 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
6557 olinfo_status
|= IXGBE_TXD_POPTS_IXSM
<<
6558 IXGBE_ADVTXD_POPTS_SHIFT
;
6560 } else if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
6561 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
6562 IXGBE_ADVTXD_POPTS_SHIFT
;
6564 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
6565 olinfo_status
|= IXGBE_ADVTXD_CC
;
6566 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
6567 if (tx_flags
& IXGBE_TX_FLAGS_FSO
)
6568 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
6571 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
6573 i
= tx_ring
->next_to_use
;
6575 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
6576 tx_desc
= IXGBE_TX_DESC_ADV(tx_ring
, i
);
6577 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
6578 tx_desc
->read
.cmd_type_len
=
6579 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
6580 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
6582 if (i
== tx_ring
->count
)
6586 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
6589 * Force memory writes to complete before letting h/w
6590 * know there are new descriptors to fetch. (Only
6591 * applicable for weak-ordered memory model archs,
6596 tx_ring
->next_to_use
= i
;
6597 writel(i
, tx_ring
->tail
);
6600 static void ixgbe_atr(struct ixgbe_ring
*ring
, struct sk_buff
*skb
,
6601 u32 tx_flags
, __be16 protocol
)
6603 struct ixgbe_q_vector
*q_vector
= ring
->q_vector
;
6604 union ixgbe_atr_hash_dword input
= { .dword
= 0 };
6605 union ixgbe_atr_hash_dword common
= { .dword
= 0 };
6607 unsigned char *network
;
6609 struct ipv6hdr
*ipv6
;
6614 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6618 /* do nothing if sampling is disabled */
6619 if (!ring
->atr_sample_rate
)
6624 /* snag network header to get L4 type and address */
6625 hdr
.network
= skb_network_header(skb
);
6627 /* Currently only IPv4/IPv6 with TCP is supported */
6628 if ((protocol
!= __constant_htons(ETH_P_IPV6
) ||
6629 hdr
.ipv6
->nexthdr
!= IPPROTO_TCP
) &&
6630 (protocol
!= __constant_htons(ETH_P_IP
) ||
6631 hdr
.ipv4
->protocol
!= IPPROTO_TCP
))
6636 /* skip this packet since the socket is closing */
6640 /* sample on all syn packets or once every atr sample count */
6641 if (!th
->syn
&& (ring
->atr_count
< ring
->atr_sample_rate
))
6644 /* reset sample count */
6645 ring
->atr_count
= 0;
6647 vlan_id
= htons(tx_flags
>> IXGBE_TX_FLAGS_VLAN_SHIFT
);
6650 * src and dst are inverted, think how the receiver sees them
6652 * The input is broken into two sections, a non-compressed section
6653 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6654 * is XORed together and stored in the compressed dword.
6656 input
.formatted
.vlan_id
= vlan_id
;
6659 * since src port and flex bytes occupy the same word XOR them together
6660 * and write the value to source port portion of compressed dword
6663 common
.port
.src
^= th
->dest
^ __constant_htons(ETH_P_8021Q
);
6665 common
.port
.src
^= th
->dest
^ protocol
;
6666 common
.port
.dst
^= th
->source
;
6668 if (protocol
== __constant_htons(ETH_P_IP
)) {
6669 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV4
;
6670 common
.ip
^= hdr
.ipv4
->saddr
^ hdr
.ipv4
->daddr
;
6672 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV6
;
6673 common
.ip
^= hdr
.ipv6
->saddr
.s6_addr32
[0] ^
6674 hdr
.ipv6
->saddr
.s6_addr32
[1] ^
6675 hdr
.ipv6
->saddr
.s6_addr32
[2] ^
6676 hdr
.ipv6
->saddr
.s6_addr32
[3] ^
6677 hdr
.ipv6
->daddr
.s6_addr32
[0] ^
6678 hdr
.ipv6
->daddr
.s6_addr32
[1] ^
6679 hdr
.ipv6
->daddr
.s6_addr32
[2] ^
6680 hdr
.ipv6
->daddr
.s6_addr32
[3];
6683 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
6684 ixgbe_fdir_add_signature_filter_82599(&q_vector
->adapter
->hw
,
6685 input
, common
, ring
->queue_index
);
6688 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
6690 netif_stop_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
6691 /* Herbert's original patch had:
6692 * smp_mb__after_netif_stop_queue();
6693 * but since that doesn't exist yet, just open code it. */
6696 /* We need to check again in a case another CPU has just
6697 * made room available. */
6698 if (likely(ixgbe_desc_unused(tx_ring
) < size
))
6701 /* A reprieve! - use start_queue because it doesn't call schedule */
6702 netif_start_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
6703 ++tx_ring
->tx_stats
.restart_queue
;
6707 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
6709 if (likely(ixgbe_desc_unused(tx_ring
) >= size
))
6711 return __ixgbe_maybe_stop_tx(tx_ring
, size
);
6714 static u16
ixgbe_select_queue(struct net_device
*dev
, struct sk_buff
*skb
)
6716 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
6717 int txq
= skb_rx_queue_recorded(skb
) ? skb_get_rx_queue(skb
) :
6720 __be16 protocol
= vlan_get_protocol(skb
);
6722 if (((protocol
== htons(ETH_P_FCOE
)) ||
6723 (protocol
== htons(ETH_P_FIP
))) &&
6724 (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)) {
6725 txq
&= (adapter
->ring_feature
[RING_F_FCOE
].indices
- 1);
6726 txq
+= adapter
->ring_feature
[RING_F_FCOE
].mask
;
6731 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
6732 while (unlikely(txq
>= dev
->real_num_tx_queues
))
6733 txq
-= dev
->real_num_tx_queues
;
6737 return skb_tx_hash(dev
, skb
);
6740 netdev_tx_t
ixgbe_xmit_frame_ring(struct sk_buff
*skb
,
6741 struct ixgbe_adapter
*adapter
,
6742 struct ixgbe_ring
*tx_ring
)
6746 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6750 u16 count
= TXD_USE_COUNT(skb_headlen(skb
));
6755 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6756 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6757 * + 2 desc gap to keep tail from touching head,
6758 * + 1 desc for context descriptor,
6759 * otherwise try next time
6761 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6762 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
6763 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
6765 count
+= skb_shinfo(skb
)->nr_frags
;
6767 if (ixgbe_maybe_stop_tx(tx_ring
, count
+ 3)) {
6768 tx_ring
->tx_stats
.tx_busy
++;
6769 return NETDEV_TX_BUSY
;
6772 protocol
= vlan_get_protocol(skb
);
6774 if (vlan_tx_tag_present(skb
)) {
6775 tx_flags
|= vlan_tx_tag_get(skb
);
6776 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) {
6777 tx_flags
&= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK
;
6778 tx_flags
|= tx_ring
->dcb_tc
<< 13;
6780 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
6781 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
6782 } else if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
&&
6783 skb
->priority
!= TC_PRIO_CONTROL
) {
6784 tx_flags
|= tx_ring
->dcb_tc
<< 13;
6785 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
6786 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
6790 /* for FCoE with DCB, we force the priority to what
6791 * was specified by the switch */
6792 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
&&
6793 (protocol
== htons(ETH_P_FCOE
)))
6794 tx_flags
|= IXGBE_TX_FLAGS_FCOE
;
6797 /* record the location of the first descriptor for this packet */
6798 first
= tx_ring
->next_to_use
;
6800 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
6802 /* setup tx offload for FCoE */
6803 tso
= ixgbe_fso(tx_ring
, skb
, tx_flags
, &hdr_len
);
6807 tx_flags
|= IXGBE_TX_FLAGS_FSO
;
6808 #endif /* IXGBE_FCOE */
6810 if (protocol
== htons(ETH_P_IP
))
6811 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
6812 tso
= ixgbe_tso(tx_ring
, skb
, tx_flags
, protocol
, &hdr_len
);
6816 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
6817 else if (ixgbe_tx_csum(tx_ring
, skb
, tx_flags
, protocol
))
6818 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
6821 count
= ixgbe_tx_map(adapter
, tx_ring
, skb
, tx_flags
, first
, hdr_len
);
6823 /* add the ATR filter if ATR is on */
6824 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE
, &tx_ring
->state
))
6825 ixgbe_atr(tx_ring
, skb
, tx_flags
, protocol
);
6826 ixgbe_tx_queue(tx_ring
, tx_flags
, count
, skb
->len
, hdr_len
);
6827 ixgbe_maybe_stop_tx(tx_ring
, DESC_NEEDED
);
6830 tx_ring
->tx_buffer_info
[first
].time_stamp
= 0;
6831 tx_ring
->next_to_use
= first
;
6835 return NETDEV_TX_OK
;
6838 dev_kfree_skb_any(skb
);
6839 return NETDEV_TX_OK
;
6842 static netdev_tx_t
ixgbe_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
6844 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6845 struct ixgbe_ring
*tx_ring
;
6847 tx_ring
= adapter
->tx_ring
[skb
->queue_mapping
];
6848 return ixgbe_xmit_frame_ring(skb
, adapter
, tx_ring
);
6852 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6853 * @netdev: network interface device structure
6854 * @p: pointer to an address structure
6856 * Returns 0 on success, negative on failure
6858 static int ixgbe_set_mac(struct net_device
*netdev
, void *p
)
6860 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6861 struct ixgbe_hw
*hw
= &adapter
->hw
;
6862 struct sockaddr
*addr
= p
;
6864 if (!is_valid_ether_addr(addr
->sa_data
))
6865 return -EADDRNOTAVAIL
;
6867 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
6868 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
6870 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, adapter
->num_vfs
,
6877 ixgbe_mdio_read(struct net_device
*netdev
, int prtad
, int devad
, u16 addr
)
6879 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6880 struct ixgbe_hw
*hw
= &adapter
->hw
;
6884 if (prtad
!= hw
->phy
.mdio
.prtad
)
6886 rc
= hw
->phy
.ops
.read_reg(hw
, addr
, devad
, &value
);
6892 static int ixgbe_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
6893 u16 addr
, u16 value
)
6895 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6896 struct ixgbe_hw
*hw
= &adapter
->hw
;
6898 if (prtad
!= hw
->phy
.mdio
.prtad
)
6900 return hw
->phy
.ops
.write_reg(hw
, addr
, devad
, value
);
6903 static int ixgbe_ioctl(struct net_device
*netdev
, struct ifreq
*req
, int cmd
)
6905 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6907 return mdio_mii_ioctl(&adapter
->hw
.phy
.mdio
, if_mii(req
), cmd
);
6911 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6913 * @netdev: network interface device structure
6915 * Returns non-zero on failure
6917 static int ixgbe_add_sanmac_netdev(struct net_device
*dev
)
6920 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
6921 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
6923 if (is_valid_ether_addr(mac
->san_addr
)) {
6925 err
= dev_addr_add(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
6932 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6934 * @netdev: network interface device structure
6936 * Returns non-zero on failure
6938 static int ixgbe_del_sanmac_netdev(struct net_device
*dev
)
6941 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
6942 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
6944 if (is_valid_ether_addr(mac
->san_addr
)) {
6946 err
= dev_addr_del(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
6952 #ifdef CONFIG_NET_POLL_CONTROLLER
6954 * Polling 'interrupt' - used by things like netconsole to send skbs
6955 * without having to re-enable interrupts. It's not called while
6956 * the interrupt routine is executing.
6958 static void ixgbe_netpoll(struct net_device
*netdev
)
6960 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6963 /* if interface is down do nothing */
6964 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
6967 adapter
->flags
|= IXGBE_FLAG_IN_NETPOLL
;
6968 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
6969 int num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
6970 for (i
= 0; i
< num_q_vectors
; i
++) {
6971 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[i
];
6972 ixgbe_msix_clean_many(0, q_vector
);
6975 ixgbe_intr(adapter
->pdev
->irq
, netdev
);
6977 adapter
->flags
&= ~IXGBE_FLAG_IN_NETPOLL
;
6981 static struct rtnl_link_stats64
*ixgbe_get_stats64(struct net_device
*netdev
,
6982 struct rtnl_link_stats64
*stats
)
6984 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6988 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
6989 struct ixgbe_ring
*ring
= ACCESS_ONCE(adapter
->rx_ring
[i
]);
6995 start
= u64_stats_fetch_begin_bh(&ring
->syncp
);
6996 packets
= ring
->stats
.packets
;
6997 bytes
= ring
->stats
.bytes
;
6998 } while (u64_stats_fetch_retry_bh(&ring
->syncp
, start
));
6999 stats
->rx_packets
+= packets
;
7000 stats
->rx_bytes
+= bytes
;
7004 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
7005 struct ixgbe_ring
*ring
= ACCESS_ONCE(adapter
->tx_ring
[i
]);
7011 start
= u64_stats_fetch_begin_bh(&ring
->syncp
);
7012 packets
= ring
->stats
.packets
;
7013 bytes
= ring
->stats
.bytes
;
7014 } while (u64_stats_fetch_retry_bh(&ring
->syncp
, start
));
7015 stats
->tx_packets
+= packets
;
7016 stats
->tx_bytes
+= bytes
;
7020 /* following stats updated by ixgbe_watchdog_task() */
7021 stats
->multicast
= netdev
->stats
.multicast
;
7022 stats
->rx_errors
= netdev
->stats
.rx_errors
;
7023 stats
->rx_length_errors
= netdev
->stats
.rx_length_errors
;
7024 stats
->rx_crc_errors
= netdev
->stats
.rx_crc_errors
;
7025 stats
->rx_missed_errors
= netdev
->stats
.rx_missed_errors
;
7029 /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7030 * #adapter: pointer to ixgbe_adapter
7031 * @tc: number of traffic classes currently enabled
7033 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7034 * 802.1Q priority maps to a packet buffer that exists.
7036 static void ixgbe_validate_rtr(struct ixgbe_adapter
*adapter
, u8 tc
)
7038 struct ixgbe_hw
*hw
= &adapter
->hw
;
7042 /* 82598 have a static priority to TC mapping that can not
7043 * be changed so no validation is needed.
7045 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
7048 reg
= IXGBE_READ_REG(hw
, IXGBE_RTRUP2TC
);
7051 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
7052 u8 up2tc
= reg
>> (i
* IXGBE_RTRUP2TC_UP_SHIFT
);
7054 /* If up2tc is out of bounds default to zero */
7056 reg
&= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT
);
7060 IXGBE_WRITE_REG(hw
, IXGBE_RTRUP2TC
, reg
);
7066 /* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7069 * @netdev: net device to configure
7070 * @tc: number of traffic classes to enable
7072 int ixgbe_setup_tc(struct net_device
*dev
, u8 tc
)
7074 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
7075 struct ixgbe_hw
*hw
= &adapter
->hw
;
7077 /* If DCB is anabled do not remove traffic classes, multiple
7078 * traffic classes are required to implement DCB
7080 if (!tc
&& (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
))
7083 /* Hardware supports up to 8 traffic classes */
7084 if (tc
> MAX_TRAFFIC_CLASS
||
7085 (hw
->mac
.type
== ixgbe_mac_82598EB
&& tc
< MAX_TRAFFIC_CLASS
))
7088 /* Hardware has to reinitialize queues and interrupts to
7089 * match packet buffer alignment. Unfortunantly, the
7090 * hardware is not flexible enough to do this dynamically.
7092 if (netif_running(dev
))
7094 ixgbe_clear_interrupt_scheme(adapter
);
7097 netdev_set_num_tc(dev
, tc
);
7099 netdev_reset_tc(dev
);
7101 ixgbe_init_interrupt_scheme(adapter
);
7102 ixgbe_validate_rtr(adapter
, tc
);
7103 if (netif_running(dev
))
7109 void ixgbe_do_reset(struct net_device
*netdev
)
7111 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7113 if (netif_running(netdev
))
7114 ixgbe_reinit_locked(adapter
);
7116 ixgbe_reset(adapter
);
7119 static u32
ixgbe_fix_features(struct net_device
*netdev
, u32 data
)
7121 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7124 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
7125 data
&= ~NETIF_F_HW_VLAN_RX
;
7128 /* return error if RXHASH is being enabled when RSS is not supported */
7129 if (!(adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
))
7130 data
&= ~NETIF_F_RXHASH
;
7132 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7133 if (!(data
& NETIF_F_RXCSUM
))
7134 data
&= ~NETIF_F_LRO
;
7136 /* Turn off LRO if not RSC capable or invalid ITR settings */
7137 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
)) {
7138 data
&= ~NETIF_F_LRO
;
7139 } else if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) &&
7140 (adapter
->rx_itr_setting
!= 1 &&
7141 adapter
->rx_itr_setting
> IXGBE_MAX_RSC_INT_RATE
)) {
7142 data
&= ~NETIF_F_LRO
;
7143 e_info(probe
, "rx-usecs set too low, not enabling RSC\n");
7149 static int ixgbe_set_features(struct net_device
*netdev
, u32 data
)
7151 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7152 bool need_reset
= false;
7154 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7155 if (!(data
& NETIF_F_RXCSUM
))
7156 adapter
->flags
&= ~IXGBE_FLAG_RX_CSUM_ENABLED
;
7158 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
7160 /* Make sure RSC matches LRO, reset if change */
7161 if (!!(data
& NETIF_F_LRO
) !=
7162 !!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)) {
7163 adapter
->flags2
^= IXGBE_FLAG2_RSC_ENABLED
;
7164 switch (adapter
->hw
.mac
.type
) {
7165 case ixgbe_mac_X540
:
7166 case ixgbe_mac_82599EB
:
7175 * Check if Flow Director n-tuple support was enabled or disabled. If
7176 * the state changed, we need to reset.
7178 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)) {
7179 /* turn off ATR, enable perfect filters and reset */
7180 if (data
& NETIF_F_NTUPLE
) {
7181 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
7182 adapter
->flags
|= IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
7185 } else if (!(data
& NETIF_F_NTUPLE
)) {
7186 /* turn off Flow Director, set ATR and reset */
7187 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
7188 if ((adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
) &&
7189 !(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
))
7190 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
7195 ixgbe_do_reset(netdev
);
7201 static const struct net_device_ops ixgbe_netdev_ops
= {
7202 .ndo_open
= ixgbe_open
,
7203 .ndo_stop
= ixgbe_close
,
7204 .ndo_start_xmit
= ixgbe_xmit_frame
,
7205 .ndo_select_queue
= ixgbe_select_queue
,
7206 .ndo_set_rx_mode
= ixgbe_set_rx_mode
,
7207 .ndo_set_multicast_list
= ixgbe_set_rx_mode
,
7208 .ndo_validate_addr
= eth_validate_addr
,
7209 .ndo_set_mac_address
= ixgbe_set_mac
,
7210 .ndo_change_mtu
= ixgbe_change_mtu
,
7211 .ndo_tx_timeout
= ixgbe_tx_timeout
,
7212 .ndo_vlan_rx_add_vid
= ixgbe_vlan_rx_add_vid
,
7213 .ndo_vlan_rx_kill_vid
= ixgbe_vlan_rx_kill_vid
,
7214 .ndo_do_ioctl
= ixgbe_ioctl
,
7215 .ndo_set_vf_mac
= ixgbe_ndo_set_vf_mac
,
7216 .ndo_set_vf_vlan
= ixgbe_ndo_set_vf_vlan
,
7217 .ndo_set_vf_tx_rate
= ixgbe_ndo_set_vf_bw
,
7218 .ndo_get_vf_config
= ixgbe_ndo_get_vf_config
,
7219 .ndo_get_stats64
= ixgbe_get_stats64
,
7220 .ndo_setup_tc
= ixgbe_setup_tc
,
7221 #ifdef CONFIG_NET_POLL_CONTROLLER
7222 .ndo_poll_controller
= ixgbe_netpoll
,
7225 .ndo_fcoe_ddp_setup
= ixgbe_fcoe_ddp_get
,
7226 .ndo_fcoe_ddp_target
= ixgbe_fcoe_ddp_target
,
7227 .ndo_fcoe_ddp_done
= ixgbe_fcoe_ddp_put
,
7228 .ndo_fcoe_enable
= ixgbe_fcoe_enable
,
7229 .ndo_fcoe_disable
= ixgbe_fcoe_disable
,
7230 .ndo_fcoe_get_wwn
= ixgbe_fcoe_get_wwn
,
7231 #endif /* IXGBE_FCOE */
7232 .ndo_set_features
= ixgbe_set_features
,
7233 .ndo_fix_features
= ixgbe_fix_features
,
7236 static void __devinit
ixgbe_probe_vf(struct ixgbe_adapter
*adapter
,
7237 const struct ixgbe_info
*ii
)
7239 #ifdef CONFIG_PCI_IOV
7240 struct ixgbe_hw
*hw
= &adapter
->hw
;
7242 int num_vf_macvlans
, i
;
7243 struct vf_macvlans
*mv_list
;
7245 if (hw
->mac
.type
== ixgbe_mac_82598EB
|| !max_vfs
)
7248 /* The 82599 supports up to 64 VFs per physical function
7249 * but this implementation limits allocation to 63 so that
7250 * basic networking resources are still available to the
7253 adapter
->num_vfs
= (max_vfs
> 63) ? 63 : max_vfs
;
7254 adapter
->flags
|= IXGBE_FLAG_SRIOV_ENABLED
;
7255 err
= pci_enable_sriov(adapter
->pdev
, adapter
->num_vfs
);
7257 e_err(probe
, "Failed to enable PCI sriov: %d\n", err
);
7261 num_vf_macvlans
= hw
->mac
.num_rar_entries
-
7262 (IXGBE_MAX_PF_MACVLANS
+ 1 + adapter
->num_vfs
);
7264 adapter
->mv_list
= mv_list
= kcalloc(num_vf_macvlans
,
7265 sizeof(struct vf_macvlans
),
7268 /* Initialize list of VF macvlans */
7269 INIT_LIST_HEAD(&adapter
->vf_mvs
.l
);
7270 for (i
= 0; i
< num_vf_macvlans
; i
++) {
7272 mv_list
->free
= true;
7273 mv_list
->rar_entry
= hw
->mac
.num_rar_entries
-
7274 (i
+ adapter
->num_vfs
+ 1);
7275 list_add(&mv_list
->l
, &adapter
->vf_mvs
.l
);
7280 /* If call to enable VFs succeeded then allocate memory
7281 * for per VF control structures.
7284 kcalloc(adapter
->num_vfs
,
7285 sizeof(struct vf_data_storage
), GFP_KERNEL
);
7286 if (adapter
->vfinfo
) {
7287 /* Now that we're sure SR-IOV is enabled
7288 * and memory allocated set up the mailbox parameters
7290 ixgbe_init_mbx_params_pf(hw
);
7291 memcpy(&hw
->mbx
.ops
, ii
->mbx_ops
,
7292 sizeof(hw
->mbx
.ops
));
7294 /* Disable RSC when in SR-IOV mode */
7295 adapter
->flags2
&= ~(IXGBE_FLAG2_RSC_CAPABLE
|
7296 IXGBE_FLAG2_RSC_ENABLED
);
7301 e_err(probe
, "Unable to allocate memory for VF Data Storage - "
7302 "SRIOV disabled\n");
7303 pci_disable_sriov(adapter
->pdev
);
7306 adapter
->flags
&= ~IXGBE_FLAG_SRIOV_ENABLED
;
7307 adapter
->num_vfs
= 0;
7308 #endif /* CONFIG_PCI_IOV */
7312 * ixgbe_probe - Device Initialization Routine
7313 * @pdev: PCI device information struct
7314 * @ent: entry in ixgbe_pci_tbl
7316 * Returns 0 on success, negative on failure
7318 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7319 * The OS initialization, configuring of the adapter private structure,
7320 * and a hardware reset occur.
7322 static int __devinit
ixgbe_probe(struct pci_dev
*pdev
,
7323 const struct pci_device_id
*ent
)
7325 struct net_device
*netdev
;
7326 struct ixgbe_adapter
*adapter
= NULL
;
7327 struct ixgbe_hw
*hw
;
7328 const struct ixgbe_info
*ii
= ixgbe_info_tbl
[ent
->driver_data
];
7329 static int cards_found
;
7330 int i
, err
, pci_using_dac
;
7331 u8 part_str
[IXGBE_PBANUM_LENGTH
];
7332 unsigned int indices
= num_possible_cpus();
7338 /* Catch broken hardware that put the wrong VF device ID in
7339 * the PCIe SR-IOV capability.
7341 if (pdev
->is_virtfn
) {
7342 WARN(1, KERN_ERR
"%s (%hx:%hx) should not be a VF!\n",
7343 pci_name(pdev
), pdev
->vendor
, pdev
->device
);
7347 err
= pci_enable_device_mem(pdev
);
7351 if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64)) &&
7352 !dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
7355 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
7357 err
= dma_set_coherent_mask(&pdev
->dev
,
7361 "No usable DMA configuration, aborting\n");
7368 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
7369 IORESOURCE_MEM
), ixgbe_driver_name
);
7372 "pci_request_selected_regions failed 0x%x\n", err
);
7376 pci_enable_pcie_error_reporting(pdev
);
7378 pci_set_master(pdev
);
7379 pci_save_state(pdev
);
7381 #ifdef CONFIG_IXGBE_DCB
7382 indices
*= MAX_TRAFFIC_CLASS
;
7385 if (ii
->mac
== ixgbe_mac_82598EB
)
7386 indices
= min_t(unsigned int, indices
, IXGBE_MAX_RSS_INDICES
);
7388 indices
= min_t(unsigned int, indices
, IXGBE_MAX_FDIR_INDICES
);
7391 indices
+= min_t(unsigned int, num_possible_cpus(),
7392 IXGBE_MAX_FCOE_INDICES
);
7394 netdev
= alloc_etherdev_mq(sizeof(struct ixgbe_adapter
), indices
);
7397 goto err_alloc_etherdev
;
7400 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
7402 adapter
= netdev_priv(netdev
);
7403 pci_set_drvdata(pdev
, adapter
);
7405 adapter
->netdev
= netdev
;
7406 adapter
->pdev
= pdev
;
7409 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
7411 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
7412 pci_resource_len(pdev
, 0));
7418 for (i
= 1; i
<= 5; i
++) {
7419 if (pci_resource_len(pdev
, i
) == 0)
7423 netdev
->netdev_ops
= &ixgbe_netdev_ops
;
7424 ixgbe_set_ethtool_ops(netdev
);
7425 netdev
->watchdog_timeo
= 5 * HZ
;
7426 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
7428 adapter
->bd_number
= cards_found
;
7431 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
7432 hw
->mac
.type
= ii
->mac
;
7435 memcpy(&hw
->eeprom
.ops
, ii
->eeprom_ops
, sizeof(hw
->eeprom
.ops
));
7436 eec
= IXGBE_READ_REG(hw
, IXGBE_EEC
);
7437 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7438 if (!(eec
& (1 << 8)))
7439 hw
->eeprom
.ops
.read
= &ixgbe_read_eeprom_bit_bang_generic
;
7442 memcpy(&hw
->phy
.ops
, ii
->phy_ops
, sizeof(hw
->phy
.ops
));
7443 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
7444 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7445 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
7446 hw
->phy
.mdio
.mmds
= 0;
7447 hw
->phy
.mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
7448 hw
->phy
.mdio
.dev
= netdev
;
7449 hw
->phy
.mdio
.mdio_read
= ixgbe_mdio_read
;
7450 hw
->phy
.mdio
.mdio_write
= ixgbe_mdio_write
;
7452 ii
->get_invariants(hw
);
7454 /* setup the private structure */
7455 err
= ixgbe_sw_init(adapter
);
7459 /* Make it possible the adapter to be woken up via WOL */
7460 switch (adapter
->hw
.mac
.type
) {
7461 case ixgbe_mac_82599EB
:
7462 case ixgbe_mac_X540
:
7463 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
7470 * If there is a fan on this device and it has failed log the
7473 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
7474 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
7475 if (esdp
& IXGBE_ESDP_SDP1
)
7476 e_crit(probe
, "Fan has stopped, replace the adapter\n");
7479 /* reset_hw fills in the perm_addr as well */
7480 hw
->phy
.reset_if_overtemp
= true;
7481 err
= hw
->mac
.ops
.reset_hw(hw
);
7482 hw
->phy
.reset_if_overtemp
= false;
7483 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
&&
7484 hw
->mac
.type
== ixgbe_mac_82598EB
) {
7486 } else if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
7487 e_dev_err("failed to load because an unsupported SFP+ "
7488 "module type was detected.\n");
7489 e_dev_err("Reload the driver after installing a supported "
7493 e_dev_err("HW Init failed: %d\n", err
);
7497 ixgbe_probe_vf(adapter
, ii
);
7499 netdev
->features
= NETIF_F_SG
|
7502 NETIF_F_HW_VLAN_TX
|
7503 NETIF_F_HW_VLAN_RX
|
7504 NETIF_F_HW_VLAN_FILTER
|
7511 netdev
->hw_features
= netdev
->features
;
7513 switch (adapter
->hw
.mac
.type
) {
7514 case ixgbe_mac_82599EB
:
7515 case ixgbe_mac_X540
:
7516 netdev
->features
|= NETIF_F_SCTP_CSUM
;
7517 netdev
->hw_features
|= NETIF_F_SCTP_CSUM
|
7524 netdev
->vlan_features
|= NETIF_F_TSO
;
7525 netdev
->vlan_features
|= NETIF_F_TSO6
;
7526 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
7527 netdev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
7528 netdev
->vlan_features
|= NETIF_F_SG
;
7530 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
7531 adapter
->flags
&= ~(IXGBE_FLAG_RSS_ENABLED
|
7532 IXGBE_FLAG_DCB_ENABLED
);
7534 #ifdef CONFIG_IXGBE_DCB
7535 netdev
->dcbnl_ops
= &dcbnl_ops
;
7539 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
7540 if (hw
->mac
.ops
.get_device_caps
) {
7541 hw
->mac
.ops
.get_device_caps(hw
, &device_caps
);
7542 if (device_caps
& IXGBE_DEVICE_CAPS_FCOE_OFFLOADS
)
7543 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
7546 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
7547 netdev
->vlan_features
|= NETIF_F_FCOE_CRC
;
7548 netdev
->vlan_features
|= NETIF_F_FSO
;
7549 netdev
->vlan_features
|= NETIF_F_FCOE_MTU
;
7551 #endif /* IXGBE_FCOE */
7552 if (pci_using_dac
) {
7553 netdev
->features
|= NETIF_F_HIGHDMA
;
7554 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
7557 if (adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
)
7558 netdev
->hw_features
|= NETIF_F_LRO
;
7559 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
7560 netdev
->features
|= NETIF_F_LRO
;
7562 /* make sure the EEPROM is good */
7563 if (hw
->eeprom
.ops
.validate_checksum(hw
, NULL
) < 0) {
7564 e_dev_err("The EEPROM Checksum Is Not Valid\n");
7569 memcpy(netdev
->dev_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
7570 memcpy(netdev
->perm_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
7572 if (ixgbe_validate_mac_addr(netdev
->perm_addr
)) {
7573 e_dev_err("invalid MAC address\n");
7578 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7579 if (hw
->mac
.ops
.disable_tx_laser
&&
7580 ((hw
->phy
.multispeed_fiber
) ||
7581 ((hw
->mac
.ops
.get_media_type(hw
) == ixgbe_media_type_fiber
) &&
7582 (hw
->mac
.type
== ixgbe_mac_82599EB
))))
7583 hw
->mac
.ops
.disable_tx_laser(hw
);
7585 setup_timer(&adapter
->service_timer
, &ixgbe_service_timer
,
7586 (unsigned long) adapter
);
7588 INIT_WORK(&adapter
->service_task
, ixgbe_service_task
);
7589 clear_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
);
7591 err
= ixgbe_init_interrupt_scheme(adapter
);
7595 if (!(adapter
->flags
& IXGBE_FLAG_RSS_ENABLED
)) {
7596 netdev
->hw_features
&= ~NETIF_F_RXHASH
;
7597 netdev
->features
&= ~NETIF_F_RXHASH
;
7600 switch (pdev
->device
) {
7601 case IXGBE_DEV_ID_82599_SFP
:
7602 /* Only this subdevice supports WOL */
7603 if (pdev
->subsystem_device
== IXGBE_SUBDEV_ID_82599_SFP
)
7604 adapter
->wol
= IXGBE_WUFC_MAG
;
7606 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE
:
7607 /* All except this subdevice support WOL */
7608 if (pdev
->subsystem_device
!= IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ
)
7609 adapter
->wol
= IXGBE_WUFC_MAG
;
7611 case IXGBE_DEV_ID_82599_KX4
:
7612 adapter
->wol
= IXGBE_WUFC_MAG
;
7618 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
7620 /* pick up the PCI bus settings for reporting later */
7621 hw
->mac
.ops
.get_bus_info(hw
);
7623 /* print bus type/speed/width info */
7624 e_dev_info("(PCI Express:%s:%s) %pM\n",
7625 (hw
->bus
.speed
== ixgbe_bus_speed_5000
? "5.0GT/s" :
7626 hw
->bus
.speed
== ixgbe_bus_speed_2500
? "2.5GT/s" :
7628 (hw
->bus
.width
== ixgbe_bus_width_pcie_x8
? "Width x8" :
7629 hw
->bus
.width
== ixgbe_bus_width_pcie_x4
? "Width x4" :
7630 hw
->bus
.width
== ixgbe_bus_width_pcie_x1
? "Width x1" :
7634 err
= ixgbe_read_pba_string_generic(hw
, part_str
, IXGBE_PBANUM_LENGTH
);
7636 strncpy(part_str
, "Unknown", IXGBE_PBANUM_LENGTH
);
7637 if (ixgbe_is_sfp(hw
) && hw
->phy
.sfp_type
!= ixgbe_sfp_type_not_present
)
7638 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
7639 hw
->mac
.type
, hw
->phy
.type
, hw
->phy
.sfp_type
,
7642 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7643 hw
->mac
.type
, hw
->phy
.type
, part_str
);
7645 if (hw
->bus
.width
<= ixgbe_bus_width_pcie_x4
) {
7646 e_dev_warn("PCI-Express bandwidth available for this card is "
7647 "not sufficient for optimal performance.\n");
7648 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7652 /* save off EEPROM version number */
7653 hw
->eeprom
.ops
.read(hw
, 0x29, &adapter
->eeprom_version
);
7655 /* reset the hardware with the new settings */
7656 err
= hw
->mac
.ops
.start_hw(hw
);
7658 if (err
== IXGBE_ERR_EEPROM_VERSION
) {
7659 /* We are running on a pre-production device, log a warning */
7660 e_dev_warn("This device is a pre-production adapter/LOM. "
7661 "Please be aware there may be issues associated "
7662 "with your hardware. If you are experiencing "
7663 "problems please contact your Intel or hardware "
7664 "representative who provided you with this "
7667 strcpy(netdev
->name
, "eth%d");
7668 err
= register_netdev(netdev
);
7672 /* carrier off reporting is important to ethtool even BEFORE open */
7673 netif_carrier_off(netdev
);
7675 #ifdef CONFIG_IXGBE_DCA
7676 if (dca_add_requester(&pdev
->dev
) == 0) {
7677 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
7678 ixgbe_setup_dca(adapter
);
7681 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
7682 e_info(probe
, "IOV is enabled with %d VFs\n", adapter
->num_vfs
);
7683 for (i
= 0; i
< adapter
->num_vfs
; i
++)
7684 ixgbe_vf_configuration(pdev
, (i
| 0x10000000));
7687 /* Inform firmware of driver version */
7688 if (hw
->mac
.ops
.set_fw_drv_ver
)
7689 hw
->mac
.ops
.set_fw_drv_ver(hw
, MAJ
, MIN
, BUILD
,
7692 /* add san mac addr to netdev */
7693 ixgbe_add_sanmac_netdev(netdev
);
7695 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
7700 ixgbe_release_hw_control(adapter
);
7701 ixgbe_clear_interrupt_scheme(adapter
);
7704 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
7705 ixgbe_disable_sriov(adapter
);
7706 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
7707 iounmap(hw
->hw_addr
);
7709 free_netdev(netdev
);
7711 pci_release_selected_regions(pdev
,
7712 pci_select_bars(pdev
, IORESOURCE_MEM
));
7715 pci_disable_device(pdev
);
7720 * ixgbe_remove - Device Removal Routine
7721 * @pdev: PCI device information struct
7723 * ixgbe_remove is called by the PCI subsystem to alert the driver
7724 * that it should release a PCI device. The could be caused by a
7725 * Hot-Plug event, or because the driver is going to be removed from
7728 static void __devexit
ixgbe_remove(struct pci_dev
*pdev
)
7730 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
7731 struct net_device
*netdev
= adapter
->netdev
;
7733 set_bit(__IXGBE_DOWN
, &adapter
->state
);
7734 cancel_work_sync(&adapter
->service_task
);
7736 #ifdef CONFIG_IXGBE_DCA
7737 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
7738 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
7739 dca_remove_requester(&pdev
->dev
);
7740 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
, 1);
7745 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
7746 ixgbe_cleanup_fcoe(adapter
);
7748 #endif /* IXGBE_FCOE */
7750 /* remove the added san mac */
7751 ixgbe_del_sanmac_netdev(netdev
);
7753 if (netdev
->reg_state
== NETREG_REGISTERED
)
7754 unregister_netdev(netdev
);
7756 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
7757 ixgbe_disable_sriov(adapter
);
7759 ixgbe_clear_interrupt_scheme(adapter
);
7761 ixgbe_release_hw_control(adapter
);
7763 iounmap(adapter
->hw
.hw_addr
);
7764 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
7767 e_dev_info("complete\n");
7769 free_netdev(netdev
);
7771 pci_disable_pcie_error_reporting(pdev
);
7773 pci_disable_device(pdev
);
7777 * ixgbe_io_error_detected - called when PCI error is detected
7778 * @pdev: Pointer to PCI device
7779 * @state: The current pci connection state
7781 * This function is called after a PCI bus error affecting
7782 * this device has been detected.
7784 static pci_ers_result_t
ixgbe_io_error_detected(struct pci_dev
*pdev
,
7785 pci_channel_state_t state
)
7787 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
7788 struct net_device
*netdev
= adapter
->netdev
;
7790 netif_device_detach(netdev
);
7792 if (state
== pci_channel_io_perm_failure
)
7793 return PCI_ERS_RESULT_DISCONNECT
;
7795 if (netif_running(netdev
))
7796 ixgbe_down(adapter
);
7797 pci_disable_device(pdev
);
7799 /* Request a slot reset. */
7800 return PCI_ERS_RESULT_NEED_RESET
;
7804 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7805 * @pdev: Pointer to PCI device
7807 * Restart the card from scratch, as if from a cold-boot.
7809 static pci_ers_result_t
ixgbe_io_slot_reset(struct pci_dev
*pdev
)
7811 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
7812 pci_ers_result_t result
;
7815 if (pci_enable_device_mem(pdev
)) {
7816 e_err(probe
, "Cannot re-enable PCI device after reset.\n");
7817 result
= PCI_ERS_RESULT_DISCONNECT
;
7819 pci_set_master(pdev
);
7820 pci_restore_state(pdev
);
7821 pci_save_state(pdev
);
7823 pci_wake_from_d3(pdev
, false);
7825 ixgbe_reset(adapter
);
7826 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
7827 result
= PCI_ERS_RESULT_RECOVERED
;
7830 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
7832 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7833 "failed 0x%0x\n", err
);
7834 /* non-fatal, continue */
7841 * ixgbe_io_resume - called when traffic can start flowing again.
7842 * @pdev: Pointer to PCI device
7844 * This callback is called when the error recovery driver tells us that
7845 * its OK to resume normal operation.
7847 static void ixgbe_io_resume(struct pci_dev
*pdev
)
7849 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
7850 struct net_device
*netdev
= adapter
->netdev
;
7852 if (netif_running(netdev
)) {
7853 if (ixgbe_up(adapter
)) {
7854 e_info(probe
, "ixgbe_up failed after reset\n");
7859 netif_device_attach(netdev
);
7862 static struct pci_error_handlers ixgbe_err_handler
= {
7863 .error_detected
= ixgbe_io_error_detected
,
7864 .slot_reset
= ixgbe_io_slot_reset
,
7865 .resume
= ixgbe_io_resume
,
7868 static struct pci_driver ixgbe_driver
= {
7869 .name
= ixgbe_driver_name
,
7870 .id_table
= ixgbe_pci_tbl
,
7871 .probe
= ixgbe_probe
,
7872 .remove
= __devexit_p(ixgbe_remove
),
7874 .suspend
= ixgbe_suspend
,
7875 .resume
= ixgbe_resume
,
7877 .shutdown
= ixgbe_shutdown
,
7878 .err_handler
= &ixgbe_err_handler
7882 * ixgbe_init_module - Driver Registration Routine
7884 * ixgbe_init_module is the first routine called when the driver is
7885 * loaded. All it does is register with the PCI subsystem.
7887 static int __init
ixgbe_init_module(void)
7890 pr_info("%s - version %s\n", ixgbe_driver_string
, ixgbe_driver_version
);
7891 pr_info("%s\n", ixgbe_copyright
);
7893 #ifdef CONFIG_IXGBE_DCA
7894 dca_register_notify(&dca_notifier
);
7897 ret
= pci_register_driver(&ixgbe_driver
);
7901 module_init(ixgbe_init_module
);
7904 * ixgbe_exit_module - Driver Exit Cleanup Routine
7906 * ixgbe_exit_module is called just before the driver is removed
7909 static void __exit
ixgbe_exit_module(void)
7911 #ifdef CONFIG_IXGBE_DCA
7912 dca_unregister_notify(&dca_notifier
);
7914 pci_unregister_driver(&ixgbe_driver
);
7915 rcu_barrier(); /* Wait for completion of call_rcu()'s */
7918 #ifdef CONFIG_IXGBE_DCA
7919 static int ixgbe_notify_dca(struct notifier_block
*nb
, unsigned long event
,
7924 ret_val
= driver_for_each_device(&ixgbe_driver
.driver
, NULL
, &event
,
7925 __ixgbe_notify_dca
);
7927 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
7930 #endif /* CONFIG_IXGBE_DCA */
7932 module_exit(ixgbe_exit_module
);